Skip to content

Adding distinct exit codes for cluster connection failures. #4933

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

Merged
merged 23 commits into from
Nov 3, 2020
Merged
Changes from 15 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
564c6bc
Adding distinct exit codes for cluster connection failures.
PriyaModali Oct 22, 2020
0f17f71
Adding unit tests.
PriyaModali Oct 23, 2020
03506c5
Merge branch 'master' into deploy_err
PriyaModali Oct 24, 2020
99d0b86
Reaming files and updatig unit test to work with latest design changes.
PriyaModali Oct 24, 2020
5ff9bff
Merging the new deploy cluster error in err_map and updated tests.
PriyaModali Oct 26, 2020
aa17382
Cleaning up deploy cluster error files.
PriyaModali Oct 26, 2020
619e322
Update pkg/skaffold/errors/err_map.go
PriyaModali Oct 26, 2020
6a108ee
Updated the known problens with deploy errors.
PriyaModali Oct 27, 2020
10c9058
Updating error message format.
PriyaModali Oct 27, 2020
c375278
Merge branch 'deploy_err' of https://github.com/PriyaModali/skaffold …
PriyaModali Oct 27, 2020
6d9f51c
Updating error message with kubecontext.
PriyaModali Oct 28, 2020
2f3d36e
Merge branch 'master' of https://github.com/GoogleContainerTools/skaf…
PriyaModali Oct 29, 2020
87e4e74
Updating error message.
PriyaModali Oct 29, 2020
ccb071d
Updated the logic & test case with modified error messages.
PriyaModali Nov 2, 2020
35ff3e3
Code re-arrange.
PriyaModali Nov 2, 2020
d0f716b
Updated existing unit test.
PriyaModali Nov 2, 2020
fb0d476
Adding unit tests.
PriyaModali Nov 3, 2020
627de26
Fixed messages.
PriyaModali Nov 3, 2020
6ab843c
Addressing lint.
PriyaModali Nov 3, 2020
9b5fb24
Merge branch 'master' of https://github.com/GoogleContainerTools/skaf…
PriyaModali Nov 3, 2020
e018818
Updated imports grouping.
PriyaModali Nov 3, 2020
be83e75
Updating suggestion code.
PriyaModali Nov 3, 2020
8d5ae6a
Updating the import order.
PriyaModali Nov 3, 2020
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
69 changes: 42 additions & 27 deletions docs/content/en/api/skaffold.swagger.json

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions docs/content/en/docs/references/api/grpc.md
Original file line number Diff line number Diff line change
@@ -825,6 +825,7 @@ For Cancelled Error code, use range 800 to 850.
| INIT_CACHE_ERROR | 907 | Skaffold encountered an error validating the artifact cache |
| INIT_CREATE_WATCH_TRIGGER_ERROR | 908 | Skaffold encountered an error when configuring file watching |
| INIT_CREATE_ARTIFACT_DEP_ERROR | 909 | Skaffold encountered an error when evaluating artifact dependencies |
| DEPLOY_CLUSTER_CONNECTION_ERR | 1001 | Unable to connect to cluster |



@@ -843,6 +844,8 @@ Enum for Suggestion codes
| DOCKER_AUTH_CONFIGURE | 104 | Run docker auth configure |
| CHECK_GCLOUD_PROJECT | 105 | Verify Gcloud Project |
| CHECK_DOCKER_RUNNING | 106 | Check if docker is running |
| CHECK_CLUSTER_CONNECTION | 201 | Check cluster connection |
| CHECK_MINIKUBE_STAUTUS | 202 | Check minikube status |
| CHECK_CONTAINER_LOGS | 301 | Container run error |
| CHECK_READINESS_PROBE | 302 | Pod Health check error |
| CHECK_CONTAINER_IMAGE | 303 | Check Container image |
66 changes: 66 additions & 0 deletions pkg/skaffold/errors/deploy_problems.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
Copyright 2020 The Skaffold Authors

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package errors

import (
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/cluster"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/config"
kubectx "github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubernetes/context"
"github.com/GoogleContainerTools/skaffold/proto"
"github.com/sirupsen/logrus"
)

var (
// for testing
currentConfig = kubectx.CurrentConfig
)

func suggestDeployFailedAction(opts config.SkaffoldOptions) []*proto.Suggestion {
kubeconfig, parsederr := currentConfig()
logrus.Debugf("Error retrieving the config: %q", parsederr)

var curctx = kubeconfig.CurrentContext
var isminikube = cluster.GetClient().IsMinikube(opts.KubeContext)
var kubectx = opts.KubeContext

if isminikube && curctx == "minkube" {
// Check if minikube is running using `minikube status` command and try again
return []*proto.Suggestion{{
SuggestionCode: proto.SuggestionCode_CHECK_MINIKUBE_STAUTUS,
Action: "Check if minikube is running using `minikube status` command and try again",
}}
}
if isminikube && curctx != "minkube" {
// Check if minikube is running using `minikube status -p cloud-run-dev-internal` command and try again.
return []*proto.Suggestion{{
SuggestionCode: proto.SuggestionCode_CHECK_MINIKUBE_STAUTUS,
Action: "Check if minikube is running using `minikube status -p <>` command and try again.",
}}
}
if isminikube && kubectx != "minkube" {
// Check your cluster connection for your named cluster.
return []*proto.Suggestion{{
SuggestionCode: proto.SuggestionCode_CHECK_CLUSTER_CONNECTION,
Action: "Check if minikube is running using `minikube status` command and try again",
}}
}

return []*proto.Suggestion{{
SuggestionCode: proto.SuggestionCode_CHECK_CLUSTER_CONNECTION,
Action: "Check your cluster connection",
}}
}
24 changes: 24 additions & 0 deletions pkg/skaffold/errors/err_map.go
Original file line number Diff line number Diff line change
@@ -22,8 +22,14 @@ import (

"github.com/GoogleContainerTools/skaffold/pkg/skaffold/config"
"github.com/GoogleContainerTools/skaffold/proto"
"github.com/sirupsen/logrus"
)

