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

Fix order of parameters to CurrentContext funcs #5439

Merged
merged 1 commit into from
Sep 27, 2019
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
2 changes: 1 addition & 1 deletion cmd/minikube/cmd/config/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ var ProfileCmd = &cobra.Command{
out.SuccessT("Skipped switching kubectl context for {{.profile_name}} because --keep-context was set.", out.V{"profile_name": profile})
out.SuccessT("To connect to this cluster, use: kubectl --context={{.profile_name}}", out.V{"profile_name": profile})
} else {
err := kubeconfig.SetCurrentContext(constants.KubeconfigPath, profile)
err := kubeconfig.SetCurrentContext(profile, constants.KubeconfigPath)
if err != nil {
out.ErrT(out.Sad, `Error while setting kubectl current context : {{.error}}`, out.V{"error": err})
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/minikube/cmd/stop.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func runStop(cmd *cobra.Command, args []string) {
}

machineName := pkg_config.GetMachineName()
err = kubeconfig.UnsetCurrentContext(constants.KubeconfigPath, machineName)
err = kubeconfig.UnsetCurrentContext(machineName, constants.KubeconfigPath)
Copy link
Contributor

@tstromberg tstromberg Sep 23, 2019

Choose a reason for hiding this comment

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

This PR caused me to LOL because of how easy it was, but sad because of how difficult to detect it was.

There is a second hidden bug here: constants.KubeconfigPath does not respect the KUBECONFIG environment variable. If the filename isn't provided, we do the right thing. Here is my suggested change to reduce the number of paths to sadness in our code base:

  • Change *SetCurrentContext to either take a second argument, or not take a second argument. Having to support two behaviors in one function is a recipe for future mistakes.
  • If you prefer the 1-argument version, update context_test.go to set the temp path via an alternative mechanism, such as KUBECONFIG
  • If you prefer the 2-argument version, update these the kubeconfig.*Context() calls to pass kubeconfig.PathFromEnv().

if err != nil {
exit.WithError("update config", err)
}
Expand Down