Skip to content
This repository has been archived by the owner on Aug 31, 2022. It is now read-only.

Use KUBECONFIG env variable if present #199

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
12 changes: 8 additions & 4 deletions pkg/kube/client.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package kube

import (
"os"
"path/filepath"

"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
"os"
"path/filepath"
)

// GetKubernetesClient returns the client if its possible in cluster, otherwise tries to read HOME
Expand All @@ -26,6 +27,9 @@ func GetKubernetesConfig() (*rest.Config, error) {
return nil, err
}

// TODO: Read KUBECONFIG env variable as fallback
return clientcmd.BuildConfigFromFlags("", filepath.Join(os.Getenv("HOME"), ".kube", "config"))
kubeConfigPath := os.Getenv("KUBECONFIG")
if kubeConfigPath == "" {
kubeConfigPath = filepath.Join(os.Getenv("HOME"), ".kube", "config")
}
return clientcmd.BuildConfigFromFlags("", kubeConfigPath)
}