Skip to content

Commit

Permalink
Add a better error message for unreachable k8s API server (#291)
Browse files Browse the repository at this point in the history
  • Loading branch information
lblackstone committed Nov 21, 2018
1 parent 2330f0b commit 067ef8a
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 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 @@ -277,10 +278,21 @@ 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")
if resourceNotFound && gvkExists(gvk) {
failures = append(failures, &pulumirpc.CheckFailure{
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 {
k8sURL = fmt.Sprintf("at %q", err.URL)
}
failures = append(failures, &pulumirpc.CheckFailure{
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
// schema). Thus, if we are directed to check resources even if they have unknown
Expand Down

0 comments on commit 067ef8a

Please sign in to comment.