-
Notifications
You must be signed in to change notification settings - Fork 244
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 (crc/machine) : KubeContext left in invalid state after crc stop (#1569) #4400
Conversation
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: 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 |
Hi @rohanKanojia. Thanks for your PR. I'm waiting for a crc-org 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-sigs/prow repository. |
/ok-to-test |
74d7c68
to
261e971
Compare
Could anyone please help me understand CI failures in the Windows-QE pipeline? Could it be a flaky failure? From the GitHub action logs, it seems that an action failed to generate a report. I'm not entirely sure whether these failures are related to changes made in this pull request. |
@rohanKanojia I would say they are related to something else, since these two pipelines fail for me too in #4343 . |
@adrianriobo and @lilyLuLiu can help you with this |
CI failures in the Windows-QE pipeline failed in copy test resource to target machine, this is qe related, not because of this pr. |
@lilyLuLiu : Is there any open issue to track this? |
pkg/crc/machine/stop.go
Outdated
if !errors.Is(err, os.ErrNotExist) { | ||
logging.Warnf("Failed to remove crc contexts from kubeconfig: %v", err) | ||
} | ||
} |
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.
@rohanKanojia this block of code should be at the end, we shouldn't clean the kubeconfig until stop the instance first.
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.
I had moved this above in order to make it easier to test. I had added tests in kubeconfig_test to verify that calling cleanupKubeconfig multiple times wouldn't affect kubeconfig.
Let me try to adapt tests after moving it to the bottom.
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.
Hello, on second thought from the user's perspective, we should always clean up .kube/config
regardless of whether the instance was stopped successfully or not (to avoid an inconsistent state, which was the problem user was facing).
Do you think it would be okay if we move this cleanup statement in a defer
block ?
defer func(input, output string) {
err := cleanKubeconfig(input, output)
if !errors.Is(err, os.ErrNotExist) {
logging.Warnf("Failed to remove crc contexts from kubeconfig: %v", err)
}
}(getGlobalKubeConfigPath(), getGlobalKubeConfigPath())
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.
yes, having it part of defer would be also good so that it is execute regardless.
261e971
to
2f2def2
Compare
test/e2e/testsuite/testsuite.go
Outdated
} | ||
if len(kubeConfig) == 0 { | ||
fmt.Println("Unable to load kubeconfig file") | ||
os.Exit(1) |
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.
should we return error here or exit? I think if we exit then other test is not run which we don't want.
3fffa8b
to
453bfbb
Compare
At the moment, we are only cleaning up crc context from kubeconfig during `crc delete`. This can be problematic if user tries to run any cluster related command after running `crc stop` as kubeconfig still points to CRC cluster that is not active. I checked minikube's behavior and noticed it's cleaning up kube config in case of both stop and delete commands. Make crc behavior consistent with minikube and perform kubeconfig cleanup in both sub commands. Signed-off-by: Rohan Kumar <[email protected]>
453bfbb
to
cdc863f
Compare
@rohanKanojia: The following test failed, say
Full PR test history. Your PR dashboard. 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-sigs/prow repository. I understand the commands that are listed here. |
Description
Fix #1569
At the moment, we are only cleaning up crc context from kubeconfig during
crc delete
. This can be problematic if user tries to run any cluster related command after runningcrc stop
as kubeconfig still points to CRC cluster that is not active.I checked minikube's behavior and noticed it's cleaning up kube config in case of both stop and delete commands. Make crc behavior consistent with minikube and perform kubeconfig cleanup in both sub commands.
Signed-off-by: Rohan Kumar [email protected]
Type of change
test, version modification, documentation, etc.)
Checklist
Fixes: Issue #1569
Relates to: Issue #1569
Solution/Idea
Clean up
.kube/config
file while doingcrc stop
in order to not leave kubeconfig in an inconsistent state.Currently after crc stop
.kube/config
file is left pointing to an outdated kube-context :This results in timeouts on the client side when user tries to access cluster using any kube client
oc
/kubectl
:This pull request would clean up
.kube/config
to align crc behavior with minikube so that it fails fast now:Trying to access cluster after crc stop
Proposed changes
Add a call to
cleanKubeconfig
instop.go
to clean up kubeconfig while stopping cluster.Testing
In order to test this branch you need to follow these steps:
make cross
to buildcrc
binary./out/linux-amd64/crc setup
./out/linux-amd64/crc start
./out/linux-amd64/crc stop
.kube/config
is cleaned up aftercrc stop
kubectl
/oc
it fails fast: