Skip to content

Commit

Permalink
feat(helm): Support for Helm Chart.yaml appVersion field defaulting t…
Browse files Browse the repository at this point in the history
…o 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 <[email protected]>
  • Loading branch information
manusa committed Nov 24, 2023
1 parent 2116a3b commit 031bca4
Show file tree
Hide file tree
Showing 13 changed files with 26 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions gradle-plugin/it/src/it/helm-dsl/expected/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ maintainers:
email: [email protected]
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ maintainers:
email: [email protected]
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
Expand Down
1 change: 1 addition & 0 deletions gradle-plugin/it/src/it/helm-fragment/expected/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ maintainers:
email: [email protected]
url: https://example.com/user1
icon: https://example.com/icon1
appVersion: 0.0.1-SNAPSHOT
dependencies:
- name: dependency-via-fragment
version: 0.0.1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
apiVersion: v1
name: helm-zero-config
version: 0.0.1-SNAPSHOT
appVersion: 0.0.1-SNAPSHOT
9 changes: 8 additions & 1 deletion jkube-kit/doc/src/main/asciidoc/inc/helm/_jkube_helm.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,13 @@
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;
import lombok.EqualsAndHashCode;
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;

Expand Down Expand Up @@ -54,6 +52,7 @@ public class HelmConfig {
private List<String> sources;
private List<Maintainer> maintainers;
private String icon;
private String appVersion;
private List<String> keywords;
private String engine;
private List<File> additionalFiles;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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\"," +
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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");
Expand All @@ -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");
Expand All @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 031bca4

Please sign in to comment.