Skip to content

Commit

Permalink
Merge branch 'main' into 2253-variables-refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Racer159 committed Apr 9, 2024
2 parents 703f59c + 0238927 commit 4d1e142
Show file tree
Hide file tree
Showing 14 changed files with 528 additions and 227 deletions.
6 changes: 0 additions & 6 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@ Fixes #
<!-- or -->
Relates to #

## Type of change

- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Other (security config, docs update, etc)

## Checklist before merging

- [ ] Test, docs, adr added or updated as needed
Expand Down
65 changes: 65 additions & 0 deletions adr/0023-chart-override.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# 23. Simplifying Helm Chart Value Overrides

Date: 2024-03-25

## Status

Accepted


## Context

The process of deploying applications with Helm charts in Kubernetes environments often necessitates the customization of chart values to align with specific operational or environmental requirements. The current method for customizing these values—either through manual edits or `###ZARF_VAR_XYZ###`. A more streamlined approach would greatly enhance the deployment experience by offering both flexibility and reliability.

## Decision

To address this issue, we propose the introduction of a feature designed to simplify the process of overriding chart values at the time of deployment. This feature would allow users to easily specify overrides for any chart values directly via command-line arguments, eliminating the need to alter the chart's default values file or manage multiple command-line arguments for each override.

Key aspects of the proposed implementation include:
- Use existing `--set` flags to specify overrides for chart values.
- The ability to list all overrides in a structured and easily understandable format within `zarf.yaml`.
- Ensuring that during deployment, these specified overrides take precedence over the chart's default values, thus facilitating customized deployments without necessitating permanent modifications to the chart.

## Consequences

Adopting this feature would lead to several key improvements:
- **Streamlined Configuration Process**: Allowing helm values overrides in the zarf package schema simplifies the user experience by reducing the reliance on extensive custom `###ZARF_VAR_XYZ###` templating and aligning more closely with standard Helm practices

Ultimately, this feature is aimed at enhancing the deployment workflow by offering a straightforward and efficient means of customizing Helm chart deployments via command-line inputs.

## Example Configuration

Below is an example of how the `zarf.yaml` configuration file might be structured to utilize the new override feature for Helm chart values:

```yaml
kind: ZarfPackageConfig
metadata:
name: helm-charts
description: Example showcasing multiple ways to deploy helm charts
version: 0.0.1

components:
- name: demo-helm-charts
required: true
charts:
- name: podinfo-local
version: 6.4.0
namespace: podinfo-from-local-chart
localPath: chart
valuesFiles:
- values.yaml
variables:
- name: REPLICA_COUNT
description: "Override the number of pod replicas"
path: replicaCount
```
This configuration allows for the specification of default values and descriptions for variables that can be overridden at deployment time. The variables section under each chart specifies the variables that can be overridden, along with a path that indicates where in the values file the variable is located.

### Command Line Example

To override the `REPLICA_COUNT` variable at deployment time, the following command can be used:

