-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[v3] Add proto for render error code and suggestions.
- Loading branch information
Showing
11 changed files
with
566 additions
and
223 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
Copyright 2021 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 mutate | ||
|
||
import ( | ||
"fmt" | ||
|
||
sErrors "github.com/GoogleContainerTools/skaffold/pkg/skaffold/errors" | ||
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/render/kptfile" | ||
latestV2 "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest/v2" | ||
"github.com/GoogleContainerTools/skaffold/proto/v1" | ||
) | ||
|
||
var ( | ||
WhitelistedMutators = []string{"search-replace"} | ||
mutatorWhitelist = map[string]kptfile.Function{ | ||
"searchReplace": {Image: "gcr.io/kpt-fn/kubeval:v0.1"}, | ||
// TODO: Add conftest validator in kpt catalog. | ||
} | ||
) | ||
|
||
// NewValidator instantiates a Validator object. | ||
func NewValidator(config []latestV2.Validator) (*Validator, error) { | ||
var fns []kptfile.Function | ||
for _, c := range config { | ||
fn, ok := validatorWhitelist[c.Name] | ||
if !ok { | ||
// TODO: Add links to explain "skaffold-managed mode" and "kpt-managed mode". | ||
return nil, sErrors.NewErrorWithStatusCode( | ||
proto.ActionableErr{ | ||
Message: fmt.Sprintf("unsupported validator %q", c.Name), | ||
ErrCode: proto.StatusCode_CONFIG_UNKNOWN_VALIDATOR, | ||
Suggestions: []*proto.Suggestion{ | ||
{ | ||
SuggestionCode: proto.SuggestionCode_CONFIG_WHITELISTED_VALIDATORS, | ||
Action: fmt.Sprintf( | ||
"please only use the following validators in skaffold-managed mode: %v. "+ | ||
"to use custom validators, please use kpt-managed mode.", WhitelistedValidators), | ||
}, | ||
}, | ||
}) | ||
} | ||
fns = append(fns, fn) | ||
} | ||
return &Validator{kptFn: fns}, nil | ||
} | ||
|
||
type Validator struct { | ||
kptFn []kptfile.Function | ||
} | ||
|
||
// GetDeclarativeValidators transforms and returns the skaffold validators defined in skaffold.yaml | ||
func (v *Validator) GetDeclarativeValidators() []kptfile.Function { | ||
// TODO: guarantee the v.kptFn is updated once users changed skaffold.yaml file. | ||
return v.kptFn | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.