From aa46caeecd99d6b65001c94f2919ed086a66f9a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arda=20G=C3=BC=C3=A7l=C3=BC?= Date: Fri, 6 May 2022 10:25:40 +0300 Subject: [PATCH] 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". Kubernetes-commit: 0245e74590a658ea911f1e5cacd270960883af2d --- pkg/cmd/util/helpers.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pkg/cmd/util/helpers.go b/pkg/cmd/util/helpers.go index 00d6ac98..2e009894 100644 --- a/pkg/cmd/util/helpers.go +++ b/pkg/cmd/util/helpers.go @@ -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":