mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 03:11:40 +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
|
var errs field.ErrorList
|
||||||
if crd != nil && crd.Spec.PreserveUnknownFields != nil && *crd.Spec.PreserveUnknownFields {
|
if crd != nil && crd.Spec.PreserveUnknownFields != nil && *crd.Spec.PreserveUnknownFields {
|
||||||
// disallow changing spec.preserveUnknownFields=false to spec.preserveUnknownFields=true
|
// 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
|
return errs
|
||||||
}
|
}
|
||||||
|
@ -608,7 +608,7 @@ func TestCelCostStability(t *testing.T) {
|
|||||||
}),
|
}),
|
||||||
expectCost: map[string]int64{
|
expectCost: map[string]int64{
|
||||||
// 'kind', 'apiVersion', 'metadata.name' and 'metadata.generateName' are always accessible
|
// '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.kind == 'Pod'": 4,
|
||||||
"self.embedded.apiVersion == 'v1'": 4,
|
"self.embedded.apiVersion == 'v1'": 4,
|
||||||
"self.embedded.metadata.name == 'foo'": 5,
|
"self.embedded.metadata.name == 'foo'": 5,
|
||||||
|
@ -772,7 +772,7 @@ func TestValidationExpressions(t *testing.T) {
|
|||||||
}),
|
}),
|
||||||
valid: []string{
|
valid: []string{
|
||||||
// 'kind', 'apiVersion', 'metadata.name' and 'metadata.generateName' are always accessible
|
// '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.kind == 'Pod'",
|
||||||
"self.embedded.apiVersion == 'v1'",
|
"self.embedded.apiVersion == 'v1'",
|
||||||
"self.embedded.metadata.name == 'foo'",
|
"self.embedded.metadata.name == 'foo'",
|
||||||
@ -782,7 +782,7 @@ func TestValidationExpressions(t *testing.T) {
|
|||||||
"has(self.embedded)",
|
"has(self.embedded)",
|
||||||
},
|
},
|
||||||
// only field declared in the schema can be field selected in CEL expressions, regardless of if
|
// 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{
|
errors: map[string]string{
|
||||||
"has(self.embedded.spec)": "undefined field 'spec'",
|
"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.
|
// as an empty object.
|
||||||
if schema.XPreserveUnknownFields {
|
if schema.XPreserveUnknownFields {
|
||||||
return &unstructuredMap{
|
return &unstructuredMap{
|
||||||
|
@ -145,8 +145,8 @@ var _ = SIGDescribe("CustomResourcePublishOpenAPI [Privileged:ClusterAdmin]", fu
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
Release: v1.16
|
Release: v1.16
|
||||||
Testname: Custom Resource OpenAPI Publish, with x-preserve-unknown-fields in object
|
Testname: Custom Resource OpenAPI Publish, with x-kubernetes-preserve-unknown-fields in object
|
||||||
Description: Register a custom resource definition with x-preserve-unknown-fields in the top level 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
|
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.
|
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
|
Release: v1.16
|
||||||
Testname: Custom Resource OpenAPI Publish, with x-preserve-unknown-fields at root
|
Testname: Custom Resource OpenAPI Publish, with x-kubernetes-preserve-unknown-fields at root
|
||||||
Description: Register a custom resource definition with x-preserve-unknown-fields in the schema 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
|
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.
|
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
|
Release: v1.16
|
||||||
Testname: Custom Resource OpenAPI Publish, with x-preserve-unknown-fields in embedded object
|
Testname: Custom Resource OpenAPI Publish, with x-kubernetes-preserve-unknown-fields in embedded object
|
||||||
Description: Register a custom resource definition with x-preserve-unknown-fields in an 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
|
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
|
properties. Attempt kubectl explain; the output MUST show that x-preserve-unknown-properties is used on the
|
||||||
nested field.
|
nested field.
|
||||||
|
Loading…
Reference in New Issue
Block a user