mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-19 09:52:49 +00:00
Merge pull request #111446 from alexzielenski/trivial-x-preserve-unknown-fields-correction
correct OpenAPI extension in error message
This commit is contained in:
commit
262d8b2a77
@ -1605,7 +1605,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,
|
||||||
|
@ -775,7 +775,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'",
|
||||||
@ -785,7 +785,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{
|
||||||
|
16
test/conformance/testdata/conformance.yaml
vendored
16
test/conformance/testdata/conformance.yaml
vendored
@ -246,20 +246,21 @@
|
|||||||
update to reflect the rename.
|
update to reflect the rename.
|
||||||
release: v1.16
|
release: v1.16
|
||||||
file: test/e2e/apimachinery/crd_publish_openapi.go
|
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]
|
codename: '[sig-api-machinery] CustomResourcePublishOpenAPI [Privileged:ClusterAdmin]
|
||||||
works for CRD preserving unknown fields at the schema root [Conformance]'
|
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
|
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;
|
kubectl; kubectl validation MUST accept unknown properties. Attempt kubectl explain;
|
||||||
the output MUST show the custom resource KIND.
|
the output MUST show the custom resource KIND.
|
||||||
release: v1.16
|
release: v1.16
|
||||||
file: test/e2e/apimachinery/crd_publish_openapi.go
|
file: test/e2e/apimachinery/crd_publish_openapi.go
|
||||||
- testname: Custom Resource OpenAPI Publish, with x-preserve-unknown-fields in embedded
|
- testname: Custom Resource OpenAPI Publish, with x-kubernetes-preserve-unknown-fields
|
||||||
object
|
in embedded object
|
||||||
codename: '[sig-api-machinery] CustomResourcePublishOpenAPI [Privileged:ClusterAdmin]
|
codename: '[sig-api-machinery] CustomResourcePublishOpenAPI [Privileged:ClusterAdmin]
|
||||||
works for CRD preserving unknown fields in an embedded object [Conformance]'
|
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,
|
in an embedded object. Attempt to create and apply a change a custom resource,
|
||||||
via kubectl; kubectl validation MUST accept unknown properties. Attempt kubectl
|
via kubectl; kubectl validation MUST accept unknown properties. Attempt kubectl
|
||||||
explain; the output MUST show that x-preserve-unknown-properties is used on the
|
explain; the output MUST show that x-preserve-unknown-properties is used on the
|
||||||
@ -279,10 +280,11 @@
|
|||||||
validation should be the same.
|
validation should be the same.
|
||||||
release: v1.16
|
release: v1.16
|
||||||
file: test/e2e/apimachinery/crd_publish_openapi.go
|
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]
|
codename: '[sig-api-machinery] CustomResourcePublishOpenAPI [Privileged:ClusterAdmin]
|
||||||
works for CRD without validation schema [Conformance]'
|
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,
|
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
|
via kubectl; kubectl validation MUST accept unknown properties. Attempt kubectl
|
||||||
explain; the output MUST contain a valid DESCRIPTION stanza.
|
explain; the output MUST contain a valid DESCRIPTION stanza.
|
||||||
|
@ -144,8 +144,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.
|
||||||
*/
|
*/
|
||||||
@ -185,8 +185,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.
|
||||||
*/
|
*/
|
||||||
@ -226,8 +226,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