From 546ef78aea9990c59dd1107eeb71d1e943ec76da Mon Sep 17 00:00:00 2001 From: Matej Pucihar Date: Sun, 6 Oct 2024 21:02:44 +0200 Subject: [PATCH] fix: respect YamlConfigSource (#367) --- .../helm/deployment/HelmProcessor.java | 4 +- .../helm-kubernetes-minimal-yaml/pom.xml | 84 +++++++++++++++++++ .../helm/tests/kubernetes/Endpoint.java | 13 +++ .../src/main/resources/application.yaml | 3 + .../KubernetesYamlConfigSourceIT.java | 56 +++++++++++++ integration-tests/pom.xml | 1 + 6 files changed, 160 insertions(+), 1 deletion(-) create mode 100644 integration-tests/helm-kubernetes-minimal-yaml/pom.xml create mode 100644 integration-tests/helm-kubernetes-minimal-yaml/src/main/java/io/quarkiverse/helm/tests/kubernetes/Endpoint.java create mode 100644 integration-tests/helm-kubernetes-minimal-yaml/src/main/resources/application.yaml create mode 100644 integration-tests/helm-kubernetes-minimal-yaml/src/test/java/io/quarkiverse/helm/tests/kubernetes/KubernetesYamlConfigSourceIT.java diff --git a/deployment/src/main/java/io/quarkiverse/helm/deployment/HelmProcessor.java b/deployment/src/main/java/io/quarkiverse/helm/deployment/HelmProcessor.java index b80ef07..3485023 100644 --- a/deployment/src/main/java/io/quarkiverse/helm/deployment/HelmProcessor.java +++ b/deployment/src/main/java/io/quarkiverse/helm/deployment/HelmProcessor.java @@ -68,6 +68,7 @@ public class HelmProcessor { private static final String SERVICE_PORT_PLACEHOLDER = "::service-port"; private static final String SPLIT = ":"; private static final String PROPERTIES_CONFIG_SOURCE = "PropertiesConfigSource"; + private static final String YAML_CONFIG_SOURCE = "YamlConfigSource"; // Lazy loaded when calling `isBuildTimeProperty(xxx)`. private static Set buildProperties; @@ -411,7 +412,8 @@ public static String getDeploymentName(Capabilities capabilities, ApplicationInf } private boolean isPropertiesConfigSource(String sourceName) { - return StringUtils.isNotEmpty(sourceName) && sourceName.startsWith(PROPERTIES_CONFIG_SOURCE); + return StringUtils.isNotEmpty(sourceName) + && (sourceName.startsWith(PROPERTIES_CONFIG_SOURCE) || sourceName.startsWith(YAML_CONFIG_SOURCE)); } private boolean isBuildTimeProperty(String name) { diff --git a/integration-tests/helm-kubernetes-minimal-yaml/pom.xml b/integration-tests/helm-kubernetes-minimal-yaml/pom.xml new file mode 100644 index 0000000..712a60a --- /dev/null +++ b/integration-tests/helm-kubernetes-minimal-yaml/pom.xml @@ -0,0 +1,84 @@ + + + 4.0.0 + + io.quarkiverse.helm + quarkus-helm-integration-tests + 1.2.5-SNAPSHOT + + + quarkus-helm-integration-tests-kubernetes-minimal-yaml + Quarkus - Helm - Integration Tests - Kubernetes - Minimal - Yaml config source + + + + io.quarkus + quarkus-resteasy-reactive + + + + io.quarkus + quarkus-container-image-jib + + + io.quarkus + quarkus-config-yaml + + + + io.quarkiverse.helm + quarkus-helm + ${project.version} + + + + io.quarkus + quarkus-junit5 + test + + + io.rest-assured + rest-assured + test + + + io.dekorate + dekorate-core + test + + + + + + + io.quarkus + quarkus-maven-plugin + + + + build + + + + + + org.apache.maven.plugins + maven-failsafe-plugin + + + + integration-test + verify + + integration-test + + + **/*IT.class + + + + + + + + \ No newline at end of file diff --git a/integration-tests/helm-kubernetes-minimal-yaml/src/main/java/io/quarkiverse/helm/tests/kubernetes/Endpoint.java b/integration-tests/helm-kubernetes-minimal-yaml/src/main/java/io/quarkiverse/helm/tests/kubernetes/Endpoint.java new file mode 100644 index 0000000..62d9cd4 --- /dev/null +++ b/integration-tests/helm-kubernetes-minimal-yaml/src/main/java/io/quarkiverse/helm/tests/kubernetes/Endpoint.java @@ -0,0 +1,13 @@ +package io.quarkiverse.helm.tests.kubernetes; + +import jakarta.ws.rs.GET; +import jakarta.ws.rs.Path; + +@Path("") +public class Endpoint { + + @GET + public String hello() { + return "Hello, World!"; + } +} \ No newline at end of file diff --git a/integration-tests/helm-kubernetes-minimal-yaml/src/main/resources/application.yaml b/integration-tests/helm-kubernetes-minimal-yaml/src/main/resources/application.yaml new file mode 100644 index 0000000..a71ff35 --- /dev/null +++ b/integration-tests/helm-kubernetes-minimal-yaml/src/main/resources/application.yaml @@ -0,0 +1,3 @@ +foo: + bar: ${FOO_BAR:baz} + ~: ${BAR_FOO} \ No newline at end of file diff --git a/integration-tests/helm-kubernetes-minimal-yaml/src/test/java/io/quarkiverse/helm/tests/kubernetes/KubernetesYamlConfigSourceIT.java b/integration-tests/helm-kubernetes-minimal-yaml/src/test/java/io/quarkiverse/helm/tests/kubernetes/KubernetesYamlConfigSourceIT.java new file mode 100644 index 0000000..21f0d89 --- /dev/null +++ b/integration-tests/helm-kubernetes-minimal-yaml/src/test/java/io/quarkiverse/helm/tests/kubernetes/KubernetesYamlConfigSourceIT.java @@ -0,0 +1,56 @@ +package io.quarkiverse.helm.tests.kubernetes; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.nio.file.Paths; +import java.util.HashMap; +import java.util.Map; + +import org.junit.jupiter.api.Test; + +import io.dekorate.utils.Serialization; + +public class KubernetesYamlConfigSourceIT { + private static final String CHART_NAME = "quarkus-helm-integration-tests-kubernetes-minimal-yaml"; + private static final String ROOT_CONFIG_NAME = "app"; + + @Test + public void shouldHelmManifestsBeGenerated() throws IOException { + Map chart = Serialization.yamlMapper() + .readValue(getResourceAsStream("Chart.yaml"), Map.class); + assertNotNull(chart, "Chart is null!"); + assertEquals(CHART_NAME, chart.get("name")); + // Values.yaml manifest + assertNotNull(getResourceAsStream("values.yaml")); + // templates + assertNotNull(getResourceAsStream("templates/deployment.yaml")); + // notes + assertNotNull(getResourceAsStream("templates/NOTES.txt")); + } + + @Test + public void valuesShouldContainExpectedData() throws IOException { + Map values = Serialization.yamlMapper() + .readValue(getResourceAsStream("values.yaml"), Map.class); + assertNotNull(values, "Values is null!"); + + assertNotNull(values.containsKey(ROOT_CONFIG_NAME), "Does not contain `" + ROOT_CONFIG_NAME + "`"); + assertNotNull(values.get(ROOT_CONFIG_NAME) instanceof Map, "Value `" + ROOT_CONFIG_NAME + "` is not a map!"); + Map helmExampleValues = (Map) values.get(ROOT_CONFIG_NAME); + // Should contain image + assertNotNull(helmExampleValues.get("image")); + + final var envs = (HashMap) helmExampleValues.get("envs"); + assertEquals("baz", envs.get("FOO_BAR")); + assertEquals("", envs.get("BAR_FOO")); + } + + private InputStream getResourceAsStream(String file) throws FileNotFoundException { + return new FileInputStream(Paths.get("target", "helm", "kubernetes").resolve(CHART_NAME).resolve(file).toFile()); + } +} diff --git a/integration-tests/pom.xml b/integration-tests/pom.xml index 3cf05d3..aaec42a 100644 --- a/integration-tests/pom.xml +++ b/integration-tests/pom.xml @@ -13,6 +13,7 @@ helm-kubernetes-minimal + helm-kubernetes-minimal-yaml helm-kubernetes-with-dependency helm-kubernetes-config helm-kubernetes-with-templates