From 8e30be30de02118ab43e12f45304039419d55ff3 Mon Sep 17 00:00:00 2001 From: Jakub Scholz Date: Tue, 10 Sep 2024 10:30:02 +0200 Subject: [PATCH] Add `OneOf` constraint to Connect external configuration (#10560) Signed-off-by: Jakub Scholz --- .../ExternalConfigurationEnvVarSource.java | 4 ++-- .../ExternalConfigurationVolumeSource.java | 4 ++-- .../crds/041-Crd-kafkaconnect.yaml | 18 ++++++++++++++++++ .../crds/048-Crd-kafkamirrormaker2.yaml | 18 ++++++++++++++++++ .../cluster-operator/041-Crd-kafkaconnect.yaml | 18 ++++++++++++++++++ .../048-Crd-kafkamirrormaker2.yaml | 18 ++++++++++++++++++ 6 files changed, 76 insertions(+), 4 deletions(-) diff --git a/api/src/main/java/io/strimzi/api/kafka/model/connect/ExternalConfigurationEnvVarSource.java b/api/src/main/java/io/strimzi/api/kafka/model/connect/ExternalConfigurationEnvVarSource.java index 9afd846f25f..57edcf3d58b 100644 --- a/api/src/main/java/io/strimzi/api/kafka/model/connect/ExternalConfigurationEnvVarSource.java +++ b/api/src/main/java/io/strimzi/api/kafka/model/connect/ExternalConfigurationEnvVarSource.java @@ -12,6 +12,7 @@ import io.strimzi.api.kafka.model.common.UnknownPropertyPreserving; import io.strimzi.crdgenerator.annotations.Description; import io.strimzi.crdgenerator.annotations.KubeLink; +import io.strimzi.crdgenerator.annotations.OneOf; import io.sundr.builder.annotations.Buildable; import lombok.EqualsAndHashCode; import lombok.ToString; @@ -28,6 +29,7 @@ ) @JsonInclude(JsonInclude.Include.NON_DEFAULT) @JsonPropertyOrder({"secretKeyRef", "configMapKeyRef"}) +@OneOf({@OneOf.Alternative(@OneOf.Alternative.Property("secretKeyRef")), @OneOf.Alternative(@OneOf.Alternative.Property("configMapKeyRef"))}) @EqualsAndHashCode @ToString public class ExternalConfigurationEnvVarSource implements UnknownPropertyPreserving { @@ -35,8 +37,6 @@ public class ExternalConfigurationEnvVarSource implements UnknownPropertyPreserv private ConfigMapKeySelector configMapKeyRef; private Map additionalProperties; - // TODO: We should make it possible to generate a CRD configuring that exactly one of secretKeyRef and configMapKeyRef has to be defined. - @Description("Reference to a key in a Secret.") @KubeLink(group = "core", version = "v1", kind = "secretkeyselector") @JsonInclude(value = JsonInclude.Include.NON_NULL) diff --git a/api/src/main/java/io/strimzi/api/kafka/model/connect/ExternalConfigurationVolumeSource.java b/api/src/main/java/io/strimzi/api/kafka/model/connect/ExternalConfigurationVolumeSource.java index 538e55368c0..ef1b3ac606f 100644 --- a/api/src/main/java/io/strimzi/api/kafka/model/connect/ExternalConfigurationVolumeSource.java +++ b/api/src/main/java/io/strimzi/api/kafka/model/connect/ExternalConfigurationVolumeSource.java @@ -13,6 +13,7 @@ import io.strimzi.api.kafka.model.common.UnknownPropertyPreserving; import io.strimzi.crdgenerator.annotations.Description; import io.strimzi.crdgenerator.annotations.KubeLink; +import io.strimzi.crdgenerator.annotations.OneOf; import io.sundr.builder.annotations.Buildable; import lombok.EqualsAndHashCode; import lombok.ToString; @@ -29,6 +30,7 @@ ) @JsonInclude(JsonInclude.Include.NON_DEFAULT) @JsonPropertyOrder({"name", "secret", "configMap"}) +@OneOf({@OneOf.Alternative(@OneOf.Alternative.Property("secret")), @OneOf.Alternative(@OneOf.Alternative.Property("configMap"))}) @EqualsAndHashCode @ToString public class ExternalConfigurationVolumeSource implements UnknownPropertyPreserving { @@ -47,8 +49,6 @@ public void setName(String name) { this.name = name; } - // TODO: We should make it possible to generate a CRD configuring that exactly one of secret and configMap has to be defined. - @Description("Reference to a key in a Secret. " + "Exactly one Secret or ConfigMap has to be specified.") @KubeLink(group = "core", version = "v1", kind = "secretvolumesource") diff --git a/packaging/helm-charts/helm3/strimzi-kafka-operator/crds/041-Crd-kafkaconnect.yaml b/packaging/helm-charts/helm3/strimzi-kafka-operator/crds/041-Crd-kafkaconnect.yaml index 9c3ebce27ba..79cd86b63d7 100644 --- a/packaging/helm-charts/helm3/strimzi-kafka-operator/crds/041-Crd-kafkaconnect.yaml +++ b/packaging/helm-charts/helm3/strimzi-kafka-operator/crds/041-Crd-kafkaconnect.yaml @@ -2213,6 +2213,15 @@ spec: optional: type: boolean description: Reference to a key in a ConfigMap. + oneOf: + - properties: + secretKeyRef: {} + required: + - secretKeyRef + - properties: + configMapKeyRef: {} + required: + - configMapKeyRef description: Value of the environment variable which will be passed to the Kafka Connect pods. It can be passed either as a reference to Secret or ConfigMap field. The field has to specify exactly one Secret or ConfigMap. required: - name @@ -2268,6 +2277,15 @@ spec: optional: type: boolean description: Reference to a key in a ConfigMap. Exactly one Secret or ConfigMap has to be specified. + oneOf: + - properties: + secret: {} + required: + - secret + - properties: + configMap: {} + required: + - configMap required: - name description: Makes data from a Secret or ConfigMap available in the Kafka Connect pods as volumes. diff --git a/packaging/helm-charts/helm3/strimzi-kafka-operator/crds/048-Crd-kafkamirrormaker2.yaml b/packaging/helm-charts/helm3/strimzi-kafka-operator/crds/048-Crd-kafkamirrormaker2.yaml index 08e3a6757dd..64c4e4189e6 100644 --- a/packaging/helm-charts/helm3/strimzi-kafka-operator/crds/048-Crd-kafkamirrormaker2.yaml +++ b/packaging/helm-charts/helm3/strimzi-kafka-operator/crds/048-Crd-kafkamirrormaker2.yaml @@ -2358,6 +2358,15 @@ spec: optional: type: boolean description: Reference to a key in a ConfigMap. + oneOf: + - properties: + secretKeyRef: {} + required: + - secretKeyRef + - properties: + configMapKeyRef: {} + required: + - configMapKeyRef description: Value of the environment variable which will be passed to the Kafka Connect pods. It can be passed either as a reference to Secret or ConfigMap field. The field has to specify exactly one Secret or ConfigMap. required: - name @@ -2413,6 +2422,15 @@ spec: optional: type: boolean description: Reference to a key in a ConfigMap. Exactly one Secret or ConfigMap has to be specified. + oneOf: + - properties: + secret: {} + required: + - secret + - properties: + configMap: {} + required: + - configMap required: - name description: Makes data from a Secret or ConfigMap available in the Kafka Connect pods as volumes. diff --git a/packaging/install/cluster-operator/041-Crd-kafkaconnect.yaml b/packaging/install/cluster-operator/041-Crd-kafkaconnect.yaml index c538523dced..f185b3e0056 100644 --- a/packaging/install/cluster-operator/041-Crd-kafkaconnect.yaml +++ b/packaging/install/cluster-operator/041-Crd-kafkaconnect.yaml @@ -2212,6 +2212,15 @@ spec: optional: type: boolean description: Reference to a key in a ConfigMap. + oneOf: + - properties: + secretKeyRef: {} + required: + - secretKeyRef + - properties: + configMapKeyRef: {} + required: + - configMapKeyRef description: Value of the environment variable which will be passed to the Kafka Connect pods. It can be passed either as a reference to Secret or ConfigMap field. The field has to specify exactly one Secret or ConfigMap. required: - name @@ -2267,6 +2276,15 @@ spec: optional: type: boolean description: Reference to a key in a ConfigMap. Exactly one Secret or ConfigMap has to be specified. + oneOf: + - properties: + secret: {} + required: + - secret + - properties: + configMap: {} + required: + - configMap required: - name description: Makes data from a Secret or ConfigMap available in the Kafka Connect pods as volumes. diff --git a/packaging/install/cluster-operator/048-Crd-kafkamirrormaker2.yaml b/packaging/install/cluster-operator/048-Crd-kafkamirrormaker2.yaml index d07988530a8..ce802a9a163 100644 --- a/packaging/install/cluster-operator/048-Crd-kafkamirrormaker2.yaml +++ b/packaging/install/cluster-operator/048-Crd-kafkamirrormaker2.yaml @@ -2357,6 +2357,15 @@ spec: optional: type: boolean description: Reference to a key in a ConfigMap. + oneOf: + - properties: + secretKeyRef: {} + required: + - secretKeyRef + - properties: + configMapKeyRef: {} + required: + - configMapKeyRef description: Value of the environment variable which will be passed to the Kafka Connect pods. It can be passed either as a reference to Secret or ConfigMap field. The field has to specify exactly one Secret or ConfigMap. required: - name @@ -2412,6 +2421,15 @@ spec: optional: type: boolean description: Reference to a key in a ConfigMap. Exactly one Secret or ConfigMap has to be specified. + oneOf: + - properties: + secret: {} + required: + - secret + - properties: + configMap: {} + required: + - configMap required: - name description: Makes data from a Secret or ConfigMap available in the Kafka Connect pods as volumes.