From e68f5875b0a4710c0745ffab6dc77ae786f26dcd Mon Sep 17 00:00:00 2001 From: zcubbs Date: Mon, 2 Oct 2023 01:01:46 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=BB=E2=80=8D=E2=9D=84=EF=B8=8F=20updat?= =?UTF-8?q?e=20config=20bootstrap?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/awx/kubeconfig.go | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/cmd/awx/kubeconfig.go b/cmd/awx/kubeconfig.go index e36589e..9e6936a 100644 --- a/cmd/awx/kubeconfig.go +++ b/cmd/awx/kubeconfig.go @@ -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 } @@ -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 }