From 094b3b18c666a37a2bb2ab7c30f8ab77d546469d Mon Sep 17 00:00:00 2001 From: csviri Date: Tue, 29 Aug 2023 11:09:00 +0200 Subject: [PATCH] improve: helm chart uses image version from values for deployment --- .../operatorsdk/deployment/helm/HelmChartProcessor.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/core/deployment/src/main/java/io/quarkiverse/operatorsdk/deployment/helm/HelmChartProcessor.java b/core/deployment/src/main/java/io/quarkiverse/operatorsdk/deployment/helm/HelmChartProcessor.java index 9d6751a21..6bce62592 100644 --- a/core/deployment/src/main/java/io/quarkiverse/operatorsdk/deployment/helm/HelmChartProcessor.java +++ b/core/deployment/src/main/java/io/quarkiverse/operatorsdk/deployment/helm/HelmChartProcessor.java @@ -16,7 +16,6 @@ import org.jboss.logging.Logger; import io.dekorate.helm.model.Chart; -import io.dekorate.utils.Serialization; import io.fabric8.kubernetes.api.model.EnvVar; import io.fabric8.kubernetes.api.model.apps.Deployment; import io.quarkiverse.operatorsdk.common.FileUtils; @@ -78,7 +77,7 @@ public void handleHelmCharts( addTemplateFiles(helmDir); addClusterRolesForReconcilers(helmDir, controllerConfigs); addPrimaryClusterRoleBindings(helmDir, controllerConfigs); - addGeneratedDeployment(helmDir, generatedResources, controllerConfigurations); + addGeneratedDeployment(helmDir, generatedResources, controllerConfigurations, appInfo); addChartYaml(helmDir, appInfo.getName(), appInfo.getVersion()); addValuesYaml(helmDir, containerImageInfoBuildItem.getTag()); addReadmeAndSchema(helmDir); @@ -93,15 +92,17 @@ private void addTemplateFiles(File helmDir) { } private void addGeneratedDeployment(File helmDir, List generatedResources, - ControllerConfigurationsBuildItem controllerConfigurations) { + ControllerConfigurationsBuildItem controllerConfigurations, + ApplicationInfoBuildItem appInfo) { final var resources = GeneratedResourcesUtils.loadFrom(generatedResources); Deployment deployment = (Deployment) resources.stream() - .filter(r -> r instanceof Deployment).findFirst() + .filter(Deployment.class::isInstance).findFirst() .orElseThrow(); addActualNamespaceConfigPlaceholderToDeployment(deployment, controllerConfigurations); var template = FileUtils.asYaml(deployment); // a bit hacky solution to get the exact placeholder without brackets String res = template.replace("\"{watchNamespaces}\"", "{{ .Values.watchNamespaces }}"); + res = res.replaceAll(appInfo.getVersion(), "{{ .Values.version }}"); try { Files.writeString(Path.of(helmDir.getPath(), TEMPLATES_DIR, "deployment.yaml"), res); } catch (IOException e) {