From b25ea4f731249e566f67a9703ad93836f123add2 Mon Sep 17 00:00:00 2001 From: Wojciech Trocki Date: Mon, 15 Mar 2021 15:26:07 +0000 Subject: [PATCH 1/5] BREAKING: Add metadata container for the KafkaConnection Motivation We constantly breaking API for the Kubernetes objects. This is not very good for already existing users using the objects. When we merge to the OpenShift console we will be locked with the API changes. This change adds all extra (mostly quarkus specific values from managed kafka to the metadata container). Those values are needed but if quarkus team will want use to add anything or rename things we will not break OpenShift console integration or bump version of the CR that will make this integration redundant. --- .../rhoas-operator.kafkaconnections.crd.yaml | 19 +++---- source/model/pom.xml | 13 +++-- .../v1alpha/models/KafkaConnectionStatus.java | 51 ++++--------------- .../cloud/v1alpha/models/UserKafka.java | 1 - .../KafkaConnectionController.java | 5 +- .../utils/ConnectionResourcesMetadata.java | 27 ++++++++++ .../src/main/resources/application.properties | 7 ++- 7 files changed, 63 insertions(+), 60 deletions(-) create mode 100644 source/rhoas/src/main/java/com/openshift/cloud/utils/ConnectionResourcesMetadata.java diff --git a/olm/olm-template/manifests/rhoas-operator.kafkaconnections.crd.yaml b/olm/olm-template/manifests/rhoas-operator.kafkaconnections.crd.yaml index e1d880aa..c1681827 100644 --- a/olm/olm-template/manifests/rhoas-operator.kafkaconnections.crd.yaml +++ b/olm/olm-template/manifests/rhoas-operator.kafkaconnections.crd.yaml @@ -3,13 +3,16 @@ kind: CustomResourceDefinition metadata: name: kafkaconnections.rhoas.redhat.com annotations: - service.binding/host: 'path={.status.bootstrapServerHost}' + service.binding/bootstrapServers: 'path={.status.bootstrapServerHost}' service.binding/password: >- path={.status.serviceAccountSecretName},objectType=Secret,sourceKey=client-secret service.binding/user: >- path={.status.serviceAccountSecretName},objectType=Secret,sourceKey=client-id - service.binding/saslMechanism: 'path={.status.saslMechanism}' - service.binding/securityProtocol: 'path={.status.securityProtocol}' + ## Additional binding metadata required for Quarkus + service.binding/saslMechanism: 'path={.status.metadata.saslMechanism}' + service.binding/securityProtocol: 'path={.status.metadata.securityProtocol}' + service.binding/type: 'path={.status.metadata.type}' + service.binding/provider: 'path={.status.metadata.provider}' spec: group: rhoas.redhat.com names: @@ -45,9 +48,9 @@ spec: message: nullable: true type: string - uiRef: + metadata: nullable: true - type: string + type: object updated: nullable: true type: string @@ -57,12 +60,6 @@ spec: serviceAccountSecretName: nullable: true type: string - saslMechanism: - nullable: true - type: string - securityProtocol: - nullable: true - type: string conditions: type: array items: diff --git a/source/model/pom.xml b/source/model/pom.xml index 20fcba61..4d95c93f 100755 --- a/source/model/pom.xml +++ b/source/model/pom.xml @@ -22,9 +22,16 @@ - io.dekorate - crd-annotations - ${dekorate.version} + io.fabric8 + crd-generator + compile + 5.1.1 + + + + io.fabric8 + kubernetes-model-common + 4.12.0 io.sundr diff --git a/source/model/src/main/java/com/openshift/cloud/v1alpha/models/KafkaConnectionStatus.java b/source/model/src/main/java/com/openshift/cloud/v1alpha/models/KafkaConnectionStatus.java index 9ae27de1..199aa824 100755 --- a/source/model/src/main/java/com/openshift/cloud/v1alpha/models/KafkaConnectionStatus.java +++ b/source/model/src/main/java/com/openshift/cloud/v1alpha/models/KafkaConnectionStatus.java @@ -1,22 +1,20 @@ package com.openshift.cloud.v1alpha.models; import io.sundr.builder.annotations.Buildable; + +import java.util.HashMap; import java.util.List; +import java.util.Map; @Buildable public class KafkaConnectionStatus { - private static final String UI_REF_TEMPLATE = - "https://cloud.redhat.com/beta/application-services/openshift-streams/kafkas/%s"; - private String message; private String updated; private String bootstrapServerHost; private String serviceAccountSecretName; - private String saslMechanism; - private String securityProtocol; - private String uiRef; private List conditions; + private Map metadata; /** No args constructor for use in serialization */ public KafkaConnectionStatus() {} @@ -24,7 +22,7 @@ public KafkaConnectionStatus() {} /** * @param serviceAccountSecretName * @param message - * @param boostrapServer + * @param bootstrapServerHost * @param updated */ public KafkaConnectionStatus( @@ -34,8 +32,7 @@ public KafkaConnectionStatus( this.updated = updated; this.bootstrapServerHost = bootstrapServerHost; this.serviceAccountSecretName = serviceAccountSecretName; - this.saslMechanism = "PLAINTEXT"; - this.securityProtocol = "SASL_SSL"; + this.metadata = new HashMap(); } public String getMessage() { @@ -62,22 +59,6 @@ public void setServiceAccountSecretName(String serviceAccountSecretName) { this.serviceAccountSecretName = serviceAccountSecretName; } - public String getSecurityProtocol() { - return securityProtocol; - } - - public void setSecurityProtocol(String securityProtocol) { - this.securityProtocol = securityProtocol; - } - - public String getSaslMechanism() { - return saslMechanism; - } - - public void setSaslMechanism(String saslMechanism) { - this.saslMechanism = saslMechanism; - } - public List getConditions() { return conditions; } @@ -94,23 +75,11 @@ public void setBootstrapServerHost(String bootstrapServerHost) { this.bootstrapServerHost = bootstrapServerHost; } - public String getUiRef() { - return uiRef; + public Map getMetadata() { + return metadata; } - public void setUiRef(String uiRef) { - this.uiRef = uiRef; - } - - /** - * Set the UI ref with a templated using a kafka ID - * - *

