Skip to content

Commit 8efea56

Browse files
authored
Merge pull request kubernetes#77207 from sttts/sttts-structural-schema
apiextensions: implement structural schema condition
2 parents b27fe7f + c836a25 commit 8efea56

File tree

26 files changed

+2640
-177
lines changed

26 files changed

+2640
-177
lines changed

api/api-rules/violation_exceptions.list

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ API rule violation: names_match,k8s.io/apiextensions-apiserver/pkg/apis/apiexten
3030
API rule violation: names_match,k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1,JSON,Raw
3131
API rule violation: names_match,k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1,JSONSchemaProps,Ref
3232
API rule violation: names_match,k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1,JSONSchemaProps,Schema
33+
API rule violation: names_match,k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1,JSONSchemaProps,XEmbeddedResource
34+
API rule violation: names_match,k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1,JSONSchemaProps,XIntOrString
35+
API rule violation: names_match,k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1,JSONSchemaProps,XPreserveUnknownFields
3336
API rule violation: names_match,k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1,JSONSchemaPropsOrArray,JSONSchemas
3437
API rule violation: names_match,k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1,JSONSchemaPropsOrArray,Schema
3538
API rule violation: names_match,k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1,JSONSchemaPropsOrBool,Allows

api/openapi-spec/swagger.json

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

staging/src/k8s.io/apiextensions-apiserver/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ filegroup(
4747
"//staging/src/k8s.io/apiextensions-apiserver/pkg/cmd/server:all-srcs",
4848
"//staging/src/k8s.io/apiextensions-apiserver/pkg/controller/establish:all-srcs",
4949
"//staging/src/k8s.io/apiextensions-apiserver/pkg/controller/finalizer:all-srcs",
50+
"//staging/src/k8s.io/apiextensions-apiserver/pkg/controller/nonstructuralschema:all-srcs",
5051
"//staging/src/k8s.io/apiextensions-apiserver/pkg/controller/openapi:all-srcs",
5152
"//staging/src/k8s.io/apiextensions-apiserver/pkg/controller/status:all-srcs",
5253
"//staging/src/k8s.io/apiextensions-apiserver/pkg/crdserverscheme:all-srcs",

staging/src/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/types.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,22 @@ const (
264264
// NamesAccepted means the names chosen for this CustomResourceDefinition do not conflict with others in
265265
// the group and are therefore accepted.
266266
NamesAccepted CustomResourceDefinitionConditionType = "NamesAccepted"
267+
// NonStructuralSchema means that one or more OpenAPI schema is not structural.
268+
//
269+
// A schema is structural if it specifies types for all values, with the only exceptions of those with
270+
// - x-kubernetes-int-or-string: true — for fields which can be integer or string
271+
// - x-kubernetes-preserve-unknown-fields: true — for raw, unspecified JSON values
272+
// and there is no type, additionalProperties, default, nullable or x-kubernetes-* vendor extenions
273+
// specified under allOf, anyOf, oneOf or not.
274+
//
275+
// Non-structural schemas will not be allowed anymore in v1 API groups. Moreover, new features will not be
276+
// available for non-structural CRDs:
277+
// - pruning
278+
// - defaulting
279+
// - read-only
280+
// - OpenAPI publishing
281+
// - webhook conversion
282+
NonStructuralSchema CustomResourceDefinitionConditionType = "NonStructuralSchema"
267283
// Terminating means that the CustomResourceDefinition has been deleted and is cleaning up.
268284
Terminating CustomResourceDefinitionConditionType = "Terminating"
269285
)

staging/src/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/types_jsonschema.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,36 @@ type JSONSchemaProps struct {
5555
Definitions JSONSchemaDefinitions
5656
ExternalDocs *ExternalDocumentation
5757
Example *JSON
58+
59+
// x-kubernetes-preserve-unknown-fields stops the API server
60+
// decoding step from pruning fields which are not specified
61+
// in the validation schema. This affects fields recursively,
62+
// but switches back to normal pruning behaviour if nested
63+
// properties or additionalProperties are specified in the schema.
64+
XPreserveUnknownFields bool
65+
66+
// x-kubernetes-embedded-resource defines that the value is an
67+
// embedded Kubernetes runtime.Object, with TypeMeta and
68+
// ObjectMeta. The type must be object. It is allowed to further
69+
// restrict the embedded object. Both ObjectMeta and TypeMeta
70+
// are validated automatically. x-kubernetes-preserve-unknown-fields
71+
// must be true.
72+
XEmbeddedResource bool
73+
74+
// x-kubernetes-int-or-string specifies that this value is
75+
// either an integer or a string. If this is true, an empty
76+
// type is allowed and type as child of anyOf is permitted
77+
// if following one of the following patterns:
78+
//
79+
// 1) anyOf:
80+
// - type: integer
81+
// - type: string
82+
// 2) allOf:
83+
// - anyOf:
84+
// - type: integer
85+
// - type: string
86+
// - ... zero or more
87+
XIntOrString bool
5888
}
5989

6090
// JSON represents any valid JSON value.

0 commit comments

Comments
 (0)