// var (
// // for testing
// currentConfig = kubectx.CurrentConfig
// )

// re is a shortcut around regexp.MustCompile
func re(s string) *regexp.Regexp {
return regexp.MustCompile(s)
@@ -87,3 +93,21 @@ var knownBuildProblems = []problem{
},
},
}

// Deploy errors in deployment phase
var knownDeployProblems = []problem{
{
regexp: re("(?i).*unable to connect.*: Get (.*)"),
errCode: proto.StatusCode_DEPLOY_CLUSTER_CONNECTION_ERR,
description: func(err error) string {
matchExp := re("(?i).*unable to connect.*Get (.*)")
kubeconfig, parsederr := currentConfig()
logrus.Debugf("Error retrieving the config: %q", parsederr)
if match := matchExp.FindStringSubmatch(fmt.Sprintf("%s", err)); len(match) >= 2 {
return fmt.Sprintf("Deploy Failed. Could not connect to cluster %s due to %s", kubeconfig.CurrentContext, match[1])
}
return fmt.Sprintf("Deploy Failed. Could not connect to %s cluster.", kubeconfig.CurrentContext)
},
suggestion: suggestDeployFailedAction,
},
}
7 changes: 4 additions & 3 deletions pkg/skaffold/errors/errors.go
Original file line number Diff line number Diff line change
@@ -72,7 +72,8 @@ func ActionableErr(phase Phase, err error) *proto.ActionableErr {
}

func ShowAIError(err error) error {
for _, v := range append(knownBuildProblems, knownInitProblems...) {
var knownProblems = append(knownBuildProblems, knownDeployProblems...)
for _, v := range append(knownProblems, knownInitProblems...) {
if v.regexp.MatchString(err.Error()) {
if suggestions := v.suggestion(skaffoldOpts); suggestions != nil {
description := fmt.Sprintf("%s\n", err)
@@ -121,11 +122,11 @@ var allErrors = map[Phase][]problem{
errCode: proto.StatusCode_INIT_UNKNOWN,
suggestion: reportIssueSuggestion,
}),
Deploy: {{
Deploy: append(knownDeployProblems, problem{
regexp: re(".*"),
errCode: proto.StatusCode_DEPLOY_UNKNOWN,
suggestion: reportIssueSuggestion,
}},
}),
StatusCheck: {{
regexp: re(".*"),
errCode: proto.StatusCode_STATUSCHECK_UNKNOWN,
18 changes: 18 additions & 0 deletions pkg/skaffold/errors/errors_test.go
Original file line number Diff line number Diff line change
@@ -23,6 +23,7 @@ import (
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/config"
"github.com/GoogleContainerTools/skaffold/proto"
"github.com/GoogleContainerTools/skaffold/testutil"
"k8s.io/client-go/tools/clientcmd/api"
)

func TestShowAIError(t *testing.T) {
@@ -243,12 +244,29 @@ func TestShowAIError(t *testing.T) {
Suggestions: reportIssueSuggestion(config.SkaffoldOptions{}),
},
},
{
description: "deploy failed",
opts: config.SkaffoldOptions{},
context: &config.ContextConfig{},
phase: Deploy,
err: fmt.Errorf(`exiting dev mode because first deploy failed: unable to connect to Kubernetes: Get "https://192.168.64.3:8443/version?timeout=32s": net/http: TLS handshake timeout`),
expected: `Deploy Failed. Could not connect to cluster test_cluster due to "https://192.168.64.3:8443/version?timeout=32s": net/http: TLS handshake timeout. Check your cluster connection.`,
expectedAE: &proto.ActionableErr{
ErrCode: proto.StatusCode_DEPLOY_CLUSTER_CONNECTION_ERR,
Message: "exiting dev mode because first deploy failed: unable to connect to Kubernetes: Get \"https://192.168.64.3:8443/version?timeout=32s\": net/http: TLS handshake timeout",
Suggestions: []*proto.Suggestion{{
SuggestionCode: proto.SuggestionCode_CHECK_CLUSTER_CONNECTION,
Action: "Check your cluster connection",
}},
},
},
}
for _, test := range append(tests, initTestCases...) {
testutil.Run(t, test.description, func(t *testutil.T) {
t.Override(&getConfigForCurrentContext, func(string) (*config.ContextConfig, error) {
return test.context, nil
})
t.SetupFakeKubernetesContext(api.Config{CurrentContext: "test_cluster"})
skaffoldOpts = test.opts
actual := ShowAIError(test.err)
t.CheckDeepEqual(test.expected, actual.Error())
Loading