Skip to content
Open
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
8 changes: 5 additions & 3 deletions api/v1/clusterextension_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,12 +176,14 @@ type ClusterExtensionConfig struct {
// inline contains JSON or YAML values specified directly in the
// ClusterExtension.
//
// inline must be set if configType is 'Inline'.
// inline accepts arbitrary JSON/YAML objects.
// inline is validation at runtime against the schema provided by the bundle if a schema is provided.
// inline is used to specify arbitrary configuration values for the ClusterExtension.
// It must be set if configType is 'Inline' and must be a valid JSON/YAML object containing at least one property.
// The configuration values are validated at runtime against a JSON schema provided by the bundle.
//
// +kubebuilder:validation:Type=object
// +kubebuilder:validation:MinProperties=1
// +optional
// +unionMember
Copy link
Contributor

Choose a reason for hiding this comment

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

Adding this did not produce any change on CRD, should it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great call out! I went poking about and here's what I found out (with the help of Gemini):

Annotation Effect on CRD Schema Notes
// +union None (Visible) Treated as documentation only.
// +unionMember None Fields remain standard optional pointers.
// +unionDiscriminator None (usually) Does not automatically generate an Enum or validation.

This means that the CEL expressions must be manually created to enforce

While controller-gen generates no visible effect, in client-gen they seem to be used.

If you are generating a full-blown Kubernetes Clientset (using k8s.io/code-generator rather than just controller-runtime), these annotations become functional.

Specifically, they affect the generation of ApplyConfigurations.

    When using Server-Side Apply (SSA) in Go code, the generated ApplyConfiguration structs need to know if a field is a union.

    If tagged correctly, the generated Go client code for "applying" the object will know to clear the other fields in the union when you set a new one.

It also suggests to keep them for other developers to make the intent clear to other developers (not a huge argument for me since it's pretty clear anyway, but ok...)

Inline *apiextensionsv1.JSON `json:"inline,omitempty"`
}

Expand Down
2 changes: 1 addition & 1 deletion docs/api-reference/olmv1-api-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ _Appears in:_
| Field | Description | Default | Validation |
| --- | --- | --- | --- |
| `configType` _[ClusterExtensionConfigType](#clusterextensionconfigtype)_ | configType is a required reference to the type of configuration source.<br />Allowed values are "Inline"<br />When this field is set to "Inline", the cluster extension configuration is defined inline within the<br />ClusterExtension resource. | | Enum: [Inline] <br />Required: \{\} <br /> |
| `inline` _[JSON](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.31/#json-v1-apiextensions-k8s-io)_ | inline contains JSON or YAML values specified directly in the<br />ClusterExtension.<br />inline must be set if configType is 'Inline'.<br />inline accepts arbitrary JSON/YAML objects.<br />inline is validation at runtime against the schema provided by the bundle if a schema is provided. | | Type: object <br /> |
| `inline` _[JSON](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.31/#json-v1-apiextensions-k8s-io)_ | inline contains JSON or YAML values specified directly in the<br />ClusterExtension.<br />inline is used to specify arbitrary configuration values for the ClusterExtension.<br />It must be set if configType is 'Inline' and must be a valid JSON/YAML object containing at least one property.<br />The configuration values are validated at runtime against a JSON schema provided by the bundle. | | MinProperties: 1 <br />Type: object <br /> |


#### ClusterExtensionConfigType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,10 @@ spec:
inline contains JSON or YAML values specified directly in the
ClusterExtension.

inline must be set if configType is 'Inline'.
inline accepts arbitrary JSON/YAML objects.
inline is validation at runtime against the schema provided by the bundle if a schema is provided.
inline is used to specify arbitrary configuration values for the ClusterExtension.
It must be set if configType is 'Inline' and must be a valid JSON/YAML object containing at least one property.
The configuration values are validated at runtime against a JSON schema provided by the bundle.
minProperties: 1
type: object
x-kubernetes-preserve-unknown-fields: true
required:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -462,9 +462,18 @@ func Test_ClusterExtensionAdmissionInlineConfig(t *testing.T) {
errMsg: "spec.config.inline in body must be of type object",
},
{
name: "accepts valid json object",
name: "rejects empty json object",
configBytes: []byte(`{}`),
errMsg: "spec.config.inline in body should have at least 1 properties",
},
{
name: "accepts valid json object with configuration",
configBytes: []byte(`{"key": "value"}`),
},
{
name: "accepts valid json object with nested configuration",
configBytes: []byte(`{"key": {"foo": ["bar", "baz"], "h4x0r": 1337}}`),
},
} {
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
Expand Down
7 changes: 4 additions & 3 deletions manifests/experimental-e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -981,9 +981,10 @@ spec:
inline contains JSON or YAML values specified directly in the
ClusterExtension.

inline must be set if configType is 'Inline'.
inline accepts arbitrary JSON/YAML objects.
inline is validation at runtime against the schema provided by the bundle if a schema is provided.
inline is used to specify arbitrary configuration values for the ClusterExtension.
It must be set if configType is 'Inline' and must be a valid JSON/YAML object containing at least one property.
The configuration values are validated at runtime against a JSON schema provided by the bundle.
minProperties: 1
type: object
x-kubernetes-preserve-unknown-fields: true
required:
Expand Down
7 changes: 4 additions & 3 deletions manifests/experimental.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -946,9 +946,10 @@ spec:
inline contains JSON or YAML values specified directly in the
ClusterExtension.

inline must be set if configType is 'Inline'.
inline accepts arbitrary JSON/YAML objects.
inline is validation at runtime against the schema provided by the bundle if a schema is provided.
inline is used to specify arbitrary configuration values for the ClusterExtension.
It must be set if configType is 'Inline' and must be a valid JSON/YAML object containing at least one property.
The configuration values are validated at runtime against a JSON schema provided by the bundle.
minProperties: 1
type: object
x-kubernetes-preserve-unknown-fields: true
required:
Expand Down
Loading