Skip to content

chore: safe type assersions #7770

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

6 changes: 4 additions & 2 deletions docs-v2/content/en/api-v2/skaffold.swagger.json

Large diffs are not rendered by default.

45 changes: 30 additions & 15 deletions docs-v2/content/en/api/skaffold.swagger.json

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions docs-v2/content/en/docs/references/api-v2/grpc.md
Original file line number Diff line number Diff line change
Expand Up @@ -1229,6 +1229,7 @@ For Cancelled Error code, use range 800 to 850.<br>
| CONFIG_UNKNOWN_TRANSFORMER | 1215 | The transformer is not allowed in skaffold-managed mode. |
| CONFIG_MISSING_MANIFEST_FILE_ERR | 1216 | Manifest file not found |
| CONFIG_REMOTE_REPO_CACHE_NOT_FOUND_ERR | 1217 | Remote config repository cache not found and sync disabled |
| CONFIG_UPGRADE_ERR | 1218 | Skaffold config version mismatch |
| 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 |
| INSPECT_BUILD_ENV_INCORRECT_TYPE_ERR | 1303 | Trying to modify build environment that doesn't exist |
Expand Down Expand Up @@ -1307,6 +1308,7 @@ Enum for Suggestion codes
| CONFIG_ALLOWLIST_transformers | 709 | Only the allow listed transformers are acceptable in skaffold-managed mode. |
| CONFIG_FIX_MISSING_MANIFEST_FILE | 710 | Check mising manifest file section of config and fix as needed. |
| CONFIG_ENABLE_REMOTE_REPO_SYNC | 711 | Enable remote repo sync, or clone manually |
| CONFIG_FIX_SKAFFOLD_CONFIG_VERSION | 712 | Upgrade skaffold config version to latest |
| INSPECT_USE_MODIFY_OR_NEW_PROFILE | 800 | Create new build env in a profile instead, or use the 'modify' command |
| INSPECT_USE_ADD_BUILD_ENV | 801 | Check profile selection, or use the 'add' command instead |
| INSPECT_CHECK_INPUT_PROFILE | 802 | Check profile flag value |
Expand Down
2 changes: 2 additions & 0 deletions docs-v2/content/en/docs/references/api/grpc.md
Original file line number Diff line number Diff line change
Expand Up @@ -1084,6 +1084,7 @@ For Cancelled Error code, use range 800 to 850.<br>
| CONFIG_UNKNOWN_TRANSFORMER | 1215 | The transformer is not allowed in skaffold-managed mode. |
| CONFIG_MISSING_MANIFEST_FILE_ERR | 1216 | Manifest file not found |
| CONFIG_REMOTE_REPO_CACHE_NOT_FOUND_ERR | 1217 | Remote config repository cache not found and sync disabled |
| CONFIG_UPGRADE_ERR | 1218 | Skaffold config version mismatch |
| 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 |
| INSPECT_BUILD_ENV_INCORRECT_TYPE_ERR | 1303 | Trying to modify build environment that doesn't exist |
Expand Down Expand Up @@ -1162,6 +1163,7 @@ Enum for Suggestion codes
| CONFIG_ALLOWLIST_transformers | 709 | Only the allow listed transformers are acceptable in skaffold-managed mode. |
| CONFIG_FIX_MISSING_MANIFEST_FILE | 710 | Check mising manifest file section of config and fix as needed. |
| CONFIG_ENABLE_REMOTE_REPO_SYNC | 711 | Enable remote repo sync, or clone manually |
| CONFIG_FIX_SKAFFOLD_CONFIG_VERSION | 712 | Upgrade skaffold config version to latest |
| INSPECT_USE_MODIFY_OR_NEW_PROFILE | 800 | Create new build env in a profile instead, or use the 'modify' command |
| INSPECT_USE_ADD_BUILD_ENV | 801 | Check profile selection, or use the 'add' command instead |
| INSPECT_CHECK_INPUT_PROFILE | 802 | Check profile flag value |
Expand Down
6 changes: 4 additions & 2 deletions docs/content/en/api-v2/skaffold.swagger.json

