Skip to content

Commit

Permalink
improve: helm chart uses image version from values for deployment (#698)
Browse files Browse the repository at this point in the history
  • Loading branch information
csviri authored Aug 29, 2023
1 parent b3a9aa4 commit 571e558
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -93,15 +92,17 @@ private void addTemplateFiles(File helmDir) {
}

private void addGeneratedDeployment(File helmDir, List<GeneratedKubernetesResourceBuildItem> 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) {
Expand Down

0 comments on commit 571e558

Please sign in to comment.