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
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions pkg/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package provider
import (
"context"
"fmt"
"net/url"
"os"
"strings"

Expand Down Expand Up @@ -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.

k8sURL = fmt.Sprintf("at %q", err.URL)
}
failures = append(failures, &pulumirpc.CheckFailure{
Reason: fmt.Sprintf(" Selected k8s API is not reachable. "+
"Make sure your kubeconfig is correct. : %v", err),
Reason: fmt.Sprintf(" Kubernetes API server %s is unreachable. It's "+
"possible that the URL or authentication information in your "+
"kubeconfig is incorrect: %v", k8sURL, err),
})
} else if k.opts.rejectUnknownResources {
// If the schema doesn't exist, it could still be a CRD (which may not have a
Expand Down