Skip to content

Commit

Permalink
add explicit error code UNKNOWN_API_VERSION (#5848)
Browse files Browse the repository at this point in the history
  • Loading branch information
gsquared94 committed May 14, 2021
1 parent 64513ee commit a26b947
Show file tree
Hide file tree
Showing 9 changed files with 255 additions and 191 deletions.
45 changes: 30 additions & 15 deletions docs/content/en/api/skaffold.swagger.json

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions docs/content/en/docs/references/api/grpc.md
Original file line number Diff line number Diff line change
Expand Up @@ -1008,6 +1008,7 @@ For Cancelled Error code, use range 800 to 850.<br>
| CONFIG_FILE_PATHS_SUBSTITUTION_ERR | 1210 | Failed to substitute absolute file paths in config |
| CONFIG_MULTI_IMPORT_PROFILE_CONFLICT_ERR | 1211 | Same config imported at least twice with different set of profiles |
| CONFIG_PROFILES_NOT_FOUND_ERR | 1212 | Profile selection did not match known profile names |
| CONFIG_UNKNOWN_API_VERSION_ERR | 1213 | Config API version not found |
| INSPECT_UNKNOWN_ERR | 1301 | Catch-all `skaffold inspect` command error |
| INSPECT_BUILD_ENV_ALREADY_EXISTS_ERR | 1302 | Trying to add new build environment that already exists |

Expand Down Expand Up @@ -1067,6 +1068,7 @@ Enum for Suggestion codes
| CONFIG_CHECK_PROFILE_DEFINITION | 704 | Check profile definition in current config |
| CONFIG_CHECK_DEPENDENCY_PROFILES_SELECTION | 705 | Check active profile selection for dependency config |
| CONFIG_CHECK_PROFILE_SELECTION | 706 | Check profile selection flag |
| CONFIG_FIX_API_VERSION | 707 | Fix config API version or upgrade the skaffold binary |
| INSPECT_DEDUP_NEW_BUILD_ENV | 800 | `skaffold inspect` command error suggestion codes |
| OPEN_ISSUE | 900 | Open an issue so this situation can be diagnosed |
| CHECK_CUSTOM_COMMAND | 1000 | Test error suggestion codes |
Expand Down
12 changes: 12 additions & 0 deletions pkg/skaffold/build/buildpacks/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (

"github.com/buildpacks/pack"
packcfg "github.com/buildpacks/pack/config"
"github.com/docker/docker/api/types"

"github.com/GoogleContainerTools/skaffold/pkg/skaffold/config"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/docker"
Expand Down Expand Up @@ -414,6 +415,8 @@ func TestBuildWithArtifactDependencies(t *testing.T) {
Add(test.artifact.BuildpackArtifact.Builder, "builderImageID").
Add(test.artifact.BuildpackArtifact.RunImage, "runImageID").
Add("img:latest", "builtImageID")
t.Override(&docker.DefaultAuthHelper, testAuthHelper{})

localDocker := fakeLocalDaemon(test.api)

builder := NewArtifactBuilder(localDocker, test.pushImages, test.mode, test.resolver)
Expand Down Expand Up @@ -478,3 +481,12 @@ func (r mockArtifactResolver) GetImageTag(imageName string) (string, bool) {
val, found := r.m[imageName]
return val, found
}

type testAuthHelper struct{}

func (t testAuthHelper) GetAuthConfig(string) (types.AuthConfig, error) {
return types.AuthConfig{}, nil
}
func (t testAuthHelper) GetAllAuthConfigs(context.Context) (map[string]types.AuthConfig, error) {
return nil, nil
}
16 changes: 16 additions & 0 deletions pkg/skaffold/schema/errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,3 +184,19 @@ func ConfigProfileConflictErr(config, file string) error {
},
})
}

// ConfigUnknownAPIVersionErr specifies that the config API version doesn't match any known versions.
func ConfigUnknownAPIVersionErr(version string) error {
msg := fmt.Sprintf("unknown skaffold config API version %q", version)
return sErrors.NewError(fmt.Errorf(msg),
proto.ActionableErr{
Message: msg,
ErrCode: proto.StatusCode_CONFIG_UNKNOWN_API_VERSION_ERR,
Suggestions: []*proto.Suggestion{
{
SuggestionCode: proto.SuggestionCode_CONFIG_FIX_API_VERSION,
Action: "Set the config 'apiVersion' to a known value. Check https://skaffold.dev/docs/references/yaml/ for the list of valid API versions. Otherwise, check that your skaffold version is up-to-date",
},
},
})
}
3 changes: 2 additions & 1 deletion pkg/skaffold/schema/versions.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (

"github.com/GoogleContainerTools/skaffold/pkg/skaffold/apiversion"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubernetes"
sErrors "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/errors"
latestV1 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v1"
latestV2 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v2"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/util"
Expand Down Expand Up @@ -225,7 +226,7 @@ func configFactoryFromAPIVersion(buf []byte) ([]func() util.VersionedConfig, err
}
factory, present := AllVersions.Find(v.Version)
if !present {
return nil, fmt.Errorf("unknown api version: %q", v.Version)
return nil, sErrors.ConfigUnknownAPIVersionErr(v.Version)
}
factories = append(factories, factory)
}
Expand Down
360 changes: 185 additions & 175 deletions proto/enums/enums.pb.go

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions proto/enums/enums.proto
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,8 @@ enum StatusCode {
CONFIG_MULTI_IMPORT_PROFILE_CONFLICT_ERR = 1211;
// Profile selection did not match known profile names
CONFIG_PROFILES_NOT_FOUND_ERR = 1212;
// Config API version not found
CONFIG_UNKNOWN_API_VERSION_ERR = 1213;

// Inspect command errors

Expand Down Expand Up @@ -539,6 +541,8 @@ enum SuggestionCode {
CONFIG_CHECK_DEPENDENCY_PROFILES_SELECTION = 705;
// Check profile selection flag
CONFIG_CHECK_PROFILE_SELECTION = 706;
// Fix config API version or upgrade the skaffold binary
CONFIG_FIX_API_VERSION = 707;

// `skaffold inspect` command error suggestion codes
INSPECT_DEDUP_NEW_BUILD_ENV = 800;
Expand Down
2 changes: 2 additions & 0 deletions proto/v1/skaffold.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions proto/v2/skaffold.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a26b947

Please sign in to comment.