Skip to content
Merged
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ client.shutdown(queue: queue) { (error: Error?) in

The client tries to resolve a `kube config` automatically from different sources in the following order:

- If set, kube config file at path of environment variable `KUBECONFIG`
- Kube config file in the user's `$HOME/.kube/config` directory
- `ServiceAccount` token located at `/var/run/secrets/kubernetes.io/serviceaccount/token` and a mounted CA certificate,
- if it's running in Kubernetes.
Expand Down
1 change: 1 addition & 0 deletions Sources/SwiftkubeClient/Client/KubernetesClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ public actor KubernetesClient {
///
/// The client tries to resolve a `kube config` automatically from different sources in the following order:
///
/// - A Kube config file at path of environment variable `KUBECONFIG` (if set)
/// - A Kube config file in the user's `$HOME/.kube/config` directory
/// - `ServiceAccount` token located at `/var/run/secrets/kubernetes.io/serviceaccount/token` and a mounted CA certificate, if it's running in Kubernetes.
///
Expand Down
13 changes: 10 additions & 3 deletions Sources/SwiftkubeClient/Config/KubernetesClientConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -286,12 +286,19 @@ internal struct LocalKubeConfigLoader: KubernetesClientConfigLoader {
redirectConfiguration: HTTPClient.Configuration.RedirectConfiguration,
logger: Logger?
) throws -> KubernetesClientConfig? {
guard let homePath = ProcessInfo.processInfo.environment["HOME"] else {
logger?.info("Skipping kubeconfig in $HOME/.kube/config because HOME env variable is not set.")
var kubeConfigURL: URL?

if let kubeConfigPath = ProcessInfo.processInfo.environment["KUBECONFIG"] {
kubeConfigURL = URL(fileURLWithPath: kubeConfigPath)
} else if let homePath = ProcessInfo.processInfo.environment["HOME"] {
kubeConfigURL = URL(fileURLWithPath: homePath + "/.kube/config")
}

guard let kubeConfigURL else {
logger?.info("Skipping local kubeconfig detection, neither environment variable KUBECONFIG nor HOME are set.")
return nil
}

let kubeConfigURL = URL(fileURLWithPath: homePath + "/.kube/config")
return try? URLConfigLoader(url: kubeConfigURL)
.load(timeout: timeout, redirectConfiguration: redirectConfiguration, logger: logger)
}
Expand Down
Loading