From e97a7d2a59c69d1a452b8445520fa75fb4c6d06c Mon Sep 17 00:00:00 2001 From: Darcy Cleaver Date: Tue, 13 Feb 2024 11:28:25 -0700 Subject: [PATCH 01/13] feat: allow you to use imported vars as override values --- docs/overrides.md | 1 + src/pkg/bundle/deploy.go | 32 ++++++++++++++----- src/test/e2e/variable_test.go | 28 ++++++++++++++++ .../packages/no-cluster/output-var/zarf.yaml | 3 ++ 4 files changed, 56 insertions(+), 8 deletions(-) diff --git a/docs/overrides.md b/docs/overrides.md index bd9bf887..b6c95d09 100644 --- a/docs/overrides.md +++ b/docs/overrides.md @@ -130,6 +130,7 @@ The `value` is the value to set at the `path`. Values can be simple values such value: customAnnotation: "customValue" ``` +If [importing](../README.md#importingexporting-variables) a variable from another package, that variable can also be used to set a value, using the template syntax `${...}` ### Variables Variables are similar to [values](#values) in that they allow users to override values in a Zarf package component's underlying Helm chart; they also share a similar syntax. However, unlike `values`, `variables` can be overridden at deploy time. For example, consider the following `variables`: diff --git a/src/pkg/bundle/deploy.go b/src/pkg/bundle/deploy.go index 45c8cb5d..4e3aeb61 100644 --- a/src/pkg/bundle/deploy.go +++ b/src/pkg/bundle/deploy.go @@ -10,6 +10,7 @@ import ( "fmt" "os" "path/filepath" + "regexp" "strings" "github.com/AlecAivazis/survey/v2" @@ -166,7 +167,7 @@ func deployPackages(packages []types.Package, resume bool, b *Bundle, zarfPackag SetVariables: pkgVars, } - valuesOverrides, err := b.loadChartOverrides(pkg) + valuesOverrides, err := b.loadChartOverrides(pkg, pkgVars) if err != nil { return err } @@ -274,7 +275,7 @@ func (b *Bundle) confirmBundleDeploy() (confirm bool) { } // loadChartOverrides converts a helm path to a ValuesOverridesMap config for Zarf -func (b *Bundle) loadChartOverrides(pkg types.Package) (ZarfOverrideMap, error) { +func (b *Bundle) loadChartOverrides(pkg types.Package, pkgVars map[string]string) (ZarfOverrideMap, error) { // Create a nested map to hold the values overrideMap := make(map[string]map[string]*values.Options) @@ -282,7 +283,7 @@ func (b *Bundle) loadChartOverrides(pkg types.Package) (ZarfOverrideMap, error) // Loop through each package component's charts and process overrides for componentName, component := range pkg.Overrides { for chartName, chart := range component { - err := b.processOverrideValues(&overrideMap, &chart.Values, componentName, chartName) + err := b.processOverrideValues(&overrideMap, &chart.Values, componentName, chartName, pkgVars) if err != nil { return nil, err } @@ -324,10 +325,10 @@ func (b *Bundle) loadChartOverrides(pkg types.Package) (ZarfOverrideMap, error) } // processOverrideValues processes a bundles values overrides and adds them to the override map -func (b *Bundle) processOverrideValues(overrideMap *map[string]map[string]*values.Options, values *[]types.BundleChartValue, componentName string, chartName string) error { +func (b *Bundle) processOverrideValues(overrideMap *map[string]map[string]*values.Options, values *[]types.BundleChartValue, componentName string, chartName string, pkgVars map[string]string) error { for _, v := range *values { // Add the override to the map, or return an error if the path is invalid - if err := addOverrideValue(*overrideMap, componentName, chartName, v.Path, v.Value); err != nil { + if err := addOverrideValue(*overrideMap, componentName, chartName, v.Path, v.Value, pkgVars); err != nil { return err } } @@ -340,7 +341,7 @@ func (b *Bundle) processOverrideVariables(overrideMap *map[string]map[string]*va var overrideVal interface{} // check for override in env vars if envVarOverride, exists := os.LookupEnv(strings.ToUpper(config.EnvVarPrefix + v.Name)); exists { - if err := addOverrideValue(*overrideMap, componentName, chartName, v.Path, envVarOverride); err != nil { + if err := addOverrideValue(*overrideMap, componentName, chartName, v.Path, envVarOverride, nil); err != nil { return err } continue @@ -363,7 +364,7 @@ func (b *Bundle) processOverrideVariables(overrideMap *map[string]map[string]*va } // Add the override to the map, or return an error if the path is invalid - if err := addOverrideValue(*overrideMap, componentName, chartName, v.Path, overrideVal); err != nil { + if err := addOverrideValue(*overrideMap, componentName, chartName, v.Path, overrideVal, nil); err != nil { return err } @@ -372,7 +373,7 @@ func (b *Bundle) processOverrideVariables(overrideMap *map[string]map[string]*va } // addOverrideValue adds a value to a ZarfOverrideMap -func addOverrideValue(overrides map[string]map[string]*values.Options, component string, chart string, valuePath string, value interface{}) error { +func addOverrideValue(overrides map[string]map[string]*values.Options, component string, chart string, valuePath string, value interface{}, pkgVars map[string]string) error { // Create the component map if it doesn't exist if _, ok := overrides[component]; !ok { overrides[component] = make(map[string]*values.Options) @@ -409,6 +410,21 @@ func addOverrideValue(overrides map[string]map[string]*values.Options, component val := fmt.Sprintf("%s=%s", valuePath, j) overrides[component][chart].JSONValues = append(overrides[component][chart].JSONValues, val) default: + // Check for any templated variables if pkgVars set + if pkgVars != nil { + // Regular expression to get text in ${...} + re := regexp.MustCompile(`\${([^}]+)}`) + templatedVariable := fmt.Sprintf("%v", v) + // Get the variable name inside of ${...} + // returns slice with the templated variable and the variable name + variableName := re.FindStringSubmatch(templatedVariable) + // If we have a templated variable, get the value from pkgVars + if len(variableName) == 2 { + if varValue, ok := pkgVars[variableName[1]]; ok { + value = varValue + } + } + } // handle default case of simple values like strings and numbers helmVal := fmt.Sprintf("%s=%v", valuePath, value) overrides[component][chart].Values = append(overrides[component][chart].Values, helmVal) diff --git a/src/test/e2e/variable_test.go b/src/test/e2e/variable_test.go index 95bbdffa..3aadd87f 100644 --- a/src/test/e2e/variable_test.go +++ b/src/test/e2e/variable_test.go @@ -203,3 +203,31 @@ func TestVariablePrecedence(t *testing.T) { remove(t, bundlePath) } + +func TestZarfPackageExportVarsAsGlobalBundleVars(t *testing.T) { + deployZarfInit(t) + zarfPkgPath1 := "src/test/packages/no-cluster/output-var" + e2e.CreateZarfPkg(t, zarfPkgPath1, false) + + e2e.SetupDockerRegistry(t, 888) + defer e2e.TeardownRegistry(t, 888) + + pkg := filepath.Join(zarfPkgPath1, fmt.Sprintf("zarf-package-output-var-%s-0.0.1.tar.zst", e2e.Arch)) + zarfPublish(t, pkg, "localhost:888") + + e2e.HelmDepUpdate(t, "src/test/packages/helm/unicorn-podinfo") + e2e.CreateZarfPkg(t, "src/test/packages/helm", false) + bundleDir := "src/test/bundles/12-exported-pkg-vars" + bundlePath := filepath.Join(bundleDir, fmt.Sprintf("uds-bundle-export-vars-%s-0.0.1.tar.zst", e2e.Arch)) + + createLocal(t, bundleDir, e2e.Arch) + deploy(t, bundlePath) + + // check variables overrides + cmd := strings.Split("zarf tools kubectl get deploy -n podinfo unicorn-podinfo -o=jsonpath='{.spec.template.spec.containers[0].env[?(@.name==\"PODINFO_UI_COLOR\")].value}'", " ") + outputUIColor, _, err := e2e.UDS(cmd...) + require.Equal(t, "'orange'", outputUIColor) + require.NoError(t, err) + + remove(t, bundlePath) +} diff --git a/src/test/packages/no-cluster/output-var/zarf.yaml b/src/test/packages/no-cluster/output-var/zarf.yaml index a958f4fc..eddb6ea2 100644 --- a/src/test/packages/no-cluster/output-var/zarf.yaml +++ b/src/test/packages/no-cluster/output-var/zarf.yaml @@ -31,3 +31,6 @@ components: echo "shared var in output-var pkg: "${ZARF_VAR_DOMAIN}"" - cmd: | echo "output-var SPECIFIC_PKG_VAR = "${ZARF_VAR_SPECIFIC_PKG_VAR}"" + - cmd: echo "orange" + setVariables: + - name: COLOR From 2b45f18d0006398b1b48ec69e5469aaa970cbbd5 Mon Sep 17 00:00:00 2001 From: Darcy Cleaver Date: Tue, 13 Feb 2024 11:36:08 -0700 Subject: [PATCH 02/13] updated test bundle --- .../12-exported-pkg-vars/uds-bundle.yaml | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/test/bundles/12-exported-pkg-vars/uds-bundle.yaml diff --git a/src/test/bundles/12-exported-pkg-vars/uds-bundle.yaml b/src/test/bundles/12-exported-pkg-vars/uds-bundle.yaml new file mode 100644 index 00000000..5966ba70 --- /dev/null +++ b/src/test/bundles/12-exported-pkg-vars/uds-bundle.yaml @@ -0,0 +1,28 @@ +kind: UDSBundle +metadata: + name: export-vars + description: testing a bundle using exported vars from zarf package + version: 0.0.1 + +packages: + - name: output-var + repository: localhost:888/output-var + ref: 0.0.1 + exports: + - name: COLOR + + - name: helm-overrides + path: "../../packages/helm" + ref: 0.0.1 + imports: + - name: COLOR + package: output-var + + overrides: + podinfo-component: + unicorn-podinfo: + values: + - path: "podinfo.replicaCount" + value: 1 + - path: "podinfo.ui.color" + value: ${COLOR} From 46da3cd9ca2777cac0b9d150801323c15c017650 Mon Sep 17 00:00:00 2001 From: Darcy Cleaver Date: Tue, 13 Feb 2024 12:30:54 -0700 Subject: [PATCH 03/13] set commitlint version --- .github/workflows/commitlint.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/commitlint.yaml b/.github/workflows/commitlint.yaml index 6d338222..fe2eda0c 100644 --- a/.github/workflows/commitlint.yaml +++ b/.github/workflows/commitlint.yaml @@ -24,7 +24,7 @@ jobs: uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2 - name: Install commitlint - run: npm install --save-dev @commitlint/{config-conventional,cli} + run: npm install --save-dev @commitlint/{config-conventional,cli}@18.6.0 - name: Lint PR title run: echo "${{ github.event.pull_request.title }}" | npx commitlint From 484db20c2b4203031c44fff9f2bbf2309b163269 Mon Sep 17 00:00:00 2001 From: Darcy Cleaver Date: Wed, 14 Feb 2024 09:07:09 -0700 Subject: [PATCH 04/13] commitlint bug fixed in latest release --- .github/workflows/commitlint.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/commitlint.yaml b/.github/workflows/commitlint.yaml index fe2eda0c..6d338222 100644 --- a/.github/workflows/commitlint.yaml +++ b/.github/workflows/commitlint.yaml @@ -24,7 +24,7 @@ jobs: uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2 - name: Install commitlint - run: npm install --save-dev @commitlint/{config-conventional,cli}@18.6.0 + run: npm install --save-dev @commitlint/{config-conventional,cli} - name: Lint PR title run: echo "${{ github.event.pull_request.title }}" | npx commitlint From 36febbc212601902cf5133f529fe5f3866c19987 Mon Sep 17 00:00:00 2001 From: Darcy Cleaver Date: Tue, 20 Feb 2024 13:26:26 -0700 Subject: [PATCH 05/13] chore: pr review updates --- src/pkg/bundle/deploy.go | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/pkg/bundle/deploy.go b/src/pkg/bundle/deploy.go index 4e3aeb61..f3f4d5aa 100644 --- a/src/pkg/bundle/deploy.go +++ b/src/pkg/bundle/deploy.go @@ -31,6 +31,9 @@ import ( // ZarfOverrideMap is a map of Zarf packages -> components -> Helm charts -> values type ZarfOverrideMap map[string]map[string]map[string]interface{} +// templatedVarRegex is the regex for templated variables +var templatedVarRegex = regexp.MustCompile(`\${([^}]+)}`) + // Deploy deploys a bundle // // : create a new provider @@ -412,18 +415,18 @@ func addOverrideValue(overrides map[string]map[string]*values.Options, component default: // Check for any templated variables if pkgVars set if pkgVars != nil { - // Regular expression to get text in ${...} - re := regexp.MustCompile(`\${([^}]+)}`) templatedVariable := fmt.Sprintf("%v", v) - // Get the variable name inside of ${...} - // returns slice with the templated variable and the variable name - variableName := re.FindStringSubmatch(templatedVariable) - // If we have a templated variable, get the value from pkgVars - if len(variableName) == 2 { - if varValue, ok := pkgVars[variableName[1]]; ok { - value = varValue + // Use ReplaceAllStringFunc to handle all occurrences of templated variables + replacedValue := templatedVarRegex.ReplaceAllStringFunc(templatedVariable, func(match string) string { + // returns slice with the templated variable and the variable name + variableName := templatedVarRegex.FindStringSubmatch(match)[1] + // If we have a templated variable, get the value from pkgVars + if varValue, ok := pkgVars[variableName]; ok { + return varValue } - } + return fmt.Sprintf("${%s_not_found}", variableName) + }) + value = replacedValue } // handle default case of simple values like strings and numbers helmVal := fmt.Sprintf("%s=%v", valuePath, value) From d506f13f2d4f7bc3b76ccc09072daf510d2dad56 Mon Sep 17 00:00:00 2001 From: Darcy Cleaver Date: Wed, 21 Feb 2024 11:31:30 -0700 Subject: [PATCH 06/13] chore: addressing pr comments, fixes, and adding additional tests --- docs/overrides.md | 32 +++++++++++++++++- src/pkg/bundle/deploy.go | 33 ++++++++++++------- .../12-exported-pkg-vars/uds-bundle.yaml | 22 +++++++++++++ src/test/e2e/variable_test.go | 17 +++++++++- .../packages/no-cluster/output-var/zarf.yaml | 9 +++++ 5 files changed, 100 insertions(+), 13 deletions(-) diff --git a/docs/overrides.md b/docs/overrides.md index b6c95d09..4bf1482d 100644 --- a/docs/overrides.md +++ b/docs/overrides.md @@ -130,7 +130,37 @@ The `value` is the value to set at the `path`. Values can be simple values such value: customAnnotation: "customValue" ``` -If [importing](../README.md#importingexporting-variables) a variable from another package, that variable can also be used to set a value, using the template syntax `${...}` +If [importing](../README.md#importingexporting-variables) a variable from another package, that variable can also be used to set a value, using the template syntax `${...}`. In the example below the `COLOR` variable is being used to set the `podinfo.ui.color` value. +``` +kind: UDSBundle +metadata: + name: export-vars + description: Example for using an imported variable to set an overrides value + version: 0.0.1 + +packages: + - name: output-var + repository: localhost:888/output-var + ref: 0.0.1 + exports: + - name: COLOR + + - name: helm-overrides + path: "../../packages/helm" + ref: 0.0.1 + imports: + - name: COLOR + package: output-var + + overrides: + podinfo-component: + unicorn-podinfo: + values: + - path: "podinfo.replicaCount" + value: 1 + - path: "podinfo.ui.color" + value: ${COLOR} +``` ### Variables Variables are similar to [values](#values) in that they allow users to override values in a Zarf package component's underlying Helm chart; they also share a similar syntax. However, unlike `values`, `variables` can be overridden at deploy time. For example, consider the following `variables`: diff --git a/src/pkg/bundle/deploy.go b/src/pkg/bundle/deploy.go index f3f4d5aa..72b79979 100644 --- a/src/pkg/bundle/deploy.go +++ b/src/pkg/bundle/deploy.go @@ -402,6 +402,9 @@ func addOverrideValue(overrides map[string]map[string]*values.Options, component } // use JSONValues because we can easily marshal the YAML to JSON and Helm understands it jsonVals := fmt.Sprintf("%s=[%s]", valuePath, strings.Join(jsonStrs, ",")) + if pkgVars != nil { + jsonVals = setTemplatedVariables(jsonVals, pkgVars) + } overrides[component][chart].JSONValues = append(overrides[component][chart].JSONValues, jsonVals) case map[string]interface{}: // handle objects by parsing them as json and appending to Options.JSONValues @@ -411,22 +414,15 @@ func addOverrideValue(overrides map[string]map[string]*values.Options, component } // use JSONValues because we can easily marshal the YAML to JSON and Helm understands it val := fmt.Sprintf("%s=%s", valuePath, j) + if pkgVars != nil { + val = setTemplatedVariables(val, pkgVars) + } overrides[component][chart].JSONValues = append(overrides[component][chart].JSONValues, val) default: // Check for any templated variables if pkgVars set if pkgVars != nil { templatedVariable := fmt.Sprintf("%v", v) - // Use ReplaceAllStringFunc to handle all occurrences of templated variables - replacedValue := templatedVarRegex.ReplaceAllStringFunc(templatedVariable, func(match string) string { - // returns slice with the templated variable and the variable name - variableName := templatedVarRegex.FindStringSubmatch(match)[1] - // If we have a templated variable, get the value from pkgVars - if varValue, ok := pkgVars[variableName]; ok { - return varValue - } - return fmt.Sprintf("${%s_not_found}", variableName) - }) - value = replacedValue + value = setTemplatedVariables(templatedVariable, pkgVars) } // handle default case of simple values like strings and numbers helmVal := fmt.Sprintf("%s=%v", valuePath, value) @@ -434,3 +430,18 @@ func addOverrideValue(overrides map[string]map[string]*values.Options, component } return nil } + +// setTemplatedVariables sets the value for the templated variables +func setTemplatedVariables(templatedVariables string, pkgVars map[string]string) string { + // Use ReplaceAllStringFunc to handle all occurrences of templated variables + replacedValue := templatedVarRegex.ReplaceAllStringFunc(templatedVariables, func(match string) string { + // returns slice with the templated variable and the variable name + variableName := templatedVarRegex.FindStringSubmatch(match)[1] + // If we have a templated variable, get the value from pkgVars + if varValue, ok := pkgVars[variableName]; ok { + return varValue + } + return fmt.Sprintf("${%s_not_found}", variableName) + }) + return replacedValue +} diff --git a/src/test/bundles/12-exported-pkg-vars/uds-bundle.yaml b/src/test/bundles/12-exported-pkg-vars/uds-bundle.yaml index 5966ba70..83d872fb 100644 --- a/src/test/bundles/12-exported-pkg-vars/uds-bundle.yaml +++ b/src/test/bundles/12-exported-pkg-vars/uds-bundle.yaml @@ -10,6 +10,9 @@ packages: ref: 0.0.1 exports: - name: COLOR + - name: ANNOTATION + - name: DEFENSE + - name: BOOL - name: helm-overrides path: "../../packages/helm" @@ -17,6 +20,12 @@ packages: imports: - name: COLOR package: output-var + - name: ANNOTATION + package: output-var + - name: DEFENSE + package: output-var + - name: BOOL + package: output-var overrides: podinfo-component: @@ -26,3 +35,16 @@ packages: value: 1 - path: "podinfo.ui.color" value: ${COLOR} + - path: podinfo.podAnnotations + value: + customAnnotation: ${COLOR}${ANNOTATION} + - path: "podinfo.tolerations" + value: + - key: "unicorn" + operator: "Equal" + value: ${DEFENSE} + effect: "NoSchedule" + - key: "uds" + operator: "Equal" + value: ${BOOL} + effect: "NoSchedule" diff --git a/src/test/e2e/variable_test.go b/src/test/e2e/variable_test.go index 3aadd87f..f8b11217 100644 --- a/src/test/e2e/variable_test.go +++ b/src/test/e2e/variable_test.go @@ -223,11 +223,26 @@ func TestZarfPackageExportVarsAsGlobalBundleVars(t *testing.T) { createLocal(t, bundleDir, e2e.Arch) deploy(t, bundlePath) - // check variables overrides + // check templated variables overrides in values cmd := strings.Split("zarf tools kubectl get deploy -n podinfo unicorn-podinfo -o=jsonpath='{.spec.template.spec.containers[0].env[?(@.name==\"PODINFO_UI_COLOR\")].value}'", " ") outputUIColor, _, err := e2e.UDS(cmd...) require.Equal(t, "'orange'", outputUIColor) require.NoError(t, err) + // check multiple templated variables as object overrides in values + cmd = strings.Split("zarf tools kubectl get deployment -n podinfo unicorn-podinfo -o=jsonpath='{.spec.template.metadata.annotations}'", " ") + annotations, _, err := e2e.UDS(cmd...) + require.Contains(t, annotations, "\"customAnnotation\":\"orangeAnnotation\"") + require.NoError(t, err) + + // check templated variable list-type overrides in values + cmd = strings.Split("zarf tools kubectl get deployment -n podinfo unicorn-podinfo -o=jsonpath='{.spec.template.spec.tolerations}'", " ") + tolerations, _, err := e2e.UDS(cmd...) + require.Contains(t, tolerations, "\"key\":\"uds\"") + require.Contains(t, tolerations, "\"value\":\"defense\"") + require.Contains(t, tolerations, "\"key\":\"unicorn\"") + require.Contains(t, tolerations, "\"effect\":\"NoSchedule\"") + require.NoError(t, err) + remove(t, bundlePath) } diff --git a/src/test/packages/no-cluster/output-var/zarf.yaml b/src/test/packages/no-cluster/output-var/zarf.yaml index eddb6ea2..a54b3477 100644 --- a/src/test/packages/no-cluster/output-var/zarf.yaml +++ b/src/test/packages/no-cluster/output-var/zarf.yaml @@ -34,3 +34,12 @@ components: - cmd: echo "orange" setVariables: - name: COLOR + - cmd: echo "Annotation" + setVariables: + - name: ANNOTATION + - cmd: echo "defense" + setVariables: + - name: DEFENSE + - cmd: echo "true" + setVariables: + - name: BOOL From a98f28e71b0320acb26a4ce50fceb7b976f45676 Mon Sep 17 00:00:00 2001 From: Darcy Cleaver Date: Wed, 21 Feb 2024 11:49:45 -0700 Subject: [PATCH 07/13] fix: package paths --- src/test/bundles/12-exported-pkg-vars/uds-bundle.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/bundles/12-exported-pkg-vars/uds-bundle.yaml b/src/test/bundles/12-exported-pkg-vars/uds-bundle.yaml index 83d872fb..1d66e205 100644 --- a/src/test/bundles/12-exported-pkg-vars/uds-bundle.yaml +++ b/src/test/bundles/12-exported-pkg-vars/uds-bundle.yaml @@ -15,7 +15,7 @@ packages: - name: BOOL - name: helm-overrides - path: "../../packages/helm" + path: "src/test/packages/helm" ref: 0.0.1 imports: - name: COLOR From e153c06d4bc1f32e66d359ce7c853123bef901e8 Mon Sep 17 00:00:00 2001 From: Darcy Cleaver Date: Wed, 21 Feb 2024 13:35:24 -0700 Subject: [PATCH 08/13] fix test case --- src/test/e2e/variable_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/e2e/variable_test.go b/src/test/e2e/variable_test.go index 0db3c471..ceb4fc56 100644 --- a/src/test/e2e/variable_test.go +++ b/src/test/e2e/variable_test.go @@ -239,9 +239,9 @@ func TestZarfPackageExportVarsAsGlobalBundleVars(t *testing.T) { cmd = strings.Split("zarf tools kubectl get deployment -n podinfo unicorn-podinfo -o=jsonpath='{.spec.template.spec.tolerations}'", " ") tolerations, _, err := e2e.UDS(cmd...) require.Contains(t, tolerations, "\"key\":\"uds\"") - require.Contains(t, tolerations, "\"value\":\"defense\"") + require.Contains(t, tolerations, "\"value\":\"true\"") require.Contains(t, tolerations, "\"key\":\"unicorn\"") - require.Contains(t, tolerations, "\"effect\":\"NoSchedule\"") + require.Contains(t, tolerations, "\"value\":\"defense\"") require.NoError(t, err) remove(t, bundlePath) From b687ff4b234291861fc1740f5a51a2a7a4d7263d Mon Sep 17 00:00:00 2001 From: Darcy Cleaver Date: Wed, 21 Feb 2024 15:03:14 -0700 Subject: [PATCH 09/13] update test to ensure templating still works when import not specified --- src/test/bundles/12-exported-pkg-vars/uds-bundle.yaml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/test/bundles/12-exported-pkg-vars/uds-bundle.yaml b/src/test/bundles/12-exported-pkg-vars/uds-bundle.yaml index 1d66e205..b22c7275 100644 --- a/src/test/bundles/12-exported-pkg-vars/uds-bundle.yaml +++ b/src/test/bundles/12-exported-pkg-vars/uds-bundle.yaml @@ -22,10 +22,6 @@ packages: package: output-var - name: ANNOTATION package: output-var - - name: DEFENSE - package: output-var - - name: BOOL - package: output-var overrides: podinfo-component: From 15fadfd41321856ca99a6d436e8a6352b8a63c4f Mon Sep 17 00:00:00 2001 From: Darcy Cleaver Date: Wed, 21 Feb 2024 15:26:55 -0700 Subject: [PATCH 10/13] linting cleanup --- src/test/e2e/commands_test.go | 2 +- src/test/e2e/variable_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/e2e/commands_test.go b/src/test/e2e/commands_test.go index 1cf9e501..90eb0e1d 100644 --- a/src/test/e2e/commands_test.go +++ b/src/test/e2e/commands_test.go @@ -30,7 +30,7 @@ func createLocal(t *testing.T, bundlePath string, arch string) { require.NoError(t, err) } -func createLocalError(t *testing.T, bundlePath string, arch string) (stderr string) { +func createLocalError(bundlePath string, arch string) (stderr string) { cmd := strings.Split(fmt.Sprintf("create %s --insecure --confirm -a %s", bundlePath, arch), " ") _, stderr, _ = e2e.UDS(cmd...) return stderr diff --git a/src/test/e2e/variable_test.go b/src/test/e2e/variable_test.go index 7bbafe6d..038bb2ed 100644 --- a/src/test/e2e/variable_test.go +++ b/src/test/e2e/variable_test.go @@ -51,7 +51,7 @@ func TestBundleVariables(t *testing.T) { // Test with bad variable name in import bundleDir = "src/test/bundles/02-simple-vars/import-all-bad-name" - stderr = createLocalError(t, bundleDir, e2e.Arch) + stderr = createLocalError(bundleDir, e2e.Arch) require.Contains(t, stderr, "does not have a matching export") // Test name collisions with exported variables From 9349ae084794a7940e10fd8fa3696c72cef3f1b9 Mon Sep 17 00:00:00 2001 From: decleaver <85503726+decleaver@users.noreply.github.com> Date: Thu, 22 Feb 2024 08:23:37 -0700 Subject: [PATCH 11/13] Update docs/overrides.md Co-authored-by: UncleGedd <42304551+UncleGedd@users.noreply.github.com> --- docs/overrides.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/overrides.md b/docs/overrides.md index 4bf1482d..afd686b6 100644 --- a/docs/overrides.md +++ b/docs/overrides.md @@ -130,7 +130,7 @@ The `value` is the value to set at the `path`. Values can be simple values such value: customAnnotation: "customValue" ``` -If [importing](../README.md#importingexporting-variables) a variable from another package, that variable can also be used to set a value, using the template syntax `${...}`. In the example below the `COLOR` variable is being used to set the `podinfo.ui.color` value. +If using a variable that has been [exported](../README.md#importingexporting-variables) from another package, that variable can also be used to set a value, using the syntax `${...}`. In the example below the `COLOR` variable is being used to set the `podinfo.ui.color` value. ``` kind: UDSBundle metadata: From 8c36d1832099c4f65e8280699559f6af1d1a48a2 Mon Sep 17 00:00:00 2001 From: Darcy Cleaver Date: Thu, 22 Feb 2024 08:28:31 -0700 Subject: [PATCH 12/13] ensure variables exist in package when exporting --- src/pkg/bundle/deploy.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/pkg/bundle/deploy.go b/src/pkg/bundle/deploy.go index fa7019f4..97274525 100644 --- a/src/pkg/bundle/deploy.go +++ b/src/pkg/bundle/deploy.go @@ -205,6 +205,10 @@ func deployPackages(packages []types.Package, resume bool, b *Bundle, zarfPackag // save exported vars pkgExportedVars := make(map[string]string) for _, exp := range pkg.Exports { + // ensure if variable exists in package + if _, ok := pkgCfg.SetVariableMap[exp.Name]; !ok { + return fmt.Errorf("cannot export variable %s because it does not exist in package %s", exp.Name, pkg.Name) + } pkgExportedVars[strings.ToUpper(exp.Name)] = pkgCfg.SetVariableMap[exp.Name].Value } bundleExportedVars[pkg.Name] = pkgExportedVars From b8c79321199f0eb676702104d18faf4f0ba5e09a Mon Sep 17 00:00:00 2001 From: decleaver <85503726+decleaver@users.noreply.github.com> Date: Thu, 22 Feb 2024 08:29:59 -0700 Subject: [PATCH 13/13] Update docs/overrides.md Co-authored-by: UncleGedd <42304551+UncleGedd@users.noreply.github.com> --- docs/overrides.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/docs/overrides.md b/docs/overrides.md index afd686b6..5935af92 100644 --- a/docs/overrides.md +++ b/docs/overrides.md @@ -148,9 +148,6 @@ packages: - name: helm-overrides path: "../../packages/helm" ref: 0.0.1 - imports: - - name: COLOR - package: output-var overrides: podinfo-component: