Skip to content

Commit 96c4914

Browse files
Make current version compile on iOS (#48)
* add guards so that the client is usable on iOS * fixed exception for iOS --------- Co-authored-by: Tobias Bachmor <tobias.bachmor@letsdev.de>
1 parent 7fb2b50 commit 96c4914

4 files changed

Lines changed: 21 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Changelog
22

3+
## [Unreleased]
4+
- Add guards so that the client is usable on iOS
5+
36
## 0.25.0
47

58
- Refactor configuration builders and add support for overriding the current k8s context (#47 by nefilim)

Sources/SwiftkubeClient/Client/KubernetesClient.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ public actor KubernetesClient {
104104
}()
105105
#endif
106106

107+
#if os(Linux) || os(macOS)
107108
/// Create a new instance of the Kubernetes client.
108109
///
109110
/// The client tries to resolve a `kube config` automatically from different sources in the following order:
@@ -114,6 +115,9 @@ public actor KubernetesClient {
114115
///
115116
/// Returns `nil` if a configuration can't be found.
116117
///
118+
/// - Note: This initializer is only available on Linux and macOS. On iOS, tvOS, and watchOS, you must use
119+
/// `init(config:provider:logger:)` with a manually configured `KubernetesClientConfig`.
120+
///
117121
/// - Parameters:
118122
/// - provider: A ``EventLoopGroupProvider`` to specify how ``EventLoopGroup`` will be created.
119123
/// - logger: The logger to use for this client.
@@ -129,6 +133,7 @@ public actor KubernetesClient {
129133

130134
self.init(config: config, provider: provider, logger: logger)
131135
}
136+
#endif
132137

133138
/// Create a new instance of the Kubernetes client.
134139
///

Sources/SwiftkubeClient/Config/KubeConfig+Loaders.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public extension KubeConfig {
3131
return try from(config: contents)
3232
}
3333

34+
#if os(Linux) || os(macOS)
3435
static func fromEnvironment(envVar: String = "KUBECONFIG", logger: Logger? = nil) throws -> KubeConfig? {
3536
guard let varContent = ProcessInfo.processInfo.environment[envVar] else {
3637
logger?.info("Skipping kubeconfig because environment variable \(envVar) is not set")
@@ -43,7 +44,9 @@ public extension KubeConfig {
4344

4445
return try from(url: kubeConfigURL)
4546
}
47+
#endif
4648

49+
#if os(Linux) || os(macOS)
4750
static func fromDefaultLocalConfig(logger: Logger? = nil) throws -> KubeConfig? {
4851
guard let homePath = ProcessInfo.processInfo.environment["HOME"] else {
4952
logger?.info("Skipping kubeconfig in $HOME/.kube/config because HOME env variable is not set.")
@@ -55,7 +58,9 @@ public extension KubeConfig {
5558

5659
return try from(url: kubeConfigURL)
5760
}
61+
#endif
5862

63+
#if os(Linux) || os(macOS)
5964
static func fromServiceAccount(logger: Logger? = nil) throws -> KubeConfig? {
6065
guard
6166
let host = ProcessInfo.processInfo.environment["KUBERNETES_SERVICE_HOST"],
@@ -120,8 +125,10 @@ public extension KubeConfig {
120125
currentContext: "service-account-context"
121126
)
122127
}
128+
#endif
123129
}
124130

131+
#if os(Linux) || os(macOS)
125132
internal extension String {
126133

127134
func stringByExpandingTildePath() -> String {
@@ -143,3 +150,4 @@ internal extension String {
143150
return FileManager.default.homeDirectoryForCurrentUser.path + "/" + relativePath
144151
}
145152
}
153+
#endif

Sources/SwiftkubeClient/Config/KubernetesClientConfig+Init.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import Yams
2222

2323
public extension KubernetesClientConfig {
2424

25+
#if os(Linux) || os(macOS)
2526
/// Initializes a client configuration.
2627
///
2728
/// This factory method tries to resolve a `kube config` automatically from different sources in the following order:
@@ -32,6 +33,9 @@ public extension KubernetesClientConfig {
3233
///
3334
/// It is also possible to override the default values for the underlying `HTTPClient` timeout and redirect config.
3435
///
36+
/// - Note: This method is only available on Linux and macOS. On iOS, tvOS, and watchOS, you must manually configure
37+
/// the client using `KubernetesClientConfig.init()` or `from(kubeConfig:)`.
38+
///
3539
/// - Parameters:
3640
/// - timeout: The desired timeout configuration to apply. If not provided, then `connect` timeout will default to 10 seconds.
3741
/// - 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 {
6670
logger: logger
6771
)
6872
}
73+
#endif
6974

7075
/// Initializes a client configuration from a given KubeConfig using the specified `current-context`.
7176
///

0 commit comments

Comments
 (0)