Skip to content

Commit

Permalink
Allow operand images to be set via configuration properties (or env) (#…
Browse files Browse the repository at this point in the history
…957)

Signed-off-by: Michael Edgar <[email protected]>
  • Loading branch information
MikeEdgar authored Aug 9, 2024
1 parent a25b152 commit 8c789cb
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.github.streamshub.console.dependents;

import java.util.Locale;
import java.util.Map;
import java.util.Optional;

Expand All @@ -23,8 +22,6 @@
public class ConsoleDeployment extends CRUDKubernetesDependentResource<Deployment, Console> implements ConsoleResource {

public static final String NAME = "console-deployment";
private static final String DEFAULT_IMAGE_API = "quay.io/streamshub/console-api";
private static final String DEFAULT_IMAGE_UI = "quay.io/streamshub/console-ui";

@Inject
PrometheusService prometheusService;
Expand All @@ -36,8 +33,12 @@ public class ConsoleDeployment extends CRUDKubernetesDependentResource<Deploymen
ConsoleSecret secret;

@Inject
@ConfigProperty(name = "quarkus.application.version")
String applicationVersion;
@ConfigProperty(name = "console.deployment.default-api-image")
String defaultAPIImage;

@Inject
@ConfigProperty(name = "console.deployment.default-ui-image")
String defaultUIImage;

public ConsoleDeployment() {
super(Deployment.class);
Expand All @@ -53,11 +54,10 @@ protected Deployment desired(Console primary, Context<Console> context) {
Deployment desired = load(context, "console.deployment.yaml", Deployment.class);
String name = instanceName(primary);
String configSecretName = secret.instanceName(primary);
String imageTag = applicationVersion.toLowerCase(Locale.ROOT);
String imageAPI = Optional.ofNullable(primary.getSpec().getImages().getApi())
.orElseGet(() -> DEFAULT_IMAGE_API + ":" + imageTag);
String imageUI = Optional.ofNullable(primary.getSpec().getImages().getUi())
.orElseGet(() -> DEFAULT_IMAGE_UI + ":" + imageTag);

var imagesSpec = primary.getSpec().getImages();
String imageAPI = Optional.ofNullable(imagesSpec.getApi()).orElse(defaultAPIImage);
String imageUI = Optional.ofNullable(imagesSpec.getUi()).orElse(defaultUIImage);

return desired.edit()
.editMetadata()
Expand Down
4 changes: 4 additions & 0 deletions operator/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
console.selector=

console.deployment.default-image-tag=${quarkus.application.version}
console.deployment.default-api-image=quay.io/streamshub/console-api:${console.deployment.default-image-tag}
console.deployment.default-ui-image=quay.io/streamshub/console-ui:${console.deployment.default-image-tag}

quarkus.container-image.build=true
#quarkus.container-image.group=
quarkus.container-image.name=console-operator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import jakarta.inject.Inject;

import org.apache.kafka.common.config.SaslConfigs;
import org.eclipse.microprofile.config.Config;
import org.jboss.logging.Logger;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -54,6 +55,9 @@ class ConsoleReconcilerTest {
@Inject
KubernetesClient client;

@Inject
Config config;

@Inject
Operator operator;

Expand Down Expand Up @@ -192,12 +196,19 @@ void testBasicConsoleReconciliation() {
assertTrue(condition.getMessage().contains("ConsoleDeployment"));
});

client.apps().deployments()
var consoleDeployment = client.apps().deployments()
.inNamespace(consoleCR.getMetadata().getNamespace())
.withName("console-1-console-deployment")
.editStatus(this::setReady);
LOGGER.info("Set ready replicas for Console deployment");

// Images were not set in CR, so assert that the defaults were used
var consoleContainers = consoleDeployment.getSpec().getTemplate().getSpec().getContainers();
assertEquals(config.getValue("console.deployment.default-api-image", String.class),
consoleContainers.get(0).getImage());
assertEquals(config.getValue("console.deployment.default-ui-image", String.class),
consoleContainers.get(1).getImage());

await().ignoreException(NullPointerException.class).atMost(LIMIT).untilAsserted(() -> {
var console = client.resources(Console.class)
.inNamespace(consoleCR.getMetadata().getNamespace())
Expand Down Expand Up @@ -482,9 +493,9 @@ void testConsoleReconciliationWithValidKafkaUser() {
assertNotNull(consoleSecret);
String configEncoded = consoleSecret.getData().get("console-config.yaml");
byte[] configDecoded = Base64.getDecoder().decode(configEncoded);
ConsoleConfig config = new ObjectMapper().readValue(configDecoded, ConsoleConfig.class);
ConsoleConfig consoleConfig = new ObjectMapper().readValue(configDecoded, ConsoleConfig.class);
assertEquals("jaas-config-value",
config.getKafka().getClusters().get(0).getProperties().get(SaslConfigs.SASL_JAAS_CONFIG));
consoleConfig.getKafka().getClusters().get(0).getProperties().get(SaslConfigs.SASL_JAAS_CONFIG));
});
}

Expand Down Expand Up @@ -559,8 +570,8 @@ void testConsoleReconciliationWithKafkaProperties() {
assertNotNull(consoleSecret);
String configEncoded = consoleSecret.getData().get("console-config.yaml");
byte[] configDecoded = Base64.getDecoder().decode(configEncoded);
ConsoleConfig config = new ObjectMapper().readValue(configDecoded, ConsoleConfig.class);
var kafkaConfig = config.getKafka().getClusters().get(0);
ConsoleConfig consoleConfig = new ObjectMapper().readValue(configDecoded, ConsoleConfig.class);
var kafkaConfig = consoleConfig.getKafka().getClusters().get(0);
assertEquals("x-prop-value", kafkaConfig.getProperties().get("x-prop-name"));
assertEquals("x-admin-prop-value", kafkaConfig.getAdminProperties().get("x-admin-prop-name"));
assertEquals("x-consumer-prop-value", kafkaConfig.getConsumerProperties().get("extra-x-consumer-prop-name"));
Expand Down

0 comments on commit 8c789cb

Please sign in to comment.