Skip to content

Commit

Permalink
🐻‍❄️ update config bootstrap
Browse files Browse the repository at this point in the history
  • Loading branch information
zcubbs committed Oct 1, 2023
1 parent 086a67d commit e68f587
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions cmd/awx/kubeconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ import (
)

func getKubeConfig(path string, debug bool) (string, error) {

const (
found = "kubeconfig found in default location %s\n"
notFound = "kubeconfig not found in default location %s\n"
rancherKubeconfig = "/etc/rancher/k3s/k3s.yaml"
)
if path != "" {
return path, nil
}
Expand All @@ -19,32 +25,31 @@ func getKubeConfig(path string, debug bool) (string, error) {
fi, err := os.Stat(kc)
os.IsNotExist(err)
if err != nil && debug {
fmt.Printf("kubeconfig not found in default location %s\n", kc)
fmt.Printf(notFound, kc)
}

if fi != nil {
fmt.Printf("kubeconfig found in default location %s\n", kc)
fmt.Printf(found, kc)
return kc, nil
}

kc = "/etc/rancher/k3s/k3s.yaml"
fi, err = os.Stat(kc)
fi, err = os.Stat(rancherKubeconfig)
os.IsNotExist(err)
if err != nil && debug {
fmt.Printf("kubeconfig not found in default location %s\n", kc)
fmt.Printf(notFound, rancherKubeconfig)
}

if fi != nil {
fmt.Printf("kubeconfig found in default location %s\n", kc)
fmt.Printf(found, rancherKubeconfig)
return kc, nil
}

kc = os.Getenv("KUBECONFIG")
if kc == "" {
return "", fmt.Errorf("kubeconfig not found")
return "", fmt.Errorf("KUBECONFIG variable not set, and no kubeconfig found in default locations")
}

fmt.Printf("kubeconfig found in default location %s\n", kc)
fmt.Printf(found, kc)
return kc, nil
}

Expand Down

0 comments on commit e68f587

Please sign in to comment.