Merge pull request #111446 from alexzielenski/trivial-x-preserve-unknown-fields-correction

correct OpenAPI extension in error message
This commit is contained in:
Kubernetes Prow Robot 2022-07-30 05:06:27 -07:00 committed by GitHub
commit 262d8b2a77
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 20 additions and 18 deletions

View File

@ -1605,7 +1605,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
}

View File

@ -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,

View File

@ -775,7 +775,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'",
@ -785,7 +785,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'",
},

View File

@ -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{

View File

@ -246,20 +246,21 @@
update to reflect the rename.
release: v1.16
file: test/e2e/apimachinery/crd_publish_openapi.go
- 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
codename: '[sig-api-machinery] CustomResourcePublishOpenAPI [Privileged:ClusterAdmin]
works for CRD preserving unknown fields at the schema root [Conformance]'
description: Register a custom resource definition with x-preserve-unknown-fields
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.
release: v1.16
file: test/e2e/apimachinery/crd_publish_openapi.go
- 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
codename: '[sig-api-machinery] CustomResourcePublishOpenAPI [Privileged:ClusterAdmin]
works for CRD preserving unknown fields in an embedded object [Conformance]'
description: Register a custom resource definition with x-preserve-unknown-fields
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
@ -279,10 +280,11 @@
validation should be the same.
release: v1.16
file: test/e2e/apimachinery/crd_publish_openapi.go
- 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
codename: '[sig-api-machinery] CustomResourcePublishOpenAPI [Privileged:ClusterAdmin]
works for CRD without validation schema [Conformance]'
description: Register a custom resource definition with x-preserve-unknown-fields
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.

View File

@ -144,8 +144,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.
*/
@ -185,8 +185,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.
*/
@ -226,8 +226,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.