Skip to content

Commit

Permalink
Merge pull request #14 from hiro-o918/main
Browse files Browse the repository at this point in the history
feat: consider `KUBECONFIG` environment as a default kubeconfig
  • Loading branch information
kitagry authored Jul 16, 2024
2 parents b7628b9 + fdafc79 commit 6806e02
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,17 @@ func main() {

func run() int {
var kubeconfig *string
if home := homedir.HomeDir(); home != "" {
kubeconfig = flag.String("kubeconfig", filepath.Join(home, ".kube", "config"), "(optional) absolute path to the kubeconfig file")
// default kubeconfig path is loaded in the following priority:
// 1. load environment variable KUBECONFIG exists
// 2. load $HOME/.kube/config
var defaultKubeConfig string
if env := os.Getenv("KUBECONFIG"); env != "" {
defaultKubeConfig = env
} else if home := homedir.HomeDir(); home != "" {
defaultKubeConfig = filepath.Join(home, ".kube", "config")
}
if defaultKubeConfig != "" {
kubeconfig = flag.String("kubeconfig", defaultKubeConfig, "(optional) absolute path to the kubeconfig file")
} else {
kubeconfig = flag.String("kubeconfig", "", "absolute path to the kubeconfig file")
}
Expand Down

0 comments on commit 6806e02

Please sign in to comment.