-
Notifications
You must be signed in to change notification settings - Fork 113
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
Conversation
@@ -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") |
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.
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? :(
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.
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)
pkg/provider/provider.go
Outdated
} 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), |
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.
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"
?
@@ -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 { |
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.
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.
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.
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.
Fixes #97
Here's what the error looks like after this fix: