mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-19 09:52:49 +00:00
correct OpenAPI extension in error message
when attemping to use preserveUnknownFields the error message leads you astray
This commit is contained in:
parent
19c8a21271
commit
59629acf47
@ -1681,7 +1681,7 @@ func validatePreserveUnknownFields(crd, oldCRD *apiextensions.CustomResourceDefi
|
||||
var errs field.ErrorList
|
||||
if crd != nil && crd.Spec.PreserveUnknownFields != nil && *crd.Spec.PreserveUnknownFields {
|
||||
// disallow changing spec.preserveUnknownFields=false to spec.preserveUnknownFields=true
|
||||
errs = append(errs, field.Invalid(field.NewPath("spec").Child("preserveUnknownFields"), crd.Spec.PreserveUnknownFields, "cannot set to true, set x-preserve-unknown-fields to true in spec.versions[*].schema instead"))
|
||||
errs = append(errs, field.Invalid(field.NewPath("spec").Child("preserveUnknownFields"), crd.Spec.PreserveUnknownFields, "cannot set to true, set x-kubernetes-preserve-unknown-fields to true in spec.versions[*].schema instead"))
|
||||
}
|
||||
return errs
|
||||
}
|
||||
|
@ -608,7 +608,7 @@ func TestCelCostStability(t *testing.T) {
|
||||
}),
|
||||
expectCost: map[string]int64{
|
||||
// 'kind', 'apiVersion', 'metadata.name' and 'metadata.generateName' are always accessible
|
||||
// even if not specified in the schema, regardless of if x-preserve-unknown-fields is set.
|
||||
// even if not specified in the schema, regardless of if x-kubernetes-preserve-unknown-fields is set.
|
||||
"self.embedded.kind == 'Pod'": 4,
|
||||
"self.embedded.apiVersion == 'v1'": 4,
|
||||
"self.embedded.metadata.name == 'foo'": 5,
|
||||
|
@ -772,7 +772,7 @@ func TestValidationExpressions(t *testing.T) {
|
||||
}),
|
||||
valid: []string{
|
||||
// 'kind', 'apiVersion', 'metadata.name' and 'metadata.generateName' are always accessible
|
||||
// even if not specified in the schema, regardless of if x-preserve-unknown-fields is set.
|
||||
// even if not specified in the schema, regardless of if x-kubernetes-preserve-unknown-fields is set.
|
||||
"self.embedded.kind == 'Pod'",
|
||||
"self.embedded.apiVersion == 'v1'",
|
||||
"self.embedded.metadata.name == 'foo'",
|
||||
@ -782,7 +782,7 @@ func TestValidationExpressions(t *testing.T) {
|
||||
"has(self.embedded)",
|
||||
},
|
||||
// only field declared in the schema can be field selected in CEL expressions, regardless of if
|
||||
// x-preserve-unknown-fields is set.
|
||||
// x-kubernetes-preserve-unknown-fields is set.
|
||||
errors: map[string]string{
|
||||
"has(self.embedded.spec)": "undefined field 'spec'",
|
||||
},
|
||||
|
@ -84,7 +84,7 @@ func UnstructuredToVal(unstructured interface{}, schema *structuralschema.Struct
|
||||
},
|
||||
}
|
||||
}
|
||||
// A object with x-preserve-unknown-fields but no properties or additionalProperties is treated
|
||||
// A object with x-kubernetes-preserve-unknown-fields but no properties or additionalProperties is treated
|
||||
// as an empty object.
|
||||
if schema.XPreserveUnknownFields {
|
||||
return &unstructuredMap{
|
||||
|
@ -145,8 +145,8 @@ var _ = SIGDescribe("CustomResourcePublishOpenAPI [Privileged:ClusterAdmin]", fu
|
||||
|
||||
/*
|
||||
Release: v1.16
|
||||
Testname: Custom Resource OpenAPI Publish, with x-preserve-unknown-fields in object
|
||||
Description: Register a custom resource definition with x-preserve-unknown-fields in the top level object.
|
||||
Testname: Custom Resource OpenAPI Publish, with x-kubernetes-preserve-unknown-fields in object
|
||||
Description: Register a custom resource definition with x-kubernetes-preserve-unknown-fields in the top level object.
|
||||
Attempt to create and apply a change a custom resource, via kubectl; kubectl validation MUST accept unknown
|
||||
properties. Attempt kubectl explain; the output MUST contain a valid DESCRIPTION stanza.
|
||||
*/
|
||||
@ -186,8 +186,8 @@ var _ = SIGDescribe("CustomResourcePublishOpenAPI [Privileged:ClusterAdmin]", fu
|
||||
|
||||
/*
|
||||
Release: v1.16
|
||||
Testname: Custom Resource OpenAPI Publish, with x-preserve-unknown-fields at root
|
||||
Description: Register a custom resource definition with x-preserve-unknown-fields in the schema root.
|
||||
Testname: Custom Resource OpenAPI Publish, with x-kubernetes-preserve-unknown-fields at root
|
||||
Description: Register a custom resource definition with x-kubernetes-preserve-unknown-fields in the schema root.
|
||||
Attempt to create and apply a change a custom resource, via kubectl; kubectl validation MUST accept unknown
|
||||
properties. Attempt kubectl explain; the output MUST show the custom resource KIND.
|
||||
*/
|
||||
@ -227,8 +227,8 @@ var _ = SIGDescribe("CustomResourcePublishOpenAPI [Privileged:ClusterAdmin]", fu
|
||||
|
||||
/*
|
||||
Release: v1.16
|
||||
Testname: Custom Resource OpenAPI Publish, with x-preserve-unknown-fields in embedded object
|
||||
Description: Register a custom resource definition with x-preserve-unknown-fields in an embedded object.
|
||||
Testname: Custom Resource OpenAPI Publish, with x-kubernetes-preserve-unknown-fields in embedded object
|
||||
Description: Register a custom resource definition with x-kubernetes-preserve-unknown-fields in an embedded object.
|
||||
Attempt to create and apply a change a custom resource, via kubectl; kubectl validation MUST accept unknown
|
||||
properties. Attempt kubectl explain; the output MUST show that x-preserve-unknown-properties is used on the
|
||||
nested field.
|
||||
|
Loading…
Reference in New Issue
Block a user