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

Unset the current-context after minikube stop #4177

Merged
merged 9 commits into from
May 15, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 8 additions & 0 deletions cmd/minikube/cmd/stop.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import (
"k8s.io/minikube/pkg/minikube/exit"
"k8s.io/minikube/pkg/minikube/machine"
pkgutil "k8s.io/minikube/pkg/util"
"k8s.io/minikube/pkg/minikube/constants"

)

// stopCmd represents the stop command
Expand Down Expand Up @@ -69,6 +71,12 @@ itself, leaving all files intact. The cluster can be started again with the "sta
if err := cmdUtil.KillMountProcess(); err != nil {
exit.WithError("Unable to kill mount process", err)
}

machineName := pkg_config.GetMachineName()
err = pkgutil.UnsetCurrentContext( constants.KubeconfigPath, machineName)
if err != nil {
exit.WithError("update config", err)
}
},
}

Expand Down
14 changes: 14 additions & 0 deletions pkg/util/kubeconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ func PopulateKubeConfig(cfg *KubeConfigSetup, kubecfg *api.Config) error {
// Only set current context to minikube if the user has not used the keepContext flag
if !cfg.KeepContext {
kubecfg.CurrentContext = cfg.ClusterName
//kubecfg.CurrentContext = ""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

}

return nil
Expand Down Expand Up @@ -312,3 +313,16 @@ func GetPortFromKubeConfig(filename, machineName string) (int, error) {
port, err := strconv.Atoi(kport)
return port, err
}

//UnsetCurrentContext unsets the current-context from minikube to "" on minikube stop
func UnsetCurrentContext(filename, machineName string) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please run gofmt -s -w on this file to reformat it to Go standards. Consider configuring your code editor to do this on save.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

formatted this one.

confg, err := ReadConfigOrNew(filename)
if err != nil {
return errors.Wrap(err, "Error getting kubeconfig status")
}
confg.CurrentContext = ""
if err := WriteConfig(confg,filename); err != nil {
return errors.Wrap(err, "writing kubeconfig")
}
return nil
}