```bash
zarf package deploy zarf-package-helm-charts-arm64-0.0.1.tar.zst --set REPLICA_COUNT=5
```
This command demonstrates how users can easily customize their Helm chart deployments by specifying overrides for chart values directly via command-line arguments, in line with the proposed feature.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ zarf dev find-images [ PACKAGE ] [flags]
--kube-version string Override the default helm template KubeVersion when performing a package chart template
--registry-url string Override the ###ZARF_REGISTRY### value (default "127.0.0.1:31999")
-p, --repo-chart-path string If git repos hold helm charts, often found with gitops tools, specify the chart path, e.g. "/" or "/chart"
--skip-cosign Skip searching for cosign artifacts related to discovered images
--why string Prints the source manifest for the specified image
```

Expand Down
115 changes: 102 additions & 13 deletions docs/3-create-a-zarf-package/4-zarf-schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -1185,6 +1185,95 @@ Must be one of:
</blockquote>
</details>

<details open>
<summary>
<strong> <a name="components_items_charts_items_variables"></a>variables</strong>
</summary>
&nbsp;
<blockquote>

## components > charts > variables

**Description:** [alpha] List of variables to set in the Helm chart

| | |
| -------- | ------- |
| **Type** | `array` |

![Min Items: N/A](https://img.shields.io/badge/Min%20Items%3A%20N/A-gold)
![Max Items: N/A](https://img.shields.io/badge/Max%20Items%3A%20N/A-gold)
![Item unicity: False](https://img.shields.io/badge/Item%20unicity%3A%20False-gold)
![Additional items: N/A](https://img.shields.io/badge/Additional%20items%3A%20N/A-gold)

### <a name="autogenerated_heading_13"></a>ZarfChartVariable

| | |
| ------------------------- | -------------------------------------------------------------------------------------------------------- |
| **Type** | `object` |
| **Additional properties** | [![Not allowed](https://img.shields.io/badge/Not%20allowed-red)](# "Additional Properties not allowed.") |
| **Defined in** | #/definitions/ZarfChartVariable |

<details>
<summary>
<strong> <a name="components_items_charts_items_variables_items_name"></a>name *</strong>
</summary>
&nbsp;
<blockquote>

![Required](https://img.shields.io/badge/Required-red)

**Description:** The name of the variable

| | |
| -------- | -------- |
| **Type** | `string` |

| Restrictions | |
| --------------------------------- | ----------------------------------------------------------------------------- |
| **Must match regular expression** | ```^[A-Z0-9_]+$``` [Test](https://regex101.com/?regex=%5E%5BA-Z0-9_%5D%2B%24) |

</blockquote>
</details>

<details>
<summary>
<strong> <a name="components_items_charts_items_variables_items_description"></a>description *</strong>
</summary>
&nbsp;
<blockquote>

![Required](https://img.shields.io/badge/Required-red)

**Description:** A brief description of what the variable controls

| | |
| -------- | -------- |
| **Type** | `string` |

</blockquote>
</details>

<details>
<summary>
<strong> <a name="components_items_charts_items_variables_items_path"></a>path *</strong>
</summary>
&nbsp;
<blockquote>

![Required](https://img.shields.io/badge/Required-red)

**Description:** The path within the Helm chart values where this variable applies

| | |
| -------- | -------- |
| **Type** | `string` |

</blockquote>
</details>

</blockquote>
</details>

</blockquote>
</details>

Expand All @@ -1208,7 +1297,7 @@ Must be one of:
![Item unicity: False](https://img.shields.io/badge/Item%20unicity%3A%20False-gold)
![Additional items: N/A](https://img.shields.io/badge/Additional%20items%3A%20N/A-gold)

### <a name="autogenerated_heading_13"></a>ZarfDataInjection
### <a name="autogenerated_heading_14"></a>ZarfDataInjection

| | |
| ------------------------- | -------------------------------------------------------------------------------------------------------- |
Expand Down Expand Up @@ -1371,7 +1460,7 @@ Must be one of:
![Item unicity: False](https://img.shields.io/badge/Item%20unicity%3A%20False-gold)
![Additional items: N/A](https://img.shields.io/badge/Additional%20items%3A%20N/A-gold)

### <a name="autogenerated_heading_14"></a>ZarfFile
### <a name="autogenerated_heading_15"></a>ZarfFile

| | |
| ------------------------- | -------------------------------------------------------------------------------------------------------- |
Expand Down Expand Up @@ -1465,7 +1554,7 @@ Must be one of:
![Item unicity: False](https://img.shields.io/badge/Item%20unicity%3A%20False-gold)
![Additional items: N/A](https://img.shields.io/badge/Additional%20items%3A%20N/A-gold)

### <a name="autogenerated_heading_15"></a>symlinks items
### <a name="autogenerated_heading_16"></a>symlinks items

| | |
| -------- | -------- |
Expand Down Expand Up @@ -1511,7 +1600,7 @@ Must be one of:
![Item unicity: False](https://img.shields.io/badge/Item%20unicity%3A%20False-gold)
![Additional items: N/A](https://img.shields.io/badge/Additional%20items%3A%20N/A-gold)

### <a name="autogenerated_heading_16"></a>images items
### <a name="autogenerated_heading_17"></a>images items

| | |
| -------- | -------- |
Expand All @@ -1538,7 +1627,7 @@ Must be one of:
![Item unicity: False](https://img.shields.io/badge/Item%20unicity%3A%20False-gold)
![Additional items: N/A](https://img.shields.io/badge/Additional%20items%3A%20N/A-gold)

### <a name="autogenerated_heading_17"></a>repos items
### <a name="autogenerated_heading_18"></a>repos items

| | |
| -------- | -------- |
Expand Down Expand Up @@ -1633,7 +1722,7 @@ Must be one of:
![Item unicity: False](https://img.shields.io/badge/Item%20unicity%3A%20False-gold)
![Additional items: N/A](https://img.shields.io/badge/Additional%20items%3A%20N/A-gold)

### <a name="autogenerated_heading_18"></a>valuesFiles items
### <a name="autogenerated_heading_19"></a>valuesFiles items

| | |
| -------- | -------- |
Expand Down Expand Up @@ -1676,7 +1765,7 @@ Must be one of:
![Item unicity: False](https://img.shields.io/badge/Item%20unicity%3A%20False-gold)
![Additional items: N/A](https://img.shields.io/badge/Additional%20items%3A%20N/A-gold)

### <a name="autogenerated_heading_19"></a>fluxPatchFiles items
### <a name="autogenerated_heading_20"></a>fluxPatchFiles items

| | |
| -------- | -------- |
Expand Down Expand Up @@ -1824,7 +1913,7 @@ Must be one of:
![Item unicity: False](https://img.shields.io/badge/Item%20unicity%3A%20False-gold)
![Additional items: N/A](https://img.shields.io/badge/Additional%20items%3A%20N/A-gold)

### <a name="autogenerated_heading_20"></a>env items
### <a name="autogenerated_heading_21"></a>env items

| | |
| -------- | -------- |
Expand Down Expand Up @@ -1939,7 +2028,7 @@ Must be one of:
![Item unicity: False](https://img.shields.io/badge/Item%20unicity%3A%20False-gold)
![Additional items: N/A](https://img.shields.io/badge/Additional%20items%3A%20N/A-gold)

### <a name="autogenerated_heading_21"></a>ZarfComponentAction
### <a name="autogenerated_heading_22"></a>ZarfComponentAction

| | |
| ------------------------- | -------------------------------------------------------------------------------------------------------- |
Expand Down Expand Up @@ -2029,7 +2118,7 @@ Must be one of:
![Item unicity: False](https://img.shields.io/badge/Item%20unicity%3A%20False-gold)
![Additional items: N/A](https://img.shields.io/badge/Additional%20items%3A%20N/A-gold)

### <a name="autogenerated_heading_22"></a>env items
### <a name="autogenerated_heading_23"></a>env items

| | |
| -------- | -------- |
Expand Down Expand Up @@ -2448,7 +2537,7 @@ Must be one of:
![Item unicity: False](https://img.shields.io/badge/Item%20unicity%3A%20False-gold)
![Additional items: N/A](https://img.shields.io/badge/Additional%20items%3A%20N/A-gold)

### <a name="autogenerated_heading_24"></a>ZarfComponentAction
### <a name="autogenerated_heading_25"></a>ZarfComponentAction

| | |
| ------------------------- | -------------------------------------------------------------------------------------------------------- |
Expand Down Expand Up @@ -2479,7 +2568,7 @@ Must be one of:
![Item unicity: False](https://img.shields.io/badge/Item%20unicity%3A%20False-gold)
![Additional items: N/A](https://img.shields.io/badge/Additional%20items%3A%20N/A-gold)

### <a name="autogenerated_heading_25"></a>ZarfComponentAction
### <a name="autogenerated_heading_26"></a>ZarfComponentAction

| | |
| ------------------------- | -------------------------------------------------------------------------------------------------------- |
Expand Down Expand Up @@ -2510,7 +2599,7 @@ Must be one of:
![Item unicity: False](https://img.shields.io/badge/Item%20unicity%3A%20False-gold)
![Additional items: N/A](https://img.shields.io/badge/Additional%20items%3A%20N/A-gold)

### <a name="autogenerated_heading_26"></a>ZarfComponentAction
### <a name="autogenerated_heading_27"></a>ZarfComponentAction

| | |
| ------------------------- | -------------------------------------------------------------------------------------------------------- |
Expand Down
7 changes: 7 additions & 0 deletions examples/helm-charts/zarf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ components:
localPath: chart
valuesFiles:
- values.yaml
# Variables are used to override the default values in the chart
# This can be overridden by the user at deployment time with the `--set` flag
variables:
- name: REPLICA_COUNT
description: "Override the number of pod replicas"
path: replicaCount

- name: podinfo-oci
version: 6.4.0
Expand Down Expand Up @@ -77,3 +83,4 @@ components:
name: cool-release-name-podinfo
namespace: podinfo-from-repo
condition: available

2 changes: 2 additions & 0 deletions src/cmd/dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,8 @@ func init() {
devFindImagesCmd.Flags().StringVar(&pkgConfig.FindImagesOpts.KubeVersionOverride, "kube-version", "", lang.CmdDevFlagKubeVersion)
// check which manifests are using this particular image
devFindImagesCmd.Flags().StringVar(&pkgConfig.FindImagesOpts.Why, "why", "", lang.CmdDevFlagFindImagesWhy)
// skip searching cosign artifacts in find images
devFindImagesCmd.Flags().BoolVar(&pkgConfig.FindImagesOpts.SkipCosign, "skip-cosign", false, lang.CmdDevFlagFindImagesSkipCosign)

defaultRegistry := fmt.Sprintf("%s:%d", helpers.IPV4Localhost, types.ZarfInClusterContainerRegistryNodePort)
devFindImagesCmd.Flags().StringVar(&pkgConfig.FindImagesOpts.RegistryURL, "registry-url", defaultRegistry, lang.CmdDevFlagFindImagesRegistry)
Expand Down
17 changes: 9 additions & 8 deletions src/config/lang/english.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,13 +385,14 @@ $ zarf package pull oci://ghcr.io/defenseunicorns/packages/dos-games:1.0.0 -a sk
"NOTE: This file must not already exist. If no filename is provided, the config will be written to the current working directory as zarf-config.toml."
CmdDevGenerateConfigErr = "Unable to write the config file %s, make sure the file doesn't already exist"

CmdDevFlagExtractPath = `The path inside of an archive to use to calculate the sha256sum (i.e. for use with "files.extractPath")`
CmdDevFlagSet = "Specify package variables to set on the command line (KEY=value). Note, if using a config file, this will be set by [package.create.set]."
CmdDevFlagRepoChartPath = `If git repos hold helm charts, often found with gitops tools, specify the chart path, e.g. "/" or "/chart"`
CmdDevFlagGitAccount = "User or organization name for the git account that the repos are created under."
CmdDevFlagKubeVersion = "Override the default helm template KubeVersion when performing a package chart template"
CmdDevFlagFindImagesRegistry = "Override the ###ZARF_REGISTRY### value"
CmdDevFlagFindImagesWhy = "Prints the source manifest for the specified image"
CmdDevFlagExtractPath = `The path inside of an archive to use to calculate the sha256sum (i.e. for use with "files.extractPath")`
CmdDevFlagSet = "Specify package variables to set on the command line (KEY=value). Note, if using a config file, this will be set by [package.create.set]."
CmdDevFlagRepoChartPath = `If git repos hold helm charts, often found with gitops tools, specify the chart path, e.g. "/" or "/chart"`
CmdDevFlagGitAccount = "User or organization name for the git account that the repos are created under."
CmdDevFlagKubeVersion = "Override the default helm template KubeVersion when performing a package chart template"
CmdDevFlagFindImagesRegistry = "Override the ###ZARF_REGISTRY### value"
CmdDevFlagFindImagesWhy = "Prints the source manifest for the specified image"
CmdDevFlagFindImagesSkipCosign = "Skip searching for cosign artifacts related to discovered images"

CmdDevLintShort = "Lints the given package for valid schema and recommended practices"
CmdDevLintLong = "Verifies the package schema, checks if any variables won't be evaluated, and checks for unpinned images/repos/files"
Expand Down Expand Up @@ -477,7 +478,7 @@ $ zarf tools registry digest reg.example.com/stefanprodan/podinfo:6.4.0
CmdToolsGetGitPasswdShort = "[Deprecated] Returns the push user's password for the Git server"
CmdToolsGetGitPasswdLong = "[Deprecated] Reads the password for a user with push access to the configured Git server in Zarf State. Note that this command has been replaced by 'zarf tools get-creds git' and will be removed in Zarf v1.0.0."
CmdToolsGetGitPasswdDeprecation = "Deprecated: This command has been replaced by 'zarf tools get-creds git' and will be removed in Zarf v1.0.0."
CmdToolsYqExample = `
CmdToolsYqExample = `
# yq defaults to 'eval' command if no command is specified. See "zarf tools yq eval --help" for more examples.
# read the "stuff" node from "myfile.yml"
Expand Down
Loading

0 comments on commit 4d1e142

Please sign in to comment.