From 70c33c8c89a93e796029ddd0008c07c85f7999ff Mon Sep 17 00:00:00 2001 From: Jakub Hadvig Date: Thu, 5 Dec 2024 11:59:16 +0100 Subject: [PATCH] OCPBUGS-45295: Make plugins name array items unique --- .../generated_openapi/zz_generated.openapi.go | 5 ++++ openapi/openapi.json | 3 ++- .../AAA_ungated.yaml | 26 +++++++++++++++++++ operator/v1/types_console.go | 9 ++++++- .../0000_50_console_01_consoles.crd.yaml | 7 +++++ operator/v1/zz_generated.deepcopy.go | 2 +- .../AAA_ungated.yaml | 7 +++++ 7 files changed, 56 insertions(+), 3 deletions(-) diff --git a/openapi/generated_openapi/zz_generated.openapi.go b/openapi/generated_openapi/zz_generated.openapi.go index 719cf8994d6..f728fbf0463 100644 --- a/openapi/generated_openapi/zz_generated.openapi.go +++ b/openapi/generated_openapi/zz_generated.openapi.go @@ -46412,6 +46412,11 @@ func schema_openshift_api_operator_v1_ConsoleSpec(ref common.ReferenceCallback) }, }, "plugins": { + VendorExtensible: spec.VendorExtensible{ + Extensions: spec.Extensions{ + "x-kubernetes-list-type": "atomic", + }, + }, SchemaProps: spec.SchemaProps{ Description: "plugins defines a list of enabled console plugin names.", Type: []string{"array"}, diff --git a/openapi/openapi.json b/openapi/openapi.json index f43d3613467..39d74b9b4d2 100644 --- a/openapi/openapi.json +++ b/openapi/openapi.json @@ -27015,7 +27015,8 @@ "items": { "type": "string", "default": "" - } + }, + "x-kubernetes-list-type": "atomic" }, "providers": { "description": "providers contains configuration for using specific service providers.", diff --git a/operator/v1/tests/consoles.operator.openshift.io/AAA_ungated.yaml b/operator/v1/tests/consoles.operator.openshift.io/AAA_ungated.yaml index a59212c95b8..6765c4af296 100644 --- a/operator/v1/tests/consoles.operator.openshift.io/AAA_ungated.yaml +++ b/operator/v1/tests/consoles.operator.openshift.io/AAA_ungated.yaml @@ -296,3 +296,29 @@ tests: visibility: state: Enables expectedError: "spec.customization.capabilities[0].visibility.state: Unsupported value: \"Enables\": supported values: \"Enabled\", \"Disabled\"" + - name: Should be able to create a Console with multiple plugins + initial: | + apiVersion: operator.openshift.io/v1 + kind: Console + spec: + plugins: + - test-plugin-1 + - test-plugin-2 + expected: | + apiVersion: operator.openshift.io/v1 + kind: Console + spec: + logLevel: Normal + operatorLogLevel: Normal + plugins: + - test-plugin-1 + - test-plugin-2 + - name: Should throw an error for duplicate plugin name + initial: | + apiVersion: operator.openshift.io/v1 + kind: Console + spec: + plugins: + - test-plugin-1 + - test-plugin-1 + expectedError: "spec.plugins: Invalid value: \"array\": each plugin name must be unique" \ No newline at end of file diff --git a/operator/v1/types_console.go b/operator/v1/types_console.go index aa39b2f950f..e89a4306edb 100644 --- a/operator/v1/types_console.go +++ b/operator/v1/types_console.go @@ -55,8 +55,11 @@ type ConsoleSpec struct { // +optional Route ConsoleConfigRoute `json:"route"` // plugins defines a list of enabled console plugin names. + // +listType=atomic + // +kubebuilder:validation:MaxItems=64 + // +kubebuilder:validation:XValidation:rule="self.all(x, self.exists_one(y, x == y))",message="each plugin name must be unique" // +optional - Plugins []string `json:"plugins,omitempty"` + Plugins []PluginName `json:"plugins,omitempty"` // ingress allows to configure the alternative ingress for the console. // This field is intended for clusters without ingress capability, // where access to routes is not possible. @@ -64,6 +67,10 @@ type ConsoleSpec struct { Ingress Ingress `json:"ingress"` } +// +kubebuilder:validation:MaxLength=128 +// +kubebuilder:validation:Pattern=^[a-zA-Z0-9-]+$ +type PluginName string + // ConsoleConfigRoute holds information on external route access to console. // DEPRECATED type ConsoleConfigRoute struct { diff --git a/operator/v1/zz_generated.crd-manifests/0000_50_console_01_consoles.crd.yaml b/operator/v1/zz_generated.crd-manifests/0000_50_console_01_consoles.crd.yaml index 505332e4b54..a305e20cbbd 100644 --- a/operator/v1/zz_generated.crd-manifests/0000_50_console_01_consoles.crd.yaml +++ b/operator/v1/zz_generated.crd-manifests/0000_50_console_01_consoles.crd.yaml @@ -779,8 +779,15 @@ spec: plugins: description: plugins defines a list of enabled console plugin names. items: + maxLength: 128 + pattern: ^[a-zA-Z0-9-]+$ type: string + maxItems: 64 type: array + x-kubernetes-list-type: atomic + x-kubernetes-validations: + - message: each plugin name must be unique + rule: self.all(x, self.exists_one(y, x == y)) providers: description: providers contains configuration for using specific service providers. diff --git a/operator/v1/zz_generated.deepcopy.go b/operator/v1/zz_generated.deepcopy.go index 3b984f2a618..ae0c62dd809 100644 --- a/operator/v1/zz_generated.deepcopy.go +++ b/operator/v1/zz_generated.deepcopy.go @@ -1024,7 +1024,7 @@ func (in *ConsoleSpec) DeepCopyInto(out *ConsoleSpec) { out.Route = in.Route if in.Plugins != nil { in, out := &in.Plugins, &out.Plugins - *out = make([]string, len(*in)) + *out = make([]PluginName, len(*in)) copy(*out, *in) } out.Ingress = in.Ingress diff --git a/operator/v1/zz_generated.featuregated-crd-manifests/consoles.operator.openshift.io/AAA_ungated.yaml b/operator/v1/zz_generated.featuregated-crd-manifests/consoles.operator.openshift.io/AAA_ungated.yaml index 93d4f95fc0d..b09d3ec5e20 100644 --- a/operator/v1/zz_generated.featuregated-crd-manifests/consoles.operator.openshift.io/AAA_ungated.yaml +++ b/operator/v1/zz_generated.featuregated-crd-manifests/consoles.operator.openshift.io/AAA_ungated.yaml @@ -780,8 +780,15 @@ spec: plugins: description: plugins defines a list of enabled console plugin names. items: + maxLength: 128 + pattern: ^[a-zA-Z0-9-]+$ type: string + maxItems: 64 type: array + x-kubernetes-list-type: atomic + x-kubernetes-validations: + - message: each plugin name must be unique + rule: self.all(x, self.exists_one(y, x == y)) providers: description: providers contains configuration for using specific service providers.