Skip to content

Commit

Permalink
feat: update use
Browse files Browse the repository at this point in the history
  • Loading branch information
joyme123 committed Mar 18, 2024
1 parent eb2b3e8 commit 7d49441
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
6 changes: 3 additions & 3 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ var rootCmd = &cobra.Command{
Long: `kubecm manager multi kube config file`,
// Uncomment the following line if your bare application
// has an action associated with it:
Run: func(cmd *cobra.Command, args []string) {
listCmd.Run(cmd, args)
},
// Run: func(cmd *cobra.Command, args []string) {
// listCmd.Run(cmd, args)
//},
}

// Execute adds all child commands to the root command and sets flags appropriately.
Expand Down
6 changes: 6 additions & 0 deletions pkg/manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ func (i *impl) Use(name string, currentSession bool) error {
item := i.conf.Items[index]
if currentSession {
_ = os.Setenv("KUBECONFIG", item.Location)
_ = os.Setenv("KUBECM_SHELL", "true")
shell := os.Getenv("SHELL")
cmd := exec.Command(shell)
cmd.Stdin = os.Stdin
Expand All @@ -193,6 +194,11 @@ func (i *impl) Use(name string, currentSession bool) error {
return cmd.Run()
}

if os.Getenv("KUBECM_SHELL") == "true" && os.Getenv("KUBECONFIG") != "" {
fmt.Printf("You can't change system kubeconfig after use `kubecm use xxx -c`. \nPlease execute cmd `exit && kubecm use %s` \n", name)
return nil
}

// create symbolic link from config file to kube config file
kubefile, err := os.Lstat(i.kubePath)
if err != nil && !os.IsNotExist(err) {
Expand Down

0 comments on commit 7d49441

Please sign in to comment.