Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 🎸 get export env KUBECONFIG #855

Merged
merged 4 commits into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
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
11 changes: 9 additions & 2 deletions .github/workflows/e2e-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -93,5 +93,12 @@ jobs:
echo "********************************************************************************"
echo "Running kubecm global flag --config..."
echo "********************************************************************************"
bin/kubecm s kind-3rd-kind --config merge.config
bin/kubecm list --config merge.config
bin/kubecm s kind-2nd-kind --config merge.config
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
8 changes: 6 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
3 changes: 2 additions & 1 deletion cmd/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Loading