Large diffs are not rendered by default.

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-v2/grpc.md
Original file line number Diff line number Diff line change
Expand Up @@ -1229,6 +1229,7 @@ For Cancelled Error code, use range 800 to 850.<br>
| CONFIG_UNKNOWN_TRANSFORMER | 1215 | The transformer is not allowed in skaffold-managed mode. |
| CONFIG_MISSING_MANIFEST_FILE_ERR | 1216 | Manifest file not found |
| CONFIG_REMOTE_REPO_CACHE_NOT_FOUND_ERR | 1217 | Remote config repository cache not found and sync disabled |
| CONFIG_UPGRADE_ERR | 1218 | Skaffold config version mismatch |
| 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 |
| INSPECT_BUILD_ENV_INCORRECT_TYPE_ERR | 1303 | Trying to modify build environment that doesn't exist |
Expand Down Expand Up @@ -1307,6 +1308,7 @@ Enum for Suggestion codes
| CONFIG_ALLOWLIST_transformers | 709 | Only the allow listed transformers are acceptable in skaffold-managed mode. |
| CONFIG_FIX_MISSING_MANIFEST_FILE | 710 | Check mising manifest file section of config and fix as needed. |
| CONFIG_ENABLE_REMOTE_REPO_SYNC | 711 | Enable remote repo sync, or clone manually |
| CONFIG_FIX_SKAFFOLD_CONFIG_VERSION | 712 | Upgrade skaffold config version to latest |
| INSPECT_USE_MODIFY_OR_NEW_PROFILE | 800 | Create new build env in a profile instead, or use the 'modify' command |
| INSPECT_USE_ADD_BUILD_ENV | 801 | Check profile selection, or use the 'add' command instead |
| INSPECT_CHECK_INPUT_PROFILE | 802 | Check profile flag value |
Expand Down
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 @@ -1084,6 +1084,7 @@ For Cancelled Error code, use range 800 to 850.<br>
| CONFIG_UNKNOWN_TRANSFORMER | 1215 | The transformer is not allowed in skaffold-managed mode. |
| CONFIG_MISSING_MANIFEST_FILE_ERR | 1216 | Manifest file not found |
| CONFIG_REMOTE_REPO_CACHE_NOT_FOUND_ERR | 1217 | Remote config repository cache not found and sync disabled |
| CONFIG_UPGRADE_ERR | 1218 | Skaffold config version mismatch |
| 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 |
| INSPECT_BUILD_ENV_INCORRECT_TYPE_ERR | 1303 | Trying to modify build environment that doesn't exist |
Expand Down Expand Up @@ -1162,6 +1163,7 @@ Enum for Suggestion codes
| CONFIG_ALLOWLIST_transformers | 709 | Only the allow listed transformers are acceptable in skaffold-managed mode. |
| CONFIG_FIX_MISSING_MANIFEST_FILE | 710 | Check mising manifest file section of config and fix as needed. |
| CONFIG_ENABLE_REMOTE_REPO_SYNC | 711 | Enable remote repo sync, or clone manually |
| CONFIG_FIX_SKAFFOLD_CONFIG_VERSION | 712 | Upgrade skaffold config version to latest |
| INSPECT_USE_MODIFY_OR_NEW_PROFILE | 800 | Create new build env in a profile instead, or use the 'modify' command |
| INSPECT_USE_ADD_BUILD_ENV | 801 | Check profile selection, or use the 'add' command instead |
| INSPECT_CHECK_INPUT_PROFILE | 802 | Check profile flag value |
Expand Down
12 changes: 10 additions & 2 deletions pkg/skaffold/parser/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,11 @@ func getConfigs(ctx context.Context, cfgOpts configOpts, opts config.SkaffoldOpt
// add profiles to record and validate that config names are unique if specified
seen := make(map[string]bool)
for _, cfg := range parsed {
config := cfg.(*latest.SkaffoldConfig)
config, ok := cfg.(*latest.SkaffoldConfig)
if !ok {
return nil, nil, sErrors.SkaffoldConfigUpgradeErr(cfg.GetVersion(), latest.Version)
}

for _, profile := range config.Profiles {
if !stringslice.Contains(r.allProfiles, profile.Name) {
r.allProfiles = append(r.allProfiles, profile.Name)
Expand All @@ -153,7 +157,11 @@ func getConfigs(ctx context.Context, cfgOpts configOpts, opts config.SkaffoldOpt

var configs SkaffoldConfigSet
for i, cfg := range parsed {
config := cfg.(*latest.SkaffoldConfig)
config, ok := cfg.(*latest.SkaffoldConfig)
if !ok {
return nil, nil, sErrors.SkaffoldConfigUpgradeErr(cfg.GetVersion(), latest.Version)
}

processed, err := processEachConfig(ctx, config, cfgOpts, opts, r, i, fieldsOverrodeByProfile)
if err != nil {
return nil, nil, err
Expand Down
16 changes: 16 additions & 0 deletions pkg/skaffold/schema/errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,3 +200,19 @@ func ConfigUnknownAPIVersionErr(version string) error {
},
})
}

// SkaffoldConfigUpgradeErr specifies that skaffold config needs to be upgraded to the latest version.
func SkaffoldConfigUpgradeErr(currentVersion, targetVersion string) error {
msg := fmt.Sprintf("skaffold cannot auto-upgrade the config from version %s to version %s", currentVersion, targetVersion)
return sErrors.NewError(fmt.Errorf(msg),
&proto.ActionableErr{
Message: msg,
ErrCode: proto.StatusCode_CONFIG_UPGRADE_ERR,
Suggestions: []*proto.Suggestion{
{
SuggestionCode: proto.SuggestionCode_CONFIG_FIX_SKAFFOLD_CONFIG_VERSION,
Action: fmt.Sprintf("Upgrade skaffold config version to %s manually", targetVersion),
},
},
})
}
Loading