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

Delete context when stopped #9414

Merged
merged 3 commits into from
Oct 8, 2020

Conversation

prezha
Copy link
Contributor

@prezha prezha commented Oct 7, 2020

fixes: #9410

as stated in the original issue: if keep-context-active is not set to true, the context for the stopped cluster should be deleted (instead of just unset as the current context) to avoid confusion

example:

❯ kubectl config get-contexts
CURRENT   NAME                          CLUSTER                    AUTHINFO                                                       NAMESPACE
          minikube                      minikube                   minikube
*         p2                            p2                         p2
          p3                            p3                         p3
❯ minikube stop -p p2
✋  Stopping node "p2"  ...
🛑  Powering off "p2" via SSH ...
🛑  1 nodes stopped.

current behaviour:

❯ kubectl config get-contexts
CURRENT   NAME                          CLUSTER                    AUTHINFO                                                       NAMESPACE
          minikube                      minikube                   minikube
          p2                            p2                         p2
          p3                            p3                         p3

new behaviour:

❯ kubectl config get-contexts
CURRENT   NAME                          CLUSTER                    AUTHINFO                                                       NAMESPACE
          minikube                      minikube                   minikube
          p3                            p3                         p3
❯ minikube start -p p2
😄  [p2] minikube v1.13.1 on "Opensuse-Tumbleweed"
✨  Using the docker driver based on existing profile
❗  docker is currently using the btrfs storage driver, consider switching to overlay2 for better performance
👍  Starting control plane node p2 in cluster p2
🔄  Restarting existing docker container for "p2" ...
🐳  Preparing Kubernetes v1.19.2 on Docker 19.03.8 ...
🔎  Verifying Kubernetes components...
🌟  Enabled addons: storage-provisioner, default-storageclass
🏄  Done! kubectl is now configured to use "p2" by default
❯ kubectl config get-contexts
CURRENT   NAME                          CLUSTER                    AUTHINFO                                                       NAMESPACE
          minikube                      minikube                   minikube
*         p2                            p2                         p2
          p3                            p3                         p3

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Oct 7, 2020
@k8s-ci-robot
Copy link
Contributor

Hi @prezha. 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 /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

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.

@k8s-ci-robot k8s-ci-robot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Oct 7, 2020
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: prezha
To complete the pull request process, please assign priyawadhwa after the PR has been reviewed.
You can assign the PR to them by writing /assign @priyawadhwa in a comment when ready.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@minikube-bot
Copy link
Collaborator

Can one of the admins verify this patch?

@codecov-io
Copy link

codecov-io commented Oct 7, 2020

Codecov Report

Merging #9414 into master will decrease coverage by 0.69%.
The diff coverage is 9.01%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #9414      +/-   ##
==========================================
- Coverage   29.48%   28.78%   -0.70%     
==========================================
  Files         170      172       +2     
  Lines       10307    10606     +299     
==========================================
+ Hits         3039     3053      +14     
- Misses       6846     7129     +283     
- Partials      422      424       +2     
Impacted Files Coverage Δ
cmd/minikube/cmd/completion.go 0.00% <ø> (ø)
cmd/minikube/cmd/config/configure.go 0.74% <ø> (ø)
cmd/minikube/cmd/config/profile_list.go 2.56% <0.00%> (-0.14%) ⬇️
cmd/minikube/cmd/delete.go 19.06% <0.00%> (-0.55%) ⬇️
cmd/minikube/cmd/mount.go 8.33% <0.00%> (ø)
cmd/minikube/cmd/stop.go 4.00% <0.00%> (-1.89%) ⬇️
cmd/minikube/cmd/update-context.go 0.00% <0.00%> (ø)
pkg/drivers/common.go 8.00% <0.00%> (ø)
pkg/drivers/kic/oci/cli_runner.go 0.00% <0.00%> (ø)
pkg/drivers/kic/oci/errors.go 0.00% <ø> (ø)
... and 33 more

if err := kubeconfig.UnsetCurrentContext(profile, kubeconfig.PathFromEnv()); err != nil {
exit.Error(reason.HostKubeconfigUnset, "update config", err)
if err := kubeconfig.DeleteContext(profile, kubeconfig.PathFromEnv()); err != nil {
exit.Error(reason.HostKubeconfigUpdate, "update config", err)
Copy link
Member

@medyagh medyagh Oct 7, 2020

Choose a reason for hiding this comment

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

thank you for this quick PR, lets create a new Reason Exit here
https://github.com/medyagh/minikube/blob/82a5189b934ea02d127be85dbdba50dfa4282984/pkg/minikube/reason/reason.go#L207

	HostKubeconfigDelete = Kind{ID: "HOST_KUBECONFIG_DELETE", ExitCode: ExHostConfig}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@medyagh you are most welcome!
that did cross my mind, but HostKubeconfigDelete sounded a bit wrong (we are not going to delete kubeconfig), while HostKubeconfigUpdate not so bad as we are effectively just updating the kubeconfig
on the other hand, maybe:

	HostKubeconfigContextDelete = Kind{ID: "HOST_KUBECONFIG_CONTEXT_DELETE", ExitCode: ExHostConfig}

would be more appropriate?
what do you think?

Copy link
Member

Choose a reason for hiding this comment

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

that is actually good thinking ! I like that

how about something shorter but unique

"HostKubeconfigDeleteCtx"

the goal is if users collect these exit codes as metrics, they should find out what was the cause of the problem in a unique word

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, that sounds just about right :)
the update is on its way...
thanks @medyagh !

@k8s-ci-robot k8s-ci-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Oct 7, 2020
@prezha prezha requested a review from medyagh October 7, 2020 21:59
Copy link
Member

@medyagh medyagh left a comment

Choose a reason for hiding this comment

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

thanks

@medyagh medyagh merged commit c459fea into kubernetes:master Oct 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

FR/crazy idea: delete context when minikube is stopped
5 participants