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 an init phase to detect skaffold errors even before skaffold runner is created. #4926

Merged
merged 6 commits into from
Oct 21, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
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
2 changes: 2 additions & 0 deletions cmd/skaffold/app/cmd/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (

"github.com/GoogleContainerTools/skaffold/pkg/skaffold/config"
sErrors "github.com/GoogleContainerTools/skaffold/pkg/skaffold/errors"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/event"
kubectx "github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubernetes/context"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/runner"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/runner/runcontext"
Expand Down Expand Up @@ -60,6 +61,7 @@ func createNewRunner(opts config.SkaffoldOptions) (runner.Runner, *latest.Skaffo

runner, err := runner.NewForConfig(runCtx)
if err != nil {
event.SkaffoldInitFailed(err)
return nil, nil, fmt.Errorf("creating runner: %w", err)
}

Expand Down
268 changes: 242 additions & 26 deletions docs/content/en/api/skaffold.swagger.json

Large diffs are not rendered by default.

30 changes: 30 additions & 0 deletions docs/content/en/docs/references/api/grpc.md
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ It is one of MetaEvent, BuildEvent, DeployEvent, PortEvent, StatusCheckEvent, Re
| fileSyncEvent | [FileSyncEvent](#proto.FileSyncEvent) | | describes the sync status. |
| debuggingContainerEvent | [DebuggingContainerEvent](#proto.DebuggingContainerEvent) | | describes the appearance or disappearance of a debugging container |
| devLoopEvent | [DevLoopEvent](#proto.DevLoopEvent) | | describes a start and end of a dev loop. |
| sessionEndEvent | [SessionEndEvent](#proto.SessionEndEvent) | | describes a skaffold session complete event |



Expand Down Expand Up @@ -515,6 +516,22 @@ will be sent with the new status.



<a name="proto.SessionEndEvent"></a>
#### SessionEndEvent
`SessionEndEvent` marks the end of the skaffold session


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| status | [string](#string) | | status oneof: Completed or Failed |
| err | [ActionableErr](#proto.ActionableErr) | | actionable error message |







<a name="proto.State"></a>
#### State
`State` represents the current state of the Skaffold components
Expand Down Expand Up @@ -789,6 +806,7 @@ For Cancelled Error code, use range 800 to 850.
| BUILD_UNKNOWN | 506 | Build failed due to unknown reason |
| DEVINIT_UNKNOWN | 507 | Dev Init failed due to unknown reason |
| CLEANUP_UNKNOWN | 508 | Cleanup failed due to unknown reason |
| INIT_UNKNOWN | 510 | Skaffold Session Init failed due to unknown reason |
| SYNC_INIT_ERROR | 601 | File Sync Initialize failure |
| DEVINIT_REGISTER_BUILD_DEPS | 701 | Failed to configure watcher for build dependencies in dev loop |
| DEVINIT_REGISTER_TEST_DEPS | 702 | Failed to configure watcher for test dependencies in dev loop |
Expand All @@ -798,6 +816,15 @@ For Cancelled Error code, use range 800 to 850.
| STATUSCHECK_DEADLINE_EXCEEDED | 801 | Deadline for status check exceeded |
| BUILD_CANCELLED | 802 | Build cancelled due to user cancellation or one or more build failed. |
| DEPLOY_CANCELLED | 803 | Deploy cancelled due to user cancellation or one or more deployers failed. |
| INIT_CREATE_TAGGER_ERROR | 901 | |
| INIT_MINIKUBE_PAUSED_ERROR | 902 | |
| INIT_MINIKUBE_NOT_RUNNING_ERROR | 903 | |
| INIT_CREATE_BUILDER_ERROR | 904 | |
| INIT_CREATE_DEPLOYER_ERROR | 905 | |
| INIT_CREATE_TEST_DEP_ERROR | 906 | |
| INIT_CACHE_ERROR | 907 | |
| INIT_CREATE_WATCH_TRIGGER_ERROR | 908 | |
| INIT_CREATE_ARTIFACT_DEP_ERROR | 909 | |



Expand Down Expand Up @@ -828,6 +855,9 @@ Enum for Suggestion codes
| ADDRESS_NODE_NOT_READY | 406 | Node not ready error |
| ADDRESS_FAILED_SCHEDULING | 407 | Scheduler failure error |
| CHECK_HOST_CONNECTION | 408 | Cluster Connectivity error |
| START_MINIKUBE | 501 | Minikube Suggestions |
| UNPAUSE_MINIKUBE | 502 | |
| OPEN_ISSUE | 900 | Open Issue Suggestion |
tejal29 marked this conversation as resolved.
Show resolved Hide resolved


<!-- end enums -->
Expand Down
2 changes: 1 addition & 1 deletion pkg/skaffold/errors/err_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ var knownBuildProblems = []problem{
suggestion: func(config.SkaffoldOptions) []*proto.Suggestion {
return []*proto.Suggestion{{
SuggestionCode: proto.SuggestionCode_CHECK_DOCKER_RUNNING,
Action: "Please check if docker is running",
Action: "Check if docker is running",
}}
},
},
Expand Down
63 changes: 47 additions & 16 deletions pkg/skaffold/errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (

// These are phases in a DevLoop
const (
Init = Phase("Init")
Build = Phase("Build")
Deploy = Phase("Deploy")
StatusCheck = Phase("StatusCheck")
Expand Down Expand Up @@ -61,10 +62,14 @@ func ActionableErr(phase Phase, err error) *proto.ActionableErr {
}

func ShowAIError(err error) error {
for _, v := range knownBuildProblems {
for _, v := range append(knownBuildProblems, knownInitProblems...) {
if v.regexp.MatchString(err.Error()) {
if suggestions := v.suggestion(skaffoldOpts); suggestions != nil {
return fmt.Errorf("%s. %s", strings.Trim(v.description(err), "."), concatSuggestions(suggestions))
description := fmt.Sprintf("%s\n", err)
if v.description != nil {
description = strings.Trim(v.description(err), ".")
}
return fmt.Errorf("%s. %s", description, concatSuggestions(suggestions))
}
return fmt.Errorf(v.description(err))
}
Expand All @@ -73,24 +78,12 @@ func ShowAIError(err error) error {
}

func getErrorCodeFromError(phase Phase, err error) (proto.StatusCode, []*proto.Suggestion) {
switch phase {
case Build:
for _, v := range knownBuildProblems {
if problems, ok := allErrors[phase]; ok {
for _, v := range problems {
if v.regexp.MatchString(err.Error()) {
return v.errCode, v.suggestion(skaffoldOpts)
}
}
return proto.StatusCode_BUILD_UNKNOWN, nil
case Deploy:
return proto.StatusCode_DEPLOY_UNKNOWN, nil
case StatusCheck:
return proto.StatusCode_STATUSCHECK_UNKNOWN, nil
case FileSync:
return proto.StatusCode_SYNC_UNKNOWN, nil
case DevInit:
return proto.StatusCode_DEVINIT_UNKNOWN, nil
case Cleanup:
return proto.StatusCode_CLEANUP_UNKNOWN, nil
}
return proto.StatusCode_UNKNOWN_ERROR, nil
}
Expand All @@ -106,3 +99,41 @@ func concatSuggestions(suggestions []*proto.Suggestion) string {
s.WriteString(".")
return s.String()
}

var allErrors = map[Phase][]problem{
gsquared94 marked this conversation as resolved.
Show resolved Hide resolved
Build: append(knownBuildProblems, problem{
regexp: re(".*"),
errCode: proto.StatusCode_BUILD_UNKNOWN,
suggestion: reportIssueSuggestion,
}),
Init: append(knownInitProblems, problem{
regexp: re(".*"),
errCode: proto.StatusCode_INIT_UNKNOWN,
suggestion: reportIssueSuggestion,
}),
Deploy: {{
regexp: re(".*"),
errCode: proto.StatusCode_DEPLOY_UNKNOWN,
suggestion: reportIssueSuggestion,
}},
StatusCheck: {{
regexp: re(".*"),
errCode: proto.StatusCode_STATUSCHECK_UNKNOWN,
suggestion: reportIssueSuggestion,
}},
FileSync: {{
regexp: re(".*"),
errCode: proto.StatusCode_SYNC_UNKNOWN,
suggestion: reportIssueSuggestion,
}},
DevInit: {{
regexp: re(".*"),
errCode: proto.StatusCode_DEVINIT_UNKNOWN,
suggestion: reportIssueSuggestion,
}},
Cleanup: {{
regexp: re(".*"),
errCode: proto.StatusCode_CLEANUP_UNKNOWN,
suggestion: reportIssueSuggestion,
}},
}
Loading