Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
5 changes: 5 additions & 0 deletions Sources/SwiftkubeClient/Client/KubernetesClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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.
Expand All @@ -129,6 +133,7 @@ public actor KubernetesClient {

self.init(config: config, provider: provider, logger: logger)
}
#endif

/// Create a new instance of the Kubernetes client.
///
Expand Down
8 changes: 8 additions & 0 deletions Sources/SwiftkubeClient/Config/KubeConfig+Loaders.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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.")
Expand All @@ -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"],
Expand Down Expand Up @@ -120,8 +125,10 @@ public extension KubeConfig {
currentContext: "service-account-context"
)
}
#endif
}

#if os(Linux) || os(macOS)
internal extension String {

func stringByExpandingTildePath() -> String {
Expand All @@ -143,3 +150,4 @@ internal extension String {
return FileManager.default.homeDirectoryForCurrentUser.path + "/" + relativePath
}
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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.
Expand Down Expand Up @@ -66,6 +70,7 @@ public extension KubernetesClientConfig {
logger: logger
)
}
#endif

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