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

diagnostics: fail gracefully on broken kubeconfig #4737

Merged

Conversation

sosiouxme
Copy link
Member

fixes #4578

@openshift-bot
Copy link
Contributor

continuous-integration/openshift-jenkins/merge SUCCESS (https://ci.openshift.redhat.com/jenkins/job/merge_pull_requests_origin/3357/) (Image: devenv-fedora_2375)

@@ -23,6 +25,9 @@ func (o DiagnosticsOptions) detectClientConfig() (bool, []types.DiagnosticError,
func (o DiagnosticsOptions) buildRawConfig() (*clientcmdapi.Config, error) {
kubeConfig, configErr := o.Factory.OpenShiftClientConfig.RawConfig()
if len(kubeConfig.Contexts) == 0 {
if configErr == nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

This will be easier to reason about and more consistent if you move this check above the len() == 0 check.

Copy link
Contributor

Choose a reason for hiding this comment

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

if configErr != nil{
    return nil, configErr
}
if len....

@deads2k
Copy link
Contributor

deads2k commented Sep 21, 2015

Merge tag removed to give a little time for review.

@@ -23,6 +25,9 @@ func (o DiagnosticsOptions) detectClientConfig() (bool, []types.DiagnosticError,
func (o DiagnosticsOptions) buildRawConfig() (*clientcmdapi.Config, error) {
kubeConfig, configErr := o.Factory.OpenShiftClientConfig.RawConfig()
if len(kubeConfig.Contexts) == 0 {
if configErr == nil {
configErr = errors.New("No contexts found in config file.")
}
return nil, configErr
}
return &kubeConfig, configErr
Copy link
Contributor

Choose a reason for hiding this comment

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

That way down here, you can simply do return &kubeConfig, nil so its very clear to readers that this is the success path.

@sosiouxme
Copy link
Member Author

@deads2k better?

@deads2k
Copy link
Contributor

deads2k commented Sep 21, 2015

lgtm [merge]

@openshift-bot
Copy link
Contributor

Evaluated for origin merge up to 85c8fcd

@openshift-bot
Copy link
Contributor

[Test]ing while waiting on the merge queue

@openshift-bot
Copy link
Contributor

continuous-integration/openshift-jenkins/test SUCCESS (https://ci.openshift.redhat.com/jenkins/job/test_pull_requests_origin/5069/)

@openshift-bot
Copy link
Contributor

Evaluated for origin test up to 85c8fcd

openshift-bot pushed a commit that referenced this pull request Sep 21, 2015
@openshift-bot openshift-bot merged commit f2174ea into openshift:master Sep 21, 2015
@sosiouxme sosiouxme deleted the 20150918-fix-broken-kubeconfig branch September 21, 2015 15:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

diagnostics stack trace doesn't print a stack trace
3 participants