The template is - * "https://cloud.redhat.com/beta/application-services/openshift-streams/kafkas/%s" - * - * @param kafkaId the value to replace - */ - public void setUiRefForKafkaId(String kafkaId) { - this.uiRef = String.format(UI_REF_TEMPLATE, kafkaId); + public void setMetadata(Map metadata) { + this.metadata = metadata; } } diff --git a/source/model/src/main/java/com/openshift/cloud/v1alpha/models/UserKafka.java b/source/model/src/main/java/com/openshift/cloud/v1alpha/models/UserKafka.java index b335a48d..192463e1 100755 --- a/source/model/src/main/java/com/openshift/cloud/v1alpha/models/UserKafka.java +++ b/source/model/src/main/java/com/openshift/cloud/v1alpha/models/UserKafka.java @@ -18,7 +18,6 @@ public UserKafka() {} /** * @param owner * @param provider - * @param created * @param id * @param region */ diff --git a/source/rhoas/src/main/java/com/openshift/cloud/controllers/KafkaConnectionController.java b/source/rhoas/src/main/java/com/openshift/cloud/controllers/KafkaConnectionController.java index 733f3939..4a651ea1 100644 --- a/source/rhoas/src/main/java/com/openshift/cloud/controllers/KafkaConnectionController.java +++ b/source/rhoas/src/main/java/com/openshift/cloud/controllers/KafkaConnectionController.java @@ -2,6 +2,7 @@ import com.openshift.cloud.beans.AccessTokenSecretTool; import com.openshift.cloud.beans.KafkaApiClient; +import com.openshift.cloud.utils.ConnectionResourcesMetadata; import com.openshift.cloud.v1alpha.models.KafkaConnection; import io.javaoperatorsdk.operator.api.*; import io.javaoperatorsdk.operator.processing.event.EventSourceManager; @@ -50,9 +51,7 @@ public UpdateControl createOrUpdateResource( status.setUpdated(Instant.now().toString()); status.setBootstrapServerHost(bootStrapHost); status.setServiceAccountSecretName(serviceAccountSecretName); - status.setUiRefForKafkaId(kafkaId); - status.setSaslMechanism("PLAIN"); - status.setSecurityProtocol("SASL_SSL"); + status.setMetadata(ConnectionResourcesMetadata.buildKafkaMetadata(kafkaId)); ConditionUtil.setAllConditionsTrue(resource.getStatus().getConditions()); } catch (ConditionAwareException e) { diff --git a/source/rhoas/src/main/java/com/openshift/cloud/utils/ConnectionResourcesMetadata.java b/source/rhoas/src/main/java/com/openshift/cloud/utils/ConnectionResourcesMetadata.java new file mode 100644 index 00000000..d51aa52d --- /dev/null +++ b/source/rhoas/src/main/java/com/openshift/cloud/utils/ConnectionResourcesMetadata.java @@ -0,0 +1,27 @@ +package com.openshift.cloud.utils; + +import java.util.HashMap; +import java.util.Map; + +/** Contains generic metadata for the resource connection instances */ +public class ConnectionResourcesMetadata { + + private static final String UI_REF_TEMPLATE = + "https://cloud.redhat.com/beta/application-services/openshift-streams/kafkas/%s"; + + /** + * Contains hardcoded values for all metadata for Kafka specific properties + * + * @param kafkaId + * @return + */ + public static Map buildKafkaMetadata(String kafkaId) { + var map = new HashMap(); + map.put("saslMechanism", "PLAIN"); + map.put("securityProtocol", "SASL_SSL"); + map.put("cloudUI", String.format(UI_REF_TEMPLATE, kafkaId)); + map.put("provider", "rhoas"); + map.put("type", "kafka"); + return map; + } +} diff --git a/source/rhoas/src/main/resources/application.properties b/source/rhoas/src/main/resources/application.properties index 80178d19..b5f7ff49 100644 --- a/source/rhoas/src/main/resources/application.properties +++ b/source/rhoas/src/main/resources/application.properties @@ -6,9 +6,14 @@ quarkus.container-image.name=service-operator quarkus.container-image.tag=0.0.10 ##overide on cli to push to registry + quarkus.container-image.push=false quarkus.container-image.registry=quay.io ## TODO Remove this when OLM is updated ## it is a workaround for a resources issue -quarkus.jib.jvm-arguments=-Xmx64m,-Xms32m \ No newline at end of file +quarkus.jib.jvm-arguments=-Xmx64m,-Xms32m + +## Local dev options +### Configure to watch only single namespace +# quarkus.operator-sdk.controllers.annotation.namespaces=rhoas-sandbox \ No newline at end of file From c87a0cb7f75a2a728ba7ed0e9d5ec43c34cf700f Mon Sep 17 00:00:00 2001 From: Wojciech Trocki Date: Mon, 15 Mar 2021 15:35:31 +0000 Subject: [PATCH 2/5] fix: remove dekorate integration --- source/model/pom.xml | 30 ++++++++----------- .../models/CloudServiceAccountRequest.java | 1 - .../v1alpha/models/CloudServicesRequest.java | 2 -- .../cloud/v1alpha/models/KafkaConnection.java | 2 -- 4 files changed, 12 insertions(+), 23 deletions(-) diff --git a/source/model/pom.xml b/source/model/pom.xml index 4d95c93f..9c0c8e1d 100755 --- a/source/model/pom.xml +++ b/source/model/pom.xml @@ -15,24 +15,11 @@ 5.0.0 1.7.0 1.11.0.Final - 2.0.0.beta3 0.24.1 - - io.fabric8 - crd-generator - compile - 5.1.1 - - - - io.fabric8 - kubernetes-model-common - 4.12.0 - io.sundr builder-annotations @@ -43,13 +30,20 @@ io.fabric8 - kubernetes-client - ${fabric8.version} + crd-generator + compile + 5.1.1 + - io.dekorate - crd-annotations - true + io.fabric8 + kubernetes-model-common + 4.12.0 + + + io.fabric8 + kubernetes-client + ${fabric8.version} io.sundr diff --git a/source/model/src/main/java/com/openshift/cloud/v1alpha/models/CloudServiceAccountRequest.java b/source/model/src/main/java/com/openshift/cloud/v1alpha/models/CloudServiceAccountRequest.java index a5f093b4..d2619e01 100755 --- a/source/model/src/main/java/com/openshift/cloud/v1alpha/models/CloudServiceAccountRequest.java +++ b/source/model/src/main/java/com/openshift/cloud/v1alpha/models/CloudServiceAccountRequest.java @@ -13,7 +13,6 @@ @Plural("cloudserviceaccountrequests") @Group("rhoas.redhat.com") @Version("v1alpha1") -@Crd(group = "rhoas.redhat.com", version = "v1alpha1") public class CloudServiceAccountRequest extends CustomResource implements Namespaced { diff --git a/source/model/src/main/java/com/openshift/cloud/v1alpha/models/CloudServicesRequest.java b/source/model/src/main/java/com/openshift/cloud/v1alpha/models/CloudServicesRequest.java index 5986c1db..6e18fd66 100755 --- a/source/model/src/main/java/com/openshift/cloud/v1alpha/models/CloudServicesRequest.java +++ b/source/model/src/main/java/com/openshift/cloud/v1alpha/models/CloudServicesRequest.java @@ -1,6 +1,5 @@ package com.openshift.cloud.v1alpha.models; -import io.dekorate.crd.annotation.Crd; import io.fabric8.kubernetes.api.model.Namespaced; import io.fabric8.kubernetes.client.CustomResource; import io.fabric8.kubernetes.model.annotation.Group; @@ -13,7 +12,6 @@ @Plural("cloudservicesrequests") @Group("rhoas.redhat.com") @Version("v1alpha1") -@Crd(group = "rhoas.redhat.com", version = "v1alpha1") public class CloudServicesRequest extends CustomResource implements Namespaced { diff --git a/source/model/src/main/java/com/openshift/cloud/v1alpha/models/KafkaConnection.java b/source/model/src/main/java/com/openshift/cloud/v1alpha/models/KafkaConnection.java index 742159d6..6581b9b1 100755 --- a/source/model/src/main/java/com/openshift/cloud/v1alpha/models/KafkaConnection.java +++ b/source/model/src/main/java/com/openshift/cloud/v1alpha/models/KafkaConnection.java @@ -1,6 +1,5 @@ package com.openshift.cloud.v1alpha.models; -import io.dekorate.crd.annotation.Crd; import io.fabric8.kubernetes.api.model.Namespaced; import io.fabric8.kubernetes.api.model.ObjectMeta; import io.fabric8.kubernetes.client.CustomResource; @@ -14,7 +13,6 @@ @Plural("kafkaconnections") @Group("rhoas.redhat.com") @Version("v1alpha1") -@Crd(group = "rhoas.redhat.com", version = "v1alpha1") public class KafkaConnection extends CustomResource implements Namespaced { From d42dbd90420c1d3e02dee32c2fd2074f4994aecc Mon Sep 17 00:00:00 2001 From: Wojciech Trocki Date: Mon, 15 Mar 2021 15:55:45 +0000 Subject: [PATCH 3/5] chore: disable generator because of bug Fatal error compiling: java.lang.IndexOutOfBoundsException: Index 0 out of bounds for length 0 -> [Help 1] --- source/model/pom.xml | 27 ++++++++++--------- .../models/CloudServiceAccountRequest.java | 1 - .../v1alpha/models/KafkaConnectionStatus.java | 4 +-- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/source/model/pom.xml b/source/model/pom.xml index 9c0c8e1d..9aa08696 100755 --- a/source/model/pom.xml +++ b/source/model/pom.xml @@ -16,6 +16,8 @@ 1.7.0 1.11.0.Final 0.24.1 + 5.2.0 + 5.1.0 @@ -28,18 +30,19 @@ - - io.fabric8 - crd-generator - compile - 5.1.1 - - - - io.fabric8 - kubernetes-model-common - 4.12.0 - + + + + + + + + + + + + + io.fabric8 kubernetes-client diff --git a/source/model/src/main/java/com/openshift/cloud/v1alpha/models/CloudServiceAccountRequest.java b/source/model/src/main/java/com/openshift/cloud/v1alpha/models/CloudServiceAccountRequest.java index d2619e01..2aa97da2 100755 --- a/source/model/src/main/java/com/openshift/cloud/v1alpha/models/CloudServiceAccountRequest.java +++ b/source/model/src/main/java/com/openshift/cloud/v1alpha/models/CloudServiceAccountRequest.java @@ -1,6 +1,5 @@ package com.openshift.cloud.v1alpha.models; -import io.dekorate.crd.annotation.Crd; import io.fabric8.kubernetes.api.model.Namespaced; import io.fabric8.kubernetes.client.CustomResource; import io.fabric8.kubernetes.model.annotation.Group; diff --git a/source/model/src/main/java/com/openshift/cloud/v1alpha/models/KafkaConnectionStatus.java b/source/model/src/main/java/com/openshift/cloud/v1alpha/models/KafkaConnectionStatus.java index 199aa824..7231176b 100755 --- a/source/model/src/main/java/com/openshift/cloud/v1alpha/models/KafkaConnectionStatus.java +++ b/source/model/src/main/java/com/openshift/cloud/v1alpha/models/KafkaConnectionStatus.java @@ -1,14 +1,12 @@ package com.openshift.cloud.v1alpha.models; import io.sundr.builder.annotations.Buildable; - import java.util.HashMap; import java.util.List; import java.util.Map; @Buildable public class KafkaConnectionStatus { - private String message; private String updated; private String bootstrapServerHost; @@ -32,7 +30,7 @@ public KafkaConnectionStatus( this.updated = updated; this.bootstrapServerHost = bootstrapServerHost; this.serviceAccountSecretName = serviceAccountSecretName; - this.metadata = new HashMap(); + this.metadata = new HashMap(); } public String getMessage() { From fff0eb4f31ab97d628a3d627fe994f533af730f7 Mon Sep 17 00:00:00 2001 From: Wojciech Trocki Date: Mon, 15 Mar 2021 17:18:52 +0000 Subject: [PATCH 4/5] chore: bump to version with problem resolved upstream --- olm/catalogsource.yaml | 4 ++-- source/model/pom.xml | 28 ++++++++++++++-------------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/olm/catalogsource.yaml b/olm/catalogsource.yaml index 16f3a474..69f46b1b 100644 --- a/olm/catalogsource.yaml +++ b/olm/catalogsource.yaml @@ -1,14 +1,14 @@ apiVersion: operators.coreos.com/v1alpha1 kind: CatalogSource metadata: - name: rhoas-operators + name: rhoas-operators2 namespace: openshift-marketplace spec: displayName: RHOAS Operators icon: base64data: "" mediatype: "" - image: quay.io/rhoasg/service-operator-registry:autolatest + image: quay.io/rhoas/service-operator-registry:autolatest priority: -400 publisher: RHOAS sourceType: grpc diff --git a/source/model/pom.xml b/source/model/pom.xml index 9aa08696..04140b0d 100755 --- a/source/model/pom.xml +++ b/source/model/pom.xml @@ -17,7 +17,7 @@ 1.11.0.Final 0.24.1 5.2.0 - 5.1.0 + 5.2.0 @@ -30,19 +30,19 @@ - - - - - - - - - - - - - + + io.fabric8 + crd-generator-apt + compile + ${fabric8.crdgen.version} + + + + io.fabric8 + kubernetes-model-common + compile + ${fabric8.models.version} + io.fabric8 kubernetes-client From ae34c06d05314f613365e37eb2b3e3f122cb62c3 Mon Sep 17 00:00:00 2001 From: Hoyt Summers Pittman Date: Mon, 15 Mar 2021 21:06:26 -0400 Subject: [PATCH 5/5] Update olm/olm-template/manifests/rhoas-operator.kafkaconnections.crd.yaml --- .../manifests/rhoas-operator.kafkaconnections.crd.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/olm/olm-template/manifests/rhoas-operator.kafkaconnections.crd.yaml b/olm/olm-template/manifests/rhoas-operator.kafkaconnections.crd.yaml index c1681827..8579088d 100644 --- a/olm/olm-template/manifests/rhoas-operator.kafkaconnections.crd.yaml +++ b/olm/olm-template/manifests/rhoas-operator.kafkaconnections.crd.yaml @@ -51,6 +51,7 @@ spec: metadata: nullable: true type: object + x-kubernetes-preserve-unknown-fields: true updated: nullable: true type: string