From 8c789cbc15031beef7e3d290a19cd3dc5d5b5173 Mon Sep 17 00:00:00 2001 From: Michael Edgar Date: Thu, 8 Aug 2024 20:03:46 -0400 Subject: [PATCH] Allow operand images to be set via configuration properties (or env) (#957) Signed-off-by: Michael Edgar --- .../console/dependents/ConsoleDeployment.java | 20 +++++++++--------- .../src/main/resources/application.properties | 4 ++++ .../console/ConsoleReconcilerTest.java | 21 ++++++++++++++----- 3 files changed, 30 insertions(+), 15 deletions(-) diff --git a/operator/src/main/java/com/github/streamshub/console/dependents/ConsoleDeployment.java b/operator/src/main/java/com/github/streamshub/console/dependents/ConsoleDeployment.java index 2b94fb191..8b053ce7f 100644 --- a/operator/src/main/java/com/github/streamshub/console/dependents/ConsoleDeployment.java +++ b/operator/src/main/java/com/github/streamshub/console/dependents/ConsoleDeployment.java @@ -1,6 +1,5 @@ package com.github.streamshub.console.dependents; -import java.util.Locale; import java.util.Map; import java.util.Optional; @@ -23,8 +22,6 @@ public class ConsoleDeployment extends CRUDKubernetesDependentResource 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; @@ -36,8 +33,12 @@ public class ConsoleDeployment extends CRUDKubernetesDependentResource 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() diff --git a/operator/src/main/resources/application.properties b/operator/src/main/resources/application.properties index 0884f8bfc..b1766a3f9 100644 --- a/operator/src/main/resources/application.properties +++ b/operator/src/main/resources/application.properties @@ -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 diff --git a/operator/src/test/java/com/github/streamshub/console/ConsoleReconcilerTest.java b/operator/src/test/java/com/github/streamshub/console/ConsoleReconcilerTest.java index d4fac62ca..95893d005 100644 --- a/operator/src/test/java/com/github/streamshub/console/ConsoleReconcilerTest.java +++ b/operator/src/test/java/com/github/streamshub/console/ConsoleReconcilerTest.java @@ -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; @@ -54,6 +55,9 @@ class ConsoleReconcilerTest { @Inject KubernetesClient client; + @Inject + Config config; + @Inject Operator operator; @@ -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()) @@ -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)); }); } @@ -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"));