mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-21 10:51:29 +00:00
Define NoOptDefVal for validate flag
validate flag does not have default value defined when there is no parameter passed, therefore it tries to use next irrelevant flag. This PR defines NoOptDefVal for validate flag which is set "strict".
This commit is contained in:
parent
7141b6d58d
commit
0245e74590
@ -407,6 +407,8 @@ func AddValidateFlags(cmd *cobra.Command) {
|
||||
"warn" will warn about unknown or duplicate fields without blocking the request if server-side field validation is enabled on the API server, and behave as "ignore" otherwise.
|
||||
"false" or "ignore" will not perform any schema validation, silently dropping any unknown or duplicate fields.`,
|
||||
)
|
||||
|
||||
cmd.Flags().Lookup("validate").NoOptDefVal = "strict"
|
||||
}
|
||||
|
||||
func AddFilenameOptionFlags(cmd *cobra.Command, options *resource.FilenameOptions, usage string) {
|
||||
@ -584,6 +586,8 @@ func GetValidationDirective(cmd *cobra.Command) (string, error) {
|
||||
b, err := strconv.ParseBool(validateFlag)
|
||||
if err != nil {
|
||||
switch validateFlag {
|
||||
case "":
|
||||
return metav1.FieldValidationStrict, nil
|
||||
case cmd.Flag("validate").NoOptDefVal:
|
||||
return metav1.FieldValidationStrict, nil
|
||||
case "strict":
|
||||
|
@ -170,6 +170,12 @@ run_kubectl_create_validate_tests() {
|
||||
|
||||
create_and_use_new_namespace
|
||||
|
||||
## test --validate no value expects default strict is used
|
||||
kube::log::status "Testing kubectl create --validate"
|
||||
# create and verify
|
||||
output_message=$(! kubectl create -f hack/testdata/invalid-deployment-unknown-and-duplicate-fields.yaml --validate 2>&1)
|
||||
has_one_of_error_message "${output_message}" 'strict decoding error' 'error validating data'
|
||||
|
||||
## test --validate=true
|
||||
kube::log::status "Testing kubectl create --validate=true"
|
||||
# create and verify
|
||||
|
Loading…
Reference in New Issue
Block a user