Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve: helm chart uses image version from values for deployment #698

Merged
merged 1 commit into from
Aug 29, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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