-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
prevent ctx-switching from failing on server err #12571
prevent ctx-switching from failing on server err #12571
Conversation
// server or an unfetchable ClientConfig. | ||
if _, exists := o.GetContextFromName(o.ProjectName); exists { | ||
o.Config.CurrentContext = o.ProjectName | ||
if err := kclientcmd.ModifyConfig(o.PathOptions, o.Config, true); err != nil { |
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.
@fabianofranz or @smarterclayton would a message to the user be appropriate here, indicating that the local context was switched anyway? (they would still see the error caused by f.ClientConfig()
failing)
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.
Hrm, is this error typed? If we can detect the exact reason I think we should bypass it and switch cleanly, without reporting the error. It's related to the actual context cluster anyway, not the one we're trying to switch to.
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.
Hrm, is this error typed? If we can detect the exact reason I think we should bypass it and switch cleanly, without reporting the error
Sounds good, we could check to see if error is errors.IsNotFound or errors.IsInternalError, and skip to switching the context if this is the case. However, the last few messages that are outputted to a user after successfully switching contexts are usually created with the host of the new context, using the ClientConfig
that caused this error to begin with:
$ oc project sample-app-2/api-preview-openshift-com:443/juanvallejo
Already on project "sample-app-2" on server "https://api.preview.openshift.com:443".
Maybe in the case of this error happening, we could modify the message to use the new "context name" instead of its hostname?
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 think it makes sense, even because you are switching by using the context name here.
[test] |
integration flaked on #12540 re[test] |
@fabianofranz thanks for the feedback, review comments addressed. I updated error checking to only attempt to switch contexts cleanly if the error returned while fetching |
integration flaked on #12558 re[test] |
LGTM, squash? |
bcf6b46
to
daa62d5
Compare
@fabianofranz thanks, done! |
[merge] |
Evaluated for origin test up to daa62d5 |
Evaluated for origin merge up to daa62d5 |
continuous-integration/openshift-jenkins/test SUCCESS (https://ci.openshift.redhat.com/jenkins/job/test_pr_origin/13257/) (Base Commit: 308e2d4) |
continuous-integration/openshift-jenkins/merge SUCCESS (https://ci.openshift.redhat.com/jenkins/job/test_pr_origin/13257/) (Base Commit: dced7f7) (Image: devenv-rhel7_5774) |
Fixes #12343
This patch fixes an issue where the config context will fail to switch if the server in the current context returns an error, or cannot be reached.
Before
After
cc @openshift/cli-review @smarterclayton