From 81f5db890a86038df058c71e07de49f0533b61f6 Mon Sep 17 00:00:00 2001 From: Xudong Guo Date: Mon, 15 Jan 2024 10:48:29 +0800 Subject: [PATCH 1/4] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20get=20export=20env?= =?UTF-8?q?=20KUBECONFIG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/e2e-test.yaml | 5 +++++ cmd/root.go | 8 ++++++-- cmd/utils.go | 3 ++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/.github/workflows/e2e-test.yaml b/.github/workflows/e2e-test.yaml index 6b97ed8b..ab547551 100644 --- a/.github/workflows/e2e-test.yaml +++ b/.github/workflows/e2e-test.yaml @@ -95,3 +95,8 @@ jobs: echo "********************************************************************************" bin/kubecm s kind-3rd-kind --config merge.config bin/kubecm list --config merge.config + echo "********************************************************************************" + echo "Running kubecm list from env KUBECONFIG..." + echo "********************************************************************************" + export KUBECONFIG="$PWD/merge.config" + bin/kubecm list diff --git a/cmd/root.go b/cmd/root.go index 6a3e4b0d..49d2d5f1 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -61,9 +61,13 @@ func NewCli() *Cli { } func (cli *Cli) setFlags() { - kubeconfig := flag.String("kubeconfig", filepath.Join(homeDir(), ".kube", "config"), "(optional) absolute path to the kubeconfig file") + // get env KUBECONFIG + kubeconfig := os.Getenv("KUBECONFIG") + if kubeconfig == "" { + kubeconfig = filepath.Join(homeDir(), ".kube", "config") + } flags := cli.rootCmd.PersistentFlags() - flags.StringVar(&cfgFile, "config", *kubeconfig, "path of kubeconfig") + flags.StringVar(&cfgFile, "config", kubeconfig, "path of kubeconfig") flags.IntVarP(&uiSize, "ui-size", "u", 4, "number of list items to show in menu at once") flags.BoolVarP(&silenceTable, "silence-table", "s", false, "enable/disable output of context table on successful config update") flags.BoolVarP(&macNotify, "mac-notify", "m", false, "enable to display Mac notification banner") diff --git a/cmd/utils.go b/cmd/utils.go index 9b2e1cea..546a729f 100644 --- a/cmd/utils.go +++ b/cmd/utils.go @@ -447,7 +447,8 @@ func CheckAndTransformFilePath(path string) (string, error) { if strings.HasPrefix(path, "~/") { path = filepath.Join(homeDir(), path[2:]) } - _, err := os.Stat(path) //os.Stat获取文件信息 + // read files info + _, err := os.Stat(path) if err != nil { return "", err } From 6fdc753ab4eb267f76d05e20af9fb5570882f378 Mon Sep 17 00:00:00 2001 From: Xudong Guo Date: Mon, 15 Jan 2024 10:56:01 +0800 Subject: [PATCH 2/4] fix e2e --- .github/workflows/e2e-test.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/e2e-test.yaml b/.github/workflows/e2e-test.yaml index ab547551..4b5ae72c 100644 --- a/.github/workflows/e2e-test.yaml +++ b/.github/workflows/e2e-test.yaml @@ -93,10 +93,10 @@ jobs: echo "********************************************************************************" echo "Running kubecm global flag --config..." echo "********************************************************************************" - bin/kubecm s kind-3rd-kind --config merge.config + bin/kubecm s kind-2nd-kind --config merge.config bin/kubecm list --config merge.config echo "********************************************************************************" echo "Running kubecm list from env KUBECONFIG..." echo "********************************************************************************" - export KUBECONFIG="$PWD/merge.config" + export KUBECONFIG="$PWD/multi.config" bin/kubecm list From e954f73b830fefe17ce34380a3a32e41a7f4dc30 Mon Sep 17 00:00:00 2001 From: Xudong Guo Date: Mon, 15 Jan 2024 11:01:09 +0800 Subject: [PATCH 3/4] fix e2e --- .github/workflows/e2e-test.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/e2e-test.yaml b/.github/workflows/e2e-test.yaml index 4b5ae72c..2cd1cce5 100644 --- a/.github/workflows/e2e-test.yaml +++ b/.github/workflows/e2e-test.yaml @@ -94,9 +94,9 @@ jobs: echo "Running kubecm global flag --config..." echo "********************************************************************************" bin/kubecm s kind-2nd-kind --config merge.config - bin/kubecm list --config merge.config echo "********************************************************************************" echo "Running kubecm list from env KUBECONFIG..." echo "********************************************************************************" export KUBECONFIG="$PWD/multi.config" + bin/kubecm s kind-3rd-kind bin/kubecm list From db8ba482388e8781459a4d020e2c47b92d3265ba Mon Sep 17 00:00:00 2001 From: Xudong Guo Date: Mon, 15 Jan 2024 11:06:58 +0800 Subject: [PATCH 4/4] fix e2e --- .github/workflows/e2e-test.yaml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/e2e-test.yaml b/.github/workflows/e2e-test.yaml index 2cd1cce5..fe645f15 100644 --- a/.github/workflows/e2e-test.yaml +++ b/.github/workflows/e2e-test.yaml @@ -97,6 +97,8 @@ jobs: echo "********************************************************************************" echo "Running kubecm list from env KUBECONFIG..." echo "********************************************************************************" + echo "default config" + bin/kubecm ls + echo "set env" export KUBECONFIG="$PWD/multi.config" bin/kubecm s kind-3rd-kind - bin/kubecm list