Skip to content

Commit

Permalink
Merge pull request #131 from bf2fc6cc711aee1a0c2a/breaking-api
Browse files Browse the repository at this point in the history
BREAKING: Add metadata container for the KafkaConnection
  • Loading branch information
secondsun authored Mar 16, 2021
2 parents f332f69 + ae34c06 commit f41afea
Show file tree
Hide file tree
Showing 11 changed files with 70 additions and 77 deletions.
4 changes: 2 additions & 2 deletions olm/catalogsource.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -45,9 +48,10 @@ spec:
message:
nullable: true
type: string
uiRef:
metadata:
nullable: true
type: string
type: object
x-kubernetes-preserve-unknown-fields: true
updated:
nullable: true
type: string
Expand All @@ -57,12 +61,6 @@ spec:
serviceAccountSecretName:
nullable: true
type: string
saslMechanism:
nullable: true
type: string
securityProtocol:
nullable: true
type: string
conditions:
type: array
items:
Expand Down
26 changes: 15 additions & 11 deletions source/model/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,13 @@
<fabric8.version>5.0.0</fabric8.version>
<operator.sdk.version>1.7.0</operator.sdk.version>
<quarkus.version>1.11.0.Final</quarkus.version>
<dekorate.version>2.0.0.beta3</dekorate.version>
<sundrio.version>0.24.1</sundrio.version>
<fabric8.models.version>5.2.0</fabric8.models.version>
<fabric8.crdgen.version>5.2.0</fabric8.crdgen.version>

</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.dekorate</groupId>
<artifactId>crd-annotations</artifactId>
<version>${dekorate.version}</version>
</dependency>
<dependency>
<groupId>io.sundr</groupId>
<artifactId>builder-annotations</artifactId>
Expand All @@ -34,16 +30,24 @@
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>crd-generator-apt</artifactId>
<scope>compile</scope>
<version>${fabric8.crdgen.version}</version>
</dependency>
<!-- This dependency will not be needed anymore in a future release of the kubernetes-client -->
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>kubernetes-model-common</artifactId>
<scope>compile</scope>
<version>${fabric8.models.version}</version>
</dependency>
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>kubernetes-client</artifactId>
<version>${fabric8.version}</version>
</dependency>
<dependency>
<groupId>io.dekorate</groupId>
<artifactId>crd-annotations</artifactId>
<optional>true</optional> <!-- we need to keep this optional to avoid conflicts with quarkus-kubernetes -->
</dependency>
<dependency>
<groupId>io.sundr</groupId>
<artifactId>builder-annotations</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -13,7 +12,6 @@
@Plural("cloudserviceaccountrequests")
@Group("rhoas.redhat.com")
@Version("v1alpha1")
@Crd(group = "rhoas.redhat.com", version = "v1alpha1")
public class CloudServiceAccountRequest
extends CustomResource<CloudServiceAccountRequestSpec, CloudServiceAccountRequestStatus>
implements Namespaced {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -13,7 +12,6 @@
@Plural("cloudservicesrequests")
@Group("rhoas.redhat.com")
@Version("v1alpha1")
@Crd(group = "rhoas.redhat.com", version = "v1alpha1")
public class CloudServicesRequest
extends CustomResource<CloudServicesRequestSpec, CloudServicesRequestStatus>
implements Namespaced {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -14,7 +13,6 @@
@Plural("kafkaconnections")
@Group("rhoas.redhat.com")
@Version("v1alpha1")
@Crd(group = "rhoas.redhat.com", version = "v1alpha1")
public class KafkaConnection extends CustomResource<KafkaConnectionSpec, KafkaConnectionStatus>
implements Namespaced {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,26 @@
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<KafkaCondition> conditions;
private Map<String, String> metadata;

/** No args constructor for use in serialization */
public KafkaConnectionStatus() {}

/**
* @param serviceAccountSecretName
* @param message
* @param boostrapServer
* @param bootstrapServerHost
* @param updated
*/
public KafkaConnectionStatus(
Expand All @@ -34,8 +30,7 @@ public KafkaConnectionStatus(
this.updated = updated;
this.bootstrapServerHost = bootstrapServerHost;
this.serviceAccountSecretName = serviceAccountSecretName;
this.saslMechanism = "PLAINTEXT";
this.securityProtocol = "SASL_SSL";
this.metadata = new HashMap<String, String>();
}

public String getMessage() {
Expand All @@ -62,22 +57,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<KafkaCondition> getConditions() {
return conditions;
}
Expand All @@ -94,23 +73,11 @@ public void setBootstrapServerHost(String bootstrapServerHost) {
this.bootstrapServerHost = bootstrapServerHost;
}

public String getUiRef() {
return uiRef;
public Map<String, String> getMetadata() {
return metadata;
}

public void setUiRef(String uiRef) {
this.uiRef = uiRef;
}

/**
* Set the UI ref with a templated using a kafka ID
*
* <p>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<String, String> metadata) {
this.metadata = metadata;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ public UserKafka() {}
/**
* @param owner
* @param provider
* @param created
* @param id
* @param region
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -50,9 +51,7 @@ public UpdateControl<KafkaConnection> 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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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<String, String> buildKafkaMetadata(String kafkaId) {
var map = new HashMap<String, String>();
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;
}
}
7 changes: 6 additions & 1 deletion source/rhoas/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
quarkus.jib.jvm-arguments=-Xmx64m,-Xms32m

## Local dev options
### Configure to watch only single namespace
# quarkus.operator-sdk.controllers.annotation.namespaces=rhoas-sandbox

0 comments on commit f41afea

Please sign in to comment.