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

Helm: Add property to configure the separator for profile values files #1192

Merged
merged 1 commit into from
May 10, 2023
Merged
Show file tree
Hide file tree
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 @@ -71,6 +71,8 @@

String valuesRootAlias() default "app";

String valuesProfileSeparator() default ".";

boolean createTarFile() default false;

boolean createValuesSchemaFile() default true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ private Map<String, String> createValuesYaml(HelmChartConfig helmConfig, Path in

// Create the values.<profile>.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
Expand Down
5 changes: 3 additions & 2 deletions assets/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. | |
Expand Down Expand Up @@ -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.<root alias>.<property> }}`. | (empty) |
| description | String | Description of the property. Optional. | |
| minimum | integer | Minimum value allowed for this property. | |
Expand Down
7 changes: 4 additions & 3 deletions docs/configuration-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. | |
Expand Down Expand Up @@ -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.<root alias>.<property> }}`. | (empty) |
| description | String | Description of the property. Optional. | |
| minimum | integer | Minimum value allowed for this property. | |
Expand Down
4 changes: 3 additions & 1 deletion docs/documentation/helm.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand Down Expand Up @@ -79,7 +79,7 @@ public void valuesShouldContainExpectedData() throws IOException {

@Test
public void valuesShouldContainExpectedDataInDevProfile() throws IOException {
Map<String, Object> values = Serialization.yamlMapper().readValue(Main.class.getClassLoader().getResourceAsStream(CHART_OUTPUT_LOCATION + "/values.dev.yaml"), Map.class);
Map<String, Object> 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 + "`");
Expand Down