Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Add support for oneOf/anyOf/allOf/not ClusterClass variable schema constructs #10637

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions api/v1beta1/clusterclass_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,54 @@ type JSONSchemaProps struct {
// It can be used to add additional data for higher level tools.
// +optional
XMetadata *VariableSchemaMetadata `json:"x-metadata,omitempty"`

// x-kubernetes-int-or-string specifies that this value is
// either an integer or a string. If this is true, an empty
// type is allowed and type as child of anyOf is permitted
// if following one of the following patterns:
//
// 1) anyOf:
// - type: integer
// - type: string
// 2) allOf:
// - anyOf:
// - type: integer
// - type: string
// - ... zero or more
sbueringer marked this conversation as resolved.
Show resolved Hide resolved
// +optional
XIntOrString bool `json:"x-kubernetes-int-or-string,omitempty"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't this field break the naming convention of camelCase?
why not xIntOrString ?

Copy link
Member

@sbueringer sbueringer Sep 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our primary goal here is to keep this as consistent as possible with the Kubernetes CRD API type.

So basically that folks who are familiar with Kubernetes CRDs can write ~ the same schema with variables (without having to map keywords)

(That being said, I don't know the reasons why Kubernetes itself chose this format)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OpenAPI extensions are custom properties prefixed by x- and it seems it is more common to use kebab-case for these extensions in the wild than camelCase for these extensions as opposed to a mix like x-intOrString. I assume the kubernetes part is there to show this is a kubernetes specific openapi extension. More details at https://swagger.io/docs/specification/v3_0/openapi-extensions/.


// AllOf specifies that the variable must validate against all of the subschemas in the array.
sbueringer marked this conversation as resolved.
Show resolved Hide resolved
// NOTE: This field uses PreserveUnknownFields and Schemaless,
// because recursive validation is not possible.
// +optional
// +kubebuilder:pruning:PreserveUnknownFields
// +kubebuilder:validation:Schemaless
AllOf []JSONSchemaProps `json:"allOf,omitempty"`

// OneOf specifies that the variable must validate against exactly one of the subschemas in the array.
// NOTE: This field uses PreserveUnknownFields and Schemaless,
// because recursive validation is not possible.
// +optional
// +kubebuilder:pruning:PreserveUnknownFields
// +kubebuilder:validation:Schemaless
OneOf []JSONSchemaProps `json:"oneOf,omitempty"`

// AnyOf specifies that the variable must validate against one or more of the subschemas in the array.
// NOTE: This field uses PreserveUnknownFields and Schemaless,
// because recursive validation is not possible.
// +optional
// +kubebuilder:pruning:PreserveUnknownFields
// +kubebuilder:validation:Schemaless
AnyOf []JSONSchemaProps `json:"anyOf,omitempty"`

// Not specifies that the variable must not validate against the subschema.
// NOTE: This field uses PreserveUnknownFields and Schemaless,
// because recursive validation is not possible.
// +optional
// +kubebuilder:pruning:PreserveUnknownFields
// +kubebuilder:validation:Schemaless
Not *JSONSchemaProps `json:"not,omitempty"`
}

// VariableSchemaMetadata is the metadata of a variable or a nested field within a variable.
Expand Down
26 changes: 26 additions & 0 deletions api/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

55 changes: 55 additions & 0 deletions api/v1beta1/zz_generated.openapi.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

80 changes: 80 additions & 0 deletions config/crd/bases/cluster.x-k8s.io_clusterclasses.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading