From 031bca44b36b4b6a1a66fed411435655940a74ed Mon Sep 17 00:00:00 2001 From: Marc Nuri Date: Fri, 24 Nov 2023 12:52:17 +0100 Subject: [PATCH] feat(helm): Support for Helm Chart.yaml appVersion field defaulting to project version Adds the appVersion field to the HelmConfig class so that it can be propagated from the Helm plugin configuration and the `jkube.helm.appVersion` property. The field is now provided by default with the current project version (i.e. by default Chart.yaml appVersion and version default to the same value) Signed-off-by: Marc Nuri --- CHANGELOG.md | 1 + gradle-plugin/it/src/it/helm-dsl/expected/Chart.yaml | 1 + .../it/src/it/helm-fragment-and-dsl/expected/Chart.yaml | 1 + .../it/src/it/helm-fragment/expected/Chart.yaml | 1 + .../it/src/it/helm-properties/expected/Chart.yaml | 1 + .../it/src/it/helm-zero-config/expected/Chart.yaml | 1 + .../doc/src/main/asciidoc/inc/helm/_jkube_helm.adoc | 9 ++++++++- .../org/eclipse/jkube/kit/resource/helm/HelmConfig.java | 3 +-- .../org/eclipse/jkube/kit/resource/helm/HelmService.java | 1 + .../eclipse/jkube/kit/resource/helm/HelmServiceUtil.java | 2 ++ .../eclipse/jkube/kit/resource/helm/HelmConfigTest.java | 5 +++++ .../eclipse/jkube/kit/resource/helm/HelmServiceTest.java | 2 ++ .../jkube/maven/plugin/mojo/build/HelmMojoTest.java | 1 + 13 files changed, 26 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dc03713321..3d949acc86 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,7 @@ Usage: * Fix #2390: support for all missing Chart.yaml fields * Fix #2444: Add support for Spring Boot application properties placeholders * Fix #2456: Add utility class to decompress archive files +* Fix #2472: Support for Helm Chart.yaml appVersion field defaulting to project version ### 1.15.0 (2023-11-10) * Fix #2138: Support for Spring Boot Native Image diff --git a/gradle-plugin/it/src/it/helm-dsl/expected/Chart.yaml b/gradle-plugin/it/src/it/helm-dsl/expected/Chart.yaml index 24da5afd46..b6fee5ce30 100644 --- a/gradle-plugin/it/src/it/helm-dsl/expected/Chart.yaml +++ b/gradle-plugin/it/src/it/helm-dsl/expected/Chart.yaml @@ -13,6 +13,7 @@ maintainers: email: maintainer@example.com url: https://example.com/user1 icon: https://example.com/icon1 +appVersion: 0.0.1-SNAPSHOT dependencies: - name: dependency-via-groovy-dsl-config version: 0.0.1 diff --git a/gradle-plugin/it/src/it/helm-fragment-and-dsl/expected/Chart.yaml b/gradle-plugin/it/src/it/helm-fragment-and-dsl/expected/Chart.yaml index 2e5fcaf2e8..9fb3a37c91 100644 --- a/gradle-plugin/it/src/it/helm-fragment-and-dsl/expected/Chart.yaml +++ b/gradle-plugin/it/src/it/helm-fragment-and-dsl/expected/Chart.yaml @@ -13,6 +13,7 @@ maintainers: email: maintainer@example.com url: https://example.com/user1 icon: https://example.com/icon-from-fragment-overrides-dsl +appVersion: 0.0.1-SNAPSHOT dependencies: - name: dependency-via-groovy-dsl-config version: 0.0.1 diff --git a/gradle-plugin/it/src/it/helm-fragment/expected/Chart.yaml b/gradle-plugin/it/src/it/helm-fragment/expected/Chart.yaml index 1a150372aa..74c7d79244 100644 --- a/gradle-plugin/it/src/it/helm-fragment/expected/Chart.yaml +++ b/gradle-plugin/it/src/it/helm-fragment/expected/Chart.yaml @@ -14,6 +14,7 @@ maintainers: email: maintainer@example.com url: https://example.com/user1 icon: https://example.com/icon1 +appVersion: 0.0.1-SNAPSHOT dependencies: - name: dependency-via-fragment version: 0.0.1 diff --git a/gradle-plugin/it/src/it/helm-properties/expected/Chart.yaml b/gradle-plugin/it/src/it/helm-properties/expected/Chart.yaml index 19abd58a2a..fd77fb944d 100644 --- a/gradle-plugin/it/src/it/helm-properties/expected/Chart.yaml +++ b/gradle-plugin/it/src/it/helm-properties/expected/Chart.yaml @@ -5,3 +5,4 @@ home: https://example.com version: 0.0.1-SNAPSHOT-from-properties description: Helm chart generation via properties integration test icon: https://example.com/chart1 +appVersion: 0.0.1-SNAPSHOT diff --git a/gradle-plugin/it/src/it/helm-zero-config/expected/Chart.yaml b/gradle-plugin/it/src/it/helm-zero-config/expected/Chart.yaml index 88939e3a4d..99753ca5a5 100644 --- a/gradle-plugin/it/src/it/helm-zero-config/expected/Chart.yaml +++ b/gradle-plugin/it/src/it/helm-zero-config/expected/Chart.yaml @@ -2,3 +2,4 @@ apiVersion: v1 name: helm-zero-config version: 0.0.1-SNAPSHOT +appVersion: 0.0.1-SNAPSHOT diff --git a/jkube-kit/doc/src/main/asciidoc/inc/helm/_jkube_helm.adoc b/jkube-kit/doc/src/main/asciidoc/inc/helm/_jkube_helm.adoc index e2768c9308..631cf5db06 100644 --- a/jkube-kit/doc/src/main/asciidoc/inc/helm/_jkube_helm.adoc +++ b/jkube-kit/doc/src/main/asciidoc/inc/helm/_jkube_helm.adoc @@ -101,10 +101,17 @@ endif::[] | | *icon* -| The Chart URL to an SVG or PNG image to be used as an icon , default is extracted from the kubernetes manifest +| The Chart URL to an SVG or PNG image to be used as an icon, default is extracted from the kubernetes manifest (`kubernetes.yml`) `jkube.eclipse.org/iconUrl` annotation if not provided. | `jkube.helm.icon` +| *appVersion* +| The version of the application that Chart contains +ifeval::["{plugin-type}" == "maven"] +, defaults to `${project.version}` if not provided. +endif::[] +| `jkube.helm.appVersion` + | *keywords* | Comma separated list of keywords to add to the chart. | diff --git a/jkube-kit/resource/helm/src/main/java/org/eclipse/jkube/kit/resource/helm/HelmConfig.java b/jkube-kit/resource/helm/src/main/java/org/eclipse/jkube/kit/resource/helm/HelmConfig.java index 3aebabddf6..b6b35a1d25 100644 --- a/jkube-kit/resource/helm/src/main/java/org/eclipse/jkube/kit/resource/helm/HelmConfig.java +++ b/jkube-kit/resource/helm/src/main/java/org/eclipse/jkube/kit/resource/helm/HelmConfig.java @@ -14,7 +14,6 @@ package org.eclipse.jkube.kit.resource.helm; import com.fasterxml.jackson.annotation.JsonProperty; -import io.fabric8.openshift.api.model.Parameter; import io.fabric8.openshift.api.model.Template; import lombok.AllArgsConstructor; import lombok.Builder; @@ -22,7 +21,6 @@ import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; -import lombok.Singular; import org.apache.commons.lang3.StringUtils; import org.eclipse.jkube.kit.common.Maintainer; @@ -54,6 +52,7 @@ public class HelmConfig { private List sources; private List maintainers; private String icon; + private String appVersion; private List keywords; private String engine; private List additionalFiles; diff --git a/jkube-kit/resource/helm/src/main/java/org/eclipse/jkube/kit/resource/helm/HelmService.java b/jkube-kit/resource/helm/src/main/java/org/eclipse/jkube/kit/resource/helm/HelmService.java index 0250772a49..7606de43c4 100644 --- a/jkube-kit/resource/helm/src/main/java/org/eclipse/jkube/kit/resource/helm/HelmService.java +++ b/jkube-kit/resource/helm/src/main/java/org/eclipse/jkube/kit/resource/helm/HelmService.java @@ -248,6 +248,7 @@ private static Chart chartFromHelmConfig(HelmConfig helmConfig) { .sources(helmConfig.getSources()) .maintainers(helmConfig.getMaintainers()) .icon(helmConfig.getIcon()) + .appVersion(helmConfig.getAppVersion()) .keywords(helmConfig.getKeywords()) .engine(helmConfig.getEngine()) .dependencies(helmConfig.getDependencies()) diff --git a/jkube-kit/resource/helm/src/main/java/org/eclipse/jkube/kit/resource/helm/HelmServiceUtil.java b/jkube-kit/resource/helm/src/main/java/org/eclipse/jkube/kit/resource/helm/HelmServiceUtil.java index e7193b3bb4..50a70f3b6e 100644 --- a/jkube-kit/resource/helm/src/main/java/org/eclipse/jkube/kit/resource/helm/HelmServiceUtil.java +++ b/jkube-kit/resource/helm/src/main/java/org/eclipse/jkube/kit/resource/helm/HelmServiceUtil.java @@ -51,6 +51,7 @@ public class HelmServiceUtil { private static final String PROPERTY_API_VERSION = "jkube.helm.apiVersion"; private static final String DEFAULT_API_VERSION = "v1"; private static final String PROPERTY_ICON = "jkube.helm.icon"; + private static final String PROPERTY_APP_VERSION = "jkube.helm.appVersion"; private static final String PROPERTY_TYPE = "jkube.helm.type"; private static final String PROPERTY_CHART = "jkube.helm.chart"; private static final String PROPERTY_CHART_EXTENSION = "jkube.helm.chartExtension"; @@ -105,6 +106,7 @@ public static HelmConfig.HelmConfigBuilder initHelmConfig( () -> String.format("%s/jkube/helm/%s", project.getBuildDirectory(), helmConfig.getChart()))); helmConfig.setIcon(resolveFromPropertyOrDefault(PROPERTY_ICON, project, helmConfig::getIcon, () -> findIconURL(new File(helmConfig.getSourceDir()), helmConfig.getTypes()))); + helmConfig.setAppVersion(resolveFromPropertyOrDefault(PROPERTY_APP_VERSION, project, helmConfig::getAppVersion, project::getVersion)); helmConfig.setTarFileClassifier(resolveFromPropertyOrDefault(PROPERTY_TARBALL_CLASSIFIER, project, helmConfig::getTarFileClassifier, () -> EMPTY)); helmConfig.setTarballOutputDir(resolveFromPropertyOrDefault(PROPERTY_TARBALL_OUTPUT_DIR, project, helmConfig::getTarballOutputDir, helmConfig::getOutputDir)); diff --git a/jkube-kit/resource/helm/src/test/java/org/eclipse/jkube/kit/resource/helm/HelmConfigTest.java b/jkube-kit/resource/helm/src/test/java/org/eclipse/jkube/kit/resource/helm/HelmConfigTest.java index 8ad42182cb..5005334d3e 100644 --- a/jkube-kit/resource/helm/src/test/java/org/eclipse/jkube/kit/resource/helm/HelmConfigTest.java +++ b/jkube-kit/resource/helm/src/test/java/org/eclipse/jkube/kit/resource/helm/HelmConfigTest.java @@ -102,6 +102,7 @@ void deserialize() throws Exception { "\"description\":\"The description\"," + "\"home\":\"e.t.\"," + "\"icon\":\"Warhol\"," + + "\"appVersion\":\"1.33.7\"," + "\"maintainers\":[{}]," + "\"sources\":[\"source\"]," + "\"engine\":\"V8\"," + @@ -131,6 +132,7 @@ void deserialize() throws Exception { .hasFieldOrPropertyWithValue("description", "The description") .hasFieldOrPropertyWithValue("home", "e.t.") .hasFieldOrPropertyWithValue("icon", "Warhol") + .hasFieldOrPropertyWithValue("appVersion", "1.33.7") .hasFieldOrPropertyWithValue("maintainers", Collections.singletonList(new Maintainer())) .hasFieldOrPropertyWithValue("sources", Collections.singletonList("source")) .hasFieldOrPropertyWithValue("engine", "V8") @@ -177,6 +179,7 @@ void createHelmConfig() throws IOException { helmConfig.setDescription("description"); helmConfig.setHome("home"); helmConfig.setIcon("icon"); + helmConfig.setAppVersion("1.33.7"); helmConfig.setMaintainers(Collections.singletonList(new Maintainer())); helmConfig.setSources(Collections.singletonList("source")); helmConfig.setEngine("engine"); @@ -201,6 +204,7 @@ void createHelmConfig() throws IOException { assertThat(helmConfig.getDescription()).isEqualTo("description"); assertThat(helmConfig.getHome()).isEqualTo("home"); assertThat(helmConfig.getIcon()).isEqualTo("icon"); + assertThat(helmConfig.getAppVersion()).isEqualTo("1.33.7"); assertThat(helmConfig.getMaintainers()).isNotEmpty(); assertThat(helmConfig.getSources().get(0)).isEqualTo("source"); assertThat(helmConfig.getEngine()).isEqualTo("engine"); @@ -226,6 +230,7 @@ void equals() { .description("description") .home("e.t.") .icon("Warhol") + .appVersion("1.33.7") .maintainers(Collections.singletonList(new Maintainer())) .sources(Arrays.asList("source-1", "source-2")) .engine("V8") diff --git a/jkube-kit/resource/helm/src/test/java/org/eclipse/jkube/kit/resource/helm/HelmServiceTest.java b/jkube-kit/resource/helm/src/test/java/org/eclipse/jkube/kit/resource/helm/HelmServiceTest.java index 277a8451c6..5aa9b5075a 100644 --- a/jkube-kit/resource/helm/src/test/java/org/eclipse/jkube/kit/resource/helm/HelmServiceTest.java +++ b/jkube-kit/resource/helm/src/test/java/org/eclipse/jkube/kit/resource/helm/HelmServiceTest.java @@ -157,6 +157,7 @@ void generateHelmCharts_withValidChartYamlFragment_usesMergedChart() throws Exce .keywords(Collections.singletonList("ci")) .maintainers(Collections.singletonList(Maintainer.builder().name("maintainer-from-config").build())) .icon("test-icon") + .appVersion("1.33.7") .engine("gotpl") .dependencies(Collections.singletonList(HelmDependency.builder().name("dependency-from-config").build())); // When @@ -171,6 +172,7 @@ void generateHelmCharts_withValidChartYamlFragment_usesMergedChart() throws Exce .hasFieldOrPropertyWithValue("description", "Description from helmconfig") .hasFieldOrPropertyWithValue("home", "https://example.com") .hasFieldOrPropertyWithValue("icon", "test-icon") + .hasFieldOrPropertyWithValue("appVersion", "1.33.7") .hasFieldOrPropertyWithValue("engine", "gotpl") .hasFieldOrPropertyWithValue("keywords", Collections.singletonList("fragment")) .hasFieldOrPropertyWithValue("sources", Collections.singletonList("https://source.example.com")) diff --git a/kubernetes-maven-plugin/plugin/src/test/java/org/eclipse/jkube/maven/plugin/mojo/build/HelmMojoTest.java b/kubernetes-maven-plugin/plugin/src/test/java/org/eclipse/jkube/maven/plugin/mojo/build/HelmMojoTest.java index 1524111916..7bd498bbba 100644 --- a/kubernetes-maven-plugin/plugin/src/test/java/org/eclipse/jkube/maven/plugin/mojo/build/HelmMojoTest.java +++ b/kubernetes-maven-plugin/plugin/src/test/java/org/eclipse/jkube/maven/plugin/mojo/build/HelmMojoTest.java @@ -99,6 +99,7 @@ void executeInternal_withNoConfig_shouldInitConfigWithDefaultValues() throws Exc .hasFieldOrPropertyWithValue("description", "A description from Maven") .hasFieldOrPropertyWithValue("home", "https://project.url") .hasFieldOrPropertyWithValue("icon", null) + .hasFieldOrPropertyWithValue("appVersion", "1337") .hasFieldOrPropertyWithValue("sourceDir", projectDir.resolve("target") .resolve("classes").resolve("META-INF").resolve("jkube") + File.separator) .hasFieldOrPropertyWithValue("outputDir", projectDir.resolve("target")