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

Add a better error message for unreachable k8s API server #291

Merged
merged 2 commits into from
Nov 21, 2018

Conversation

lblackstone
Copy link
Member

Fixes #97

Here's what the error looks like after this fix:

error: kubernetes:core/v1:Service resource 'nginx' has a problem:  Selected k8s API is not reachable. Make sure your kubeconfig is correct. : Get https://localhost:6444/openapi/v2: dial tcp [::1]:6444: connect: connection refused

@@ -277,10 +277,16 @@ func (k *kubeProvider) Check(ctx context.Context, req *pulumirpc.CheckRequest) (
if err != nil {
resourceNotFound := errors.IsNotFound(err) ||
strings.Contains(err.Error(), "is not supported by the server")
k8sAPIUnreachable := strings.Contains(err.Error(), "connection refused")
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, it looks like this should return *errors.StatusError -- although that string munging above this line (which I've forgotten the reasoning behind) gives me a sinking feeling that this API also emits stringly-typed errors. I'm guessing we did double-check this and we have no better options? :(

Copy link
Member Author

Choose a reason for hiding this comment

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

Nope, looks like it's returning a *url.Error instead:

&url.Error{Op:"Get", URL:"https://localhost:6444/openapi/v2", Err:(*net.OpError)(0xc000024000)} (*url.Error)

} else if k8sAPIUnreachable {
failures = append(failures, &pulumirpc.CheckFailure{
Reason: fmt.Sprintf(" Selected k8s API is not reachable. "+
"Make sure your kubeconfig is correct. : %v", err),
Copy link
Contributor

Choose a reason for hiding this comment

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

How about something like " Kubernetes API server at %s is unreachable. It is possible that the URL or authentication information in the kubeconfig file is incorrect"?

@lblackstone
Copy link
Member Author

Here's the revised output:
screen shot 2018-11-21 at 1 37 33 pm

@@ -283,9 +284,14 @@ func (k *kubeProvider) Check(ctx context.Context, req *pulumirpc.CheckRequest) (
Reason: fmt.Sprintf(" Found API Group, but it did not contain a schema for '%s'", gvk),
})
} else if k8sAPIUnreachable {
k8sURL := ""
if err, ok := err.(*url.Error); ok {
Copy link
Contributor

Choose a reason for hiding this comment

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

Are we confident this is the only time we see this type of error? If not, might make sense to assert strings.Contains(err.URL, k8sURL) and that the error message contains connection refused -- in which case it seems like would have someway high confidence that this is the error we think it is.

Up to you though.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I'm reasonably confident in this logic. It's difficult to track down the source of the error, but if we've hit this branch, it should be a *url.Error. If not, it just skips printing the URL.

@lblackstone lblackstone merged commit 067ef8a into master Nov 21, 2018
@pulumi-bot pulumi-bot deleted the lblackstone/api-not-reachable-error branch November 21, 2018 22:56
@lblackstone lblackstone added this to the 0.19 milestone Nov 30, 2018
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.

Improve error message when Kubernetes master is not available
2 participants