Merge pull request #109850 from ardaguclu/validate-nooptdefval
Define NoOptDefVal for validate flag Kubernetes-commit: 661cbe6823fc5b7d62b80c6dc43447af53976290
This commit is contained in:
commit
aa640b9cbc
|
@ -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.
|
"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.`,
|
"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) {
|
func AddFilenameOptionFlags(cmd *cobra.Command, options *resource.FilenameOptions, usage string) {
|
||||||
|
@ -584,8 +586,6 @@ func GetValidationDirective(cmd *cobra.Command) (string, error) {
|
||||||
b, err := strconv.ParseBool(validateFlag)
|
b, err := strconv.ParseBool(validateFlag)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
switch validateFlag {
|
switch validateFlag {
|
||||||
case cmd.Flag("validate").NoOptDefVal:
|
|
||||||
return metav1.FieldValidationStrict, nil
|
|
||||||
case "strict":
|
case "strict":
|
||||||
return metav1.FieldValidationStrict, nil
|
return metav1.FieldValidationStrict, nil
|
||||||
case "warn":
|
case "warn":
|
||||||
|
|
|
@ -517,7 +517,9 @@ func TestGetValidationDirective(t *testing.T) {
|
||||||
for _, tc := range tests {
|
for _, tc := range tests {
|
||||||
cmd := &cobra.Command{}
|
cmd := &cobra.Command{}
|
||||||
AddValidateFlags(cmd)
|
AddValidateFlags(cmd)
|
||||||
cmd.Flags().Set("validate", tc.validateFlag)
|
if tc.validateFlag != "" {
|
||||||
|
cmd.Flags().Set("validate", tc.validateFlag)
|
||||||
|
}
|
||||||
directive, err := GetValidationDirective(cmd)
|
directive, err := GetValidationDirective(cmd)
|
||||||
if directive != tc.expectedDirective {
|
if directive != tc.expectedDirective {
|
||||||
t.Errorf("validation directive, expected: %v, but got: %v", tc.expectedDirective, directive)
|
t.Errorf("validation directive, expected: %v, but got: %v", tc.expectedDirective, directive)
|
||||||
|
|
Loading…
Reference in New Issue