From ec8990a6f299e063df667668e06d9ebbff750b3f Mon Sep 17 00:00:00 2001 From: Tobias Bachmor Date: Sun, 14 Dec 2025 15:57:15 +0100 Subject: [PATCH 1/2] add guards so that the client is usable on iOS --- CHANGELOG.md | 3 +++ Sources/SwiftkubeClient/Config/KubeConfig+Loaders.swift | 8 ++++++++ .../Config/KubernetesClientConfig+Init.swift | 5 +++++ 3 files changed, 16 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 385f80a..e3535f7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog +## [Unreleased] +- Add guards so that the client is usable on iOS + ## 0.25.0 - Refactor configuration builders and add support for overriding the current k8s context (#47 by nefilim) diff --git a/Sources/SwiftkubeClient/Config/KubeConfig+Loaders.swift b/Sources/SwiftkubeClient/Config/KubeConfig+Loaders.swift index 2ff58c2..27b20f5 100644 --- a/Sources/SwiftkubeClient/Config/KubeConfig+Loaders.swift +++ b/Sources/SwiftkubeClient/Config/KubeConfig+Loaders.swift @@ -31,6 +31,7 @@ public extension KubeConfig { return try from(config: contents) } + #if os(Linux) || os(macOS) static func fromEnvironment(envVar: String = "KUBECONFIG", logger: Logger? = nil) throws -> KubeConfig? { guard let varContent = ProcessInfo.processInfo.environment[envVar] else { logger?.info("Skipping kubeconfig because environment variable \(envVar) is not set") @@ -43,7 +44,9 @@ public extension KubeConfig { return try from(url: kubeConfigURL) } + #endif + #if os(Linux) || os(macOS) static func fromDefaultLocalConfig(logger: Logger? = nil) throws -> KubeConfig? { guard let homePath = ProcessInfo.processInfo.environment["HOME"] else { logger?.info("Skipping kubeconfig in $HOME/.kube/config because HOME env variable is not set.") @@ -55,7 +58,9 @@ public extension KubeConfig { return try from(url: kubeConfigURL) } + #endif + #if os(Linux) || os(macOS) static func fromServiceAccount(logger: Logger? = nil) throws -> KubeConfig? { guard let host = ProcessInfo.processInfo.environment["KUBERNETES_SERVICE_HOST"], @@ -120,8 +125,10 @@ public extension KubeConfig { currentContext: "service-account-context" ) } + #endif } +#if os(Linux) || os(macOS) internal extension String { func stringByExpandingTildePath() -> String { @@ -143,3 +150,4 @@ internal extension String { return FileManager.default.homeDirectoryForCurrentUser.path + "/" + relativePath } } +#endif diff --git a/Sources/SwiftkubeClient/Config/KubernetesClientConfig+Init.swift b/Sources/SwiftkubeClient/Config/KubernetesClientConfig+Init.swift index 29a641c..0028f0c 100644 --- a/Sources/SwiftkubeClient/Config/KubernetesClientConfig+Init.swift +++ b/Sources/SwiftkubeClient/Config/KubernetesClientConfig+Init.swift @@ -22,6 +22,7 @@ import Yams public extension KubernetesClientConfig { + #if os(Linux) || os(macOS) /// Initializes a client configuration. /// /// This factory method tries to resolve a `kube config` automatically from different sources in the following order: @@ -32,6 +33,9 @@ public extension KubernetesClientConfig { /// /// It is also possible to override the default values for the underlying `HTTPClient` timeout and redirect config. /// + /// - Note: This method is only available on Linux and macOS. On iOS, tvOS, and watchOS, you must manually configure + /// the client using `KubernetesClientConfig.init()` or `from(kubeConfig:)`. + /// /// - Parameters: /// - timeout: The desired timeout configuration to apply. If not provided, then `connect` timeout will default to 10 seconds. /// - redirectConfiguration: Specifies redirect processing settings. If not provided, then it will default to a maximum of 5 follows w/o cycles. @@ -66,6 +70,7 @@ public extension KubernetesClientConfig { logger: logger ) } + #endif /// Initializes a client configuration from a given KubeConfig using the specified `current-context`. /// From 37d69eb082315de14ef1e5da990a46d01dece9db Mon Sep 17 00:00:00 2001 From: Tobias Bachmor Date: Sun, 14 Dec 2025 16:24:01 +0100 Subject: [PATCH 2/2] fixed exception for iOS --- Sources/SwiftkubeClient/Client/KubernetesClient.swift | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Sources/SwiftkubeClient/Client/KubernetesClient.swift b/Sources/SwiftkubeClient/Client/KubernetesClient.swift index 9e59bc2..affcf8f 100644 --- a/Sources/SwiftkubeClient/Client/KubernetesClient.swift +++ b/Sources/SwiftkubeClient/Client/KubernetesClient.swift @@ -104,6 +104,7 @@ public actor KubernetesClient { }() #endif + #if os(Linux) || os(macOS) /// Create a new instance of the Kubernetes client. /// /// The client tries to resolve a `kube config` automatically from different sources in the following order: @@ -114,6 +115,9 @@ public actor KubernetesClient { /// /// Returns `nil` if a configuration can't be found. /// + /// - Note: This initializer is only available on Linux and macOS. On iOS, tvOS, and watchOS, you must use + /// `init(config:provider:logger:)` with a manually configured `KubernetesClientConfig`. + /// /// - Parameters: /// - provider: A ``EventLoopGroupProvider`` to specify how ``EventLoopGroup`` will be created. /// - logger: The logger to use for this client. @@ -129,6 +133,7 @@ public actor KubernetesClient { self.init(config: config, provider: provider, logger: logger) } + #endif /// Create a new instance of the Kubernetes client. ///