-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Conversation
Hi @hpandeycodeit. Thanks for your PR. I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: hpandeycodeit If they are not already assigned, you can assign the PR to them by writing The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Can one of the admins verify this patch? |
@minikube-bot OK to test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great, and will be a really nice improvement for users, particularly those who show their kubectl context in their shells. This PR looks like it does exactly what it should be doing.
To guard against breaking this in the future, do you mind adding a few lines to start_stop_delete_test.go
to verify the behavior? For example, before you call stop, assert that there is a context, and that it goes away after stop. Something like:
`k = util.NewKubeCtlRunner()
got := k.RunCommand("config", "current-context")
if got != "minikube" { fail }
and after stop:
got := k.RunCommand("config", "current-context")
if got != "" { fail }
Thank you again for your contribution!
pkg/util/kubeconfig.go
Outdated
@@ -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 = "" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
pkg/util/kubeconfig.go
Outdated
@@ -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 { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
formatted this one.
@tstromberg I have included the tests. Let me know if it looks okay. Thanks for the pointer :) |
Looks great, but you'll need to do a tiny bit more work to plumb the runner through correctly:
Also, please run
|
@tstromberg Fixed the gofmt errors. Integration tests passed as well. Hopefully it should be fine this time. |
@minikube-bot OK to test |
@minikube-bot OK to test |
Tests are failing:
|
It might help here if the test showed the error in got vs want syntax, such as: got context %q, want context %q |
@tstromberg I have changed it. Not sure why the context is different. Not getting this error in my local though. |
@tstromberg thanks for approving the changes! Above failing tests still showing a failure in current-context mismatch.
not sure from where it's getting "minikube\n" Any Idea? |
You may want to call strings.TrimRight() before comparing the value. |
Looks like it's getting better, but something is still not quite right:
Does running |
@tstromberg I am able to test this in my local and it's failing as well. So the issue here is, if I put this code right below the stop, since the minikube takes time to stop and the code still retrieves current-context as "minikube":
However if I put this code after the code that checks stopped status, minikube is stopped then but there is no context and then it throws error something like this util.go:295: Temporary Error: error running command [config current-context]: exit status 1. Stdout: So looks like I can't really compare the current-context with an empty string here "" |
@tstromberg let me know if this looks okay to you or any other change is needed to the test. |
Looks good. Thank you! |
Thank you @tstromberg! |
This PR implements Feature Request #4154