From 96b5aa6f0ab0383e1aa29312d2892ad985164d60 Mon Sep 17 00:00:00 2001 From: Jose Date: Wed, 10 May 2023 10:23:55 +0200 Subject: [PATCH] Helm: Add property to configure the separator for profile values files Related to https://github.com/quarkiverse/quarkus-helm/pull/246 --- .../main/java/io/dekorate/helm/annotation/HelmChart.java | 2 ++ .../dekorate/helm/listener/HelmWriterSessionListener.java | 2 +- assets/config.md | 5 +++-- docs/configuration-guide.md | 7 ++++--- docs/documentation/helm.md | 4 +++- .../src/main/java/io/dekorate/example/Main.java | 1 + .../java/io/dekorate/example/HelmOpenshiftExampleTest.java | 4 ++-- 7 files changed, 16 insertions(+), 9 deletions(-) diff --git a/annotations/helm-annotations/src/main/java/io/dekorate/helm/annotation/HelmChart.java b/annotations/helm-annotations/src/main/java/io/dekorate/helm/annotation/HelmChart.java index b114c0982..dd4a4dae6 100644 --- a/annotations/helm-annotations/src/main/java/io/dekorate/helm/annotation/HelmChart.java +++ b/annotations/helm-annotations/src/main/java/io/dekorate/helm/annotation/HelmChart.java @@ -71,6 +71,8 @@ String valuesRootAlias() default "app"; + String valuesProfileSeparator() default "."; + boolean createTarFile() default false; boolean createValuesSchemaFile() default true; diff --git a/annotations/helm-annotations/src/main/java/io/dekorate/helm/listener/HelmWriterSessionListener.java b/annotations/helm-annotations/src/main/java/io/dekorate/helm/listener/HelmWriterSessionListener.java index 679f0e995..05de08165 100644 --- a/annotations/helm-annotations/src/main/java/io/dekorate/helm/listener/HelmWriterSessionListener.java +++ b/annotations/helm-annotations/src/main/java/io/dekorate/helm/listener/HelmWriterSessionListener.java @@ -405,7 +405,7 @@ private Map createValuesYaml(HelmChartConfig helmConfig, Path in // Create the values..yaml file artifacts.putAll(writeFileAsYaml(mergeWithFileIfExists(inputDir, VALUES + YAML, toValuesMap(values)), - getChartOutputDir(helmConfig, outputDir).resolve(VALUES + "." + profile + YAML))); + getChartOutputDir(helmConfig, outputDir).resolve(VALUES + helmConfig.getValuesProfileSeparator() + profile + YAML))); } // Next, we process the prod profile diff --git a/assets/config.md b/assets/config.md index c26b7b223..84898c9ff 100644 --- a/assets/config.md +++ b/assets/config.md @@ -490,6 +490,7 @@ The section below describes all the available subtypes. | dekorate.helm.createTarFile | boolean | Generates the Helm tarball file. | false | | dekorate.helm.createValuesSchemaFile | boolean | Generates the `values.schema.json` file that is used to validate the Helm Chart input values. | true | | dekorate.helm.createReadmeFile | boolean | Generates the `README.md` file that includes the Chart description and table with the configurable parameters and their default values. | true | +| dekorate.helm.valuesProfileSeparator | String | Configuration for the separator string in the filename of profile specific values files i.e. values.profile.yaml. | . | | dekorate.helm.valuesSchema | ValuesSchema | Configuration for the `values.schema.json` file. | | | dekorate.helm.annotations | Annotation[] | Annotations are additional mappings uninterpreted by Helm, made available for inspection by other applications. | | | dekorate.helm.kubeVersion | String | KubeVersion is a SemVer constraint specifying the version of Kubernetes required. | | @@ -537,8 +538,8 @@ The section below describes all the available subtypes. |------------|----------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------| | property | String | The name of the property in the Helm values file. If the property starts with `@.`, then the property won't be added under the root element in the generated `values.yaml` file. | | | paths | String | A comma-separated list of path expressions to map the Dekorate auto-generated properties to the final Helm values file. | | -| profile | String | The dependency repository. | (empty) | -| value | String | The dependency repository. | (empty) | +| profile | String | The profile where this value reference will be mapped to. For example, if the profile is `dev`, then a `values.dev.yml` file will be created with the value. | (empty) | +| value | String | The value that the property will have in the Helm values file. If not set, the extension will resolve it from the generated artifacts. | (empty) | | expression | String | The complete Helm expression to be replaced with. If not provided, it will use `{{ .Values.. }}`. | (empty) | | description | String | Description of the property. Optional. | | | minimum | integer | Minimum value allowed for this property. | | diff --git a/docs/configuration-guide.md b/docs/configuration-guide.md index f46b2a33e..12140e532 100644 --- a/docs/configuration-guide.md +++ b/docs/configuration-guide.md @@ -547,6 +547,7 @@ The section below describes all the available subtypes. | dekorate.helm.createTarFile | boolean | Generates the Helm tarball file. | false | | dekorate.helm.createValuesSchemaFile | boolean | Generates the `values.schema.json` file that is used to validate the Helm Chart input values. | true | | dekorate.helm.createReadmeFile | boolean | Generates the `README.md` file that includes the Chart description and table with the configurable parameters and their default values. | true | +| dekorate.helm.valuesProfileSeparator | String | Configuration for the separator string in the filename of profile specific values files i.e. values.profile.yaml. | . | | dekorate.helm.valuesSchema | ValuesSchema | Configuration for the `values.schema.json` file. | | | dekorate.helm.annotations | Annotation[] | Annotations are additional mappings uninterpreted by Helm, made available for inspection by other applications. | | | dekorate.helm.kubeVersion | String | KubeVersion is a SemVer constraint specifying the version of Kubernetes required. | | @@ -592,10 +593,10 @@ The section below describes all the available subtypes. | Property | Type | Description | Default Value | |------------|----------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------| -| property | String | The name of the property in the Helm values file. If the property starts with `@.`, then the property won't be added under the root element in the generated `values.yaml` file. | | +| property | String | The name of the property in the Helm values file. If the property starts with `@.`, then the property won't be added under the root element in the generated `values.yaml` file. | | | paths | String | A comma-separated list of path expressions to map the Dekorate auto-generated properties to the final Helm values file. | | -| profile | String | The dependency repository. | (empty) | -| value | String | The dependency repository. | (empty) | +| profile | String | The profile where this value reference will be mapped to. For example, if the profile is `dev`, then a `values.dev.yml` file will be created with the value. | (empty) | +| value | String | The value that the property will have in the Helm values file. If not set, the extension will resolve it from the generated artifacts. | (empty) | | expression | String | The complete Helm expression to be replaced with. If not provided, it will use `{{ .Values.. }}`. | (empty) | | description | String | Description of the property. Optional. | | | minimum | integer | Minimum value allowed for this property. | | diff --git a/docs/documentation/helm.md b/docs/documentation/helm.md index 37e46ef50..c01dd9a02 100644 --- a/docs/documentation/helm.md +++ b/docs/documentation/helm.md @@ -490,13 +490,15 @@ app: host: my-host ``` -But as you are now using a profile named `test` in one of your mapped properties, it will also generate a `values-test.yaml` file with the content: +But as you are now using a profile named `test` in one of your mapped properties, it will also generate a `values.test.yaml` file with the content: ```yaml app: host: my-test-host ``` +**TIP**: By default, Dekorate Helm uses the "." character in the filename of profile specific values files i.e. `values.test.yaml`. You can configure this separator using the property `dekorate.helm.valuesProfileSeparator`. For example, using `dekorate.helm.valuesProfileSeparator=-` would generate `values-test.yaml` instead. + #### Helm Usage First, make sure you have installed [the Helm command line](https://helm.sh/docs/intro/install/) and connected/logged to a kubernetes cluster. diff --git a/examples/helm-on-openshift-example/src/main/java/io/dekorate/example/Main.java b/examples/helm-on-openshift-example/src/main/java/io/dekorate/example/Main.java index 1c81b8586..255311485 100644 --- a/examples/helm-on-openshift-example/src/main/java/io/dekorate/example/Main.java +++ b/examples/helm-on-openshift-example/src/main/java/io/dekorate/example/Main.java @@ -23,6 +23,7 @@ import io.dekorate.openshift.annotation.OpenshiftApplication; @HelmChart(name = "myOcpChart", + valuesProfileSeparator = "-", values = { @ValueReference(property = "notFound", paths = "metadata.not-found"), @ValueReference(property = "vcsUrl", paths = "(kind == DeploymentConfig).spec.template.metadata.annotations.'app.dekorate.io/vcs-url'", value = "Overridden"), @ValueReference(property = "vcsUrl", paths = "(kind == DeploymentConfig).spec.template.metadata.annotations.'app.dekorate.io/vcs-url'", value = "Only for DEV!", profile = "dev") diff --git a/examples/helm-on-openshift-example/src/test/java/io/dekorate/example/HelmOpenshiftExampleTest.java b/examples/helm-on-openshift-example/src/test/java/io/dekorate/example/HelmOpenshiftExampleTest.java index a13a2fba2..428095a36 100644 --- a/examples/helm-on-openshift-example/src/test/java/io/dekorate/example/HelmOpenshiftExampleTest.java +++ b/examples/helm-on-openshift-example/src/test/java/io/dekorate/example/HelmOpenshiftExampleTest.java @@ -42,7 +42,7 @@ public void shouldHelmManifestsBeGenerated() throws IOException { assertEquals(CHART_NAME, chart.getName()); // Values.yaml manifest assertNotNull(Main.class.getClassLoader().getResourceAsStream(CHART_OUTPUT_LOCATION + "/values.yaml")); - assertNotNull(Main.class.getClassLoader().getResourceAsStream(CHART_OUTPUT_LOCATION + "/values.dev.yaml")); + assertNotNull(Main.class.getClassLoader().getResourceAsStream(CHART_OUTPUT_LOCATION + "/values-dev.yaml")); // templates assertNotNull(Main.class.getClassLoader().getResourceAsStream(CHART_OUTPUT_LOCATION + "/templates/buildconfig.yaml")); assertNotNull(Main.class.getClassLoader().getResourceAsStream(CHART_OUTPUT_LOCATION + "/templates/deploymentconfig.yaml")); @@ -79,7 +79,7 @@ public void valuesShouldContainExpectedData() throws IOException { @Test public void valuesShouldContainExpectedDataInDevProfile() throws IOException { - Map values = Serialization.yamlMapper().readValue(Main.class.getClassLoader().getResourceAsStream(CHART_OUTPUT_LOCATION + "/values.dev.yaml"), Map.class); + Map values = Serialization.yamlMapper().readValue(Main.class.getClassLoader().getResourceAsStream(CHART_OUTPUT_LOCATION + "/values-dev.yaml"), Map.class); assertNotNull(values, "Values is null!"); assertNotNull(values.containsKey(ROOT_CONFIG_NAME), "Does not contain `" + ROOT_CONFIG_NAME + "`");