From f05eb5ec5a387cfe14233b6fab22e28c5f40fb6e Mon Sep 17 00:00:00 2001 From: Austin Abro Date: Mon, 22 Jan 2024 16:28:30 +0000 Subject: [PATCH 01/68] WIP, now signed --- src/cmd/dev.go | 10 +++ src/config/lang/english.go | 1 + src/extensions/bigbang/bigbang.go | 1 + src/internal/packager/helm/chart.go | 19 ++++- src/internal/packager/helm/common.go | 12 ++- src/internal/packager/helm/post-render.go | 5 +- src/internal/packager/helm/prepare-render.go | 80 +++++++++++++++++++ src/internal/packager/helm/repo.go | 2 +- src/internal/packager/helm/utils.go | 3 +- src/internal/packager/template/template.go | 10 +++ src/pkg/packager/create_stages.go | 2 +- src/pkg/packager/deploy.go | 2 +- src/pkg/packager/prepare.go | 36 +++++++-- src/test/e2e/00_use_cli_test.go | 16 ++++ .../packages/00-find-images/deployment.yaml | 19 +++++ .../packages/00-find-images/gitea-values.yaml | 1 + .../00-find-images/simple-helm/.helmignore | 23 ++++++ .../00-find-images/simple-helm/Chart.yaml | 6 ++ .../simple-helm/templates/NOTES.txt | 1 + .../simple-helm/templates/_helpers.tpl | 6 ++ .../simple-helm/templates/deployment.yaml | 21 +++++ .../00-find-images/simple-helm/values.yaml | 4 + src/test/packages/00-find-images/zarf.yaml | 36 +++++++++ src/types/runtime.go | 1 + 24 files changed, 295 insertions(+), 22 deletions(-) create mode 100644 src/internal/packager/helm/prepare-render.go create mode 100644 src/test/packages/00-find-images/deployment.yaml create mode 100644 src/test/packages/00-find-images/gitea-values.yaml create mode 100644 src/test/packages/00-find-images/simple-helm/.helmignore create mode 100644 src/test/packages/00-find-images/simple-helm/Chart.yaml create mode 100644 src/test/packages/00-find-images/simple-helm/templates/NOTES.txt create mode 100644 src/test/packages/00-find-images/simple-helm/templates/_helpers.tpl create mode 100644 src/test/packages/00-find-images/simple-helm/templates/deployment.yaml create mode 100644 src/test/packages/00-find-images/simple-helm/values.yaml create mode 100644 src/test/packages/00-find-images/zarf.yaml diff --git a/src/cmd/dev.go b/src/cmd/dev.go index 63426692ea..e45f244e23 100644 --- a/src/cmd/dev.go +++ b/src/cmd/dev.go @@ -190,8 +190,11 @@ var devFindImagesCmd = &cobra.Command{ // Ensure uppercase keys from viper v := common.GetViper() + pkgConfig.CreateOpts.SetVariables = helpers.TransformAndMergeMap( v.GetStringMapString(common.VPkgCreateSet), pkgConfig.CreateOpts.SetVariables, strings.ToUpper) + pkgConfig.PkgOpts.SetVariables = helpers.TransformAndMergeMap( + v.GetStringMapString(common.VPkgDeploySet), pkgConfig.PkgOpts.SetVariables, strings.ToUpper) // Configure the packager pkgClient := packager.NewOrDie(&pkgConfig) @@ -265,9 +268,16 @@ func init() { devFindImagesCmd.Flags().StringVarP(&pkgConfig.FindImagesOpts.RepoHelmChartPath, "repo-chart-path", "p", "", lang.CmdDevFlagRepoChartPath) // use the package create config for this and reset it here to avoid overwriting the config.CreateOptions.SetVariables devFindImagesCmd.Flags().StringToStringVar(&pkgConfig.CreateOpts.SetVariables, "set", v.GetStringMapString(common.VPkgCreateSet), lang.CmdDevFlagSet) + + devFindImagesCmd.Flags().MarkDeprecated("set", "This field is replaced by create-set") + devFindImagesCmd.Flags().MarkHidden("set") + devFindImagesCmd.Flags().StringToStringVar(&pkgConfig.CreateOpts.SetVariables, "create-set", v.GetStringMapString(common.VPkgCreateSet), lang.CmdDevFlagSet) + devFindImagesCmd.Flags().StringToStringVar(&pkgConfig.PkgOpts.SetVariables, "deploy-set", v.GetStringMapString(common.VPkgDeploySet), lang.CmdPackageDeployFlagSet) // allow for the override of the default helm KubeVersion devFindImagesCmd.Flags().StringVar(&pkgConfig.FindImagesOpts.KubeVersionOverride, "kube-version", "", lang.CmdDevFlagKubeVersion) + devFindImagesCmd.Flags().StringVar(&pkgConfig.FindImagesOpts.RegistryOverride, "registry", "127.0.0.1:31999", lang.CmdDevFlagRegistry) + devLintCmd.Flags().StringToStringVar(&pkgConfig.CreateOpts.SetVariables, "set", v.GetStringMapString(common.VPkgCreateSet), lang.CmdPackageCreateFlagSet) devLintCmd.Flags().StringVarP(&pkgConfig.CreateOpts.Flavor, "flavor", "f", v.GetString(common.VPkgCreateFlavor), lang.CmdPackageCreateFlagFlavor) devTransformGitLinksCmd.Flags().StringVar(&pkgConfig.InitOpts.GitServer.PushUsername, "git-account", config.ZarfGitPushUser, lang.CmdDevFlagGitAccount) diff --git a/src/config/lang/english.go b/src/config/lang/english.go index 6a666474d7..6f9383ba8b 100644 --- a/src/config/lang/english.go +++ b/src/config/lang/english.go @@ -384,6 +384,7 @@ $ zarf package pull oci://ghcr.io/defenseunicorns/packages/dos-games:1.0.0 -a sk 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" + CmdDevFlagRegistry = "Override the ###ZARF_REGISTRY### value for checks on images using the zarf registry" 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" diff --git a/src/extensions/bigbang/bigbang.go b/src/extensions/bigbang/bigbang.go index 66427a682f..a0d46b0b40 100644 --- a/src/extensions/bigbang/bigbang.go +++ b/src/extensions/bigbang/bigbang.go @@ -94,6 +94,7 @@ func Run(YOLO bool, tmpPaths *layout.ComponentPaths, c types.ZarfComponent) (typ }, path.Join(tmpPaths.Temp, bb), path.Join(tmpPaths.Temp, bb, "values"), + helm.WithPackageConfig(&types.PackagerConfig{}), ) // Download the chart from Git and save it to a temporary directory. diff --git a/src/internal/packager/helm/chart.go b/src/internal/packager/helm/chart.go index a52c51967f..91ebf921c0 100644 --- a/src/internal/packager/helm/chart.go +++ b/src/internal/packager/helm/chart.go @@ -139,12 +139,18 @@ func (h *Helm) InstallOrUpgradeChart() (types.ConnectStrings, string, error) { } // TemplateChart generates a helm template from a given chart. -func (h *Helm) TemplateChart() (string, chartutil.Values, error) { +func (h *Helm) TemplateChart() (manifest string, chartValues chartutil.Values, err error) { message.Debugf("helm.TemplateChart()") spinner := message.NewProgressSpinner("Templating helm chart %s", h.chart.Name) - defer spinner.Stop() + defer func() { + if err != nil { + spinner.Errorf(err, "Problem rendering the helm template for %s: %s", h.chart.Name, err.Error()) + } else { + spinner.Stop() + } + }() - err := h.createActionConfig(h.chart.Namespace, spinner) + err = h.createActionConfig(h.chart.Namespace, spinner) // Setup K8s connection. if err != nil { @@ -183,13 +189,18 @@ func (h *Helm) TemplateChart() (string, chartutil.Values, error) { return "", nil, fmt.Errorf("unable to load chart data: %w", err) } + client.PostRenderer, err = h.newDevRenderer() + if err != nil { + return "", nil, fmt.Errorf("unable to get dev renderer: %w", err) + } + // Perform the loadedChart installation. templatedChart, err := client.Run(loadedChart, chartValues) if err != nil { return "", nil, fmt.Errorf("error generating helm chart template: %w", err) } - manifest := templatedChart.Manifest + manifest = templatedChart.Manifest for _, hook := range templatedChart.Hooks { manifest += fmt.Sprintf("\n---\n%s", hook.Manifest) diff --git a/src/internal/packager/helm/common.go b/src/internal/packager/helm/common.go index b8f7dafb1a..00f04be284 100644 --- a/src/internal/packager/helm/common.go +++ b/src/internal/packager/helm/common.go @@ -15,8 +15,8 @@ import ( "time" "github.com/defenseunicorns/zarf/src/config" - "github.com/defenseunicorns/zarf/src/pkg/message" "github.com/defenseunicorns/zarf/src/pkg/cluster" + "github.com/defenseunicorns/zarf/src/pkg/message" "github.com/defenseunicorns/zarf/src/types" "helm.sh/helm/v3/pkg/action" "helm.sh/helm/v3/pkg/chart" @@ -148,7 +148,17 @@ func WithKubeVersion(kubeVersion string) Modifier { } } +func WithPackageConfig(cfg *types.PackagerConfig) Modifier { + return func(h *Helm) { + h.cfg = cfg + } +} + // StandardName generates a predictable full path for a helm chart for Zarf. func StandardName(destination string, chart types.ZarfChart) string { return filepath.Join(destination, chart.Name+"-"+chart.Version) } + +func StandardValuesName(destination string, chart types.ZarfChart, idx int) string { + return fmt.Sprintf("%s-%d.yaml", StandardName(destination, chart), idx) +} diff --git a/src/internal/packager/helm/post-render.go b/src/internal/packager/helm/post-render.go index 7d89098ad3..bf5f00de80 100644 --- a/src/internal/packager/helm/post-render.go +++ b/src/internal/packager/helm/post-render.go @@ -16,7 +16,6 @@ import ( "github.com/defenseunicorns/zarf/src/pkg/message" "github.com/defenseunicorns/zarf/src/pkg/utils" "github.com/defenseunicorns/zarf/src/types" - "helm.sh/helm/v3/pkg/action" "helm.sh/helm/v3/pkg/releaseutil" corev1 "k8s.io/api/core/v1" "sigs.k8s.io/yaml" @@ -27,7 +26,6 @@ import ( type renderer struct { *Helm - actionConfig *action.Configuration connectStrings types.ConnectStrings namespaces map[string]*corev1.Namespace values template.Values @@ -48,8 +46,7 @@ func (h *Helm) newRenderer() (*renderer, error) { // Add the passed-in namespace to the list h.chart.Namespace: h.cluster.NewZarfManagedNamespace(h.chart.Namespace), }, - values: *valueTemplate, - actionConfig: h.actionConfig, + values: *valueTemplate, }, nil } diff --git a/src/internal/packager/helm/prepare-render.go b/src/internal/packager/helm/prepare-render.go new file mode 100644 index 0000000000..49e8237562 --- /dev/null +++ b/src/internal/packager/helm/prepare-render.go @@ -0,0 +1,80 @@ +// SPDX-License-Identifier: Apache-2.0 +// SPDX-FileCopyrightText: 2021-Present The Zarf Authors + +// Package helm contains operations for working with helm charts. +package helm + +import ( + "bytes" + "fmt" + "os" + "path/filepath" + + "github.com/defenseunicorns/zarf/src/internal/packager/template" + "github.com/defenseunicorns/zarf/src/pkg/utils" + "github.com/defenseunicorns/zarf/src/types" + "helm.sh/helm/v3/pkg/releaseutil" +) + +type devRenderer struct { + *Helm + values template.Values +} + +func (h *Helm) newDevRenderer() (*devRenderer, error) { + values, err := template.Generate(h.cfg) + if err != nil { + return nil, err + } + values.SetState(&types.ZarfState{}) + + return &devRenderer{ + Helm: h, + values: *values, + }, nil +} + +func (r *devRenderer) Run(renderedManifests *bytes.Buffer) (*bytes.Buffer, error) { + // This is very low cost and consistent for how we replace elsewhere, also good for debugging + tempDir, err := utils.MakeTempDir(r.chartPath) + if err != nil { + return nil, fmt.Errorf("unable to create tmpdir: %w", err) + } + path := filepath.Join(tempDir, "chart.yaml") + + // Write the context to a file for processing + if err := utils.WriteFile(path, renderedManifests.Bytes()); err != nil { + return nil, fmt.Errorf("unable to write the post-render file for the helm chart") + } + + // Run the template engine against the chart output + if _, err := template.ProcessYamlFilesInPath(tempDir, r.component, r.values); err != nil { + return nil, fmt.Errorf("error templating the helm chart: %w", err) + } + + // Read back the templated file contents + buff, err := os.ReadFile(path) + if err != nil { + return nil, fmt.Errorf("error reading temporary post-rendered helm chart: %w", err) + } + + // Use helm to re-split the manifest byte (same call used by helm to pass this data to postRender) + _, resources, err := releaseutil.SortManifests(map[string]string{path: string(buff)}, + r.actionConfig.Capabilities.APIVersions, + releaseutil.InstallOrder, + ) + + if err != nil { + return nil, fmt.Errorf("error re-rendering helm output: %w", err) + } + + finalManifestsOutput := bytes.NewBuffer(nil) + + // Otherwise, loop over the resources, + for _, resource := range resources { + fmt.Fprintf(finalManifestsOutput, "---\n# Source: %s\n%s\n", resource.Name, resource.Content) + } + + // Send the bytes back to helm + return finalManifestsOutput, nil +} diff --git a/src/internal/packager/helm/repo.go b/src/internal/packager/helm/repo.go index ae41d2b0bc..664f8f8b71 100644 --- a/src/internal/packager/helm/repo.go +++ b/src/internal/packager/helm/repo.go @@ -242,7 +242,7 @@ func (h *Helm) finalizeChartPackage(saved, cosignKeyPath string) error { func (h *Helm) packageValues(cosignKeyPath string) error { for valuesIdx, path := range h.chart.ValuesFiles { - dst := fmt.Sprintf("%s-%d", StandardName(h.valuesPath, h.chart), valuesIdx) + dst := StandardValuesName(h.valuesPath, h.chart, valuesIdx) if helpers.IsURL(path) { if err := utils.DownloadToFile(path, dst, cosignKeyPath); err != nil { diff --git a/src/internal/packager/helm/utils.go b/src/internal/packager/helm/utils.go index 0ea8d91938..563ff5200a 100644 --- a/src/internal/packager/helm/utils.go +++ b/src/internal/packager/helm/utils.go @@ -6,7 +6,6 @@ package helm import ( "fmt" - "strconv" "github.com/defenseunicorns/zarf/src/pkg/message" "github.com/defenseunicorns/zarf/src/pkg/utils/helpers" @@ -43,7 +42,7 @@ func (h *Helm) parseChartValues() (chartutil.Values, error) { valueOpts := &values.Options{} for idx := range h.chart.ValuesFiles { - path := StandardName(h.valuesPath, h.chart) + "-" + strconv.Itoa(idx) + path := StandardValuesName(h.valuesPath, h.chart, idx) valueOpts.ValueFiles = append(valueOpts.ValueFiles, path) } diff --git a/src/internal/packager/template/template.go b/src/internal/packager/template/template.go index 7239947e8b..4b59373e3b 100644 --- a/src/internal/packager/template/template.go +++ b/src/internal/packager/template/template.go @@ -71,6 +71,16 @@ func (values *Values) GetRegistry() string { return values.registry } +// SetRegistry sets the registry +func (values *Values) SetRegistry(registry string) { + values.registry = registry +} + +// SetState sets the state +func (values *Values) SetState(state *types.ZarfState) { + values.config.State = state +} + // GetVariables returns the variables to be used in the template. func (values *Values) GetVariables(component types.ZarfComponent) (templateMap map[string]*utils.TextTemplate, deprecations map[string]string) { templateMap = make(map[string]*utils.TextTemplate) diff --git a/src/pkg/packager/create_stages.go b/src/pkg/packager/create_stages.go index 2ae7f06ad9..cc3b7af2c1 100644 --- a/src/pkg/packager/create_stages.go +++ b/src/pkg/packager/create_stages.go @@ -403,7 +403,7 @@ func (p *Packager) addComponent(index int, component types.ZarfComponent) error continue } - rel := fmt.Sprintf("%s-%d", helm.StandardName(layout.ValuesDir, chart), valuesIdx) + rel := helm.StandardValuesName(layout.ValuesDir, chart, valuesIdx) p.cfg.Pkg.Components[index].Charts[chartIdx].ValuesFiles[valuesIdx] = rel if err := utils.CreatePathAndCopy(path, filepath.Join(componentPaths.Base, rel)); err != nil { diff --git a/src/pkg/packager/deploy.go b/src/pkg/packager/deploy.go index a4a2408431..79afe0ceb4 100644 --- a/src/pkg/packager/deploy.go +++ b/src/pkg/packager/deploy.go @@ -521,7 +521,7 @@ func (p *Packager) installChartAndManifests(componentPaths *layout.ComponentPath // zarf magic for the value file for idx := range chart.ValuesFiles { - chartValueName := fmt.Sprintf("%s-%d", helm.StandardName(componentPaths.Values, chart), idx) + chartValueName := helm.StandardValuesName(componentPaths.Values, chart, idx) if err := p.valueTemplate.Apply(component, chartValueName, false); err != nil { return installedCharts, err } diff --git a/src/pkg/packager/prepare.go b/src/pkg/packager/prepare.go index 3bdde325d9..d4f51880f1 100644 --- a/src/pkg/packager/prepare.go +++ b/src/pkg/packager/prepare.go @@ -15,6 +15,7 @@ import ( "github.com/defenseunicorns/zarf/src/config/lang" "github.com/defenseunicorns/zarf/src/internal/packager/helm" "github.com/defenseunicorns/zarf/src/internal/packager/kustomize" + "github.com/defenseunicorns/zarf/src/internal/packager/template" "github.com/defenseunicorns/zarf/src/pkg/k8s" "github.com/defenseunicorns/zarf/src/pkg/layout" "github.com/defenseunicorns/zarf/src/pkg/message" @@ -75,6 +76,10 @@ func (p *Packager) FindImages() (imgMap map[string][]string, err error) { componentDefinition := "\ncomponents:\n" + if err := p.setVariableMapInConfig(); err != nil { + return nil, fmt.Errorf("unable to set the active variables: %w", err) + } + for _, component := range p.cfg.Pkg.Components { if len(component.Charts)+len(component.Manifests)+len(component.Repos) < 1 { @@ -115,36 +120,44 @@ func (p *Packager) FindImages() (imgMap map[string][]string, err error) { if err != nil { return nil, err } - + values, err := template.Generate(p.cfg) + if err != nil { + return nil, fmt.Errorf("unable to generate template values") + } + values.SetState(&types.ZarfState{}) + values.SetRegistry(p.cfg.FindImagesOpts.RegistryOverride) for _, chart := range component.Charts { + helmCfg := helm.New( chart, componentPaths.Charts, componentPaths.Values, helm.WithKubeVersion(kubeVersionOverride), + helm.WithPackageConfig(p.cfg), ) - err := helmCfg.PackageChart(component.DeprecatedCosignKeyPath) + err = helmCfg.PackageChart(component.DeprecatedCosignKeyPath) if err != nil { - return nil, fmt.Errorf("unable to package the chart %s: %s", chart.URL, err.Error()) + return nil, fmt.Errorf("unable to package the chart %s: %s", chart.Name, err.Error()) } + template.ProcessYamlFilesInPath(componentPaths.Values, component, *values) + // Generate helm templates for this chart - template, values, err := helmCfg.TemplateChart() + chartTemplate, chartValues, err := helmCfg.TemplateChart() if err != nil { - message.WarnErrf(err, "Problem rendering the helm template for %s: %s", chart.URL, err.Error()) - erroredCharts = append(erroredCharts, chart.URL) + erroredCharts = append(erroredCharts, chart.Name) continue } // Break the template into separate resources - yamls, _ := utils.SplitYAML([]byte(template)) + yamls, _ := utils.SplitYAML([]byte(chartTemplate)) resources = append(resources, yamls...) chartTarball := helm.StandardName(componentPaths.Charts, chart) + ".tgz" - annotatedImages, err := helm.FindAnnotatedImagesForChart(chartTarball, values) + annotatedImages, err := helm.FindAnnotatedImagesForChart(chartTarball, chartValues) if err != nil { message.WarnErrf(err, "Problem looking for image annotations for %s: %s", chart.URL, err.Error()) erroredCharts = append(erroredCharts, chart.URL) @@ -174,8 +187,15 @@ func (p *Packager) FindImages() (imgMap map[string][]string, err error) { return nil, fmt.Errorf(lang.ErrDownloading, f, err.Error()) } f = destination + } else { + newDestination := filepath.Join(componentPaths.Manifests, f) + utils.CreatePathAndCopy(f, newDestination) + f = newDestination } + if err := values.Apply(component, f, true); err != nil { + return nil, err + } // Read the contents of each file contents, err := os.ReadFile(f) if err != nil { diff --git a/src/test/e2e/00_use_cli_test.go b/src/test/e2e/00_use_cli_test.go index 2eaf6a6ed8..11aa7a9f34 100644 --- a/src/test/e2e/00_use_cli_test.go +++ b/src/test/e2e/00_use_cli_test.go @@ -79,6 +79,10 @@ func TestUseCLI(t *testing.T) { stdOut, stdErr, err = e2e.Zarf("prepare", "find-images", "src/test/packages/00-helm-annotations") require.NoError(t, err, stdOut, stdErr) require.Contains(t, stdOut, "registry1.dso.mil/ironbank/opensource/istio/pilot:1.17.2", "The pilot image should be found by Zarf") + + stdOut, stdErr, err = e2e.Zarf("prepare", "find-images", "src/test/packages/00-helm-annotations") + require.NoError(t, err, stdOut, stdErr) + require.Contains(t, stdOut, "registry1.dso.mil/ironbank/opensource/istio/pilot:1.17.2", "The pilot image should be found by Zarf") }) t.Run("zarf prepare find-images --kube-version", func(t *testing.T) { @@ -243,3 +247,15 @@ func TestUseCLI(t *testing.T) { require.FileExists(t, tlsKey) }) } + +func TestUseCLI2(t *testing.T) { + t.Run("zarf prepare find-images with helm or manifest vars", func(t *testing.T) { + t.Parallel() + // Test `zarf prepare find-images` for a package with zarf variables in the chart, values file, and manifests + path := filepath.Join("src", "test", "packages", "00-find-images") + stdOut, _, err := e2e.Zarf("prepare", "find-images", path) + require.NoError(t, err) + require.Contains(t, stdOut, "defenseunicorns/zarf/agent:local", "If this isn't found manifests aren't interpreting vars") + require.Contains(t, stdOut, "nginx:stable-perl", "If this isn't found helm or values files aren't interpreting vars") + }) +} diff --git a/src/test/packages/00-find-images/deployment.yaml b/src/test/packages/00-find-images/deployment.yaml new file mode 100644 index 0000000000..ff2a7fbc32 --- /dev/null +++ b/src/test/packages/00-find-images/deployment.yaml @@ -0,0 +1,19 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: simple-deployment + labels: + app: simple-deployment +spec: + replicas: 1 + selector: + matchLabels: + app: simple-deployment + template: + metadata: + labels: + app: simple-deployment + spec: + containers: + - name: server + image: "###ZARF_REGISTRY###/###ZARF_CONST_AGENT_IMAGE###:###ZARF_CONST_AGENT_IMAGE_TAG###" diff --git a/src/test/packages/00-find-images/gitea-values.yaml b/src/test/packages/00-find-images/gitea-values.yaml new file mode 100644 index 0000000000..296825df9d --- /dev/null +++ b/src/test/packages/00-find-images/gitea-values.yaml @@ -0,0 +1 @@ +replicaCount: ###ZARF_VAR_GIT_SERVER_REPLICA_COUNT### diff --git a/src/test/packages/00-find-images/simple-helm/.helmignore b/src/test/packages/00-find-images/simple-helm/.helmignore new file mode 100644 index 0000000000..0e8a0eb36f --- /dev/null +++ b/src/test/packages/00-find-images/simple-helm/.helmignore @@ -0,0 +1,23 @@ +# Patterns to ignore when building packages. +# This supports shell glob matching, relative path matching, and +# negation (prefixed with !). Only one pattern per line. +.DS_Store +# Common VCS dirs +.git/ +.gitignore +.bzr/ +.bzrignore +.hg/ +.hgignore +.svn/ +# Common backup files +*.swp +*.bak +*.tmp +*.orig +*~ +# Various IDEs +.project +.idea/ +*.tmproj +.vscode/ diff --git a/src/test/packages/00-find-images/simple-helm/Chart.yaml b/src/test/packages/00-find-images/simple-helm/Chart.yaml new file mode 100644 index 0000000000..3027fceee2 --- /dev/null +++ b/src/test/packages/00-find-images/simple-helm/Chart.yaml @@ -0,0 +1,6 @@ +apiVersion: v2 +name: simple-helm +description: A Helm chart for Kubernetes +type: application +version: 0.1.0 +appVersion: "1.16.0" diff --git a/src/test/packages/00-find-images/simple-helm/templates/NOTES.txt b/src/test/packages/00-find-images/simple-helm/templates/NOTES.txt new file mode 100644 index 0000000000..7d790da089 --- /dev/null +++ b/src/test/packages/00-find-images/simple-helm/templates/NOTES.txt @@ -0,0 +1 @@ +1. Get the application URL by running these commands: diff --git a/src/test/packages/00-find-images/simple-helm/templates/_helpers.tpl b/src/test/packages/00-find-images/simple-helm/templates/_helpers.tpl new file mode 100644 index 0000000000..51a7e88ab8 --- /dev/null +++ b/src/test/packages/00-find-images/simple-helm/templates/_helpers.tpl @@ -0,0 +1,6 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "simple-helm.name" -}} +{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }} +{{- end }} diff --git a/src/test/packages/00-find-images/simple-helm/templates/deployment.yaml b/src/test/packages/00-find-images/simple-helm/templates/deployment.yaml new file mode 100644 index 0000000000..7fe9c208fb --- /dev/null +++ b/src/test/packages/00-find-images/simple-helm/templates/deployment.yaml @@ -0,0 +1,21 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: simple-deployment + labels: + app: simple-deployment +spec: +{{- if gt .Values.replicaCount 1.0 -}} + replicas: 1 +{{- end }} + selector: + matchLabels: + app: simple-deployment + template: + metadata: + labels: + app: simple-deployment + spec: + containers: + - name: server + image: "###ZARF_CONST_HELM_IMAGE###:stable-perl" diff --git a/src/test/packages/00-find-images/simple-helm/values.yaml b/src/test/packages/00-find-images/simple-helm/values.yaml new file mode 100644 index 0000000000..ee7ea11c10 --- /dev/null +++ b/src/test/packages/00-find-images/simple-helm/values.yaml @@ -0,0 +1,4 @@ +# Default values for simple-helm. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. +replicaCount: 1 diff --git a/src/test/packages/00-find-images/zarf.yaml b/src/test/packages/00-find-images/zarf.yaml new file mode 100644 index 0000000000..00834d3796 --- /dev/null +++ b/src/test/packages/00-find-images/zarf.yaml @@ -0,0 +1,36 @@ +kind: ZarfPackageConfig +metadata: + name: find-image-with-variables + description: Simple zarf package with variables + +variables: + - name: GIT_SERVER_REPLICA_COUNT + description: The number of git server replicas to deploy + default: "1" + +constants: + - name: AGENT_IMAGE + value: "defenseunicorns/zarf/agent" + - name: AGENT_IMAGE_TAG + value: "local" + - name: HELM_IMAGE + value: "nginx" + +components: +- name: simple-var + required: true + manifests: + - name: simple-deployment + namespace: zarf + files: + - deployment.yaml +- name: chart-with-var + required: true + charts: + - name: simple + releaseName: simple + localPath: simple-helm + namespace: zarf-simple + version: 0.1.0 + valuesFiles: + - gitea-values.yaml diff --git a/src/types/runtime.go b/src/types/runtime.go index 3878bb0aef..5d17df74e0 100644 --- a/src/types/runtime.go +++ b/src/types/runtime.go @@ -55,6 +55,7 @@ type ZarfInspectOptions struct { type ZarfFindImagesOptions struct { RepoHelmChartPath string `json:"repoHelmChartPath" jsonschema:"description=Path to the helm chart directory"` KubeVersionOverride string `json:"kubeVersionOverride" jsonschema:"description=Kubernetes version to use for the helm chart"` + RegistryOverride string `json:"registryOverride" jsonschema:"description=Manual override for ###ZARF_REGISTRY###` } // ZarfDeployOptions tracks the user-defined preferences during a package deploy. From 700255f6322bf9be8a513f2982a4e5299a13c8e5 Mon Sep 17 00:00:00 2001 From: Austin Abro Date: Mon, 22 Jan 2024 17:23:31 +0000 Subject: [PATCH 02/68] changing spinnners --- src/internal/packager/helm/chart.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/internal/packager/helm/chart.go b/src/internal/packager/helm/chart.go index 91ebf921c0..e2544e0e39 100644 --- a/src/internal/packager/helm/chart.go +++ b/src/internal/packager/helm/chart.go @@ -144,10 +144,12 @@ func (h *Helm) TemplateChart() (manifest string, chartValues chartutil.Values, e spinner := message.NewProgressSpinner("Templating helm chart %s", h.chart.Name) defer func() { if err != nil { + spinner.Stop() spinner.Errorf(err, "Problem rendering the helm template for %s: %s", h.chart.Name, err.Error()) } else { - spinner.Stop() + spinner.Success() } + }() err = h.createActionConfig(h.chart.Namespace, spinner) @@ -206,8 +208,6 @@ func (h *Helm) TemplateChart() (manifest string, chartValues chartutil.Values, e manifest += fmt.Sprintf("\n---\n%s", hook.Manifest) } - spinner.Success() - return manifest, chartValues, nil } From 1f963bfc737663e5b8636c8734a353d8c730567a Mon Sep 17 00:00:00 2001 From: Austin Abro Date: Fri, 2 Feb 2024 14:13:52 +0000 Subject: [PATCH 03/68] revert yaml name change --- src/internal/packager/helm/chart.go | 6 +++--- src/internal/packager/helm/common.go | 2 +- src/pkg/packager/prepare.go | 7 ++++++- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/internal/packager/helm/chart.go b/src/internal/packager/helm/chart.go index e2544e0e39..a3715301d7 100644 --- a/src/internal/packager/helm/chart.go +++ b/src/internal/packager/helm/chart.go @@ -254,7 +254,7 @@ func (h *Helm) UpdateReleaseValues(updatedValues map[string]interface{}) error { // Namespace must be specified. client.Namespace = h.chart.Namespace - // Post-processing our manifests for reasons.... + // Post-processing our manifests to apply vars and run zarf helm logic in cluster client.PostRenderer = postRender // Set reuse values to only override the values we are explicitly given @@ -296,7 +296,7 @@ func (h *Helm) installChart(postRender *renderer) (*release.Release, error) { // Namespace must be specified. client.Namespace = h.chart.Namespace - // Post-processing our manifests for reasons.... + // Post-processing our manifests to apply vars and run zarf helm logic in cluster client.PostRenderer = postRender loadedChart, chartValues, err := h.loadChartData() @@ -333,7 +333,7 @@ func (h *Helm) upgradeChart(lastRelease *release.Release, postRender *renderer) // Namespace must be specified. client.Namespace = h.chart.Namespace - // Post-processing our manifests for reasons.... + // Post-processing our manifests to apply vars and run zarf helm logic in cluster client.PostRenderer = postRender loadedChart, chartValues, err := h.loadChartData() diff --git a/src/internal/packager/helm/common.go b/src/internal/packager/helm/common.go index 00f04be284..8f260cfe0d 100644 --- a/src/internal/packager/helm/common.go +++ b/src/internal/packager/helm/common.go @@ -160,5 +160,5 @@ func StandardName(destination string, chart types.ZarfChart) string { } func StandardValuesName(destination string, chart types.ZarfChart, idx int) string { - return fmt.Sprintf("%s-%d.yaml", StandardName(destination, chart), idx) + return fmt.Sprintf("%s-%d", StandardName(destination, chart), idx) } diff --git a/src/pkg/packager/prepare.go b/src/pkg/packager/prepare.go index d4f51880f1..07c05cc0a6 100644 --- a/src/pkg/packager/prepare.go +++ b/src/pkg/packager/prepare.go @@ -141,7 +141,12 @@ func (p *Packager) FindImages() (imgMap map[string][]string, err error) { return nil, fmt.Errorf("unable to package the chart %s: %s", chart.Name, err.Error()) } - template.ProcessYamlFilesInPath(componentPaths.Values, component, *values) + manifests, _ := utils.RecursiveFileList(componentPaths.Values, nil, false) + for _, manifest := range manifests { + if err := values.Apply(component, manifest, false); err != nil { + return nil, err + } + } // Generate helm templates for this chart chartTemplate, chartValues, err := helmCfg.TemplateChart() From e7223aa08ee63b82c448855aa0330de531384e0b Mon Sep 17 00:00:00 2001 From: Austin Abro Date: Mon, 5 Feb 2024 15:17:02 +0000 Subject: [PATCH 04/68] make test cases more clear, fix helm test case --- eks.yaml | 23 +++++++++++++++++++ src/test/e2e/00_use_cli_test.go | 9 ++++---- .../packages/00-find-images/gitea-values.yaml | 1 - .../simple-helm/templates/deployment.yaml | 2 ++ .../00-find-images/simple-helm/values.yaml | 4 ---- src/test/packages/00-find-images/values.yaml | 2 ++ src/test/packages/00-find-images/zarf.yaml | 7 +++--- 7 files changed, 36 insertions(+), 12 deletions(-) create mode 100644 eks.yaml delete mode 100644 src/test/packages/00-find-images/gitea-values.yaml delete mode 100644 src/test/packages/00-find-images/simple-helm/values.yaml create mode 100644 src/test/packages/00-find-images/values.yaml diff --git a/eks.yaml b/eks.yaml new file mode 100644 index 0000000000..bc7c002b10 --- /dev/null +++ b/eks.yaml @@ -0,0 +1,23 @@ +# eksctl create cluster --config-file=eks.yaml +apiVersion: eksctl.io/v1alpha5 +kind: ClusterConfig +metadata: + name: + region: us-east-1 + version: "1.27" + +iam: + withOIDC: true + +addons: + - name: aws-ebs-csi-driver + version: "v1.21.0-eksbuild.1" + attachPolicyARNs: + - arn:aws:iam::aws:policy/service-role/AmazonEBSCSIDriverPolicy + +managedNodeGroups: +- instanceType: t3.small + name: -ng + minSize: 3 + maxSize: 6 + spot: true diff --git a/src/test/e2e/00_use_cli_test.go b/src/test/e2e/00_use_cli_test.go index 11aa7a9f34..479255a357 100644 --- a/src/test/e2e/00_use_cli_test.go +++ b/src/test/e2e/00_use_cli_test.go @@ -100,8 +100,8 @@ func TestUseCLI(t *testing.T) { // Test `zarf prepare find-images` with `--kube-version` specified and less than than the declared minimum (v1.21.0) stdOut, stdErr, err = e2e.Zarf("prepare", "find-images", "--kube-version=v1.20.0", "src/test/packages/00-kube-version-override") require.Error(t, err, stdOut, stdErr) - require.Contains(t, stdErr, "Problem rendering the helm template for https://charts.jetstack.io/", "The kubeVersion declaration should prevent this from templating") - require.Contains(t, stdErr, "following charts had errors: [https://charts.jetstack.io/]", "Zarf should print an ending error message") + require.Contains(t, stdErr, "Problem rendering the helm template for cert-manager", "The kubeVersion declaration should prevent this from templating") + require.Contains(t, stdErr, "following charts had errors: [cert-manager]", "Zarf should print an ending error message") }) t.Run("zarf deploy should fail when given a bad component input", func(t *testing.T) { @@ -255,7 +255,8 @@ func TestUseCLI2(t *testing.T) { path := filepath.Join("src", "test", "packages", "00-find-images") stdOut, _, err := e2e.Zarf("prepare", "find-images", path) require.NoError(t, err) - require.Contains(t, stdOut, "defenseunicorns/zarf/agent:local", "If this isn't found manifests aren't interpreting vars") - require.Contains(t, stdOut, "nginx:stable-perl", "If this isn't found helm or values files aren't interpreting vars") + require.Contains(t, stdOut, "defenseunicorns/zarf/agent:local", "Manifests aren't interpreting vars") + require.Contains(t, stdOut, "busybox:latest", "Values files aren't interpreting vars") + require.Contains(t, stdOut, "nginx:stable-perl", "Helm isn't interpreting vars") }) } diff --git a/src/test/packages/00-find-images/gitea-values.yaml b/src/test/packages/00-find-images/gitea-values.yaml deleted file mode 100644 index 296825df9d..0000000000 --- a/src/test/packages/00-find-images/gitea-values.yaml +++ /dev/null @@ -1 +0,0 @@ -replicaCount: ###ZARF_VAR_GIT_SERVER_REPLICA_COUNT### diff --git a/src/test/packages/00-find-images/simple-helm/templates/deployment.yaml b/src/test/packages/00-find-images/simple-helm/templates/deployment.yaml index 7fe9c208fb..8fdfd32485 100644 --- a/src/test/packages/00-find-images/simple-helm/templates/deployment.yaml +++ b/src/test/packages/00-find-images/simple-helm/templates/deployment.yaml @@ -19,3 +19,5 @@ spec: containers: - name: server image: "###ZARF_CONST_HELM_IMAGE###:stable-perl" + - name: another-container + image: {{.Values.otherContainer}} diff --git a/src/test/packages/00-find-images/simple-helm/values.yaml b/src/test/packages/00-find-images/simple-helm/values.yaml deleted file mode 100644 index ee7ea11c10..0000000000 --- a/src/test/packages/00-find-images/simple-helm/values.yaml +++ /dev/null @@ -1,4 +0,0 @@ -# Default values for simple-helm. -# This is a YAML-formatted file. -# Declare variables to be passed into your templates. -replicaCount: 1 diff --git a/src/test/packages/00-find-images/values.yaml b/src/test/packages/00-find-images/values.yaml new file mode 100644 index 0000000000..69d6065662 --- /dev/null +++ b/src/test/packages/00-find-images/values.yaml @@ -0,0 +1,2 @@ +replicaCount: ###ZARF_VAR_REPLICA_COUNT### +otherContainer: ###ZARF_VAR_OTHER_CONTAINER### diff --git a/src/test/packages/00-find-images/zarf.yaml b/src/test/packages/00-find-images/zarf.yaml index 00834d3796..85547e3ae0 100644 --- a/src/test/packages/00-find-images/zarf.yaml +++ b/src/test/packages/00-find-images/zarf.yaml @@ -4,9 +4,10 @@ metadata: description: Simple zarf package with variables variables: - - name: GIT_SERVER_REPLICA_COUNT - description: The number of git server replicas to deploy + - name: REPLICA_COUNT default: "1" + - name: OTHER_CONTAINER + default: "busybox:latest" constants: - name: AGENT_IMAGE @@ -33,4 +34,4 @@ components: namespace: zarf-simple version: 0.1.0 valuesFiles: - - gitea-values.yaml + - values.yaml From c5bfbaef4a8b9ca4225d34d51cf47dca912646e8 Mon Sep 17 00:00:00 2001 From: Austin Abro Date: Mon, 5 Feb 2024 15:31:55 +0000 Subject: [PATCH 05/68] delete eks.yaml --- eks.yaml | 23 ----------------------- 1 file changed, 23 deletions(-) delete mode 100644 eks.yaml diff --git a/eks.yaml b/eks.yaml deleted file mode 100644 index bc7c002b10..0000000000 --- a/eks.yaml +++ /dev/null @@ -1,23 +0,0 @@ -# eksctl create cluster --config-file=eks.yaml -apiVersion: eksctl.io/v1alpha5 -kind: ClusterConfig -metadata: - name: - region: us-east-1 - version: "1.27" - -iam: - withOIDC: true - -addons: - - name: aws-ebs-csi-driver - version: "v1.21.0-eksbuild.1" - attachPolicyARNs: - - arn:aws:iam::aws:policy/service-role/AmazonEBSCSIDriverPolicy - -managedNodeGroups: -- instanceType: t3.small - name: -ng - minSize: 3 - maxSize: 6 - spot: true From 32dc5180c0e943db7cca61ee487b09927f2d00e0 Mon Sep 17 00:00:00 2001 From: Austin Abro Date: Mon, 5 Feb 2024 15:47:40 +0000 Subject: [PATCH 06/68] refactor: name --- src/internal/packager/helm/chart.go | 2 +- src/internal/packager/helm/prepare-render.go | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/internal/packager/helm/chart.go b/src/internal/packager/helm/chart.go index a3715301d7..073a31fe11 100644 --- a/src/internal/packager/helm/chart.go +++ b/src/internal/packager/helm/chart.go @@ -191,7 +191,7 @@ func (h *Helm) TemplateChart() (manifest string, chartValues chartutil.Values, e return "", nil, fmt.Errorf("unable to load chart data: %w", err) } - client.PostRenderer, err = h.newDevRenderer() + client.PostRenderer, err = h.newVariableRenderer() if err != nil { return "", nil, fmt.Errorf("unable to get dev renderer: %w", err) } diff --git a/src/internal/packager/helm/prepare-render.go b/src/internal/packager/helm/prepare-render.go index 49e8237562..f31d0d1c83 100644 --- a/src/internal/packager/helm/prepare-render.go +++ b/src/internal/packager/helm/prepare-render.go @@ -16,25 +16,25 @@ import ( "helm.sh/helm/v3/pkg/releaseutil" ) -type devRenderer struct { +type variableRenderer struct { *Helm values template.Values } -func (h *Helm) newDevRenderer() (*devRenderer, error) { +func (h *Helm) newVariableRenderer() (*variableRenderer, error) { values, err := template.Generate(h.cfg) if err != nil { return nil, err } values.SetState(&types.ZarfState{}) - return &devRenderer{ + return &variableRenderer{ Helm: h, values: *values, }, nil } -func (r *devRenderer) Run(renderedManifests *bytes.Buffer) (*bytes.Buffer, error) { +func (r *variableRenderer) Run(renderedManifests *bytes.Buffer) (*bytes.Buffer, error) { // This is very low cost and consistent for how we replace elsewhere, also good for debugging tempDir, err := utils.MakeTempDir(r.chartPath) if err != nil { From 6c0324a49554e2ac5ca3e3014849191f050d90bd Mon Sep 17 00:00:00 2001 From: Austin Abro Date: Mon, 5 Feb 2024 16:19:07 +0000 Subject: [PATCH 07/68] de-dup text --- src/config/lang/english.go | 5 +++++ src/pkg/packager/deploy.go | 2 +- src/pkg/packager/dev.go | 3 ++- src/pkg/packager/prepare.go | 2 +- 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/config/lang/english.go b/src/config/lang/english.go index 6f9383ba8b..0b5d30f0a4 100644 --- a/src/config/lang/english.go +++ b/src/config/lang/english.go @@ -619,6 +619,11 @@ const ( AgentErrUnableTransform = "unable to transform the provided request; see zarf http proxy logs for more details" ) +// src/internal/packager +const ( + PkgErrsetVariableMap = "unable to set the active variables: %w" +) + // src/internal/packager/create const ( PkgCreateErrDifferentialSameVersion = "unable to create a differential package with the same version as the package you are using as a reference; the package version must be incremented" diff --git a/src/pkg/packager/deploy.go b/src/pkg/packager/deploy.go index 9577ba69f6..df30d56c75 100644 --- a/src/pkg/packager/deploy.go +++ b/src/pkg/packager/deploy.go @@ -63,7 +63,7 @@ func (p *Packager) Deploy() (err error) { // Set variables and prompt if --confirm is not set if err := p.setVariableMapInConfig(); err != nil { - return fmt.Errorf("unable to set the active variables: %w", err) + return fmt.Errorf(lang.PkgErrsetVariableMap, err) } p.hpaModified = false diff --git a/src/pkg/packager/dev.go b/src/pkg/packager/dev.go index b4e1744d46..110e90dd70 100644 --- a/src/pkg/packager/dev.go +++ b/src/pkg/packager/dev.go @@ -9,6 +9,7 @@ import ( "os" "github.com/defenseunicorns/zarf/src/config" + "github.com/defenseunicorns/zarf/src/config/lang" "github.com/defenseunicorns/zarf/src/internal/packager/validate" "github.com/defenseunicorns/zarf/src/pkg/message" "github.com/defenseunicorns/zarf/src/types" @@ -62,7 +63,7 @@ func (p *Packager) DevDeploy() error { // Set variables and prompt if --confirm is not set if err := p.setVariableMapInConfig(); err != nil { - return fmt.Errorf("unable to set the active variables: %w", err) + return fmt.Errorf(lang.PkgErrsetVariableMap, err) } p.connectStrings = make(types.ConnectStrings) diff --git a/src/pkg/packager/prepare.go b/src/pkg/packager/prepare.go index 07c05cc0a6..5fba750369 100644 --- a/src/pkg/packager/prepare.go +++ b/src/pkg/packager/prepare.go @@ -77,7 +77,7 @@ func (p *Packager) FindImages() (imgMap map[string][]string, err error) { componentDefinition := "\ncomponents:\n" if err := p.setVariableMapInConfig(); err != nil { - return nil, fmt.Errorf("unable to set the active variables: %w", err) + return nil, fmt.Errorf(lang.PkgErrsetVariableMap, err) } for _, component := range p.cfg.Pkg.Components { From da4d3fc27d48fac398e479998b5948406f40bb72 Mon Sep 17 00:00:00 2001 From: Austin Abro Date: Mon, 5 Feb 2024 16:28:41 +0000 Subject: [PATCH 08/68] simplying test --- .../00-find-images/simple-helm/.helmignore | 23 ------------------- .../00-find-images/simple-helm/Chart.yaml | 2 +- .../simple-helm/templates/NOTES.txt | 1 - .../simple-helm/templates/_helpers.tpl | 6 ----- 4 files changed, 1 insertion(+), 31 deletions(-) delete mode 100644 src/test/packages/00-find-images/simple-helm/.helmignore delete mode 100644 src/test/packages/00-find-images/simple-helm/templates/NOTES.txt delete mode 100644 src/test/packages/00-find-images/simple-helm/templates/_helpers.tpl diff --git a/src/test/packages/00-find-images/simple-helm/.helmignore b/src/test/packages/00-find-images/simple-helm/.helmignore deleted file mode 100644 index 0e8a0eb36f..0000000000 --- a/src/test/packages/00-find-images/simple-helm/.helmignore +++ /dev/null @@ -1,23 +0,0 @@ -# Patterns to ignore when building packages. -# This supports shell glob matching, relative path matching, and -# negation (prefixed with !). Only one pattern per line. -.DS_Store -# Common VCS dirs -.git/ -.gitignore -.bzr/ -.bzrignore -.hg/ -.hgignore -.svn/ -# Common backup files -*.swp -*.bak -*.tmp -*.orig -*~ -# Various IDEs -.project -.idea/ -*.tmproj -.vscode/ diff --git a/src/test/packages/00-find-images/simple-helm/Chart.yaml b/src/test/packages/00-find-images/simple-helm/Chart.yaml index 3027fceee2..2c128bf819 100644 --- a/src/test/packages/00-find-images/simple-helm/Chart.yaml +++ b/src/test/packages/00-find-images/simple-helm/Chart.yaml @@ -3,4 +3,4 @@ name: simple-helm description: A Helm chart for Kubernetes type: application version: 0.1.0 -appVersion: "1.16.0" +appVersion: "0.0.1" diff --git a/src/test/packages/00-find-images/simple-helm/templates/NOTES.txt b/src/test/packages/00-find-images/simple-helm/templates/NOTES.txt deleted file mode 100644 index 7d790da089..0000000000 --- a/src/test/packages/00-find-images/simple-helm/templates/NOTES.txt +++ /dev/null @@ -1 +0,0 @@ -1. Get the application URL by running these commands: diff --git a/src/test/packages/00-find-images/simple-helm/templates/_helpers.tpl b/src/test/packages/00-find-images/simple-helm/templates/_helpers.tpl deleted file mode 100644 index 51a7e88ab8..0000000000 --- a/src/test/packages/00-find-images/simple-helm/templates/_helpers.tpl +++ /dev/null @@ -1,6 +0,0 @@ -{{/* -Expand the name of the chart. -*/}} -{{- define "simple-helm.name" -}} -{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }} -{{- end }} From a0314ad0a714f30903a2167a0008f9c9b46af9ad Mon Sep 17 00:00:00 2001 From: Austin Abro Date: Mon, 5 Feb 2024 16:30:16 +0000 Subject: [PATCH 09/68] bettter test name --- src/test/packages/00-find-images/values.yaml | 2 +- src/test/packages/00-find-images/zarf.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/packages/00-find-images/values.yaml b/src/test/packages/00-find-images/values.yaml index 69d6065662..5c30b9ac2f 100644 --- a/src/test/packages/00-find-images/values.yaml +++ b/src/test/packages/00-find-images/values.yaml @@ -1,2 +1,2 @@ replicaCount: ###ZARF_VAR_REPLICA_COUNT### -otherContainer: ###ZARF_VAR_OTHER_CONTAINER### +otherContainer: ###ZARF_VAR_VALUES_IMAGE### diff --git a/src/test/packages/00-find-images/zarf.yaml b/src/test/packages/00-find-images/zarf.yaml index 85547e3ae0..482b35ff8d 100644 --- a/src/test/packages/00-find-images/zarf.yaml +++ b/src/test/packages/00-find-images/zarf.yaml @@ -6,7 +6,7 @@ metadata: variables: - name: REPLICA_COUNT default: "1" - - name: OTHER_CONTAINER + - name: VALUES_IMAGE default: "busybox:latest" constants: From de984abc41af2253abe1f4878f95340ab10c1bc4 Mon Sep 17 00:00:00 2001 From: Austin Abro Date: Mon, 5 Feb 2024 16:35:18 +0000 Subject: [PATCH 10/68] refactor test --- src/test/e2e/00_use_cli_test.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/test/e2e/00_use_cli_test.go b/src/test/e2e/00_use_cli_test.go index 479255a357..1b7c52a28f 100644 --- a/src/test/e2e/00_use_cli_test.go +++ b/src/test/e2e/00_use_cli_test.go @@ -246,16 +246,16 @@ func TestUseCLI(t *testing.T) { require.FileExists(t, tlsKey) }) -} -func TestUseCLI2(t *testing.T) { - t.Run("zarf prepare find-images with helm or manifest vars", func(t *testing.T) { + t.Run("zarf dev find-images with helm or manifest vars", func(t *testing.T) { t.Parallel() // Test `zarf prepare find-images` for a package with zarf variables in the chart, values file, and manifests path := filepath.Join("src", "test", "packages", "00-find-images") - stdOut, _, err := e2e.Zarf("prepare", "find-images", path) + registry := "coolregistry.gov" + stdOut, _, err := e2e.Zarf("prepare", "find-images", path, "--registry", registry) require.NoError(t, err) - require.Contains(t, stdOut, "defenseunicorns/zarf/agent:local", "Manifests aren't interpreting vars") + manifestImage := fmt.Sprintf("%s/%s", registry, "defenseunicorns/zarf/agent:local") + require.Contains(t, stdOut, manifestImage, "Manifests aren't interpreting vars") require.Contains(t, stdOut, "busybox:latest", "Values files aren't interpreting vars") require.Contains(t, stdOut, "nginx:stable-perl", "Helm isn't interpreting vars") }) From 59750399aa6acefdb9a394d946be3322b077ace7 Mon Sep 17 00:00:00 2001 From: Austin Abro Date: Mon, 5 Feb 2024 16:52:15 +0000 Subject: [PATCH 11/68] make docs and schema --- .../100-cli-commands/zarf_dev_find-images.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/docs/2-the-zarf-cli/100-cli-commands/zarf_dev_find-images.md b/docs/2-the-zarf-cli/100-cli-commands/zarf_dev_find-images.md index 01e43dfbcb..da848494f5 100644 --- a/docs/2-the-zarf-cli/100-cli-commands/zarf_dev_find-images.md +++ b/docs/2-the-zarf-cli/100-cli-commands/zarf_dev_find-images.md @@ -16,10 +16,12 @@ zarf dev find-images [ PACKAGE ] [flags] ## Options ``` - -h, --help help for find-images - --kube-version string Override the default helm template KubeVersion when performing a package chart template - -p, --repo-chart-path string If git repos hold helm charts, often found with gitops tools, specify the chart path, e.g. "/" or "/chart" - --set stringToString 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]. (default []) + --create-set stringToString 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]. (default []) + --deploy-set stringToString Specify deployment variables to set on the command line (KEY=value) (default []) + -h, --help help for find-images + --kube-version string Override the default helm template KubeVersion when performing a package chart template + --registry string Override the ###ZARF_REGISTRY### value for checks on images using the zarf registry (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" ``` ## Options inherited from parent commands From fc882d81aeb293b71cb4604f712171f236d6efb2 Mon Sep 17 00:00:00 2001 From: Austin Abro Date: Mon, 5 Feb 2024 21:42:01 +0000 Subject: [PATCH 12/68] lint + duplicated code --- src/internal/packager/helm/common.go | 2 ++ src/test/e2e/00_use_cli_test.go | 4 ---- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/internal/packager/helm/common.go b/src/internal/packager/helm/common.go index 8f260cfe0d..e06fe3fd3b 100644 --- a/src/internal/packager/helm/common.go +++ b/src/internal/packager/helm/common.go @@ -148,6 +148,7 @@ func WithKubeVersion(kubeVersion string) Modifier { } } +// WithPackageConfig sets the packager config for the chart func WithPackageConfig(cfg *types.PackagerConfig) Modifier { return func(h *Helm) { h.cfg = cfg @@ -159,6 +160,7 @@ func StandardName(destination string, chart types.ZarfChart) string { return filepath.Join(destination, chart.Name+"-"+chart.Version) } +// StandardValuesName generates a predictable full path for the values file for a helm chart for zarf func StandardValuesName(destination string, chart types.ZarfChart, idx int) string { return fmt.Sprintf("%s-%d", StandardName(destination, chart), idx) } diff --git a/src/test/e2e/00_use_cli_test.go b/src/test/e2e/00_use_cli_test.go index 1b7c52a28f..b27270abf2 100644 --- a/src/test/e2e/00_use_cli_test.go +++ b/src/test/e2e/00_use_cli_test.go @@ -79,10 +79,6 @@ func TestUseCLI(t *testing.T) { stdOut, stdErr, err = e2e.Zarf("prepare", "find-images", "src/test/packages/00-helm-annotations") require.NoError(t, err, stdOut, stdErr) require.Contains(t, stdOut, "registry1.dso.mil/ironbank/opensource/istio/pilot:1.17.2", "The pilot image should be found by Zarf") - - stdOut, stdErr, err = e2e.Zarf("prepare", "find-images", "src/test/packages/00-helm-annotations") - require.NoError(t, err, stdOut, stdErr) - require.Contains(t, stdOut, "registry1.dso.mil/ironbank/opensource/istio/pilot:1.17.2", "The pilot image should be found by Zarf") }) t.Run("zarf prepare find-images --kube-version", func(t *testing.T) { From 56a69f32e77b146d43a2caf245d8336fd4c1ee61 Mon Sep 17 00:00:00 2001 From: Austin Abro <37223396+AustinAbro321@users.noreply.github.com> Date: Mon, 5 Feb 2024 16:43:50 -0500 Subject: [PATCH 13/68] Apply suggestions from code review Co-authored-by: Wayne Starr --- src/cmd/dev.go | 2 +- src/config/lang/english.go | 2 +- src/types/runtime.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cmd/dev.go b/src/cmd/dev.go index e45f244e23..c43600c8f0 100644 --- a/src/cmd/dev.go +++ b/src/cmd/dev.go @@ -276,7 +276,7 @@ func init() { // allow for the override of the default helm KubeVersion devFindImagesCmd.Flags().StringVar(&pkgConfig.FindImagesOpts.KubeVersionOverride, "kube-version", "", lang.CmdDevFlagKubeVersion) - devFindImagesCmd.Flags().StringVar(&pkgConfig.FindImagesOpts.RegistryOverride, "registry", "127.0.0.1:31999", lang.CmdDevFlagRegistry) + devFindImagesCmd.Flags().StringVar(&pkgConfig.FindImagesOpts.RegistryOverride, "registry-url", "127.0.0.1:31999", lang.CmdDevFlagRegistry) devLintCmd.Flags().StringToStringVar(&pkgConfig.CreateOpts.SetVariables, "set", v.GetStringMapString(common.VPkgCreateSet), lang.CmdPackageCreateFlagSet) devLintCmd.Flags().StringVarP(&pkgConfig.CreateOpts.Flavor, "flavor", "f", v.GetString(common.VPkgCreateFlavor), lang.CmdPackageCreateFlagFlavor) diff --git a/src/config/lang/english.go b/src/config/lang/english.go index 0b5d30f0a4..c15cf05535 100644 --- a/src/config/lang/english.go +++ b/src/config/lang/english.go @@ -621,7 +621,7 @@ const ( // src/internal/packager const ( - PkgErrsetVariableMap = "unable to set the active variables: %w" + PkgErrSetVariableMap = "unable to set the active variables: %w" ) // src/internal/packager/create diff --git a/src/types/runtime.go b/src/types/runtime.go index 5d17df74e0..4304c327b6 100644 --- a/src/types/runtime.go +++ b/src/types/runtime.go @@ -55,7 +55,7 @@ type ZarfInspectOptions struct { type ZarfFindImagesOptions struct { RepoHelmChartPath string `json:"repoHelmChartPath" jsonschema:"description=Path to the helm chart directory"` KubeVersionOverride string `json:"kubeVersionOverride" jsonschema:"description=Kubernetes version to use for the helm chart"` - RegistryOverride string `json:"registryOverride" jsonschema:"description=Manual override for ###ZARF_REGISTRY###` + RegistryURL string `json:"registryURL" jsonschema:"description=Manual override for ###ZARF_REGISTRY###` } // ZarfDeployOptions tracks the user-defined preferences during a package deploy. From e2efae035a7d40b556a1dde9f451d8fb55ccc28c Mon Sep 17 00:00:00 2001 From: Austin Abro Date: Mon, 5 Feb 2024 21:53:38 +0000 Subject: [PATCH 14/68] fix suggestions --- src/cmd/dev.go | 2 +- src/pkg/packager/deploy.go | 2 +- src/pkg/packager/dev.go | 2 +- src/pkg/packager/prepare.go | 4 ++-- src/test/e2e/00_use_cli_test.go | 2 +- src/types/runtime.go | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/cmd/dev.go b/src/cmd/dev.go index c43600c8f0..71f98e868c 100644 --- a/src/cmd/dev.go +++ b/src/cmd/dev.go @@ -276,7 +276,7 @@ func init() { // allow for the override of the default helm KubeVersion devFindImagesCmd.Flags().StringVar(&pkgConfig.FindImagesOpts.KubeVersionOverride, "kube-version", "", lang.CmdDevFlagKubeVersion) - devFindImagesCmd.Flags().StringVar(&pkgConfig.FindImagesOpts.RegistryOverride, "registry-url", "127.0.0.1:31999", lang.CmdDevFlagRegistry) + devFindImagesCmd.Flags().StringVar(&pkgConfig.FindImagesOpts.RegistryURL, "registry-url", "127.0.0.1:31999", lang.CmdDevFlagRegistry) devLintCmd.Flags().StringToStringVar(&pkgConfig.CreateOpts.SetVariables, "set", v.GetStringMapString(common.VPkgCreateSet), lang.CmdPackageCreateFlagSet) devLintCmd.Flags().StringVarP(&pkgConfig.CreateOpts.Flavor, "flavor", "f", v.GetString(common.VPkgCreateFlavor), lang.CmdPackageCreateFlagFlavor) diff --git a/src/pkg/packager/deploy.go b/src/pkg/packager/deploy.go index df30d56c75..af441b2441 100644 --- a/src/pkg/packager/deploy.go +++ b/src/pkg/packager/deploy.go @@ -63,7 +63,7 @@ func (p *Packager) Deploy() (err error) { // Set variables and prompt if --confirm is not set if err := p.setVariableMapInConfig(); err != nil { - return fmt.Errorf(lang.PkgErrsetVariableMap, err) + return fmt.Errorf(lang.PkgErrSetVariableMap, err) } p.hpaModified = false diff --git a/src/pkg/packager/dev.go b/src/pkg/packager/dev.go index 110e90dd70..a8acd07667 100644 --- a/src/pkg/packager/dev.go +++ b/src/pkg/packager/dev.go @@ -63,7 +63,7 @@ func (p *Packager) DevDeploy() error { // Set variables and prompt if --confirm is not set if err := p.setVariableMapInConfig(); err != nil { - return fmt.Errorf(lang.PkgErrsetVariableMap, err) + return fmt.Errorf(lang.PkgErrSetVariableMap, err) } p.connectStrings = make(types.ConnectStrings) diff --git a/src/pkg/packager/prepare.go b/src/pkg/packager/prepare.go index 5fba750369..c6611b541e 100644 --- a/src/pkg/packager/prepare.go +++ b/src/pkg/packager/prepare.go @@ -77,7 +77,7 @@ func (p *Packager) FindImages() (imgMap map[string][]string, err error) { componentDefinition := "\ncomponents:\n" if err := p.setVariableMapInConfig(); err != nil { - return nil, fmt.Errorf(lang.PkgErrsetVariableMap, err) + return nil, fmt.Errorf(lang.PkgErrSetVariableMap, err) } for _, component := range p.cfg.Pkg.Components { @@ -125,7 +125,7 @@ func (p *Packager) FindImages() (imgMap map[string][]string, err error) { return nil, fmt.Errorf("unable to generate template values") } values.SetState(&types.ZarfState{}) - values.SetRegistry(p.cfg.FindImagesOpts.RegistryOverride) + values.SetRegistry(p.cfg.FindImagesOpts.RegistryURL) for _, chart := range component.Charts { helmCfg := helm.New( diff --git a/src/test/e2e/00_use_cli_test.go b/src/test/e2e/00_use_cli_test.go index b27270abf2..336f0794b3 100644 --- a/src/test/e2e/00_use_cli_test.go +++ b/src/test/e2e/00_use_cli_test.go @@ -248,7 +248,7 @@ func TestUseCLI(t *testing.T) { // Test `zarf prepare find-images` for a package with zarf variables in the chart, values file, and manifests path := filepath.Join("src", "test", "packages", "00-find-images") registry := "coolregistry.gov" - stdOut, _, err := e2e.Zarf("prepare", "find-images", path, "--registry", registry) + stdOut, _, err := e2e.Zarf("prepare", "find-images", path, "--registry-url", registry) require.NoError(t, err) manifestImage := fmt.Sprintf("%s/%s", registry, "defenseunicorns/zarf/agent:local") require.Contains(t, stdOut, manifestImage, "Manifests aren't interpreting vars") diff --git a/src/types/runtime.go b/src/types/runtime.go index 4304c327b6..1c88083758 100644 --- a/src/types/runtime.go +++ b/src/types/runtime.go @@ -55,7 +55,7 @@ type ZarfInspectOptions struct { type ZarfFindImagesOptions struct { RepoHelmChartPath string `json:"repoHelmChartPath" jsonschema:"description=Path to the helm chart directory"` KubeVersionOverride string `json:"kubeVersionOverride" jsonschema:"description=Kubernetes version to use for the helm chart"` - RegistryURL string `json:"registryURL" jsonschema:"description=Manual override for ###ZARF_REGISTRY###` + RegistryURL string `json:"registryURL" jsonschema:"description=Manual override for ###ZARF_REGISTRY###"` } // ZarfDeployOptions tracks the user-defined preferences during a package deploy. From 8d8762d95163146055b97bc12bf56c63d962a4ea Mon Sep 17 00:00:00 2001 From: Austin Abro Date: Mon, 5 Feb 2024 22:05:13 +0000 Subject: [PATCH 15/68] better name --- src/pkg/packager/prepare.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/pkg/packager/prepare.go b/src/pkg/packager/prepare.go index c6611b541e..c52c971fc3 100644 --- a/src/pkg/packager/prepare.go +++ b/src/pkg/packager/prepare.go @@ -141,9 +141,12 @@ func (p *Packager) FindImages() (imgMap map[string][]string, err error) { return nil, fmt.Errorf("unable to package the chart %s: %s", chart.Name, err.Error()) } - manifests, _ := utils.RecursiveFileList(componentPaths.Values, nil, false) - for _, manifest := range manifests { - if err := values.Apply(component, manifest, false); err != nil { + valuesFilePaths, err := utils.RecursiveFileList(componentPaths.Values, nil, false) + if err != nil { + return nil, fmt.Errorf("unable to get values file for chart %s: %s", chart.Name, err.Error()) + } + for _, path := range valuesFilePaths { + if err := values.Apply(component, path, false); err != nil { return nil, err } } From 8bbadfd78dc984856468c882011e489dd8efe2c4 Mon Sep 17 00:00:00 2001 From: Austin Abro Date: Tue, 6 Feb 2024 14:16:52 +0000 Subject: [PATCH 16/68] simplify spinner logic --- src/internal/packager/helm/chart.go | 12 +++--------- src/internal/packager/helm/post-render.go | 1 - src/pkg/packager/prepare.go | 7 ++----- 3 files changed, 5 insertions(+), 15 deletions(-) diff --git a/src/internal/packager/helm/chart.go b/src/internal/packager/helm/chart.go index 073a31fe11..6ece309f00 100644 --- a/src/internal/packager/helm/chart.go +++ b/src/internal/packager/helm/chart.go @@ -142,15 +142,7 @@ func (h *Helm) InstallOrUpgradeChart() (types.ConnectStrings, string, error) { func (h *Helm) TemplateChart() (manifest string, chartValues chartutil.Values, err error) { message.Debugf("helm.TemplateChart()") spinner := message.NewProgressSpinner("Templating helm chart %s", h.chart.Name) - defer func() { - if err != nil { - spinner.Stop() - spinner.Errorf(err, "Problem rendering the helm template for %s: %s", h.chart.Name, err.Error()) - } else { - spinner.Success() - } - - }() + defer spinner.Stop() err = h.createActionConfig(h.chart.Namespace, spinner) @@ -208,6 +200,8 @@ func (h *Helm) TemplateChart() (manifest string, chartValues chartutil.Values, e manifest += fmt.Sprintf("\n---\n%s", hook.Manifest) } + spinner.Success() + return manifest, chartValues, nil } diff --git a/src/internal/packager/helm/post-render.go b/src/internal/packager/helm/post-render.go index bf5f00de80..e94af421ee 100644 --- a/src/internal/packager/helm/post-render.go +++ b/src/internal/packager/helm/post-render.go @@ -43,7 +43,6 @@ func (h *Helm) newRenderer() (*renderer, error) { Helm: h, connectStrings: make(types.ConnectStrings), namespaces: map[string]*corev1.Namespace{ - // Add the passed-in namespace to the list h.chart.Namespace: h.cluster.NewZarfManagedNamespace(h.chart.Namespace), }, values: *valueTemplate, diff --git a/src/pkg/packager/prepare.go b/src/pkg/packager/prepare.go index c52c971fc3..c77665bfe8 100644 --- a/src/pkg/packager/prepare.go +++ b/src/pkg/packager/prepare.go @@ -141,10 +141,7 @@ func (p *Packager) FindImages() (imgMap map[string][]string, err error) { return nil, fmt.Errorf("unable to package the chart %s: %s", chart.Name, err.Error()) } - valuesFilePaths, err := utils.RecursiveFileList(componentPaths.Values, nil, false) - if err != nil { - return nil, fmt.Errorf("unable to get values file for chart %s: %s", chart.Name, err.Error()) - } + valuesFilePaths, _ := utils.RecursiveFileList(componentPaths.Values, nil, false) for _, path := range valuesFilePaths { if err := values.Apply(component, path, false); err != nil { return nil, err @@ -153,8 +150,8 @@ func (p *Packager) FindImages() (imgMap map[string][]string, err error) { // Generate helm templates for this chart chartTemplate, chartValues, err := helmCfg.TemplateChart() - if err != nil { + message.WarnErrf(err, "Problem rendering the helm template for %s: %s", chart.Name, err.Error()) erroredCharts = append(erroredCharts, chart.Name) continue } From 6430697c8510f300a405620c609ca6ee6376ec50 Mon Sep 17 00:00:00 2001 From: Austin Abro Date: Tue, 6 Feb 2024 14:20:27 +0000 Subject: [PATCH 17/68] delete eks.yaml created from test --- src/test/e2e/00_use_cli_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/e2e/00_use_cli_test.go b/src/test/e2e/00_use_cli_test.go index 336f0794b3..252c41d705 100644 --- a/src/test/e2e/00_use_cli_test.go +++ b/src/test/e2e/00_use_cli_test.go @@ -163,7 +163,7 @@ func TestUseCLI(t *testing.T) { require.FileExists(t, "binaries/eksctl_Darwin_arm64") require.FileExists(t, "binaries/eksctl_Linux_x86_64") - e2e.CleanFiles("binaries/eksctl_Darwin_x86_64", "binaries/eksctl_Darwin_arm64", "binaries/eksctl_Linux_x86_64", path) + e2e.CleanFiles("binaries/eksctl_Darwin_x86_64", "binaries/eksctl_Darwin_arm64", "binaries/eksctl_Linux_x86_64", path, "eks.yaml") }) t.Run("zarf package create with tmpdir and cache", func(t *testing.T) { From f328ae8dd7893e0db8d991fe48d99f74518d7657 Mon Sep 17 00:00:00 2001 From: Austin Abro Date: Tue, 6 Feb 2024 16:03:24 +0000 Subject: [PATCH 18/68] use only one renderer --- src/internal/packager/helm/chart.go | 2 +- src/internal/packager/helm/post-render.go | 154 +++++++++++-------- src/internal/packager/helm/prepare-render.go | 80 ---------- 3 files changed, 88 insertions(+), 148 deletions(-) delete mode 100644 src/internal/packager/helm/prepare-render.go diff --git a/src/internal/packager/helm/chart.go b/src/internal/packager/helm/chart.go index 6ece309f00..9ec96f8ed8 100644 --- a/src/internal/packager/helm/chart.go +++ b/src/internal/packager/helm/chart.go @@ -183,7 +183,7 @@ func (h *Helm) TemplateChart() (manifest string, chartValues chartutil.Values, e return "", nil, fmt.Errorf("unable to load chart data: %w", err) } - client.PostRenderer, err = h.newVariableRenderer() + client.PostRenderer, err = h.newRenderer() if err != nil { return "", nil, fmt.Errorf("unable to get dev renderer: %w", err) } diff --git a/src/internal/packager/helm/post-render.go b/src/internal/packager/helm/post-render.go index e94af421ee..e3d7021086 100644 --- a/src/internal/packager/helm/post-render.go +++ b/src/internal/packager/helm/post-render.go @@ -39,13 +39,16 @@ func (h *Helm) newRenderer() (*renderer, error) { return nil, err } + namespaces := make(map[string]*corev1.Namespace) + if h.cluster != nil { + namespaces[h.chart.Namespace] = h.cluster.NewZarfManagedNamespace(h.chart.Namespace) + } + return &renderer{ Helm: h, connectStrings: make(types.ConnectStrings), - namespaces: map[string]*corev1.Namespace{ - h.chart.Namespace: h.cluster.NewZarfManagedNamespace(h.chart.Namespace), - }, - values: *valueTemplate, + namespaces: namespaces, + values: *valueTemplate, }, nil } @@ -86,12 +89,88 @@ func (r *renderer) Run(renderedManifests *bytes.Buffer) (*bytes.Buffer, error) { finalManifestsOutput := bytes.NewBuffer(nil) // Otherwise, loop over the resources, - for _, resource := range resources { + if r.cluster != nil { + if err := r.editResourceForHelm(resources, finalManifestsOutput); err != nil { + return nil, err + } + + if err := r.adoptAndUpdateNamespaces(); err != nil { + return nil, err + } + } else { + for _, resource := range resources { + fmt.Fprintf(finalManifestsOutput, "---\n# Source: %s\n%s\n", resource.Name, resource.Content) + } + } + + // Send the bytes back to helm + return finalManifestsOutput, nil +} + +func (r *renderer) adoptAndUpdateNamespaces() error { + c := r.cluster + existingNamespaces, _ := c.GetNamespaces() + for name, namespace := range r.namespaces { + + // Check to see if this namespace already exists + var existingNamespace bool + for _, serverNamespace := range existingNamespaces.Items { + if serverNamespace.Name == name { + existingNamespace = true + } + } + + if !existingNamespace { + // This is a new namespace, add it + if _, err := c.CreateNamespace(namespace); err != nil { + return fmt.Errorf("unable to create the missing namespace %s", name) + } + } else if r.cfg.DeployOpts.AdoptExistingResources { + if r.cluster.IsInitialNamespace(name) { + // If this is a K8s initial namespace, refuse to adopt it + message.Warnf("Refusing to adopt the initial namespace: %s", name) + } else { + // This is an existing namespace to adopt + if _, err := c.UpdateNamespace(namespace); err != nil { + return fmt.Errorf("unable to adopt the existing namespace %s", name) + } + } + } + + // If the package is marked as YOLO and the state is empty, skip the secret creation for this namespace + if r.cfg.Pkg.Metadata.YOLO && r.cfg.State.Distro == "YOLO" { + continue + } + + // Create the secret + validRegistrySecret := c.GenerateRegistryPullCreds(name, config.ZarfImagePullSecretName, r.cfg.State.RegistryInfo) + + // Try to get a valid existing secret + currentRegistrySecret, _ := c.GetSecret(name, config.ZarfImagePullSecretName) + if currentRegistrySecret.Name != config.ZarfImagePullSecretName || !reflect.DeepEqual(currentRegistrySecret.Data, validRegistrySecret.Data) { + // Create or update the zarf registry secret + if _, err := c.CreateOrUpdateSecret(validRegistrySecret); err != nil { + message.WarnErrf(err, "Problem creating registry secret for the %s namespace", name) + } + + // Generate the git server secret + gitServerSecret := c.GenerateGitPullCreds(name, config.ZarfGitServerSecretName, r.cfg.State.GitServer) + + // Create or update the zarf git server secret + if _, err := c.CreateOrUpdateSecret(gitServerSecret); err != nil { + message.WarnErrf(err, "Problem creating git server secret for the %s namespace", name) + } + } + } + return nil +} +func (r *renderer) editResourceForHelm(resources []releaseutil.Manifest, finalManifestsOutput *bytes.Buffer) error { + for _, resource := range resources { // parse to unstructured to have access to more data than just the name rawData := &unstructured.Unstructured{} if err := yaml.Unmarshal([]byte(resource.Content), rawData); err != nil { - return nil, fmt.Errorf("failed to unmarshal manifest: %#v", err) + return fmt.Errorf("failed to unmarshal manifest: %#v", err) } switch rawData.GetKind() { @@ -114,7 +193,7 @@ func (r *renderer) Run(renderedManifests *bytes.Buffer) (*bytes.Buffer, error) { r.namespaces[namespace.Name] = &namespace } // skip so we can strip namespaces from helm's brain - continue + return nil case "Service": // Check service resources for the zarf-connect label @@ -157,67 +236,8 @@ func (r *renderer) Run(renderedManifests *bytes.Buffer) (*bytes.Buffer, error) { message.Debugf("Unable to adopt resource %s: %s", rawData.GetName(), err.Error()) } } - // Finally place this back onto the output buffer fmt.Fprintf(finalManifestsOutput, "---\n# Source: %s\n%s\n", resource.Name, resource.Content) } - - c := r.cluster - existingNamespaces, _ := c.GetNamespaces() - - for name, namespace := range r.namespaces { - - // Check to see if this namespace already exists - var existingNamespace bool - for _, serverNamespace := range existingNamespaces.Items { - if serverNamespace.Name == name { - existingNamespace = true - } - } - - if !existingNamespace { - // This is a new namespace, add it - if _, err := c.CreateNamespace(namespace); err != nil { - return nil, fmt.Errorf("unable to create the missing namespace %s", name) - } - } else if r.cfg.DeployOpts.AdoptExistingResources { - if r.cluster.IsInitialNamespace(name) { - // If this is a K8s initial namespace, refuse to adopt it - message.Warnf("Refusing to adopt the initial namespace: %s", name) - } else { - // This is an existing namespace to adopt - if _, err := c.UpdateNamespace(namespace); err != nil { - return nil, fmt.Errorf("unable to adopt the existing namespace %s", name) - } - } - } - - // If the package is marked as YOLO and the state is empty, skip the secret creation for this namespace - if r.cfg.Pkg.Metadata.YOLO && r.cfg.State.Distro == "YOLO" { - continue - } - - // Create the secret - validRegistrySecret := c.GenerateRegistryPullCreds(name, config.ZarfImagePullSecretName, r.cfg.State.RegistryInfo) - - // Try to get a valid existing secret - currentRegistrySecret, _ := c.GetSecret(name, config.ZarfImagePullSecretName) - if currentRegistrySecret.Name != config.ZarfImagePullSecretName || !reflect.DeepEqual(currentRegistrySecret.Data, validRegistrySecret.Data) { - // Create or update the zarf registry secret - if _, err := c.CreateOrUpdateSecret(validRegistrySecret); err != nil { - message.WarnErrf(err, "Problem creating registry secret for the %s namespace", name) - } - - // Generate the git server secret - gitServerSecret := c.GenerateGitPullCreds(name, config.ZarfGitServerSecretName, r.cfg.State.GitServer) - - // Create or update the zarf git server secret - if _, err := c.CreateOrUpdateSecret(gitServerSecret); err != nil { - message.WarnErrf(err, "Problem creating git server secret for the %s namespace", name) - } - } - } - - // Send the bytes back to helm - return finalManifestsOutput, nil + return nil } diff --git a/src/internal/packager/helm/prepare-render.go b/src/internal/packager/helm/prepare-render.go deleted file mode 100644 index f31d0d1c83..0000000000 --- a/src/internal/packager/helm/prepare-render.go +++ /dev/null @@ -1,80 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 -// SPDX-FileCopyrightText: 2021-Present The Zarf Authors - -// Package helm contains operations for working with helm charts. -package helm - -import ( - "bytes" - "fmt" - "os" - "path/filepath" - - "github.com/defenseunicorns/zarf/src/internal/packager/template" - "github.com/defenseunicorns/zarf/src/pkg/utils" - "github.com/defenseunicorns/zarf/src/types" - "helm.sh/helm/v3/pkg/releaseutil" -) - -type variableRenderer struct { - *Helm - values template.Values -} - -func (h *Helm) newVariableRenderer() (*variableRenderer, error) { - values, err := template.Generate(h.cfg) - if err != nil { - return nil, err - } - values.SetState(&types.ZarfState{}) - - return &variableRenderer{ - Helm: h, - values: *values, - }, nil -} - -func (r *variableRenderer) Run(renderedManifests *bytes.Buffer) (*bytes.Buffer, error) { - // This is very low cost and consistent for how we replace elsewhere, also good for debugging - tempDir, err := utils.MakeTempDir(r.chartPath) - if err != nil { - return nil, fmt.Errorf("unable to create tmpdir: %w", err) - } - path := filepath.Join(tempDir, "chart.yaml") - - // Write the context to a file for processing - if err := utils.WriteFile(path, renderedManifests.Bytes()); err != nil { - return nil, fmt.Errorf("unable to write the post-render file for the helm chart") - } - - // Run the template engine against the chart output - if _, err := template.ProcessYamlFilesInPath(tempDir, r.component, r.values); err != nil { - return nil, fmt.Errorf("error templating the helm chart: %w", err) - } - - // Read back the templated file contents - buff, err := os.ReadFile(path) - if err != nil { - return nil, fmt.Errorf("error reading temporary post-rendered helm chart: %w", err) - } - - // Use helm to re-split the manifest byte (same call used by helm to pass this data to postRender) - _, resources, err := releaseutil.SortManifests(map[string]string{path: string(buff)}, - r.actionConfig.Capabilities.APIVersions, - releaseutil.InstallOrder, - ) - - if err != nil { - return nil, fmt.Errorf("error re-rendering helm output: %w", err) - } - - finalManifestsOutput := bytes.NewBuffer(nil) - - // Otherwise, loop over the resources, - for _, resource := range resources { - fmt.Fprintf(finalManifestsOutput, "---\n# Source: %s\n%s\n", resource.Name, resource.Content) - } - - // Send the bytes back to helm - return finalManifestsOutput, nil -} From 1c789545dfe9d68ccc6ffacd7bf1fdb00550dfba Mon Sep 17 00:00:00 2001 From: Austin Abro Date: Tue, 6 Feb 2024 16:07:28 +0000 Subject: [PATCH 19/68] update flag sentence --- docs/2-the-zarf-cli/100-cli-commands/zarf_dev_find-images.md | 2 +- src/config/lang/english.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/2-the-zarf-cli/100-cli-commands/zarf_dev_find-images.md b/docs/2-the-zarf-cli/100-cli-commands/zarf_dev_find-images.md index da848494f5..8ae54d36ed 100644 --- a/docs/2-the-zarf-cli/100-cli-commands/zarf_dev_find-images.md +++ b/docs/2-the-zarf-cli/100-cli-commands/zarf_dev_find-images.md @@ -20,7 +20,7 @@ zarf dev find-images [ PACKAGE ] [flags] --deploy-set stringToString Specify deployment variables to set on the command line (KEY=value) (default []) -h, --help help for find-images --kube-version string Override the default helm template KubeVersion when performing a package chart template - --registry string Override the ###ZARF_REGISTRY### value for checks on images using the zarf registry (default "127.0.0.1:31999") + --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" ``` diff --git a/src/config/lang/english.go b/src/config/lang/english.go index c15cf05535..c7b6bdc5dc 100644 --- a/src/config/lang/english.go +++ b/src/config/lang/english.go @@ -384,7 +384,7 @@ $ zarf package pull oci://ghcr.io/defenseunicorns/packages/dos-games:1.0.0 -a sk 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" - CmdDevFlagRegistry = "Override the ###ZARF_REGISTRY### value for checks on images using the zarf registry" + CmdDevFlagRegistry = "Override the ###ZARF_REGISTRY### value" 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" From 6964c6bedb22cd6cf197a189e213835662cf24f8 Mon Sep 17 00:00:00 2001 From: Austin Abro Date: Tue, 6 Feb 2024 16:14:16 +0000 Subject: [PATCH 20/68] rename folder --- src/test/e2e/00_use_cli_test.go | 2 +- .../deployment.yaml | 0 .../simple-helm/Chart.yaml | 0 .../simple-helm/templates/deployment.yaml | 0 .../{00-find-images => 00-find-images-with-vars}/values.yaml | 0 .../{00-find-images => 00-find-images-with-vars}/zarf.yaml | 0 6 files changed, 1 insertion(+), 1 deletion(-) rename src/test/packages/{00-find-images => 00-find-images-with-vars}/deployment.yaml (100%) rename src/test/packages/{00-find-images => 00-find-images-with-vars}/simple-helm/Chart.yaml (100%) rename src/test/packages/{00-find-images => 00-find-images-with-vars}/simple-helm/templates/deployment.yaml (100%) rename src/test/packages/{00-find-images => 00-find-images-with-vars}/values.yaml (100%) rename src/test/packages/{00-find-images => 00-find-images-with-vars}/zarf.yaml (100%) diff --git a/src/test/e2e/00_use_cli_test.go b/src/test/e2e/00_use_cli_test.go index 252c41d705..30a31fe437 100644 --- a/src/test/e2e/00_use_cli_test.go +++ b/src/test/e2e/00_use_cli_test.go @@ -246,7 +246,7 @@ func TestUseCLI(t *testing.T) { t.Run("zarf dev find-images with helm or manifest vars", func(t *testing.T) { t.Parallel() // Test `zarf prepare find-images` for a package with zarf variables in the chart, values file, and manifests - path := filepath.Join("src", "test", "packages", "00-find-images") + path := filepath.Join("src", "test", "packages", "00-find-images-with-vars") registry := "coolregistry.gov" stdOut, _, err := e2e.Zarf("prepare", "find-images", path, "--registry-url", registry) require.NoError(t, err) diff --git a/src/test/packages/00-find-images/deployment.yaml b/src/test/packages/00-find-images-with-vars/deployment.yaml similarity index 100% rename from src/test/packages/00-find-images/deployment.yaml rename to src/test/packages/00-find-images-with-vars/deployment.yaml diff --git a/src/test/packages/00-find-images/simple-helm/Chart.yaml b/src/test/packages/00-find-images-with-vars/simple-helm/Chart.yaml similarity index 100% rename from src/test/packages/00-find-images/simple-helm/Chart.yaml rename to src/test/packages/00-find-images-with-vars/simple-helm/Chart.yaml diff --git a/src/test/packages/00-find-images/simple-helm/templates/deployment.yaml b/src/test/packages/00-find-images-with-vars/simple-helm/templates/deployment.yaml similarity index 100% rename from src/test/packages/00-find-images/simple-helm/templates/deployment.yaml rename to src/test/packages/00-find-images-with-vars/simple-helm/templates/deployment.yaml diff --git a/src/test/packages/00-find-images/values.yaml b/src/test/packages/00-find-images-with-vars/values.yaml similarity index 100% rename from src/test/packages/00-find-images/values.yaml rename to src/test/packages/00-find-images-with-vars/values.yaml diff --git a/src/test/packages/00-find-images/zarf.yaml b/src/test/packages/00-find-images-with-vars/zarf.yaml similarity index 100% rename from src/test/packages/00-find-images/zarf.yaml rename to src/test/packages/00-find-images-with-vars/zarf.yaml From 6f4ef70ab73ad46cec8d49bae503ef6c3e819e5b Mon Sep 17 00:00:00 2001 From: Austin Abro Date: Wed, 7 Feb 2024 17:58:58 +0000 Subject: [PATCH 21/68] fix early return --- src/internal/packager/helm/post-render.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/internal/packager/helm/post-render.go b/src/internal/packager/helm/post-render.go index e3d7021086..52e2772bb7 100644 --- a/src/internal/packager/helm/post-render.go +++ b/src/internal/packager/helm/post-render.go @@ -193,7 +193,7 @@ func (r *renderer) editResourceForHelm(resources []releaseutil.Manifest, finalMa r.namespaces[namespace.Name] = &namespace } // skip so we can strip namespaces from helm's brain - return nil + continue case "Service": // Check service resources for the zarf-connect label From 4de06746300226122863cbcd1bd809bf08f1ca6e Mon Sep 17 00:00:00 2001 From: Austin Abro Date: Wed, 7 Feb 2024 20:11:39 +0000 Subject: [PATCH 22/68] hack fix for renderer with big bang --- src/internal/packager/helm/post-render.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/internal/packager/helm/post-render.go b/src/internal/packager/helm/post-render.go index 52e2772bb7..dd16a0b707 100644 --- a/src/internal/packager/helm/post-render.go +++ b/src/internal/packager/helm/post-render.go @@ -39,6 +39,11 @@ func (h *Helm) newRenderer() (*renderer, error) { return nil, err } + // TODO (austinabro321) this should be cleaned up after https://github.com/defenseunicorns/zarf/pull/2276 gets merged + if h.cfg.State == nil { + valueTemplate.SetState(&types.ZarfState{}) + } + namespaces := make(map[string]*corev1.Namespace) if h.cluster != nil { namespaces[h.chart.Namespace] = h.cluster.NewZarfManagedNamespace(h.chart.Namespace) From ebc9dbda43751b8221de28f570a965004a6745c1 Mon Sep 17 00:00:00 2001 From: Austin Abro Date: Thu, 8 Feb 2024 15:51:39 +0000 Subject: [PATCH 23/68] error message --- src/internal/packager/helm/chart.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/internal/packager/helm/chart.go b/src/internal/packager/helm/chart.go index 9ec96f8ed8..7934811974 100644 --- a/src/internal/packager/helm/chart.go +++ b/src/internal/packager/helm/chart.go @@ -185,7 +185,7 @@ func (h *Helm) TemplateChart() (manifest string, chartValues chartutil.Values, e client.PostRenderer, err = h.newRenderer() if err != nil { - return "", nil, fmt.Errorf("unable to get dev renderer: %w", err) + return "", nil, fmt.Errorf("unable to create helm renderer: %w", err) } // Perform the loadedChart installation. From 8aec3678b8c3c6ce2663e49590f9570edb37f5cc Mon Sep 17 00:00:00 2001 From: Austin Abro <37223396+AustinAbro321@users.noreply.github.com> Date: Fri, 9 Feb 2024 08:32:20 -0500 Subject: [PATCH 24/68] Update src/cmd/dev.go Co-authored-by: Wayne Starr --- src/cmd/dev.go | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cmd/dev.go b/src/cmd/dev.go index 71f98e868c..7d0007adac 100644 --- a/src/cmd/dev.go +++ b/src/cmd/dev.go @@ -271,6 +271,7 @@ func init() { devFindImagesCmd.Flags().MarkDeprecated("set", "This field is replaced by create-set") devFindImagesCmd.Flags().MarkHidden("set") + devFindImagesCmd.Flags().StringToStringVar(&pkgConfig.CreateOpts.Flavor, "flavor", v.GetStringMapString(common.VPkgCreateFlavor), lang.CmdPackageCreateFlagFlavor) devFindImagesCmd.Flags().StringToStringVar(&pkgConfig.CreateOpts.SetVariables, "create-set", v.GetStringMapString(common.VPkgCreateSet), lang.CmdDevFlagSet) devFindImagesCmd.Flags().StringToStringVar(&pkgConfig.PkgOpts.SetVariables, "deploy-set", v.GetStringMapString(common.VPkgDeploySet), lang.CmdPackageDeployFlagSet) // allow for the override of the default helm KubeVersion From f86e7a2418139e9435486c4cc6314a7ca513f835 Mon Sep 17 00:00:00 2001 From: Austin Abro Date: Fri, 9 Feb 2024 15:04:02 +0000 Subject: [PATCH 25/68] adding flavor --- src/cmd/dev.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cmd/dev.go b/src/cmd/dev.go index 7d0007adac..511bcbce38 100644 --- a/src/cmd/dev.go +++ b/src/cmd/dev.go @@ -271,7 +271,7 @@ func init() { devFindImagesCmd.Flags().MarkDeprecated("set", "This field is replaced by create-set") devFindImagesCmd.Flags().MarkHidden("set") - devFindImagesCmd.Flags().StringToStringVar(&pkgConfig.CreateOpts.Flavor, "flavor", v.GetStringMapString(common.VPkgCreateFlavor), lang.CmdPackageCreateFlagFlavor) + devFindImagesCmd.Flags().StringVarP(&pkgConfig.CreateOpts.Flavor, "flavor", "f", v.GetString(common.VPkgCreateFlavor), lang.CmdPackageCreateFlagFlavor) devFindImagesCmd.Flags().StringToStringVar(&pkgConfig.CreateOpts.SetVariables, "create-set", v.GetStringMapString(common.VPkgCreateSet), lang.CmdDevFlagSet) devFindImagesCmd.Flags().StringToStringVar(&pkgConfig.PkgOpts.SetVariables, "deploy-set", v.GetStringMapString(common.VPkgDeploySet), lang.CmdPackageDeployFlagSet) // allow for the override of the default helm KubeVersion From 5c276225641c745ca0dcfdf2d9c715d82ba07ce7 Mon Sep 17 00:00:00 2001 From: Austin Abro Date: Tue, 13 Feb 2024 21:20:27 +0000 Subject: [PATCH 26/68] make docs and schema --- docs/2-the-zarf-cli/100-cli-commands/zarf_dev_find-images.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/2-the-zarf-cli/100-cli-commands/zarf_dev_find-images.md b/docs/2-the-zarf-cli/100-cli-commands/zarf_dev_find-images.md index 8ae54d36ed..7393437fa4 100644 --- a/docs/2-the-zarf-cli/100-cli-commands/zarf_dev_find-images.md +++ b/docs/2-the-zarf-cli/100-cli-commands/zarf_dev_find-images.md @@ -18,6 +18,7 @@ zarf dev find-images [ PACKAGE ] [flags] ``` --create-set stringToString 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]. (default []) --deploy-set stringToString Specify deployment variables to set on the command line (KEY=value) (default []) + -f, --flavor string The flavor of components to include in the resulting package (i.e. have a matching or empty "only.flavor" key) -h, --help help for find-images --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") From 30448ff4c7691b8bf5570d3f1e2022c4f1299efe Mon Sep 17 00:00:00 2001 From: Austin Abro Date: Tue, 13 Feb 2024 21:36:46 +0000 Subject: [PATCH 27/68] removing setRegistry function --- src/internal/packager/helm/post-render.go | 2 +- src/internal/packager/template/template.go | 7 +------ src/pkg/packager/prepare.go | 4 ++-- src/test/e2e/00_use_cli_test.go | 4 ++++ 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/internal/packager/helm/post-render.go b/src/internal/packager/helm/post-render.go index dd16a0b707..684f0e36d8 100644 --- a/src/internal/packager/helm/post-render.go +++ b/src/internal/packager/helm/post-render.go @@ -39,7 +39,7 @@ func (h *Helm) newRenderer() (*renderer, error) { return nil, err } - // TODO (austinabro321) this should be cleaned up after https://github.com/defenseunicorns/zarf/pull/2276 gets merged + // TODO (@austinabro321) this should be cleaned up after https://github.com/defenseunicorns/zarf/pull/2276 gets merged if h.cfg.State == nil { valueTemplate.SetState(&types.ZarfState{}) } diff --git a/src/internal/packager/template/template.go b/src/internal/packager/template/template.go index 4b59373e3b..834e1a739c 100644 --- a/src/internal/packager/template/template.go +++ b/src/internal/packager/template/template.go @@ -71,11 +71,6 @@ func (values *Values) GetRegistry() string { return values.registry } -// SetRegistry sets the registry -func (values *Values) SetRegistry(registry string) { - values.registry = registry -} - // SetState sets the state func (values *Values) SetState(state *types.ZarfState) { values.config.State = state @@ -99,7 +94,7 @@ func (values *Values) GetVariables(component types.ZarfComponent) (templateMap m "STORAGE_CLASS": values.config.State.StorageClass, // Registry info - "REGISTRY": values.registry, + "REGISTRY": regInfo.Address, "NODEPORT": fmt.Sprintf("%d", regInfo.NodePort), "REGISTRY_AUTH_PUSH": regInfo.PushPassword, "REGISTRY_AUTH_PULL": regInfo.PullPassword, diff --git a/src/pkg/packager/prepare.go b/src/pkg/packager/prepare.go index 1e2d721dd6..88ecb91e3f 100644 --- a/src/pkg/packager/prepare.go +++ b/src/pkg/packager/prepare.go @@ -129,8 +129,8 @@ func (p *Packager) FindImages() (imgMap map[string][]string, err error) { if err != nil { return nil, fmt.Errorf("unable to generate template values") } - values.SetState(&types.ZarfState{}) - values.SetRegistry(p.cfg.FindImagesOpts.RegistryURL) + + values.SetState(&types.ZarfState{RegistryInfo: types.RegistryInfo{Address: p.cfg.FindImagesOpts.RegistryURL}}) for _, chart := range component.Charts { helmCfg := helm.New( diff --git a/src/test/e2e/00_use_cli_test.go b/src/test/e2e/00_use_cli_test.go index 30a31fe437..53ebf8fc8a 100644 --- a/src/test/e2e/00_use_cli_test.go +++ b/src/test/e2e/00_use_cli_test.go @@ -243,6 +243,10 @@ func TestUseCLI(t *testing.T) { require.FileExists(t, tlsKey) }) +} + +func TestUseCLI2(t *testing.T) { + t.Run("zarf dev find-images with helm or manifest vars", func(t *testing.T) { t.Parallel() // Test `zarf prepare find-images` for a package with zarf variables in the chart, values file, and manifests From f11c61590a1c80c9f62df8c8d9cd8c6bee0545ed Mon Sep 17 00:00:00 2001 From: Austin Abro Date: Wed, 14 Feb 2024 13:19:20 +0000 Subject: [PATCH 28/68] switching test to be on already created packages --- examples/manifests/httpd-deployment.yaml | 2 +- examples/manifests/zarf.yaml | 4 ++++ src/pkg/packager/prepare.go | 8 +++++++- src/test/e2e/00_use_cli_test.go | 17 ++++++++++------- 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/examples/manifests/httpd-deployment.yaml b/examples/manifests/httpd-deployment.yaml index 8465e727f3..7a57b02994 100644 --- a/examples/manifests/httpd-deployment.yaml +++ b/examples/manifests/httpd-deployment.yaml @@ -14,6 +14,6 @@ spec: spec: containers: - name: httpd - image: httpd:alpine3.18 + image: httpd:alpine###ZARF_CONST_HTTPD_VERSION### ports: - containerPort: 80 diff --git a/examples/manifests/zarf.yaml b/examples/manifests/zarf.yaml index cb363312c0..4b87ac9b21 100644 --- a/examples/manifests/zarf.yaml +++ b/examples/manifests/zarf.yaml @@ -3,6 +3,10 @@ metadata: name: manifests version: 0.0.1 +constants: + - name: HTTPD_VERSION + value: "3.18" + components: - name: httpd-local required: true diff --git a/src/pkg/packager/prepare.go b/src/pkg/packager/prepare.go index 88ecb91e3f..b90dbe46d7 100644 --- a/src/pkg/packager/prepare.go +++ b/src/pkg/packager/prepare.go @@ -130,7 +130,13 @@ func (p *Packager) FindImages() (imgMap map[string][]string, err error) { return nil, fmt.Errorf("unable to generate template values") } - values.SetState(&types.ZarfState{RegistryInfo: types.RegistryInfo{Address: p.cfg.FindImagesOpts.RegistryURL}}) + values.SetState( + &types.ZarfState{ + RegistryInfo: types.RegistryInfo{ + Address: p.cfg.FindImagesOpts.RegistryURL, + // Adding a fake secret here so if a chart expects the registry secret, like the init package, it won't fail + Secret: "fake-zarf-secret", + }}) for _, chart := range component.Charts { helmCfg := helm.New( diff --git a/src/test/e2e/00_use_cli_test.go b/src/test/e2e/00_use_cli_test.go index 53ebf8fc8a..5a99d622c7 100644 --- a/src/test/e2e/00_use_cli_test.go +++ b/src/test/e2e/00_use_cli_test.go @@ -249,14 +249,17 @@ func TestUseCLI2(t *testing.T) { t.Run("zarf dev find-images with helm or manifest vars", func(t *testing.T) { t.Parallel() - // Test `zarf prepare find-images` for a package with zarf variables in the chart, values file, and manifests - path := filepath.Join("src", "test", "packages", "00-find-images-with-vars") registry := "coolregistry.gov" - stdOut, _, err := e2e.Zarf("prepare", "find-images", path, "--registry-url", registry) + stdOut, _, err := e2e.Zarf("prepare", "find-images", ".", "--registry-url", registry) require.NoError(t, err) - manifestImage := fmt.Sprintf("%s/%s", registry, "defenseunicorns/zarf/agent:local") - require.Contains(t, stdOut, manifestImage, "Manifests aren't interpreting vars") - require.Contains(t, stdOut, "busybox:latest", "Values files aren't interpreting vars") - require.Contains(t, stdOut, "nginx:stable-perl", "Helm isn't interpreting vars") + internalRegistryImage := fmt.Sprintf("%s/%s", registry, "defenseunicorns/zarf/agent:local") + require.Contains(t, stdOut, internalRegistryImage, "registry image should be found with registry url") + require.Contains(t, stdOut, "busybox:latest", "Busybox image should be found as long as helm chart doesn't error") + + path := filepath.Join("examples", "manifests") + + stdOut, _, err = e2e.Zarf("prepare", "find-images", path) + require.NoError(t, err) + require.Contains(t, stdOut, "httpd:alpine3.18", "Should contain the templated image from manifests") }) } From 256341e5482ac85390c7a7bf74657496384b97f5 Mon Sep 17 00:00:00 2001 From: Austin Abro Date: Wed, 14 Feb 2024 13:57:19 +0000 Subject: [PATCH 29/68] put test in right place --- src/test/e2e/00_use_cli_test.go | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/test/e2e/00_use_cli_test.go b/src/test/e2e/00_use_cli_test.go index 5a99d622c7..64763b5952 100644 --- a/src/test/e2e/00_use_cli_test.go +++ b/src/test/e2e/00_use_cli_test.go @@ -243,12 +243,9 @@ func TestUseCLI(t *testing.T) { require.FileExists(t, tlsKey) }) -} - -func TestUseCLI2(t *testing.T) { - t.Run("zarf dev find-images with helm or manifest vars", func(t *testing.T) { t.Parallel() + registry := "coolregistry.gov" stdOut, _, err := e2e.Zarf("prepare", "find-images", ".", "--registry-url", registry) require.NoError(t, err) @@ -257,7 +254,6 @@ func TestUseCLI2(t *testing.T) { require.Contains(t, stdOut, "busybox:latest", "Busybox image should be found as long as helm chart doesn't error") path := filepath.Join("examples", "manifests") - stdOut, _, err = e2e.Zarf("prepare", "find-images", path) require.NoError(t, err) require.Contains(t, stdOut, "httpd:alpine3.18", "Should contain the templated image from manifests") From 9fd22a7ba1c24ccda72bc9221642942c37a3e7b9 Mon Sep 17 00:00:00 2001 From: Austin Abro Date: Wed, 14 Feb 2024 14:25:42 +0000 Subject: [PATCH 30/68] refactor --- src/pkg/packager/prepare.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/pkg/packager/prepare.go b/src/pkg/packager/prepare.go index b90dbe46d7..683155a3d9 100644 --- a/src/pkg/packager/prepare.go +++ b/src/pkg/packager/prepare.go @@ -130,13 +130,13 @@ func (p *Packager) FindImages() (imgMap map[string][]string, err error) { return nil, fmt.Errorf("unable to generate template values") } - values.SetState( - &types.ZarfState{ - RegistryInfo: types.RegistryInfo{ - Address: p.cfg.FindImagesOpts.RegistryURL, - // Adding a fake secret here so if a chart expects the registry secret, like the init package, it won't fail - Secret: "fake-zarf-secret", - }}) + values.SetState(&types.ZarfState{ + RegistryInfo: types.RegistryInfo{ + Address: p.cfg.FindImagesOpts.RegistryURL, + // Adding a fake secret here so if a chart expects the registry secret, like the init package, it won't fail + Secret: "fake-zarf-secret", + }, + }) for _, chart := range component.Charts { helmCfg := helm.New( From 77b3a10b8079aad417ca5a2c49fff3cc99955983 Mon Sep 17 00:00:00 2001 From: Austin Abro Date: Wed, 14 Feb 2024 14:32:54 +0000 Subject: [PATCH 31/68] removing unused test package --- .../00-find-images-with-vars/deployment.yaml | 19 ---------- .../simple-helm/Chart.yaml | 6 --- .../simple-helm/templates/deployment.yaml | 23 ------------ .../00-find-images-with-vars/values.yaml | 2 - .../00-find-images-with-vars/zarf.yaml | 37 ------------------- 5 files changed, 87 deletions(-) delete mode 100644 src/test/packages/00-find-images-with-vars/deployment.yaml delete mode 100644 src/test/packages/00-find-images-with-vars/simple-helm/Chart.yaml delete mode 100644 src/test/packages/00-find-images-with-vars/simple-helm/templates/deployment.yaml delete mode 100644 src/test/packages/00-find-images-with-vars/values.yaml delete mode 100644 src/test/packages/00-find-images-with-vars/zarf.yaml diff --git a/src/test/packages/00-find-images-with-vars/deployment.yaml b/src/test/packages/00-find-images-with-vars/deployment.yaml deleted file mode 100644 index ff2a7fbc32..0000000000 --- a/src/test/packages/00-find-images-with-vars/deployment.yaml +++ /dev/null @@ -1,19 +0,0 @@ -apiVersion: apps/v1 -kind: Deployment -metadata: - name: simple-deployment - labels: - app: simple-deployment -spec: - replicas: 1 - selector: - matchLabels: - app: simple-deployment - template: - metadata: - labels: - app: simple-deployment - spec: - containers: - - name: server - image: "###ZARF_REGISTRY###/###ZARF_CONST_AGENT_IMAGE###:###ZARF_CONST_AGENT_IMAGE_TAG###" diff --git a/src/test/packages/00-find-images-with-vars/simple-helm/Chart.yaml b/src/test/packages/00-find-images-with-vars/simple-helm/Chart.yaml deleted file mode 100644 index 2c128bf819..0000000000 --- a/src/test/packages/00-find-images-with-vars/simple-helm/Chart.yaml +++ /dev/null @@ -1,6 +0,0 @@ -apiVersion: v2 -name: simple-helm -description: A Helm chart for Kubernetes -type: application -version: 0.1.0 -appVersion: "0.0.1" diff --git a/src/test/packages/00-find-images-with-vars/simple-helm/templates/deployment.yaml b/src/test/packages/00-find-images-with-vars/simple-helm/templates/deployment.yaml deleted file mode 100644 index 8fdfd32485..0000000000 --- a/src/test/packages/00-find-images-with-vars/simple-helm/templates/deployment.yaml +++ /dev/null @@ -1,23 +0,0 @@ -apiVersion: apps/v1 -kind: Deployment -metadata: - name: simple-deployment - labels: - app: simple-deployment -spec: -{{- if gt .Values.replicaCount 1.0 -}} - replicas: 1 -{{- end }} - selector: - matchLabels: - app: simple-deployment - template: - metadata: - labels: - app: simple-deployment - spec: - containers: - - name: server - image: "###ZARF_CONST_HELM_IMAGE###:stable-perl" - - name: another-container - image: {{.Values.otherContainer}} diff --git a/src/test/packages/00-find-images-with-vars/values.yaml b/src/test/packages/00-find-images-with-vars/values.yaml deleted file mode 100644 index 5c30b9ac2f..0000000000 --- a/src/test/packages/00-find-images-with-vars/values.yaml +++ /dev/null @@ -1,2 +0,0 @@ -replicaCount: ###ZARF_VAR_REPLICA_COUNT### -otherContainer: ###ZARF_VAR_VALUES_IMAGE### diff --git a/src/test/packages/00-find-images-with-vars/zarf.yaml b/src/test/packages/00-find-images-with-vars/zarf.yaml deleted file mode 100644 index 482b35ff8d..0000000000 --- a/src/test/packages/00-find-images-with-vars/zarf.yaml +++ /dev/null @@ -1,37 +0,0 @@ -kind: ZarfPackageConfig -metadata: - name: find-image-with-variables - description: Simple zarf package with variables - -variables: - - name: REPLICA_COUNT - default: "1" - - name: VALUES_IMAGE - default: "busybox:latest" - -constants: - - name: AGENT_IMAGE - value: "defenseunicorns/zarf/agent" - - name: AGENT_IMAGE_TAG - value: "local" - - name: HELM_IMAGE - value: "nginx" - -components: -- name: simple-var - required: true - manifests: - - name: simple-deployment - namespace: zarf - files: - - deployment.yaml -- name: chart-with-var - required: true - charts: - - name: simple - releaseName: simple - localPath: simple-helm - namespace: zarf-simple - version: 0.1.0 - valuesFiles: - - values.yaml From 2d2c7cbc8dfddb08072b8e532cc92ea45e4f9b94 Mon Sep 17 00:00:00 2001 From: Austin Abro Date: Wed, 14 Feb 2024 15:25:38 +0000 Subject: [PATCH 32/68] fix incorrect paths --- src/pkg/packager/prepare.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/pkg/packager/prepare.go b/src/pkg/packager/prepare.go index 683155a3d9..cf71a05f90 100644 --- a/src/pkg/packager/prepare.go +++ b/src/pkg/packager/prepare.go @@ -204,7 +204,8 @@ func (p *Packager) FindImages() (imgMap map[string][]string, err error) { } f = destination } else { - newDestination := filepath.Join(componentPaths.Manifests, f) + filename := filepath.Base(f) + newDestination := filepath.Join(componentPaths.Manifests, filename) utils.CreatePathAndCopy(f, newDestination) f = newDestination } From 4c3bfd979effff98c4042fe407ce3c2e6a62df41 Mon Sep 17 00:00:00 2001 From: Austin Abro Date: Thu, 15 Feb 2024 16:17:57 +0000 Subject: [PATCH 33/68] using contants over magic string --- src/cmd/dev.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cmd/dev.go b/src/cmd/dev.go index 511bcbce38..31dd51b44c 100644 --- a/src/cmd/dev.go +++ b/src/cmd/dev.go @@ -277,7 +277,8 @@ func init() { // allow for the override of the default helm KubeVersion devFindImagesCmd.Flags().StringVar(&pkgConfig.FindImagesOpts.KubeVersionOverride, "kube-version", "", lang.CmdDevFlagKubeVersion) - devFindImagesCmd.Flags().StringVar(&pkgConfig.FindImagesOpts.RegistryURL, "registry-url", "127.0.0.1:31999", lang.CmdDevFlagRegistry) + defaultRegistry := fmt.Sprintf("%s:%d", helpers.IPV4Localhost, config.ZarfInClusterContainerRegistryNodePort) + devFindImagesCmd.Flags().StringVar(&pkgConfig.FindImagesOpts.RegistryURL, "registry-url", defaultRegistry, lang.CmdDevFlagRegistry) devLintCmd.Flags().StringToStringVar(&pkgConfig.CreateOpts.SetVariables, "set", v.GetStringMapString(common.VPkgCreateSet), lang.CmdPackageCreateFlagSet) devLintCmd.Flags().StringVarP(&pkgConfig.CreateOpts.Flavor, "flavor", "f", v.GetString(common.VPkgCreateFlavor), lang.CmdPackageCreateFlagFlavor) From 4d6d4985f0229edc602a587c73b2814b93958682 Mon Sep 17 00:00:00 2001 From: Austin Abro Date: Thu, 15 Feb 2024 16:26:28 +0000 Subject: [PATCH 34/68] rename + lint --- src/cmd/dev.go | 12 ++++++------ src/internal/packager/helm/post-render.go | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/cmd/dev.go b/src/cmd/dev.go index 31dd51b44c..f1f4ad6ea5 100644 --- a/src/cmd/dev.go +++ b/src/cmd/dev.go @@ -39,7 +39,7 @@ var devDeployCmd = &cobra.Command{ Args: cobra.MaximumNArgs(1), Short: lang.CmdDevDeployShort, Long: lang.CmdDevDeployLong, - Run: func(cmd *cobra.Command, args []string) { + Run: func(_ *cobra.Command, args []string) { common.SetBaseDirectory(args, &pkgConfig) v := common.GetViper() @@ -65,7 +65,7 @@ var devTransformGitLinksCmd = &cobra.Command{ Aliases: []string{"p"}, Short: lang.CmdDevPatchGitShort, Args: cobra.ExactArgs(2), - Run: func(cmd *cobra.Command, args []string) { + Run: func(_ *cobra.Command, args []string) { host, fileName := args[0], args[1] // Read the contents of the given file @@ -108,7 +108,7 @@ var devSha256SumCmd = &cobra.Command{ Aliases: []string{"s"}, Short: lang.CmdDevSha256sumShort, Args: cobra.ExactArgs(1), - Run: func(cmd *cobra.Command, args []string) { + Run: func(_ *cobra.Command, args []string) { fileName := args[0] var tmp string @@ -184,7 +184,7 @@ var devFindImagesCmd = &cobra.Command{ Args: cobra.MaximumNArgs(1), Short: lang.CmdDevFindImagesShort, Long: lang.CmdDevFindImagesLong, - Run: func(cmd *cobra.Command, args []string) { + Run: func(_ *cobra.Command, args []string) { // If a directory was provided, use that as the base directory common.SetBaseDirectory(args, &pkgConfig) @@ -213,7 +213,7 @@ var devGenConfigFileCmd = &cobra.Command{ Args: cobra.MaximumNArgs(1), Short: lang.CmdDevGenerateConfigShort, Long: lang.CmdDevGenerateConfigLong, - Run: func(cmd *cobra.Command, args []string) { + Run: func(_ *cobra.Command, args []string) { fileName := "zarf-config.toml" // If a filename was provided, use that @@ -234,7 +234,7 @@ var devLintCmd = &cobra.Command{ Aliases: []string{"l"}, Short: lang.CmdDevLintShort, Long: lang.CmdDevLintLong, - Run: func(cmd *cobra.Command, args []string) { + Run: func(_ *cobra.Command, args []string) { common.SetBaseDirectory(args, &pkgConfig) v := common.GetViper() pkgConfig.CreateOpts.SetVariables = helpers.TransformAndMergeMap( diff --git a/src/internal/packager/helm/post-render.go b/src/internal/packager/helm/post-render.go index 684f0e36d8..9555c78478 100644 --- a/src/internal/packager/helm/post-render.go +++ b/src/internal/packager/helm/post-render.go @@ -95,7 +95,7 @@ func (r *renderer) Run(renderedManifests *bytes.Buffer) (*bytes.Buffer, error) { // Otherwise, loop over the resources, if r.cluster != nil { - if err := r.editResourceForHelm(resources, finalManifestsOutput); err != nil { + if err := r.editHelmResources(resources, finalManifestsOutput); err != nil { return nil, err } @@ -170,7 +170,7 @@ func (r *renderer) adoptAndUpdateNamespaces() error { return nil } -func (r *renderer) editResourceForHelm(resources []releaseutil.Manifest, finalManifestsOutput *bytes.Buffer) error { +func (r *renderer) editHelmResources(resources []releaseutil.Manifest, finalManifestsOutput *bytes.Buffer) error { for _, resource := range resources { // parse to unstructured to have access to more data than just the name rawData := &unstructured.Unstructured{} From 3b0d7eb6bf97ba7863755d9472f97eb857782f16 Mon Sep 17 00:00:00 2001 From: Austin Abro Date: Thu, 15 Feb 2024 16:47:59 +0000 Subject: [PATCH 35/68] switching to %w directive --- src/pkg/packager/prepare.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/pkg/packager/prepare.go b/src/pkg/packager/prepare.go index cf71a05f90..d549f4749c 100644 --- a/src/pkg/packager/prepare.go +++ b/src/pkg/packager/prepare.go @@ -54,7 +54,7 @@ func (p *Packager) FindImages() (imgMap map[string][]string, err error) { message.Note(fmt.Sprintf("Using build directory %s", p.cfg.CreateOpts.BaseDir)) if err = p.readZarfYAML(layout.ZarfYAML); err != nil { - return nil, fmt.Errorf("unable to read the zarf.yaml file: %s", err.Error()) + return nil, fmt.Errorf("unable to read the zarf.yaml file: %w", err) } if err := p.composeComponents(); err != nil { @@ -67,7 +67,7 @@ func (p *Packager) FindImages() (imgMap map[string][]string, err error) { // After components are composed, template the active package if err := p.fillActiveTemplate(); err != nil { - return nil, fmt.Errorf("unable to fill values in template: %s", err.Error()) + return nil, fmt.Errorf("unable to fill values in template: %w", err) } for _, component := range p.cfg.Pkg.Components { @@ -149,7 +149,7 @@ func (p *Packager) FindImages() (imgMap map[string][]string, err error) { err = helmCfg.PackageChart(component.DeprecatedCosignKeyPath) if err != nil { - return nil, fmt.Errorf("unable to package the chart %s: %s", chart.Name, err.Error()) + return nil, fmt.Errorf("unable to package the chart %s: %w", chart.Name, err) } valuesFilePaths, _ := utils.RecursiveFileList(componentPaths.Values, nil, false) @@ -190,7 +190,7 @@ func (p *Packager) FindImages() (imgMap map[string][]string, err error) { kname := fmt.Sprintf("kustomization-%s-%d.yaml", manifest.Name, idx) destination := filepath.Join(componentPaths.Manifests, kname) if err := kustomize.Build(k, destination, manifest.KustomizeAllowAnyDirectory); err != nil { - return nil, fmt.Errorf("unable to build the kustomization for %s: %s", k, err.Error()) + return nil, fmt.Errorf("unable to build the kustomization for %s: %w", k, err) } manifest.Files = append(manifest.Files, destination) } From 5bb96647bcabd4e32e02fcc476cd1b9020d2877c Mon Sep 17 00:00:00 2001 From: Austin Abro Date: Thu, 15 Feb 2024 16:57:33 +0000 Subject: [PATCH 36/68] removing unnecessary code --- src/pkg/packager/prepare.go | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/pkg/packager/prepare.go b/src/pkg/packager/prepare.go index d549f4749c..90931b7735 100644 --- a/src/pkg/packager/prepare.go +++ b/src/pkg/packager/prepare.go @@ -203,11 +203,6 @@ func (p *Packager) FindImages() (imgMap map[string][]string, err error) { return nil, fmt.Errorf(lang.ErrDownloading, f, err.Error()) } f = destination - } else { - filename := filepath.Base(f) - newDestination := filepath.Join(componentPaths.Manifests, filename) - utils.CreatePathAndCopy(f, newDestination) - f = newDestination } if err := values.Apply(component, f, true); err != nil { From 9d1ede53c7aa4743a9cebb90c2b85cdbabef4f06 Mon Sep 17 00:00:00 2001 From: Austin Abro Date: Thu, 15 Feb 2024 17:59:38 +0000 Subject: [PATCH 37/68] adding create set / deploy set to test and adding back necessary code --- examples/manifests/httpd-deployment.yaml | 2 +- src/pkg/packager/prepare.go | 5 +++++ src/test/e2e/00_use_cli_test.go | 9 +++++---- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/examples/manifests/httpd-deployment.yaml b/examples/manifests/httpd-deployment.yaml index 7a57b02994..ddd961971e 100644 --- a/examples/manifests/httpd-deployment.yaml +++ b/examples/manifests/httpd-deployment.yaml @@ -14,6 +14,6 @@ spec: spec: containers: - name: httpd - image: httpd:alpine###ZARF_CONST_HTTPD_VERSION### + image: httpd:alpine3.19 ports: - containerPort: 80 diff --git a/src/pkg/packager/prepare.go b/src/pkg/packager/prepare.go index 90931b7735..d549f4749c 100644 --- a/src/pkg/packager/prepare.go +++ b/src/pkg/packager/prepare.go @@ -203,6 +203,11 @@ func (p *Packager) FindImages() (imgMap map[string][]string, err error) { return nil, fmt.Errorf(lang.ErrDownloading, f, err.Error()) } f = destination + } else { + filename := filepath.Base(f) + newDestination := filepath.Join(componentPaths.Manifests, filename) + utils.CreatePathAndCopy(f, newDestination) + f = newDestination } if err := values.Apply(component, f, true); err != nil { diff --git a/src/test/e2e/00_use_cli_test.go b/src/test/e2e/00_use_cli_test.go index 64763b5952..54f3207182 100644 --- a/src/test/e2e/00_use_cli_test.go +++ b/src/test/e2e/00_use_cli_test.go @@ -247,15 +247,16 @@ func TestUseCLI(t *testing.T) { t.Parallel() registry := "coolregistry.gov" - stdOut, _, err := e2e.Zarf("prepare", "find-images", ".", "--registry-url", registry) + agentTag := "test" + stdOut, _, err := e2e.Zarf("prepare", "find-images", ".", "--registry-url", registry, "--create-set", fmt.Sprintf("agent_image_tag=%s", agentTag)) require.NoError(t, err) - internalRegistryImage := fmt.Sprintf("%s/%s", registry, "defenseunicorns/zarf/agent:local") + internalRegistryImage := fmt.Sprintf("%s/%s:%s", registry, "defenseunicorns/zarf/agent", agentTag) require.Contains(t, stdOut, internalRegistryImage, "registry image should be found with registry url") require.Contains(t, stdOut, "busybox:latest", "Busybox image should be found as long as helm chart doesn't error") path := filepath.Join("examples", "manifests") - stdOut, _, err = e2e.Zarf("prepare", "find-images", path) + stdOut, _, err = e2e.Zarf("prepare", "find-images", path, "--deploy-set", "httpd_version=3.19") require.NoError(t, err) - require.Contains(t, stdOut, "httpd:alpine3.18", "Should contain the templated image from manifests") + require.Contains(t, stdOut, "httpd:alpine3.19", "Should contain the templated image from manifests") }) } From 4547ba92318533547dfc3ed616f78fdc72148ca6 Mon Sep 17 00:00:00 2001 From: Austin Abro Date: Thu, 15 Feb 2024 18:00:39 +0000 Subject: [PATCH 38/68] capitals --- src/cmd/dev.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cmd/dev.go b/src/cmd/dev.go index f1f4ad6ea5..15a92da8b9 100644 --- a/src/cmd/dev.go +++ b/src/cmd/dev.go @@ -269,7 +269,7 @@ func init() { // use the package create config for this and reset it here to avoid overwriting the config.CreateOptions.SetVariables devFindImagesCmd.Flags().StringToStringVar(&pkgConfig.CreateOpts.SetVariables, "set", v.GetStringMapString(common.VPkgCreateSet), lang.CmdDevFlagSet) - devFindImagesCmd.Flags().MarkDeprecated("set", "This field is replaced by create-set") + devFindImagesCmd.Flags().MarkDeprecated("set", "this field is replaced by create-set") devFindImagesCmd.Flags().MarkHidden("set") devFindImagesCmd.Flags().StringVarP(&pkgConfig.CreateOpts.Flavor, "flavor", "f", v.GetString(common.VPkgCreateFlavor), lang.CmdPackageCreateFlagFlavor) devFindImagesCmd.Flags().StringToStringVar(&pkgConfig.CreateOpts.SetVariables, "create-set", v.GetStringMapString(common.VPkgCreateSet), lang.CmdDevFlagSet) From bb506e22035937ebe618a8f506c60646ba765391 Mon Sep 17 00:00:00 2001 From: Austin Abro Date: Thu, 15 Feb 2024 20:30:34 +0000 Subject: [PATCH 39/68] fix tests --- examples/manifests/httpd-deployment.yaml | 8 ++++---- examples/manifests/zarf.yaml | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/manifests/httpd-deployment.yaml b/examples/manifests/httpd-deployment.yaml index ddd961971e..6a45482aeb 100644 --- a/examples/manifests/httpd-deployment.yaml +++ b/examples/manifests/httpd-deployment.yaml @@ -13,7 +13,7 @@ spec: app: httpd spec: containers: - - name: httpd - image: httpd:alpine3.19 - ports: - - containerPort: 80 + - name: httpd + image: httpd:alpine###ZARF_VAR_HTTPD_VERSION### + ports: + - containerPort: 80 diff --git a/examples/manifests/zarf.yaml b/examples/manifests/zarf.yaml index 4b87ac9b21..e8b7a776e6 100644 --- a/examples/manifests/zarf.yaml +++ b/examples/manifests/zarf.yaml @@ -3,9 +3,9 @@ metadata: name: manifests version: 0.0.1 -constants: +variables: - name: HTTPD_VERSION - value: "3.18" + default: "3.18" components: - name: httpd-local From 395008ac7a943caa4478cb0b975733dc8831eb93 Mon Sep 17 00:00:00 2001 From: Austin Abro Date: Mon, 26 Feb 2024 18:46:58 +0000 Subject: [PATCH 40/68] change test and example --- examples/helm-charts/values.yaml | 3 +++ examples/helm-charts/zarf.yaml | 7 ++++++- examples/manifests/httpd-deployment.yaml | 8 ++++---- examples/manifests/zarf.yaml | 4 ---- src/test/e2e/00_use_cli_test.go | 4 ++-- 5 files changed, 15 insertions(+), 11 deletions(-) diff --git a/examples/helm-charts/values.yaml b/examples/helm-charts/values.yaml index f86a45afe7..b9cd41c3ba 100644 --- a/examples/helm-charts/values.yaml +++ b/examples/helm-charts/values.yaml @@ -1,3 +1,6 @@ +redis: + enabled: ###ZARF_VAR_REDIS_ENABLED### + ui: color: "#0d133d" message: "greetings from podinfo (as deployed by Zarf)" diff --git a/examples/helm-charts/zarf.yaml b/examples/helm-charts/zarf.yaml index e43d87beef..0d2895ee7a 100644 --- a/examples/helm-charts/zarf.yaml +++ b/examples/helm-charts/zarf.yaml @@ -1,9 +1,13 @@ kind: ZarfPackageConfig metadata: name: helm-charts - description: Example showcasing mutiple ways to deploy helm charts + description: Example showcasing multiple ways to deploy helm charts version: 0.0.1 +variables: + - name: REDIS_ENABLED + default: "false" + components: - name: demo-helm-charts required: true @@ -50,6 +54,7 @@ components: - ghcr.io/stefanprodan/podinfo:6.4.0 # This is the cosign signature for the podinfo image for image signature verification - ghcr.io/stefanprodan/podinfo:sha256-57a654ace69ec02ba8973093b6a786faa15640575fbf0dbb603db55aca2ccec8.sig + - docker.io/redis:7.0.7 actions: onDeploy: after: diff --git a/examples/manifests/httpd-deployment.yaml b/examples/manifests/httpd-deployment.yaml index 6a45482aeb..c9b327a9f4 100644 --- a/examples/manifests/httpd-deployment.yaml +++ b/examples/manifests/httpd-deployment.yaml @@ -13,7 +13,7 @@ spec: app: httpd spec: containers: - - name: httpd - image: httpd:alpine###ZARF_VAR_HTTPD_VERSION### - ports: - - containerPort: 80 + - name: httpd + image: httpd:alpine3.18 + ports: + - containerPort: 80 diff --git a/examples/manifests/zarf.yaml b/examples/manifests/zarf.yaml index e8b7a776e6..cb363312c0 100644 --- a/examples/manifests/zarf.yaml +++ b/examples/manifests/zarf.yaml @@ -3,10 +3,6 @@ metadata: name: manifests version: 0.0.1 -variables: - - name: HTTPD_VERSION - default: "3.18" - components: - name: httpd-local required: true diff --git a/src/test/e2e/00_use_cli_test.go b/src/test/e2e/00_use_cli_test.go index 54f3207182..a03df87ca1 100644 --- a/src/test/e2e/00_use_cli_test.go +++ b/src/test/e2e/00_use_cli_test.go @@ -255,8 +255,8 @@ func TestUseCLI(t *testing.T) { require.Contains(t, stdOut, "busybox:latest", "Busybox image should be found as long as helm chart doesn't error") path := filepath.Join("examples", "manifests") - stdOut, _, err = e2e.Zarf("prepare", "find-images", path, "--deploy-set", "httpd_version=3.19") + stdOut, _, err = e2e.Zarf("prepare", "find-images", path, "--deploy-set", "redis_enabled=false") require.NoError(t, err) - require.Contains(t, stdOut, "httpd:alpine3.19", "Should contain the templated image from manifests") + require.Contains(t, stdOut, "redis:7.0.7", "Should contain the templated image from manifests") }) } From 8092254ba08ac9c9fb0503686a766de8e6fa5c57 Mon Sep 17 00:00:00 2001 From: Austin Abro Date: Tue, 27 Feb 2024 14:13:04 +0000 Subject: [PATCH 41/68] refactoring how state gets default values in --- src/cmd/dev.go | 5 +- src/cmd/initialize.go | 5 +- src/cmd/package.go | 5 +- src/config/config.go | 14 +- src/internal/agent/hooks/argocd-repository.go | 3 +- src/pkg/cluster/state.go | 124 ++---------------- src/test/e2e/22_git_and_gitops_test.go | 16 +-- src/types/k8s.go | 119 +++++++++++++++++ 8 files changed, 150 insertions(+), 141 deletions(-) diff --git a/src/cmd/dev.go b/src/cmd/dev.go index 15a92da8b9..4eb3612648 100644 --- a/src/cmd/dev.go +++ b/src/cmd/dev.go @@ -21,6 +21,7 @@ import ( "github.com/defenseunicorns/zarf/src/pkg/transform" "github.com/defenseunicorns/zarf/src/pkg/utils" "github.com/defenseunicorns/zarf/src/pkg/utils/helpers" + "github.com/defenseunicorns/zarf/src/types" "github.com/mholt/archiver/v3" "github.com/spf13/cobra" "github.com/spf13/viper" @@ -277,12 +278,12 @@ func init() { // allow for the override of the default helm KubeVersion devFindImagesCmd.Flags().StringVar(&pkgConfig.FindImagesOpts.KubeVersionOverride, "kube-version", "", lang.CmdDevFlagKubeVersion) - defaultRegistry := fmt.Sprintf("%s:%d", helpers.IPV4Localhost, config.ZarfInClusterContainerRegistryNodePort) + defaultRegistry := fmt.Sprintf("%s:%d", helpers.IPV4Localhost, types.ZarfInClusterContainerRegistryNodePort) devFindImagesCmd.Flags().StringVar(&pkgConfig.FindImagesOpts.RegistryURL, "registry-url", defaultRegistry, lang.CmdDevFlagRegistry) devLintCmd.Flags().StringToStringVar(&pkgConfig.CreateOpts.SetVariables, "set", v.GetStringMapString(common.VPkgCreateSet), lang.CmdPackageCreateFlagSet) devLintCmd.Flags().StringVarP(&pkgConfig.CreateOpts.Flavor, "flavor", "f", v.GetString(common.VPkgCreateFlavor), lang.CmdPackageCreateFlagFlavor) - devTransformGitLinksCmd.Flags().StringVar(&pkgConfig.InitOpts.GitServer.PushUsername, "git-account", config.ZarfGitPushUser, lang.CmdDevFlagGitAccount) + devTransformGitLinksCmd.Flags().StringVar(&pkgConfig.InitOpts.GitServer.PushUsername, "git-account", types.ZarfGitPushUser, lang.CmdDevFlagGitAccount) } func bindDevDeployFlags(v *viper.Viper) { diff --git a/src/cmd/initialize.go b/src/cmd/initialize.go index 906f484720..6510129013 100644 --- a/src/cmd/initialize.go +++ b/src/cmd/initialize.go @@ -22,6 +22,7 @@ import ( "github.com/defenseunicorns/zarf/src/pkg/packager/sources" "github.com/defenseunicorns/zarf/src/pkg/utils" "github.com/defenseunicorns/zarf/src/pkg/utils/helpers" + "github.com/defenseunicorns/zarf/src/types" "github.com/spf13/cobra" ) @@ -180,8 +181,8 @@ func init() { // Init package variable defaults that are non-zero values // NOTE: these are not in common.setDefaults so that zarf tools update-creds does not erroneously update values back to the default - v.SetDefault(common.VInitGitPushUser, config.ZarfGitPushUser) - v.SetDefault(common.VInitRegistryPushUser, config.ZarfRegistryPushUser) + v.SetDefault(common.VInitGitPushUser, types.ZarfGitPushUser) + v.SetDefault(common.VInitRegistryPushUser, types.ZarfRegistryPushUser) // Init package set variable flags initCmd.Flags().StringToStringVar(&pkgConfig.PkgOpts.SetVariables, "set", v.GetStringMapString(common.VPkgDeploySet), lang.CmdInitFlagSet) diff --git a/src/cmd/package.go b/src/cmd/package.go index 3e29b74b64..460f74014c 100644 --- a/src/cmd/package.go +++ b/src/cmd/package.go @@ -15,6 +15,7 @@ import ( "github.com/defenseunicorns/zarf/src/pkg/message" "github.com/defenseunicorns/zarf/src/pkg/packager/sources" "github.com/defenseunicorns/zarf/src/pkg/utils" + "github.com/defenseunicorns/zarf/src/types" "oras.land/oras-go/v2/registry" @@ -395,8 +396,8 @@ func bindMirrorFlags(v *viper.Viper) { // Init package variable defaults that are non-zero values // NOTE: these are not in common.setDefaults so that zarf tools update-creds does not erroneously update values back to the default - v.SetDefault(common.VInitGitPushUser, config.ZarfGitPushUser) - v.SetDefault(common.VInitRegistryPushUser, config.ZarfRegistryPushUser) + v.SetDefault(common.VInitGitPushUser, types.ZarfGitPushUser) + v.SetDefault(common.VInitRegistryPushUser, types.ZarfRegistryPushUser) // Always require confirm flag (no viper) mirrorFlags.BoolVar(&config.CommonOptions.Confirm, "confirm", false, lang.CmdPackageDeployFlagConfirm) diff --git a/src/config/config.go b/src/config/config.go index df4deb9030..f307e5268d 100644 --- a/src/config/config.go +++ b/src/config/config.go @@ -26,9 +26,7 @@ const ( GithubProject = "defenseunicorns/zarf" // ZarfMaxChartNameLength limits helm chart name size to account for K8s/helm limits and zarf prefix - ZarfMaxChartNameLength = 40 - ZarfGeneratedPasswordLen = 24 - ZarfGeneratedSecretLen = 48 + ZarfMaxChartNameLength = 40 ZarfAgentHost = "agent-hook.zarf.svc" @@ -53,16 +51,6 @@ const ( ZarfImagePullSecretName = "private-registry" ZarfGitServerSecretName = "private-git-server" - ZarfRegistryPushUser = "zarf-push" - ZarfRegistryPullUser = "zarf-pull" - ZarfInClusterContainerRegistryNodePort = 31999 - - ZarfGitPushUser = "zarf-git-user" - ZarfGitReadUser = "zarf-git-read-user" - - ZarfInClusterGitServiceURL = "http://zarf-gitea-http.zarf.svc.cluster.local:3000" - ZarfInClusterArtifactServiceURL = ZarfInClusterGitServiceURL + "/api/packages/" + ZarfGitPushUser - ZarfLoggingUser = "zarf-admin" ) diff --git a/src/internal/agent/hooks/argocd-repository.go b/src/internal/agent/hooks/argocd-repository.go index 00368863a3..4e4c0c5ef3 100644 --- a/src/internal/agent/hooks/argocd-repository.go +++ b/src/internal/agent/hooks/argocd-repository.go @@ -9,7 +9,6 @@ import ( "encoding/json" "fmt" - "github.com/defenseunicorns/zarf/src/config" "github.com/defenseunicorns/zarf/src/config/lang" "github.com/defenseunicorns/zarf/src/internal/agent/operations" "github.com/defenseunicorns/zarf/src/internal/agent/state" @@ -102,7 +101,7 @@ func mutateRepository(r *v1.AdmissionRequest) (result *operations.Result, err er func populateArgoRepositoryPatchOperations(repoURL string, zarfGitPullPassword string) []operations.PatchOperation { var patches []operations.PatchOperation patches = append(patches, operations.ReplacePatchOperation("/data/url", base64.StdEncoding.EncodeToString([]byte(repoURL)))) - patches = append(patches, operations.ReplacePatchOperation("/data/username", base64.StdEncoding.EncodeToString([]byte(config.ZarfGitReadUser)))) + patches = append(patches, operations.ReplacePatchOperation("/data/username", base64.StdEncoding.EncodeToString([]byte(types.ZarfGitReadUser)))) patches = append(patches, operations.ReplacePatchOperation("/data/password", base64.StdEncoding.EncodeToString([]byte(zarfGitPullPassword)))) return patches diff --git a/src/pkg/cluster/state.go b/src/pkg/cluster/state.go index 5fe6e4d9dd..8ab725c31a 100644 --- a/src/pkg/cluster/state.go +++ b/src/pkg/cluster/state.go @@ -72,7 +72,7 @@ func (c *Cluster) InitZarfState(initOptions types.ZarfInitOptions) error { // Defaults state.Distro = distro - if state.LoggingSecret, err = helpers.RandomString(config.ZarfGeneratedPasswordLen); err != nil { + if state.LoggingSecret, err = helpers.RandomString(types.ZarfGeneratedPasswordLen); err != nil { return fmt.Errorf("%s: %w", lang.ErrUnableToGenerateRandomSecret, err) } @@ -112,13 +112,15 @@ func (c *Cluster) InitZarfState(initOptions types.ZarfInitOptions) error { return fmt.Errorf("unable get default Zarf service account: %w", err) } - if state.GitServer, err = c.fillInEmptyGitServerValues(initOptions.GitServer); err != nil { + state.GitServer, err = initOptions.GitServer.FillInEmptyValues() + if err != nil { return err } - if state.RegistryInfo, err = c.fillInEmptyContainerRegistryValues(initOptions.RegistryInfo); err != nil { + state.RegistryInfo, err = initOptions.RegistryInfo.FillInEmptyValues() + if err != nil { return err } - state.ArtifactServer = c.fillInEmptyArtifactServerValues(initOptions.ArtifactServer) + state.ArtifactServer = initOptions.ArtifactServer.FillInEmptyValues() } else { if helpers.IsNotZeroAndNotEqual(initOptions.GitServer, state.GitServer) { message.Warn("Detected a change in Git Server init options on a re-init. Ignoring... To update run:") @@ -265,12 +267,12 @@ func (c *Cluster) MergeZarfState(oldState *types.ZarfState, initOptions types.Za // Set the new passwords if they should be autogenerated if newState.RegistryInfo.PushPassword == oldState.RegistryInfo.PushPassword && oldState.RegistryInfo.InternalRegistry { - if newState.RegistryInfo.PushPassword, err = helpers.RandomString(config.ZarfGeneratedPasswordLen); err != nil { + if newState.RegistryInfo.PushPassword, err = helpers.RandomString(types.ZarfGeneratedPasswordLen); err != nil { return nil, fmt.Errorf("%s: %w", lang.ErrUnableToGenerateRandomSecret, err) } } if newState.RegistryInfo.PullPassword == oldState.RegistryInfo.PullPassword && oldState.RegistryInfo.InternalRegistry { - if newState.RegistryInfo.PullPassword, err = helpers.RandomString(config.ZarfGeneratedPasswordLen); err != nil { + if newState.RegistryInfo.PullPassword, err = helpers.RandomString(types.ZarfGeneratedPasswordLen); err != nil { return nil, fmt.Errorf("%s: %w", lang.ErrUnableToGenerateRandomSecret, err) } } @@ -279,7 +281,7 @@ func (c *Cluster) MergeZarfState(oldState *types.ZarfState, initOptions types.Za newState.GitServer = helpers.MergeNonZero(newState.GitServer, initOptions.GitServer) // Set the state of the internal git server if it has changed - if newState.GitServer.Address == config.ZarfInClusterGitServiceURL { + if newState.GitServer.Address == types.ZarfInClusterGitServiceURL { newState.GitServer.InternalServer = true } else { newState.GitServer.InternalServer = false @@ -287,12 +289,12 @@ func (c *Cluster) MergeZarfState(oldState *types.ZarfState, initOptions types.Za // Set the new passwords if they should be autogenerated if newState.GitServer.PushPassword == oldState.GitServer.PushPassword && oldState.GitServer.InternalServer { - if newState.GitServer.PushPassword, err = helpers.RandomString(config.ZarfGeneratedPasswordLen); err != nil { + if newState.GitServer.PushPassword, err = helpers.RandomString(types.ZarfGeneratedPasswordLen); err != nil { return nil, fmt.Errorf("%s: %w", lang.ErrUnableToGenerateRandomSecret, err) } } if newState.GitServer.PullPassword == oldState.GitServer.PullPassword && oldState.GitServer.InternalServer { - if newState.GitServer.PullPassword, err = helpers.RandomString(config.ZarfGeneratedPasswordLen); err != nil { + if newState.GitServer.PullPassword, err = helpers.RandomString(types.ZarfGeneratedPasswordLen); err != nil { return nil, fmt.Errorf("%s: %w", lang.ErrUnableToGenerateRandomSecret, err) } } @@ -301,7 +303,7 @@ func (c *Cluster) MergeZarfState(oldState *types.ZarfState, initOptions types.Za newState.ArtifactServer = helpers.MergeNonZero(newState.ArtifactServer, initOptions.ArtifactServer) // Set the state of the internal artifact server if it has changed - if newState.ArtifactServer.Address == config.ZarfInClusterArtifactServiceURL { + if newState.ArtifactServer.Address == types.ZarfInClusterArtifactServiceURL { newState.ArtifactServer.InternalServer = true } else { newState.ArtifactServer.InternalServer = false @@ -318,105 +320,3 @@ func (c *Cluster) MergeZarfState(oldState *types.ZarfState, initOptions types.Za return &newState, nil } - -func (c *Cluster) fillInEmptyContainerRegistryValues(containerRegistry types.RegistryInfo) (types.RegistryInfo, error) { - var err error - // Set default NodePort if none was provided - if containerRegistry.NodePort == 0 { - containerRegistry.NodePort = config.ZarfInClusterContainerRegistryNodePort - } - - // Set default url if an external registry was not provided - if containerRegistry.Address == "" { - containerRegistry.InternalRegistry = true - containerRegistry.Address = fmt.Sprintf("%s:%d", helpers.IPV4Localhost, containerRegistry.NodePort) - } - - // Generate a push-user password if not provided by init flag - if containerRegistry.PushPassword == "" { - if containerRegistry.PushPassword, err = helpers.RandomString(config.ZarfGeneratedPasswordLen); err != nil { - return containerRegistry, fmt.Errorf("%s: %w", lang.ErrUnableToGenerateRandomSecret, err) - } - } - - // Set pull-username if not provided by init flag - if containerRegistry.PullUsername == "" { - if containerRegistry.InternalRegistry { - containerRegistry.PullUsername = config.ZarfRegistryPullUser - } else { - // If this is an external registry and a pull-user wasn't provided, use the same credentials as the push user - containerRegistry.PullUsername = containerRegistry.PushUsername - } - } - if containerRegistry.PullPassword == "" { - if containerRegistry.InternalRegistry { - if containerRegistry.PullPassword, err = helpers.RandomString(config.ZarfGeneratedPasswordLen); err != nil { - return containerRegistry, fmt.Errorf("%s: %w", lang.ErrUnableToGenerateRandomSecret, err) - } - } else { - // If this is an external registry and a pull-user wasn't provided, use the same credentials as the push user - containerRegistry.PullPassword = containerRegistry.PushPassword - } - } - - if containerRegistry.Secret == "" { - if containerRegistry.Secret, err = helpers.RandomString(config.ZarfGeneratedPasswordLen); err != nil { - return containerRegistry, fmt.Errorf("%s: %w", lang.ErrUnableToGenerateRandomSecret, err) - } - } - - return containerRegistry, nil -} - -// Fill in empty GitServerInfo values with the defaults. -func (c *Cluster) fillInEmptyGitServerValues(gitServer types.GitServerInfo) (types.GitServerInfo, error) { - var err error - // Set default svc url if an external repository was not provided - if gitServer.Address == "" { - gitServer.Address = config.ZarfInClusterGitServiceURL - gitServer.InternalServer = true - } - - // Generate a push-user password if not provided by init flag - if gitServer.PushPassword == "" { - if gitServer.PushPassword, err = helpers.RandomString(config.ZarfGeneratedPasswordLen); err != nil { - return gitServer, fmt.Errorf("%s: %w", lang.ErrUnableToGenerateRandomSecret, err) - } - } - - // Set read-user information if using an internal repository, otherwise copy from the push-user - if gitServer.PullUsername == "" { - if gitServer.InternalServer { - gitServer.PullUsername = config.ZarfGitReadUser - } else { - gitServer.PullUsername = gitServer.PushUsername - } - } - if gitServer.PullPassword == "" { - if gitServer.InternalServer { - if gitServer.PullPassword, err = helpers.RandomString(config.ZarfGeneratedPasswordLen); err != nil { - return gitServer, fmt.Errorf("%s: %w", lang.ErrUnableToGenerateRandomSecret, err) - } - } else { - gitServer.PullPassword = gitServer.PushPassword - } - } - - return gitServer, nil -} - -// Fill in empty ArtifactServerInfo values with the defaults. -func (c *Cluster) fillInEmptyArtifactServerValues(artifactServer types.ArtifactServerInfo) types.ArtifactServerInfo { - // Set default svc url if an external registry was not provided - if artifactServer.Address == "" { - artifactServer.Address = config.ZarfInClusterArtifactServiceURL - artifactServer.InternalServer = true - } - - // Set the push username to the git push user if not specified - if artifactServer.PushUsername == "" { - artifactServer.PushUsername = config.ZarfGitPushUser - } - - return artifactServer -} diff --git a/src/test/e2e/22_git_and_gitops_test.go b/src/test/e2e/22_git_and_gitops_test.go index dd8b534736..ad0e5d0255 100644 --- a/src/test/e2e/22_git_and_gitops_test.go +++ b/src/test/e2e/22_git_and_gitops_test.go @@ -12,9 +12,9 @@ import ( "path/filepath" "testing" - "github.com/defenseunicorns/zarf/src/config" "github.com/defenseunicorns/zarf/src/internal/packager/git" "github.com/defenseunicorns/zarf/src/pkg/cluster" + "github.com/defenseunicorns/zarf/src/types" "github.com/stretchr/testify/require" ) @@ -77,7 +77,7 @@ func testGitServerReadOnly(t *testing.T, gitURL string) { // Get the repo as the readonly user repoName := "zarf-public-test-2469062884" getRepoRequest, _ := http.NewRequest("GET", fmt.Sprintf("%s/api/v1/repos/%s/%s", gitURL, state.GitServer.PushUsername, repoName), nil) - getRepoResponseBody, _, err := gitCfg.DoHTTPThings(getRepoRequest, config.ZarfGitReadUser, state.GitServer.PullPassword) + getRepoResponseBody, _, err := gitCfg.DoHTTPThings(getRepoRequest, types.ZarfGitReadUser, state.GitServer.PullPassword) require.NoError(t, err) // Make sure the only permissions are pull (read) @@ -100,8 +100,8 @@ func testGitServerTagAndHash(t *testing.T, gitURL string) { // Get the Zarf repo tag repoTag := "v0.0.1" - getRepoTagsRequest, _ := http.NewRequest("GET", fmt.Sprintf("%s/api/v1/repos/%s/%s/tags/%s", gitURL, config.ZarfGitPushUser, repoName, repoTag), nil) - getRepoTagsResponseBody, _, err := gitCfg.DoHTTPThings(getRepoTagsRequest, config.ZarfGitReadUser, state.GitServer.PullPassword) + getRepoTagsRequest, _ := http.NewRequest("GET", fmt.Sprintf("%s/api/v1/repos/%s/%s/tags/%s", gitURL, types.ZarfGitPushUser, repoName, repoTag), nil) + getRepoTagsResponseBody, _, err := gitCfg.DoHTTPThings(getRepoTagsRequest, types.ZarfGitReadUser, state.GitServer.PullPassword) require.NoError(t, err) // Make sure the pushed tag exists @@ -112,8 +112,8 @@ func testGitServerTagAndHash(t *testing.T, gitURL string) { // Get the Zarf repo commit repoHash := "01a23218923f24194133b5eb11268cf8d73ff1bb" - getRepoCommitsRequest, _ := http.NewRequest("GET", fmt.Sprintf("%s/api/v1/repos/%s/%s/git/commits/%s", gitURL, config.ZarfGitPushUser, repoName, repoHash), nil) - getRepoCommitsResponseBody, _, err := gitCfg.DoHTTPThings(getRepoCommitsRequest, config.ZarfGitReadUser, state.GitServer.PullPassword) + getRepoCommitsRequest, _ := http.NewRequest("GET", fmt.Sprintf("%s/api/v1/repos/%s/%s/git/commits/%s", gitURL, types.ZarfGitPushUser, repoName, repoHash), nil) + getRepoCommitsResponseBody, _, err := gitCfg.DoHTTPThings(getRepoCommitsRequest, types.ZarfGitReadUser, state.GitServer.PullPassword) require.NoError(t, err) require.Contains(t, string(getRepoCommitsResponseBody), repoHash) } @@ -127,7 +127,7 @@ func waitFluxPodInfoDeployment(t *testing.T) { // Tests the URL mutation for GitRepository CRD for Flux. stdOut, stdErr, err = e2e.Kubectl("get", "gitrepositories", "podinfo", "-n", "flux-system", "-o", "jsonpath={.spec.url}") require.NoError(t, err, stdOut, stdErr) - expectedMutatedRepoURL := fmt.Sprintf("%s/%s/podinfo-1646971829.git", config.ZarfInClusterGitServiceURL, config.ZarfGitPushUser) + expectedMutatedRepoURL := fmt.Sprintf("%s/%s/podinfo-1646971829.git", types.ZarfInClusterGitServiceURL, types.ZarfGitPushUser) require.Equal(t, expectedMutatedRepoURL, stdOut) // Remove the flux example when deployment completes @@ -145,7 +145,7 @@ func waitArgoDeployment(t *testing.T) { stdOut, stdErr, err := e2e.Zarf("package", "deploy", path, "--components=argocd-apps", "--confirm") require.NoError(t, err, stdOut, stdErr) - expectedMutatedRepoURL := fmt.Sprintf("%s/%s/podinfo-1646971829.git", config.ZarfInClusterGitServiceURL, config.ZarfGitPushUser) + expectedMutatedRepoURL := fmt.Sprintf("%s/%s/podinfo-1646971829.git", types.ZarfInClusterGitServiceURL, types.ZarfGitPushUser) // Tests the mutation of the private repository Secret for ArgoCD. stdOut, stdErr, err = e2e.Kubectl("get", "secret", "argocd-repo-github-podinfo", "-n", "argocd", "-o", "jsonpath={.data.url}") diff --git a/src/types/k8s.go b/src/types/k8s.go index b01cea1848..a79c0238e5 100644 --- a/src/types/k8s.go +++ b/src/types/k8s.go @@ -5,9 +5,12 @@ package types import ( + "fmt" "time" + "github.com/defenseunicorns/zarf/src/config/lang" "github.com/defenseunicorns/zarf/src/pkg/k8s" + "github.com/defenseunicorns/zarf/src/pkg/utils/helpers" ) // WebhookStatus defines the status of a Component Webhook operating on a Zarf package secret. @@ -32,6 +35,20 @@ const ( ComponentStatusRemoving ComponentStatus = "Removing" ) +// Values during setup of the initial zarf state +const ( + ZarfGeneratedPasswordLen = 24 + ZarfInClusterContainerRegistryNodePort = 31999 + ZarfRegistryPushUser = "zarf-push" + ZarfRegistryPullUser = "zarf-pull" + + ZarfGitPushUser = "zarf-git-user" + ZarfGitReadUser = "zarf-git-read-user" + + ZarfInClusterGitServiceURL = "http://zarf-gitea-http.zarf.svc.cluster.local:3000" + ZarfInClusterArtifactServiceURL = ZarfInClusterGitServiceURL + "/api/packages/" + ZarfGitPushUser +) + // ZarfState is maintained as a secret in the Zarf namespace to track Zarf init data. type ZarfState struct { ZarfAppliance bool `json:"zarfAppliance" jsonschema:"description=Indicates if Zarf was initialized while deploying its own k8s cluster"` @@ -91,6 +108,43 @@ type GitServerInfo struct { InternalServer bool `json:"internalServer" jsonschema:"description=Indicates if we are using a git server that Zarf is directly managing"` } +// FillInEmptyValues sets every necessary value that's currently empty to a reasonable default +func (gs GitServerInfo) FillInEmptyValues() (GitServerInfo, error) { + var err error + // Set default svc url if an external repository was not provided + if gs.Address == "" { + gs.Address = ZarfInClusterGitServiceURL + gs.InternalServer = true + } + + // Generate a push-user password if not provided by init flag + if gs.PushPassword == "" { + if gs.PushPassword, err = helpers.RandomString(ZarfGeneratedPasswordLen); err != nil { + return GitServerInfo{}, fmt.Errorf("%s: %w", lang.ErrUnableToGenerateRandomSecret, err) + } + } + + // Set read-user information if using an internal repository, otherwise copy from the push-user + if gs.PullUsername == "" { + if gs.InternalServer { + gs.PullUsername = ZarfGitReadUser + } else { + gs.PullUsername = gs.PushUsername + } + } + if gs.PullPassword == "" { + if gs.InternalServer { + if gs.PullPassword, err = helpers.RandomString(ZarfGeneratedPasswordLen); err != nil { + return GitServerInfo{}, fmt.Errorf("%s: %w", lang.ErrUnableToGenerateRandomSecret, err) + } + } else { + gs.PullPassword = gs.PushPassword + } + } + + return gs, nil +} + // ArtifactServerInfo contains information Zarf uses to communicate with a artifact registry to push/pull repositories to. type ArtifactServerInfo struct { PushUsername string `json:"pushUsername" jsonschema:"description=Username of a user with push access to the artifact registry"` @@ -100,6 +154,21 @@ type ArtifactServerInfo struct { InternalServer bool `json:"internalServer" jsonschema:"description=Indicates if we are using a artifact registry that Zarf is directly managing"` } +// FillInEmptyValues sets every necessary value that's currently empty to a reasonable default +func (as ArtifactServerInfo) FillInEmptyValues() ArtifactServerInfo { + // Set default svc url if an external registry was not provided + if as.Address == "" { + as.Address = ZarfInClusterArtifactServiceURL + as.InternalServer = true + } + + // Set the push username to the git push user if not specified + if as.PushUsername == "" { + as.PushUsername = ZarfGitPushUser + } + return as +} + // RegistryInfo contains information Zarf uses to communicate with a container registry to push/pull images. type RegistryInfo struct { PushUsername string `json:"pushUsername" jsonschema:"description=Username of a user with push access to the registry"` @@ -113,3 +182,53 @@ type RegistryInfo struct { Secret string `json:"secret" jsonschema:"description=Secret value that the registry was seeded with"` } + +// FillInEmptyValues sets every necessary value not already set to a reasonable default +func (ri RegistryInfo) FillInEmptyValues() (RegistryInfo, error) { + var err error + // Set default NodePort if none was provided + if ri.NodePort == 0 { + ri.NodePort = ZarfInClusterContainerRegistryNodePort + } + + // Set default url if an external registry was not provided + if ri.Address == "" { + ri.InternalRegistry = true + ri.Address = fmt.Sprintf("%s:%d", helpers.IPV4Localhost, ri.NodePort) + } + + // Generate a push-user password if not provided by init flag + if ri.PushPassword == "" { + if ri.PushPassword, err = helpers.RandomString(ZarfGeneratedPasswordLen); err != nil { + return RegistryInfo{}, fmt.Errorf("%s: %w", lang.ErrUnableToGenerateRandomSecret, err) + } + } + + // Set pull-username if not provided by init flag + if ri.PullUsername == "" { + if ri.InternalRegistry { + ri.PullUsername = ZarfRegistryPullUser + } else { + // If this is an external registry and a pull-user wasn't provided, use the same credentials as the push user + ri.PullUsername = ri.PushUsername + } + } + if ri.PullPassword == "" { + if ri.InternalRegistry { + if ri.PullPassword, err = helpers.RandomString(ZarfGeneratedPasswordLen); err != nil { + return RegistryInfo{}, fmt.Errorf("%s: %w", lang.ErrUnableToGenerateRandomSecret, err) + } + } else { + // If this is an external registry and a pull-user wasn't provided, use the same credentials as the push user + ri.PullPassword = ri.PushPassword + } + } + + if ri.Secret == "" { + if ri.Secret, err = helpers.RandomString(ZarfGeneratedPasswordLen); err != nil { + return RegistryInfo{}, fmt.Errorf("%s: %w", lang.ErrUnableToGenerateRandomSecret, err) + } + } + + return ri, nil +} From b1e7807643589e12de69c77e19397f0818e4c68e Mon Sep 17 00:00:00 2001 From: Austin Abro Date: Tue, 27 Feb 2024 14:47:51 +0000 Subject: [PATCH 42/68] fixing test, editing code to use new functions --- src/pkg/packager/prepare.go | 13 +++++-------- src/pkg/utils/helpers/random.go | 1 - src/test/e2e/00_use_cli_test.go | 4 ++-- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src/pkg/packager/prepare.go b/src/pkg/packager/prepare.go index d549f4749c..4590544305 100644 --- a/src/pkg/packager/prepare.go +++ b/src/pkg/packager/prepare.go @@ -129,14 +129,11 @@ func (p *Packager) FindImages() (imgMap map[string][]string, err error) { if err != nil { return nil, fmt.Errorf("unable to generate template values") } - - values.SetState(&types.ZarfState{ - RegistryInfo: types.RegistryInfo{ - Address: p.cfg.FindImagesOpts.RegistryURL, - // Adding a fake secret here so if a chart expects the registry secret, like the init package, it won't fail - Secret: "fake-zarf-secret", - }, - }) + registryInfo, err := types.RegistryInfo{Address: p.cfg.FindImagesOpts.RegistryURL}.FillInEmptyValues() + if err != nil { + return nil, fmt.Errorf("unable to set registry secret") + } + values.SetState(&types.ZarfState{RegistryInfo: registryInfo}) for _, chart := range component.Charts { helmCfg := helm.New( diff --git a/src/pkg/utils/helpers/random.go b/src/pkg/utils/helpers/random.go index 63e7bfa89c..d06700ad7f 100644 --- a/src/pkg/utils/helpers/random.go +++ b/src/pkg/utils/helpers/random.go @@ -17,7 +17,6 @@ func RandomString(length int) (string, error) { bytes := make([]byte, length) if _, err := rand.Read(bytes); err != nil { - //message.Fatal(err, "unable to generate a random secret") return "", err } diff --git a/src/test/e2e/00_use_cli_test.go b/src/test/e2e/00_use_cli_test.go index a03df87ca1..4e2a31a611 100644 --- a/src/test/e2e/00_use_cli_test.go +++ b/src/test/e2e/00_use_cli_test.go @@ -254,8 +254,8 @@ func TestUseCLI(t *testing.T) { require.Contains(t, stdOut, internalRegistryImage, "registry image should be found with registry url") require.Contains(t, stdOut, "busybox:latest", "Busybox image should be found as long as helm chart doesn't error") - path := filepath.Join("examples", "manifests") - stdOut, _, err = e2e.Zarf("prepare", "find-images", path, "--deploy-set", "redis_enabled=false") + path := filepath.Join("examples", "helm-charts") + stdOut, _, err = e2e.Zarf("prepare", "find-images", path, "--deploy-set", "redis_enabled=true") require.NoError(t, err) require.Contains(t, stdOut, "redis:7.0.7", "Should contain the templated image from manifests") }) From 3ec5504512f11d2eb3eb743fd06648bccc1595de Mon Sep 17 00:00:00 2001 From: Austin Abro Date: Tue, 27 Feb 2024 15:02:53 +0000 Subject: [PATCH 43/68] allowing more builtins to be there by default --- src/pkg/packager/prepare.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/pkg/packager/prepare.go b/src/pkg/packager/prepare.go index 4590544305..9cee33e914 100644 --- a/src/pkg/packager/prepare.go +++ b/src/pkg/packager/prepare.go @@ -131,9 +131,17 @@ func (p *Packager) FindImages() (imgMap map[string][]string, err error) { } registryInfo, err := types.RegistryInfo{Address: p.cfg.FindImagesOpts.RegistryURL}.FillInEmptyValues() if err != nil { - return nil, fmt.Errorf("unable to set registry secret") + return nil, err + } + gitServer, err := types.GitServerInfo{}.FillInEmptyValues() + if err != nil { + return nil, err } - values.SetState(&types.ZarfState{RegistryInfo: registryInfo}) + artifactServer := types.ArtifactServerInfo{}.FillInEmptyValues() + values.SetState(&types.ZarfState{ + RegistryInfo: registryInfo, + GitServer: gitServer, + ArtifactServer: artifactServer}) for _, chart := range component.Charts { helmCfg := helm.New( From 202d35134166f470efc8ab3b3298d85c92ba18f3 Mon Sep 17 00:00:00 2001 From: Austin Abro Date: Tue, 27 Feb 2024 15:18:38 +0000 Subject: [PATCH 44/68] format --- examples/manifests/httpd-deployment.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/manifests/httpd-deployment.yaml b/examples/manifests/httpd-deployment.yaml index c9b327a9f4..8465e727f3 100644 --- a/examples/manifests/httpd-deployment.yaml +++ b/examples/manifests/httpd-deployment.yaml @@ -16,4 +16,4 @@ spec: - name: httpd image: httpd:alpine3.18 ports: - - containerPort: 80 + - containerPort: 80 From 28be0b83e41f6347147888dbbc7bf00e6bcd2c81 Mon Sep 17 00:00:00 2001 From: Austin Abro Date: Tue, 27 Feb 2024 15:23:11 +0000 Subject: [PATCH 45/68] comment --- src/pkg/packager/prepare.go | 1 + 1 file changed, 1 insertion(+) diff --git a/src/pkg/packager/prepare.go b/src/pkg/packager/prepare.go index 9cee33e914..9404153a59 100644 --- a/src/pkg/packager/prepare.go +++ b/src/pkg/packager/prepare.go @@ -129,6 +129,7 @@ func (p *Packager) FindImages() (imgMap map[string][]string, err error) { if err != nil { return nil, fmt.Errorf("unable to generate template values") } + // Adding these so the default builtin values exist in case any helm charts rely on them registryInfo, err := types.RegistryInfo{Address: p.cfg.FindImagesOpts.RegistryURL}.FillInEmptyValues() if err != nil { return nil, err From c8180a81f97e0c369312e70f42a244b4bd2648af Mon Sep 17 00:00:00 2001 From: Austin Abro Date: Tue, 27 Feb 2024 21:50:46 +0000 Subject: [PATCH 46/68] switching registry secret length back --- src/types/k8s.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/types/k8s.go b/src/types/k8s.go index a79c0238e5..20d0752ae3 100644 --- a/src/types/k8s.go +++ b/src/types/k8s.go @@ -38,6 +38,7 @@ const ( // Values during setup of the initial zarf state const ( ZarfGeneratedPasswordLen = 24 + ZarfGeneratedSecretLen = 48 ZarfInClusterContainerRegistryNodePort = 31999 ZarfRegistryPushUser = "zarf-push" ZarfRegistryPullUser = "zarf-pull" @@ -225,7 +226,7 @@ func (ri RegistryInfo) FillInEmptyValues() (RegistryInfo, error) { } if ri.Secret == "" { - if ri.Secret, err = helpers.RandomString(ZarfGeneratedPasswordLen); err != nil { + if ri.Secret, err = helpers.RandomString(ZarfGeneratedSecretLen); err != nil { return RegistryInfo{}, fmt.Errorf("%s: %w", lang.ErrUnableToGenerateRandomSecret, err) } } From aa24dc9b267bcaa230b6d05bb62e4cc8b7e3a72d Mon Sep 17 00:00:00 2001 From: Austin Abro Date: Mon, 4 Mar 2024 13:56:59 +0000 Subject: [PATCH 47/68] removing registry from struct --- src/internal/packager/helm/chart.go | 4 ---- src/internal/packager/template/template.go | 8 -------- 2 files changed, 12 deletions(-) diff --git a/src/internal/packager/helm/chart.go b/src/internal/packager/helm/chart.go index 7934811974..d8ffd3414b 100644 --- a/src/internal/packager/helm/chart.go +++ b/src/internal/packager/helm/chart.go @@ -303,10 +303,6 @@ func (h *Helm) installChart(postRender *renderer) (*release.Release, error) { } func (h *Helm) upgradeChart(lastRelease *release.Release, postRender *renderer) (*release.Release, error) { - // Print the postRender object piece by piece to not print the htpasswd - message.Debugf("helm.upgradeChart(%#v, %#v, %#v, %#v, %s)", postRender.actionConfig, postRender.connectStrings, - postRender.namespaces, postRender.Helm, fmt.Sprintf("values:template.Values{ registry: \"%s\" }", postRender.values.GetRegistry())) - // Migrate any deprecated APIs (if applicable) err := h.migrateDeprecatedAPIs(lastRelease) if err != nil { diff --git a/src/internal/packager/template/template.go b/src/internal/packager/template/template.go index 834e1a739c..75882e6bdf 100644 --- a/src/internal/packager/template/template.go +++ b/src/internal/packager/template/template.go @@ -20,7 +20,6 @@ import ( // Values contains the values to be used in the template. type Values struct { config *types.PackagerConfig - registry string htpasswd string } @@ -56,8 +55,6 @@ func Generate(cfg *types.PackagerConfig) (*Values, error) { generated.htpasswd = fmt.Sprintf("%s\\n%s", pushUser, pullUser) } - generated.registry = regInfo.Address - return &generated, nil } @@ -66,11 +63,6 @@ func (values *Values) Ready() bool { return values.config.State != nil } -// GetRegistry returns the registry address. -func (values *Values) GetRegistry() string { - return values.registry -} - // SetState sets the state func (values *Values) SetState(state *types.ZarfState) { values.config.State = state From 9a623c916c7c9a40ac0180ccc7d622555978bb20 Mon Sep 17 00:00:00 2001 From: Austin Abro Date: Mon, 4 Mar 2024 19:28:12 +0000 Subject: [PATCH 48/68] using smaller redis image --- .../chart/templates/redis/config.yaml | 12 ++++ .../chart/templates/redis/deployment.yaml | 68 +++++++++++++++++++ .../chart/templates/redis/service.yaml | 17 +++++ examples/helm-charts/values.yaml | 2 + examples/helm-charts/zarf.yaml | 2 +- src/test/e2e/00_use_cli_test.go | 2 +- 6 files changed, 101 insertions(+), 2 deletions(-) create mode 100644 examples/helm-charts/chart/templates/redis/config.yaml create mode 100644 examples/helm-charts/chart/templates/redis/deployment.yaml create mode 100644 examples/helm-charts/chart/templates/redis/service.yaml diff --git a/examples/helm-charts/chart/templates/redis/config.yaml b/examples/helm-charts/chart/templates/redis/config.yaml new file mode 100644 index 0000000000..cd63785c83 --- /dev/null +++ b/examples/helm-charts/chart/templates/redis/config.yaml @@ -0,0 +1,12 @@ +{{- if .Values.redis.enabled -}} +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ template "podinfo.fullname" . }}-redis +data: + redis.conf: | + maxmemory 64mb + maxmemory-policy allkeys-lru + save "" + appendonly no +{{- end }} diff --git a/examples/helm-charts/chart/templates/redis/deployment.yaml b/examples/helm-charts/chart/templates/redis/deployment.yaml new file mode 100644 index 0000000000..78888555a8 --- /dev/null +++ b/examples/helm-charts/chart/templates/redis/deployment.yaml @@ -0,0 +1,68 @@ +{{- if .Values.redis.enabled -}} +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ template "podinfo.fullname" . }}-redis + labels: + app: {{ template "podinfo.fullname" . }}-redis +spec: + strategy: + type: Recreate + selector: + matchLabels: + app: {{ template "podinfo.fullname" . }}-redis + template: + metadata: + labels: + app: {{ template "podinfo.fullname" . }}-redis + annotations: + checksum/config: {{ include (print $.Template.BasePath "/redis/config.yaml") . | sha256sum | quote }} + spec: + {{- if .Values.serviceAccount.enabled }} + serviceAccountName: {{ template "podinfo.serviceAccountName" . }} + {{- end }} + containers: + - name: redis + image: "{{ .Values.redis.repository }}:{{ .Values.redis.tag }}" + imagePullPolicy: IfNotPresent + command: + - redis-server + - "/redis-master/redis.conf" + ports: + - name: redis + containerPort: 6379 + protocol: TCP + livenessProbe: + tcpSocket: + port: redis + initialDelaySeconds: 5 + timeoutSeconds: 5 + readinessProbe: + exec: + command: + - redis-cli + - ping + initialDelaySeconds: 5 + timeoutSeconds: 5 + resources: + limits: + cpu: 1000m + memory: 128Mi + requests: + cpu: 100m + memory: 32Mi + volumeMounts: + - mountPath: /var/lib/redis + name: data + - mountPath: /redis-master + name: config + volumes: + - name: data + emptyDir: {} + - name: config + configMap: + name: {{ template "podinfo.fullname" . }}-redis + items: + - key: redis.conf + path: redis.conf +{{- end }} diff --git a/examples/helm-charts/chart/templates/redis/service.yaml b/examples/helm-charts/chart/templates/redis/service.yaml new file mode 100644 index 0000000000..e2068514c3 --- /dev/null +++ b/examples/helm-charts/chart/templates/redis/service.yaml @@ -0,0 +1,17 @@ +{{- if .Values.redis.enabled -}} +apiVersion: v1 +kind: Service +metadata: + name: {{ template "podinfo.fullname" . }}-redis + labels: + app: {{ template "podinfo.fullname" . }}-redis +spec: + type: ClusterIP + selector: + app: {{ template "podinfo.fullname" . }}-redis + ports: + - name: redis + port: 6379 + protocol: TCP + targetPort: redis +{{- end }} diff --git a/examples/helm-charts/values.yaml b/examples/helm-charts/values.yaml index b9cd41c3ba..61ef40f742 100644 --- a/examples/helm-charts/values.yaml +++ b/examples/helm-charts/values.yaml @@ -1,5 +1,7 @@ redis: enabled: ###ZARF_VAR_REDIS_ENABLED### + repository: docker.io/library/redis + tag: 7.0.15-alpine ui: color: "#0d133d" diff --git a/examples/helm-charts/zarf.yaml b/examples/helm-charts/zarf.yaml index 0d2895ee7a..e83a6d6ffe 100644 --- a/examples/helm-charts/zarf.yaml +++ b/examples/helm-charts/zarf.yaml @@ -54,7 +54,7 @@ components: - ghcr.io/stefanprodan/podinfo:6.4.0 # This is the cosign signature for the podinfo image for image signature verification - ghcr.io/stefanprodan/podinfo:sha256-57a654ace69ec02ba8973093b6a786faa15640575fbf0dbb603db55aca2ccec8.sig - - docker.io/redis:7.0.7 + - docker.io/library/redis:7.0.15-alpine actions: onDeploy: after: diff --git a/src/test/e2e/00_use_cli_test.go b/src/test/e2e/00_use_cli_test.go index 4e2a31a611..0ba581d8cb 100644 --- a/src/test/e2e/00_use_cli_test.go +++ b/src/test/e2e/00_use_cli_test.go @@ -257,6 +257,6 @@ func TestUseCLI(t *testing.T) { path := filepath.Join("examples", "helm-charts") stdOut, _, err = e2e.Zarf("prepare", "find-images", path, "--deploy-set", "redis_enabled=true") require.NoError(t, err) - require.Contains(t, stdOut, "redis:7.0.7", "Should contain the templated image from manifests") + require.Contains(t, stdOut, "docker.io/library/redis:7.0.15-alpine", "Should contain the templated image from manifests") }) } From 9b874a635a8010dc46d4541a9e823d432d56d8cf Mon Sep 17 00:00:00 2001 From: Austin Abro Date: Tue, 5 Mar 2024 14:21:40 +0000 Subject: [PATCH 49/68] clearing up error messaging --- src/config/lang/english.go | 5 ----- src/pkg/packager/deploy.go | 2 +- src/pkg/packager/dev.go | 3 +-- src/pkg/packager/prepare.go | 2 +- src/pkg/packager/variables.go | 2 +- 5 files changed, 4 insertions(+), 10 deletions(-) diff --git a/src/config/lang/english.go b/src/config/lang/english.go index a3a0ef5b32..7b7e3223ab 100644 --- a/src/config/lang/english.go +++ b/src/config/lang/english.go @@ -626,11 +626,6 @@ const ( AgentErrUnableTransform = "unable to transform the provided request; see zarf http proxy logs for more details" ) -// src/internal/packager -const ( - PkgErrSetVariableMap = "unable to set the active variables: %w" -) - // src/internal/packager/create const ( PkgCreateErrDifferentialSameVersion = "unable to create a differential package with the same version as the package you are using as a reference; the package version must be incremented" diff --git a/src/pkg/packager/deploy.go b/src/pkg/packager/deploy.go index af441b2441..c5047074a4 100644 --- a/src/pkg/packager/deploy.go +++ b/src/pkg/packager/deploy.go @@ -63,7 +63,7 @@ func (p *Packager) Deploy() (err error) { // Set variables and prompt if --confirm is not set if err := p.setVariableMapInConfig(); err != nil { - return fmt.Errorf(lang.PkgErrSetVariableMap, err) + return err } p.hpaModified = false diff --git a/src/pkg/packager/dev.go b/src/pkg/packager/dev.go index a8acd07667..675ee540ee 100644 --- a/src/pkg/packager/dev.go +++ b/src/pkg/packager/dev.go @@ -9,7 +9,6 @@ import ( "os" "github.com/defenseunicorns/zarf/src/config" - "github.com/defenseunicorns/zarf/src/config/lang" "github.com/defenseunicorns/zarf/src/internal/packager/validate" "github.com/defenseunicorns/zarf/src/pkg/message" "github.com/defenseunicorns/zarf/src/types" @@ -63,7 +62,7 @@ func (p *Packager) DevDeploy() error { // Set variables and prompt if --confirm is not set if err := p.setVariableMapInConfig(); err != nil { - return fmt.Errorf(lang.PkgErrSetVariableMap, err) + return err } p.connectStrings = make(types.ConnectStrings) diff --git a/src/pkg/packager/prepare.go b/src/pkg/packager/prepare.go index 9404153a59..8c1199ae4b 100644 --- a/src/pkg/packager/prepare.go +++ b/src/pkg/packager/prepare.go @@ -82,7 +82,7 @@ func (p *Packager) FindImages() (imgMap map[string][]string, err error) { componentDefinition := "\ncomponents:\n" if err := p.setVariableMapInConfig(); err != nil { - return nil, fmt.Errorf(lang.PkgErrSetVariableMap, err) + return nil, err } for _, component := range p.cfg.Pkg.Components { diff --git a/src/pkg/packager/variables.go b/src/pkg/packager/variables.go index fb3e20f6d3..8e3ddb8df9 100644 --- a/src/pkg/packager/variables.go +++ b/src/pkg/packager/variables.go @@ -126,7 +126,7 @@ func (p *Packager) setVariableMapInConfig() error { val, err := interactive.PromptVariable(variable) if err != nil { - return err + return fmt.Errorf("unable to get variable from prompt: %w", err) } p.setVariableInConfig(variable.Name, val, variable.Sensitive, variable.AutoIndent, variable.Type) From 11c5c16831b6db86a9e46245ded5df8345daba3b Mon Sep 17 00:00:00 2001 From: Austin Abro Date: Tue, 5 Mar 2024 14:26:30 +0000 Subject: [PATCH 50/68] add err message --- src/pkg/packager/prepare.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/pkg/packager/prepare.go b/src/pkg/packager/prepare.go index 8c1199ae4b..1b7216a7c9 100644 --- a/src/pkg/packager/prepare.go +++ b/src/pkg/packager/prepare.go @@ -212,7 +212,9 @@ func (p *Packager) FindImages() (imgMap map[string][]string, err error) { } else { filename := filepath.Base(f) newDestination := filepath.Join(componentPaths.Manifests, filename) - utils.CreatePathAndCopy(f, newDestination) + if err := utils.CreatePathAndCopy(f, newDestination); err != nil { + return nil, fmt.Errorf("unable to copy manifest %s: %w", f, err) + } f = newDestination } From e8322a922b8aecb082223c7d1cf0c96fcf8fa12f Mon Sep 17 00:00:00 2001 From: Austin Abro Date: Tue, 5 Mar 2024 14:27:56 +0000 Subject: [PATCH 51/68] message --- src/pkg/packager/variables.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pkg/packager/variables.go b/src/pkg/packager/variables.go index 8e3ddb8df9..53f4e05df3 100644 --- a/src/pkg/packager/variables.go +++ b/src/pkg/packager/variables.go @@ -126,7 +126,7 @@ func (p *Packager) setVariableMapInConfig() error { val, err := interactive.PromptVariable(variable) if err != nil { - return fmt.Errorf("unable to get variable from prompt: %w", err) + return fmt.Errorf("unable to get value from prompt: %w", err) } p.setVariableInConfig(variable.Name, val, variable.Sensitive, variable.AutoIndent, variable.Type) From 1aec808d62dc68334e1f499ecaaa6765a487b1b3 Mon Sep 17 00:00:00 2001 From: Austin Abro Date: Tue, 5 Mar 2024 14:55:51 +0000 Subject: [PATCH 52/68] refactor to pointer recievers to set default for types --- src/pkg/cluster/state.go | 9 ++++++--- src/pkg/packager/prepare.go | 9 ++++++--- src/types/k8s.go | 21 ++++++++++----------- 3 files changed, 22 insertions(+), 17 deletions(-) diff --git a/src/pkg/cluster/state.go b/src/pkg/cluster/state.go index 4de12ef94c..d9f7aee483 100644 --- a/src/pkg/cluster/state.go +++ b/src/pkg/cluster/state.go @@ -113,15 +113,18 @@ func (c *Cluster) InitZarfState(initOptions types.ZarfInitOptions) error { return fmt.Errorf("unable get default Zarf service account: %w", err) } - state.GitServer, err = initOptions.GitServer.FillInEmptyValues() + err = initOptions.GitServer.FillInEmptyValues() if err != nil { return err } - state.RegistryInfo, err = initOptions.RegistryInfo.FillInEmptyValues() + state.GitServer = initOptions.GitServer + err = initOptions.RegistryInfo.FillInEmptyValues() if err != nil { return err } - state.ArtifactServer = initOptions.ArtifactServer.FillInEmptyValues() + state.RegistryInfo = initOptions.RegistryInfo + initOptions.ArtifactServer.FillInEmptyValues() + state.ArtifactServer = initOptions.ArtifactServer } else { if helpers.IsNotZeroAndNotEqual(initOptions.GitServer, state.GitServer) { message.Warn("Detected a change in Git Server init options on a re-init. Ignoring... To update run:") diff --git a/src/pkg/packager/prepare.go b/src/pkg/packager/prepare.go index 1b7216a7c9..5e49d98de1 100644 --- a/src/pkg/packager/prepare.go +++ b/src/pkg/packager/prepare.go @@ -130,15 +130,18 @@ func (p *Packager) FindImages() (imgMap map[string][]string, err error) { return nil, fmt.Errorf("unable to generate template values") } // Adding these so the default builtin values exist in case any helm charts rely on them - registryInfo, err := types.RegistryInfo{Address: p.cfg.FindImagesOpts.RegistryURL}.FillInEmptyValues() + registryInfo := types.RegistryInfo{Address: p.cfg.FindImagesOpts.RegistryURL} + err = registryInfo.FillInEmptyValues() if err != nil { return nil, err } - gitServer, err := types.GitServerInfo{}.FillInEmptyValues() + gitServer := types.GitServerInfo{} + err = gitServer.FillInEmptyValues() if err != nil { return nil, err } - artifactServer := types.ArtifactServerInfo{}.FillInEmptyValues() + artifactServer := types.ArtifactServerInfo{} + artifactServer.FillInEmptyValues() values.SetState(&types.ZarfState{ RegistryInfo: registryInfo, GitServer: gitServer, diff --git a/src/types/k8s.go b/src/types/k8s.go index 20d0752ae3..b34b10a211 100644 --- a/src/types/k8s.go +++ b/src/types/k8s.go @@ -110,7 +110,7 @@ type GitServerInfo struct { } // FillInEmptyValues sets every necessary value that's currently empty to a reasonable default -func (gs GitServerInfo) FillInEmptyValues() (GitServerInfo, error) { +func (gs *GitServerInfo) FillInEmptyValues() error { var err error // Set default svc url if an external repository was not provided if gs.Address == "" { @@ -121,7 +121,7 @@ func (gs GitServerInfo) FillInEmptyValues() (GitServerInfo, error) { // Generate a push-user password if not provided by init flag if gs.PushPassword == "" { if gs.PushPassword, err = helpers.RandomString(ZarfGeneratedPasswordLen); err != nil { - return GitServerInfo{}, fmt.Errorf("%s: %w", lang.ErrUnableToGenerateRandomSecret, err) + return fmt.Errorf("%s: %w", lang.ErrUnableToGenerateRandomSecret, err) } } @@ -136,14 +136,14 @@ func (gs GitServerInfo) FillInEmptyValues() (GitServerInfo, error) { if gs.PullPassword == "" { if gs.InternalServer { if gs.PullPassword, err = helpers.RandomString(ZarfGeneratedPasswordLen); err != nil { - return GitServerInfo{}, fmt.Errorf("%s: %w", lang.ErrUnableToGenerateRandomSecret, err) + return fmt.Errorf("%s: %w", lang.ErrUnableToGenerateRandomSecret, err) } } else { gs.PullPassword = gs.PushPassword } } - return gs, nil + return nil } // ArtifactServerInfo contains information Zarf uses to communicate with a artifact registry to push/pull repositories to. @@ -156,7 +156,7 @@ type ArtifactServerInfo struct { } // FillInEmptyValues sets every necessary value that's currently empty to a reasonable default -func (as ArtifactServerInfo) FillInEmptyValues() ArtifactServerInfo { +func (as *ArtifactServerInfo) FillInEmptyValues() { // Set default svc url if an external registry was not provided if as.Address == "" { as.Address = ZarfInClusterArtifactServiceURL @@ -167,7 +167,6 @@ func (as ArtifactServerInfo) FillInEmptyValues() ArtifactServerInfo { if as.PushUsername == "" { as.PushUsername = ZarfGitPushUser } - return as } // RegistryInfo contains information Zarf uses to communicate with a container registry to push/pull images. @@ -185,7 +184,7 @@ type RegistryInfo struct { } // FillInEmptyValues sets every necessary value not already set to a reasonable default -func (ri RegistryInfo) FillInEmptyValues() (RegistryInfo, error) { +func (ri *RegistryInfo) FillInEmptyValues() error { var err error // Set default NodePort if none was provided if ri.NodePort == 0 { @@ -201,7 +200,7 @@ func (ri RegistryInfo) FillInEmptyValues() (RegistryInfo, error) { // Generate a push-user password if not provided by init flag if ri.PushPassword == "" { if ri.PushPassword, err = helpers.RandomString(ZarfGeneratedPasswordLen); err != nil { - return RegistryInfo{}, fmt.Errorf("%s: %w", lang.ErrUnableToGenerateRandomSecret, err) + return fmt.Errorf("%s: %w", lang.ErrUnableToGenerateRandomSecret, err) } } @@ -217,7 +216,7 @@ func (ri RegistryInfo) FillInEmptyValues() (RegistryInfo, error) { if ri.PullPassword == "" { if ri.InternalRegistry { if ri.PullPassword, err = helpers.RandomString(ZarfGeneratedPasswordLen); err != nil { - return RegistryInfo{}, fmt.Errorf("%s: %w", lang.ErrUnableToGenerateRandomSecret, err) + return fmt.Errorf("%s: %w", lang.ErrUnableToGenerateRandomSecret, err) } } else { // If this is an external registry and a pull-user wasn't provided, use the same credentials as the push user @@ -227,9 +226,9 @@ func (ri RegistryInfo) FillInEmptyValues() (RegistryInfo, error) { if ri.Secret == "" { if ri.Secret, err = helpers.RandomString(ZarfGeneratedSecretLen); err != nil { - return RegistryInfo{}, fmt.Errorf("%s: %w", lang.ErrUnableToGenerateRandomSecret, err) + return fmt.Errorf("%s: %w", lang.ErrUnableToGenerateRandomSecret, err) } } - return ri, nil + return nil } From 9a93268caa89d2b4623cfd355661df6db588b17a Mon Sep 17 00:00:00 2001 From: Austin Abro Date: Tue, 5 Mar 2024 17:15:41 +0000 Subject: [PATCH 53/68] changing tests to point to test package over examples --- src/test/e2e/00_use_cli_test.go | 8 +++-- .../00-find-images-with-vars/deployment.yaml | 19 +++++++++++ .../simple-helm/Chart.yaml | 6 ++++ .../simple-helm/templates/deployment.yaml | 19 +++++++++++ .../00-find-images-with-vars/values.yaml | 1 + .../00-find-images-with-vars/zarf.yaml | 33 +++++++++++++++++++ 6 files changed, 83 insertions(+), 3 deletions(-) create mode 100644 src/test/packages/00-find-images-with-vars/deployment.yaml create mode 100644 src/test/packages/00-find-images-with-vars/simple-helm/Chart.yaml create mode 100644 src/test/packages/00-find-images-with-vars/simple-helm/templates/deployment.yaml create mode 100644 src/test/packages/00-find-images-with-vars/values.yaml create mode 100644 src/test/packages/00-find-images-with-vars/zarf.yaml diff --git a/src/test/e2e/00_use_cli_test.go b/src/test/e2e/00_use_cli_test.go index dbe1be2fcb..b776c8b55b 100644 --- a/src/test/e2e/00_use_cli_test.go +++ b/src/test/e2e/00_use_cli_test.go @@ -255,9 +255,11 @@ func TestUseCLI(t *testing.T) { require.Contains(t, stdOut, internalRegistryImage, "registry image should be found with registry url") require.Contains(t, stdOut, "busybox:latest", "Busybox image should be found as long as helm chart doesn't error") - path := filepath.Join("examples", "helm-charts") - stdOut, _, err = e2e.Zarf("prepare", "find-images", path, "--deploy-set", "redis_enabled=true") + path := filepath.Join("src", "test", "packages", "00-find-images-with-vars") + stdOut, _, err = e2e.Zarf("prepare", "find-images", path, "--deploy-set", "BUSYBOX_IMAGE=busybox:earliest") require.NoError(t, err) - require.Contains(t, stdOut, "docker.io/library/redis:7.0.15-alpine", "Should contain the templated image from manifests") + + require.Contains(t, stdOut, "nginx:latest", "Manifests aren't interpreting vars") + require.Contains(t, stdOut, "busybox:earliest", "Values files aren't interpreting vars") }) } diff --git a/src/test/packages/00-find-images-with-vars/deployment.yaml b/src/test/packages/00-find-images-with-vars/deployment.yaml new file mode 100644 index 0000000000..afb315bc21 --- /dev/null +++ b/src/test/packages/00-find-images-with-vars/deployment.yaml @@ -0,0 +1,19 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: simple-deployment + labels: + app: simple-deployment +spec: + replicas: 1 + selector: + matchLabels: + app: simple-deployment + template: + metadata: + labels: + app: simple-deployment + spec: + containers: + - name: server + image: "###ZARF_CONST_SAMPLE_IMAGE###:###ZARF_CONST_SAMPLE_TAG###" diff --git a/src/test/packages/00-find-images-with-vars/simple-helm/Chart.yaml b/src/test/packages/00-find-images-with-vars/simple-helm/Chart.yaml new file mode 100644 index 0000000000..2c128bf819 --- /dev/null +++ b/src/test/packages/00-find-images-with-vars/simple-helm/Chart.yaml @@ -0,0 +1,6 @@ +apiVersion: v2 +name: simple-helm +description: A Helm chart for Kubernetes +type: application +version: 0.1.0 +appVersion: "0.0.1" diff --git a/src/test/packages/00-find-images-with-vars/simple-helm/templates/deployment.yaml b/src/test/packages/00-find-images-with-vars/simple-helm/templates/deployment.yaml new file mode 100644 index 0000000000..335cb8afbb --- /dev/null +++ b/src/test/packages/00-find-images-with-vars/simple-helm/templates/deployment.yaml @@ -0,0 +1,19 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: simple-deployment + labels: + app: simple-deployment +spec: + replicas: 1 + selector: + matchLabels: + app: simple-deployment + template: + metadata: + labels: + app: simple-deployment + spec: + containers: + - name: busybox + image: {{.Values.busybox}} diff --git a/src/test/packages/00-find-images-with-vars/values.yaml b/src/test/packages/00-find-images-with-vars/values.yaml new file mode 100644 index 0000000000..da10dacc6b --- /dev/null +++ b/src/test/packages/00-find-images-with-vars/values.yaml @@ -0,0 +1 @@ +busybox: ###ZARF_VAR_BUSYBOX_IMAGE### diff --git a/src/test/packages/00-find-images-with-vars/zarf.yaml b/src/test/packages/00-find-images-with-vars/zarf.yaml new file mode 100644 index 0000000000..7f6a8e28a8 --- /dev/null +++ b/src/test/packages/00-find-images-with-vars/zarf.yaml @@ -0,0 +1,33 @@ +kind: ZarfPackageConfig +metadata: + name: find-image-with-variables + description: Simple zarf package with variables + +variables: + - name: BUSYBOX_IMAGE + default: "busybox:latest" + +constants: + - name: SAMPLE_IMAGE + value: "nginx" + - name: SAMPLE_TAG + value: "latest" + +components: +- name: simple-var + required: true + manifests: + - name: simple-deployment + namespace: zarf + files: + - deployment.yaml +- name: chart-with-var + required: true + charts: + - name: simple + releaseName: simple + localPath: simple-helm + namespace: zarf-simple + version: 0.1.0 + valuesFiles: + - values.yaml From cf326af41817b91e72da1504f288b302bdbcab3a Mon Sep 17 00:00:00 2001 From: Austin Abro Date: Tue, 5 Mar 2024 17:17:03 +0000 Subject: [PATCH 54/68] reverting chart --- examples/helm-charts/values.yaml | 5 ----- examples/helm-charts/zarf.yaml | 5 ----- 2 files changed, 10 deletions(-) diff --git a/examples/helm-charts/values.yaml b/examples/helm-charts/values.yaml index 61ef40f742..f86a45afe7 100644 --- a/examples/helm-charts/values.yaml +++ b/examples/helm-charts/values.yaml @@ -1,8 +1,3 @@ -redis: - enabled: ###ZARF_VAR_REDIS_ENABLED### - repository: docker.io/library/redis - tag: 7.0.15-alpine - ui: color: "#0d133d" message: "greetings from podinfo (as deployed by Zarf)" diff --git a/examples/helm-charts/zarf.yaml b/examples/helm-charts/zarf.yaml index e83a6d6ffe..d6481b334d 100644 --- a/examples/helm-charts/zarf.yaml +++ b/examples/helm-charts/zarf.yaml @@ -4,10 +4,6 @@ metadata: description: Example showcasing multiple ways to deploy helm charts version: 0.0.1 -variables: - - name: REDIS_ENABLED - default: "false" - components: - name: demo-helm-charts required: true @@ -54,7 +50,6 @@ components: - ghcr.io/stefanprodan/podinfo:6.4.0 # This is the cosign signature for the podinfo image for image signature verification - ghcr.io/stefanprodan/podinfo:sha256-57a654ace69ec02ba8973093b6a786faa15640575fbf0dbb603db55aca2ccec8.sig - - docker.io/library/redis:7.0.15-alpine actions: onDeploy: after: From d4c032d1e5e0ce315094d96eadd250929c0d68a6 Mon Sep 17 00:00:00 2001 From: Austin Abro Date: Tue, 5 Mar 2024 17:21:22 +0000 Subject: [PATCH 55/68] simplify deployment --- src/test/packages/00-find-images-with-vars/deployment.yaml | 2 +- src/test/packages/00-find-images-with-vars/zarf.yaml | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/test/packages/00-find-images-with-vars/deployment.yaml b/src/test/packages/00-find-images-with-vars/deployment.yaml index afb315bc21..8d4b344dae 100644 --- a/src/test/packages/00-find-images-with-vars/deployment.yaml +++ b/src/test/packages/00-find-images-with-vars/deployment.yaml @@ -16,4 +16,4 @@ spec: spec: containers: - name: server - image: "###ZARF_CONST_SAMPLE_IMAGE###:###ZARF_CONST_SAMPLE_TAG###" + image: "###ZARF_CONST_SAMPLE_IMAGE###" diff --git a/src/test/packages/00-find-images-with-vars/zarf.yaml b/src/test/packages/00-find-images-with-vars/zarf.yaml index 7f6a8e28a8..b58911d993 100644 --- a/src/test/packages/00-find-images-with-vars/zarf.yaml +++ b/src/test/packages/00-find-images-with-vars/zarf.yaml @@ -9,9 +9,7 @@ variables: constants: - name: SAMPLE_IMAGE - value: "nginx" - - name: SAMPLE_TAG - value: "latest" + value: "nginx:latest" components: - name: simple-var From 36e286995fdc778977d06fea2fdc1b4c3f8eedc6 Mon Sep 17 00:00:00 2001 From: Austin Abro Date: Tue, 5 Mar 2024 17:31:27 +0000 Subject: [PATCH 56/68] fix flake (hopefully) --- src/test/common.go | 16 +++++++--------- src/test/e2e/25_helm_test.go | 2 +- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/test/common.go b/src/test/common.go index 99fe96614c..03a164e409 100644 --- a/src/test/common.go +++ b/src/test/common.go @@ -8,6 +8,7 @@ import ( "bufio" "context" "fmt" + "math/rand" "os" "path/filepath" "regexp" @@ -72,15 +73,12 @@ func (e2e *ZarfE2ETest) Zarf(args ...string) (string, string, error) { defer os.RemoveAll(tmpdir) args = append(args, "--tmpdir", tmpdir) } - if !slices.Contains(args, "--zarf-cache") && !slices.Contains(args, "tools") { - if os.Getenv("CI") == "true" { - // We make the cache dir relative to the working directory to make it work on the Windows Runners - // - they use two drives which filepath.Rel cannot cope with. - relCacheDir, _ := filepath.Abs(".cache-location") - args = append(args, "--zarf-cache", relCacheDir) - defer os.RemoveAll(relCacheDir) - } - + if !slices.Contains(args, "--zarf-cache") && !slices.Contains(args, "tools") && os.Getenv("CI") == "true" { + // We make the cache dir relative to the working directory to make it work on the Windows Runners + // - they use two drives which filepath.Rel cannot cope with. + relCacheDir, _ := filepath.Abs(fmt.Sprintf(".%d-cache-location", rand.Intn(10000000))) + args = append(args, "--zarf-cache", relCacheDir) + defer os.RemoveAll(relCacheDir) } return exec.CmdWithContext(context.TODO(), exec.PrintCfg(), e2e.ZarfBinPath, args...) } diff --git a/src/test/e2e/25_helm_test.go b/src/test/e2e/25_helm_test.go index fef3433e76..1926785c9a 100644 --- a/src/test/e2e/25_helm_test.go +++ b/src/test/e2e/25_helm_test.go @@ -60,7 +60,7 @@ func testHelmChartsExample(t *testing.T) { require.NoError(t, err, stdOut, stdErr) // Create a test package (with a registry override (host to host+subpath) to test that as well) - // expect to fail as ghcr.io is overriden and the expected final image doesn't exist but the override works well based on the error message in the output + // expect to fail as ghcr.io is overridden and the expected final image doesn't exist but the override works well based on the error message in the output stdOut, stdErr, err = e2e.Zarf("package", "create", "examples/helm-charts", "-o", "build", "--registry-override", "ghcr.io=localhost:555/noway", "--tmpdir", tmpdir, "--confirm") require.Error(t, err, stdOut, stdErr) require.Contains(t, string(stdErr), "localhost:555/noway") From 40c74285a5914d6e6a8a828255cd3269f17ef890 Mon Sep 17 00:00:00 2001 From: Austin Abro Date: Tue, 5 Mar 2024 17:36:32 +0000 Subject: [PATCH 57/68] deleting redis templates to declutter --- .../chart/templates/redis/config.yaml | 12 ---- .../chart/templates/redis/deployment.yaml | 68 ------------------- .../chart/templates/redis/service.yaml | 17 ----- 3 files changed, 97 deletions(-) delete mode 100644 examples/helm-charts/chart/templates/redis/config.yaml delete mode 100644 examples/helm-charts/chart/templates/redis/deployment.yaml delete mode 100644 examples/helm-charts/chart/templates/redis/service.yaml diff --git a/examples/helm-charts/chart/templates/redis/config.yaml b/examples/helm-charts/chart/templates/redis/config.yaml deleted file mode 100644 index cd63785c83..0000000000 --- a/examples/helm-charts/chart/templates/redis/config.yaml +++ /dev/null @@ -1,12 +0,0 @@ -{{- if .Values.redis.enabled -}} -apiVersion: v1 -kind: ConfigMap -metadata: - name: {{ template "podinfo.fullname" . }}-redis -data: - redis.conf: | - maxmemory 64mb - maxmemory-policy allkeys-lru - save "" - appendonly no -{{- end }} diff --git a/examples/helm-charts/chart/templates/redis/deployment.yaml b/examples/helm-charts/chart/templates/redis/deployment.yaml deleted file mode 100644 index 78888555a8..0000000000 --- a/examples/helm-charts/chart/templates/redis/deployment.yaml +++ /dev/null @@ -1,68 +0,0 @@ -{{- if .Values.redis.enabled -}} -apiVersion: apps/v1 -kind: Deployment -metadata: - name: {{ template "podinfo.fullname" . }}-redis - labels: - app: {{ template "podinfo.fullname" . }}-redis -spec: - strategy: - type: Recreate - selector: - matchLabels: - app: {{ template "podinfo.fullname" . }}-redis - template: - metadata: - labels: - app: {{ template "podinfo.fullname" . }}-redis - annotations: - checksum/config: {{ include (print $.Template.BasePath "/redis/config.yaml") . | sha256sum | quote }} - spec: - {{- if .Values.serviceAccount.enabled }} - serviceAccountName: {{ template "podinfo.serviceAccountName" . }} - {{- end }} - containers: - - name: redis - image: "{{ .Values.redis.repository }}:{{ .Values.redis.tag }}" - imagePullPolicy: IfNotPresent - command: - - redis-server - - "/redis-master/redis.conf" - ports: - - name: redis - containerPort: 6379 - protocol: TCP - livenessProbe: - tcpSocket: - port: redis - initialDelaySeconds: 5 - timeoutSeconds: 5 - readinessProbe: - exec: - command: - - redis-cli - - ping - initialDelaySeconds: 5 - timeoutSeconds: 5 - resources: - limits: - cpu: 1000m - memory: 128Mi - requests: - cpu: 100m - memory: 32Mi - volumeMounts: - - mountPath: /var/lib/redis - name: data - - mountPath: /redis-master - name: config - volumes: - - name: data - emptyDir: {} - - name: config - configMap: - name: {{ template "podinfo.fullname" . }}-redis - items: - - key: redis.conf - path: redis.conf -{{- end }} diff --git a/examples/helm-charts/chart/templates/redis/service.yaml b/examples/helm-charts/chart/templates/redis/service.yaml deleted file mode 100644 index e2068514c3..0000000000 --- a/examples/helm-charts/chart/templates/redis/service.yaml +++ /dev/null @@ -1,17 +0,0 @@ -{{- if .Values.redis.enabled -}} -apiVersion: v1 -kind: Service -metadata: - name: {{ template "podinfo.fullname" . }}-redis - labels: - app: {{ template "podinfo.fullname" . }}-redis -spec: - type: ClusterIP - selector: - app: {{ template "podinfo.fullname" . }}-redis - ports: - - name: redis - port: 6379 - protocol: TCP - targetPort: redis -{{- end }} From 4f76006076ed46bdc50ef61f4bd45cf094d3226c Mon Sep 17 00:00:00 2001 From: Austin Abro Date: Tue, 5 Mar 2024 18:03:53 +0000 Subject: [PATCH 58/68] changing values to pointers for consistency --- src/pkg/packager/prepare.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/pkg/packager/prepare.go b/src/pkg/packager/prepare.go index 5e49d98de1..215861b2e1 100644 --- a/src/pkg/packager/prepare.go +++ b/src/pkg/packager/prepare.go @@ -130,22 +130,22 @@ func (p *Packager) FindImages() (imgMap map[string][]string, err error) { return nil, fmt.Errorf("unable to generate template values") } // Adding these so the default builtin values exist in case any helm charts rely on them - registryInfo := types.RegistryInfo{Address: p.cfg.FindImagesOpts.RegistryURL} + registryInfo := &types.RegistryInfo{Address: p.cfg.FindImagesOpts.RegistryURL} err = registryInfo.FillInEmptyValues() if err != nil { return nil, err } - gitServer := types.GitServerInfo{} + gitServer := &types.GitServerInfo{} err = gitServer.FillInEmptyValues() if err != nil { return nil, err } - artifactServer := types.ArtifactServerInfo{} + artifactServer := &types.ArtifactServerInfo{} artifactServer.FillInEmptyValues() values.SetState(&types.ZarfState{ - RegistryInfo: registryInfo, - GitServer: gitServer, - ArtifactServer: artifactServer}) + RegistryInfo: *registryInfo, + GitServer: *gitServer, + ArtifactServer: *artifactServer}) for _, chart := range component.Charts { helmCfg := helm.New( From 63a35ce281613727cdea9c08dd17b79c9aefd52d Mon Sep 17 00:00:00 2001 From: Austin Abro Date: Tue, 5 Mar 2024 18:07:53 +0000 Subject: [PATCH 59/68] cleaning up ci fix --- src/test/common.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/test/common.go b/src/test/common.go index 03a164e409..eab1f58fde 100644 --- a/src/test/common.go +++ b/src/test/common.go @@ -8,9 +8,7 @@ import ( "bufio" "context" "fmt" - "math/rand" "os" - "path/filepath" "regexp" "runtime" "strings" @@ -76,9 +74,16 @@ func (e2e *ZarfE2ETest) Zarf(args ...string) (string, string, error) { if !slices.Contains(args, "--zarf-cache") && !slices.Contains(args, "tools") && os.Getenv("CI") == "true" { // We make the cache dir relative to the working directory to make it work on the Windows Runners // - they use two drives which filepath.Rel cannot cope with. - relCacheDir, _ := filepath.Abs(fmt.Sprintf(".%d-cache-location", rand.Intn(10000000))) - args = append(args, "--zarf-cache", relCacheDir) - defer os.RemoveAll(relCacheDir) + cwd, err := os.Getwd() + if err != nil { + return "", "", err + } + cacheDir, err := os.MkdirTemp(cwd, "zarf-") + if err != nil { + return "", "", err + } + args = append(args, "--zarf-cache", cacheDir) + defer os.RemoveAll(cacheDir) } return exec.CmdWithContext(context.TODO(), exec.PrintCfg(), e2e.ZarfBinPath, args...) } From d2423df4e66efe1ae1b6755e47bca31df500f59c Mon Sep 17 00:00:00 2001 From: Austin Abro Date: Wed, 6 Mar 2024 13:21:21 +0000 Subject: [PATCH 60/68] disabling traefik on ci cluster --- .github/actions/k3d/action.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/k3d/action.yaml b/.github/actions/k3d/action.yaml index b5496adcc0..d4d1d5bbbf 100644 --- a/.github/actions/k3d/action.yaml +++ b/.github/actions/k3d/action.yaml @@ -7,5 +7,5 @@ runs: - run: "curl -s https://raw.githubusercontent.com/k3d-io/k3d/main/install.sh | bash" shell: bash - - run: k3d cluster delete && k3d cluster create + - run: k3d cluster delete && k3d cluster create --k3s-arg="--disable=traefik@server:0" shell: bash From 7384e4433f7e546ea86336339e5063449e58ca96 Mon Sep 17 00:00:00 2001 From: Austin Abro Date: Wed, 6 Mar 2024 18:17:34 +0000 Subject: [PATCH 61/68] update text description --- src/cmd/dev.go | 2 +- src/config/lang/english.go | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/cmd/dev.go b/src/cmd/dev.go index dbe55021c8..2020a2be76 100644 --- a/src/cmd/dev.go +++ b/src/cmd/dev.go @@ -281,7 +281,7 @@ func init() { devFindImagesCmd.Flags().StringVar(&pkgConfig.FindImagesOpts.Why, "why", "", lang.CmdDevFlagFindImagesWhy) defaultRegistry := fmt.Sprintf("%s:%d", helpers.IPV4Localhost, types.ZarfInClusterContainerRegistryNodePort) - devFindImagesCmd.Flags().StringVar(&pkgConfig.FindImagesOpts.RegistryURL, "registry-url", defaultRegistry, lang.CmdDevFlagRegistry) + devFindImagesCmd.Flags().StringVar(&pkgConfig.FindImagesOpts.RegistryURL, "registry-url", defaultRegistry, lang.CmdDevFlagFindImagesRegistry) devLintCmd.Flags().StringToStringVar(&pkgConfig.CreateOpts.SetVariables, "set", v.GetStringMapString(common.VPkgCreateSet), lang.CmdPackageCreateFlagSet) devLintCmd.Flags().StringVarP(&pkgConfig.CreateOpts.Flavor, "flavor", "f", v.GetString(common.VPkgCreateFlavor), lang.CmdPackageCreateFlagFlavor) diff --git a/src/config/lang/english.go b/src/config/lang/english.go index ea5fa20053..7bce402f94 100644 --- a/src/config/lang/english.go +++ b/src/config/lang/english.go @@ -379,13 +379,13 @@ $ 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" - CmdDevFlagRegistry = "Override the ###ZARF_REGISTRY### value" - CmdDevFlagFindImagesWhy = "Find the location of the image given as an argument and print it to the console." + 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" 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" From fb83b66d92315835bca23e6a298a0c923e46f41b Mon Sep 17 00:00:00 2001 From: Austin Abro Date: Wed, 6 Mar 2024 18:18:33 +0000 Subject: [PATCH 62/68] make docs and schema --- docs/2-the-zarf-cli/100-cli-commands/zarf_dev_find-images.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/2-the-zarf-cli/100-cli-commands/zarf_dev_find-images.md b/docs/2-the-zarf-cli/100-cli-commands/zarf_dev_find-images.md index f4987c997e..221ee2020a 100644 --- a/docs/2-the-zarf-cli/100-cli-commands/zarf_dev_find-images.md +++ b/docs/2-the-zarf-cli/100-cli-commands/zarf_dev_find-images.md @@ -23,7 +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" - --why string Find the location of the image given as an argument and print it to the console. + --why string Prints the source manifest for the specified image ``` ## Options inherited from parent commands From 2397afac86be4f9d48759ef7f7f84ee3be9af010 Mon Sep 17 00:00:00 2001 From: Austin Abro Date: Wed, 6 Mar 2024 19:55:50 +0000 Subject: [PATCH 63/68] fix tests --- src/pkg/packager/prepare.go | 1 + .../helm-charts-find-images-why-expected.txt | 11 +++++------ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/pkg/packager/prepare.go b/src/pkg/packager/prepare.go index 9993e099fb..c3ace0f135 100644 --- a/src/pkg/packager/prepare.go +++ b/src/pkg/packager/prepare.go @@ -37,6 +37,7 @@ type imageMap map[string]bool // FindImages iterates over a Zarf.yaml and attempts to parse any images. func (p *Packager) FindImages() (imgMap map[string][]string, err error) { + config.CommonOptions.Confirm = true repoHelmChartPath := p.cfg.FindImagesOpts.RepoHelmChartPath kubeVersionOverride := p.cfg.FindImagesOpts.KubeVersionOverride whyImage := p.cfg.FindImagesOpts.Why diff --git a/src/test/packages/13-find-images/helm-charts-find-images-why-expected.txt b/src/test/packages/13-find-images/helm-charts-find-images-why-expected.txt index 132a02e855..9140c95e5b 100644 --- a/src/test/packages/13-find-images/helm-charts-find-images-why-expected.txt +++ b/src/test/packages/13-find-images/helm-charts-find-images-why-expected.txt @@ -61,24 +61,24 @@ spec: key: mariadb-password name: wordpress-mariadb - name: WORDPRESS_USERNAME - value: null + value: zarf - name: WORDPRESS_PASSWORD valueFrom: secretKeyRef: key: wordpress-password name: wordpress - name: WORDPRESS_EMAIL - value: null + value: hello@defenseunicorns.com - name: WORDPRESS_FIRST_NAME - value: null + value: Zarf - name: WORDPRESS_LAST_NAME - value: null + value: The Axolotl - name: WORDPRESS_HTACCESS_OVERRIDE_NONE value: "no" - name: WORDPRESS_ENABLE_HTACCESS_PERSISTENCE value: "no" - name: WORDPRESS_BLOG_NAME - value: null + value: The Zarf Blog - name: WORDPRESS_SKIP_BOOTSTRAP value: "no" - name: WORDPRESS_TABLE_PREFIX @@ -184,4 +184,3 @@ spec: - name: wordpress-data persistentVolumeClaim: claimName: wordpress - From 64a9f8548c1c891b52b11ff95849135d6e2d9ae0 Mon Sep 17 00:00:00 2001 From: Austin Abro Date: Wed, 6 Mar 2024 20:01:51 +0000 Subject: [PATCH 64/68] moving find images tests together --- src/test/e2e/00_use_cli_test.go | 49 --------------------------- src/test/e2e/13_find_images_test.go | 51 +++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 49 deletions(-) diff --git a/src/test/e2e/00_use_cli_test.go b/src/test/e2e/00_use_cli_test.go index b776c8b55b..df9ece1db3 100644 --- a/src/test/e2e/00_use_cli_test.go +++ b/src/test/e2e/00_use_cli_test.go @@ -70,37 +70,6 @@ func TestUseCLI(t *testing.T) { require.Contains(t, stdOut, yamlVersion, "Zarf version should be the same in all formats") }) - t.Run("zarf prepare find-images", func(t *testing.T) { - t.Parallel() - // Test `zarf prepare find-images` for a remote asset - stdOut, stdErr, err := e2e.Zarf("prepare", "find-images", "examples/helm-charts", "--kube-version=v1.23.0") - require.NoError(t, err, stdOut, stdErr) - require.Contains(t, stdOut, "ghcr.io/stefanprodan/podinfo:6.4.0", "The chart image should be found by Zarf") - // Test `zarf prepare find-images` with a chart that uses helm annotations - stdOut, stdErr, err = e2e.Zarf("prepare", "find-images", "src/test/packages/00-helm-annotations") - require.NoError(t, err, stdOut, stdErr) - require.Contains(t, stdOut, "registry1.dso.mil/ironbank/opensource/istio/pilot:1.17.2", "The pilot image should be found by Zarf") - }) - - t.Run("zarf prepare find-images --kube-version", func(t *testing.T) { - t.Parallel() - controllerImageWithTag := "quay.io/jetstack/cert-manager-controller:v1.11.1" - controlImageWithSignature := "quay.io/jetstack/cert-manager-controller:sha256-4f1782c8316f34aae6b9ab823c3e6b7e6e4d92ec5dac21de6a17c3da44c364f1.sig" - - // Test `zarf prepare find-images` on a chart that has a `kubeVersion` declaration greater than the Helm default (v1.20.0) - // This should pass because we build Zarf specifying the kubeVersion value from the kubernetes client-go library instead - stdOut, stdErr, err := e2e.Zarf("prepare", "find-images", "src/test/packages/00-kube-version-override") - require.NoError(t, err, stdOut, stdErr) - require.Contains(t, stdOut, controllerImageWithTag, "The chart image should be found by Zarf") - require.Contains(t, stdOut, controlImageWithSignature, "The image signature should be found by Zarf") - - // Test `zarf prepare find-images` with `--kube-version` specified and less than than the declared minimum (v1.21.0) - stdOut, stdErr, err = e2e.Zarf("prepare", "find-images", "--kube-version=v1.20.0", "src/test/packages/00-kube-version-override") - require.Error(t, err, stdOut, stdErr) - require.Contains(t, stdErr, "Problem rendering the helm template for cert-manager", "The kubeVersion declaration should prevent this from templating") - require.Contains(t, stdErr, "following charts had errors: [cert-manager]", "Zarf should print an ending error message") - }) - t.Run("zarf deploy should fail when given a bad component input", func(t *testing.T) { t.Parallel() // Test for expected failure when given a bad component input @@ -244,22 +213,4 @@ func TestUseCLI(t *testing.T) { require.FileExists(t, tlsKey) }) - t.Run("zarf dev find-images with helm or manifest vars", func(t *testing.T) { - t.Parallel() - - registry := "coolregistry.gov" - agentTag := "test" - stdOut, _, err := e2e.Zarf("prepare", "find-images", ".", "--registry-url", registry, "--create-set", fmt.Sprintf("agent_image_tag=%s", agentTag)) - require.NoError(t, err) - internalRegistryImage := fmt.Sprintf("%s/%s:%s", registry, "defenseunicorns/zarf/agent", agentTag) - require.Contains(t, stdOut, internalRegistryImage, "registry image should be found with registry url") - require.Contains(t, stdOut, "busybox:latest", "Busybox image should be found as long as helm chart doesn't error") - - path := filepath.Join("src", "test", "packages", "00-find-images-with-vars") - stdOut, _, err = e2e.Zarf("prepare", "find-images", path, "--deploy-set", "BUSYBOX_IMAGE=busybox:earliest") - require.NoError(t, err) - - require.Contains(t, stdOut, "nginx:latest", "Manifests aren't interpreting vars") - require.Contains(t, stdOut, "busybox:earliest", "Values files aren't interpreting vars") - }) } diff --git a/src/test/e2e/13_find_images_test.go b/src/test/e2e/13_find_images_test.go index c37e1967c8..7873a25d09 100644 --- a/src/test/e2e/13_find_images_test.go +++ b/src/test/e2e/13_find_images_test.go @@ -1,6 +1,7 @@ package test import ( + "fmt" "os" "path/filepath" "testing" @@ -47,4 +48,54 @@ func TestFindImages(t *testing.T) { require.Contains(t, stdout, string(expectedOutput)) }) + t.Run("zarf prepare find-images", func(t *testing.T) { + t.Parallel() + // Test `zarf prepare find-images` for a remote asset + stdOut, stdErr, err := e2e.Zarf("prepare", "find-images", "examples/helm-charts") + require.NoError(t, err, stdOut, stdErr) + require.Contains(t, stdOut, "ghcr.io/stefanprodan/podinfo:6.4.0", "The chart image should be found by Zarf") + // Test `zarf prepare find-images` with a chart that uses helm annotations + stdOut, stdErr, err = e2e.Zarf("prepare", "find-images", "src/test/packages/00-helm-annotations") + require.NoError(t, err, stdOut, stdErr) + require.Contains(t, stdOut, "registry1.dso.mil/ironbank/opensource/istio/pilot:1.17.2", "The pilot image should be found by Zarf") + }) + + t.Run("zarf prepare find-images --kube-version", func(t *testing.T) { + t.Parallel() + controllerImageWithTag := "quay.io/jetstack/cert-manager-controller:v1.11.1" + controlImageWithSignature := "quay.io/jetstack/cert-manager-controller:sha256-4f1782c8316f34aae6b9ab823c3e6b7e6e4d92ec5dac21de6a17c3da44c364f1.sig" + + // Test `zarf prepare find-images` on a chart that has a `kubeVersion` declaration greater than the Helm default (v1.20.0) + // This should pass because we build Zarf specifying the kubeVersion value from the kubernetes client-go library instead + stdOut, stdErr, err := e2e.Zarf("prepare", "find-images", "src/test/packages/00-kube-version-override") + require.NoError(t, err, stdOut, stdErr) + require.Contains(t, stdOut, controllerImageWithTag, "The chart image should be found by Zarf") + require.Contains(t, stdOut, controlImageWithSignature, "The image signature should be found by Zarf") + + // Test `zarf prepare find-images` with `--kube-version` specified and less than than the declared minimum (v1.21.0) + stdOut, stdErr, err = e2e.Zarf("prepare", "find-images", "--kube-version=v1.20.0", "src/test/packages/00-kube-version-override") + require.Error(t, err, stdOut, stdErr) + require.Contains(t, stdErr, "Problem rendering the helm template for cert-manager", "The kubeVersion declaration should prevent this from templating") + require.Contains(t, stdErr, "following charts had errors: [cert-manager]", "Zarf should print an ending error message") + }) + + t.Run("zarf dev find-images with helm or manifest vars", func(t *testing.T) { + t.Parallel() + + registry := "coolregistry.gov" + agentTag := "test" + stdOut, _, err := e2e.Zarf("prepare", "find-images", ".", "--registry-url", registry, "--create-set", fmt.Sprintf("agent_image_tag=%s", agentTag)) + require.NoError(t, err) + internalRegistryImage := fmt.Sprintf("%s/%s:%s", registry, "defenseunicorns/zarf/agent", agentTag) + require.Contains(t, stdOut, internalRegistryImage, "registry image should be found with registry url") + require.Contains(t, stdOut, "busybox:latest", "Busybox image should be found as long as helm chart doesn't error") + + path := filepath.Join("src", "test", "packages", "00-find-images-with-vars") + stdOut, _, err = e2e.Zarf("prepare", "find-images", path, "--deploy-set", "BUSYBOX_IMAGE=busybox:earliest") + require.NoError(t, err) + + require.Contains(t, stdOut, "nginx:latest", "Manifests aren't interpreting vars") + require.Contains(t, stdOut, "busybox:earliest", "Values files aren't interpreting vars") + }) + } From b251a629b0785f4330b80044ed7321e5f1da8db0 Mon Sep 17 00:00:00 2001 From: Austin Abro Date: Wed, 6 Mar 2024 20:17:16 +0000 Subject: [PATCH 65/68] reformatting tests --- src/pkg/packager/prepare.go | 15 +- src/test/e2e/13_find_images_test.go | 63 +++--- .../dos-games-find-images-expected.txt | 7 - .../helm-charts-find-images-why-expected.txt | 186 ------------------ .../manifests-find-images-why-expected.txt | 24 --- 5 files changed, 33 insertions(+), 262 deletions(-) delete mode 100644 src/test/packages/13-find-images/dos-games-find-images-expected.txt delete mode 100644 src/test/packages/13-find-images/helm-charts-find-images-why-expected.txt delete mode 100644 src/test/packages/13-find-images/manifests-find-images-why-expected.txt diff --git a/src/pkg/packager/prepare.go b/src/pkg/packager/prepare.go index c3ace0f135..7d8ebabbc8 100644 --- a/src/pkg/packager/prepare.go +++ b/src/pkg/packager/prepare.go @@ -6,13 +6,14 @@ package packager import ( "fmt" - "github.com/goccy/go-yaml" "os" "path/filepath" "regexp" "sort" "strings" + "github.com/goccy/go-yaml" + "github.com/defenseunicorns/zarf/src/config" "github.com/defenseunicorns/zarf/src/config/lang" "github.com/defenseunicorns/zarf/src/internal/packager/helm" @@ -134,22 +135,22 @@ func (p *Packager) FindImages() (imgMap map[string][]string, err error) { return nil, fmt.Errorf("unable to generate template values") } // Adding these so the default builtin values exist in case any helm charts rely on them - registryInfo := &types.RegistryInfo{Address: p.cfg.FindImagesOpts.RegistryURL} + registryInfo := types.RegistryInfo{Address: p.cfg.FindImagesOpts.RegistryURL} err = registryInfo.FillInEmptyValues() if err != nil { return nil, err } - gitServer := &types.GitServerInfo{} + gitServer := types.GitServerInfo{} err = gitServer.FillInEmptyValues() if err != nil { return nil, err } - artifactServer := &types.ArtifactServerInfo{} + artifactServer := types.ArtifactServerInfo{} artifactServer.FillInEmptyValues() values.SetState(&types.ZarfState{ - RegistryInfo: *registryInfo, - GitServer: *gitServer, - ArtifactServer: *artifactServer}) + RegistryInfo: registryInfo, + GitServer: gitServer, + ArtifactServer: artifactServer}) for _, chart := range component.Charts { helmCfg := helm.New( diff --git a/src/test/e2e/13_find_images_test.go b/src/test/e2e/13_find_images_test.go index 7873a25d09..5b73a0bafe 100644 --- a/src/test/e2e/13_find_images_test.go +++ b/src/test/e2e/13_find_images_test.go @@ -2,7 +2,6 @@ package test import ( "fmt" - "os" "path/filepath" "testing" @@ -12,42 +11,6 @@ import ( func TestFindImages(t *testing.T) { t.Log("E2E: Find Images") - t.Run("zarf test find images success", func(t *testing.T) { - t.Log("E2E: Test Find Images") - - testPackagePath := filepath.Join("examples", "dos-games") - expectedOutput, err := os.ReadFile("src/test/packages/13-find-images/dos-games-find-images-expected.txt") - require.NoError(t, err) - - stdout, _, err := e2e.Zarf("dev", "find-images", testPackagePath) - require.NoError(t, err) - require.Contains(t, stdout, string(expectedOutput)) - }) - - t.Run("zarf test find images --why w/ helm chart success", func(t *testing.T) { - t.Log("E2E: Test Find Images against a helm chart with why flag") - - testPackagePath := filepath.Join("examples", "wordpress") - expectedOutput, err := os.ReadFile("src/test/packages/13-find-images/helm-charts-find-images-why-expected.txt") - require.NoError(t, err) - - stdout, _, err := e2e.Zarf("dev", "find-images", testPackagePath, "--why", "docker.io/bitnami/apache-exporter:0.13.3-debian-11-r2") - require.NoError(t, err) - require.Contains(t, stdout, string(expectedOutput)) - }) - - t.Run("zarf test find images --why w/ manifests success", func(t *testing.T) { - t.Log("E2E: Test Find Images against manifests with why flag") - - testPackagePath := filepath.Join("examples", "manifests") - expectedOutput, err := os.ReadFile("src/test/packages/13-find-images/manifests-find-images-why-expected.txt") - require.NoError(t, err) - - stdout, _, err := e2e.Zarf("dev", "find-images", testPackagePath, "--why", "httpd:alpine3.18") - require.NoError(t, err) - require.Contains(t, stdout, string(expectedOutput)) - }) - t.Run("zarf prepare find-images", func(t *testing.T) { t.Parallel() // Test `zarf prepare find-images` for a remote asset @@ -84,6 +47,7 @@ func TestFindImages(t *testing.T) { registry := "coolregistry.gov" agentTag := "test" + stdOut, _, err := e2e.Zarf("prepare", "find-images", ".", "--registry-url", registry, "--create-set", fmt.Sprintf("agent_image_tag=%s", agentTag)) require.NoError(t, err) internalRegistryImage := fmt.Sprintf("%s/%s:%s", registry, "defenseunicorns/zarf/agent", agentTag) @@ -93,9 +57,32 @@ func TestFindImages(t *testing.T) { path := filepath.Join("src", "test", "packages", "00-find-images-with-vars") stdOut, _, err = e2e.Zarf("prepare", "find-images", path, "--deploy-set", "BUSYBOX_IMAGE=busybox:earliest") require.NoError(t, err) - require.Contains(t, stdOut, "nginx:latest", "Manifests aren't interpreting vars") require.Contains(t, stdOut, "busybox:earliest", "Values files aren't interpreting vars") }) + t.Run("zarf test find images --why w/ helm chart success", func(t *testing.T) { + t.Parallel() + + testPackagePath := filepath.Join("examples", "wordpress") + stdOut, _, err := e2e.Zarf("dev", "find-images", testPackagePath, "--why", "docker.io/bitnami/apache-exporter:0.13.3-debian-11-r2") + require.NoError(t, err) + require.Contains(t, stdOut, "component: wordpress") + require.Contains(t, stdOut, "chart: wordpress") + require.Contains(t, stdOut, "image: docker.io/bitnami/wordpress:6.2.0-debian-11-r18") + }) + + t.Run("zarf test find images --why w/ manifests success", func(t *testing.T) { + t.Parallel() + + testPackagePath := filepath.Join("examples", "manifests") + + stdOut, _, err := e2e.Zarf("dev", "find-images", testPackagePath, "--why", "httpd:alpine3.18") + require.NoError(t, err) + require.Contains(t, stdOut, "component: httpd-local") + require.Contains(t, stdOut, "manifest: simple-httpd-deployment") + require.Contains(t, stdOut, "image: httpd:alpine3.18") + + }) + } diff --git a/src/test/packages/13-find-images/dos-games-find-images-expected.txt b/src/test/packages/13-find-images/dos-games-find-images-expected.txt deleted file mode 100644 index 8d661f4e52..0000000000 --- a/src/test/packages/13-find-images/dos-games-find-images-expected.txt +++ /dev/null @@ -1,7 +0,0 @@ -components: - - - name: baseline - images: - - defenseunicorns/zarf-game:multi-tile-dark - # Cosign artifacts for images - dos-games - baseline - - index.docker.io/defenseunicorns/zarf-game:sha256-0b694ca1c33afae97b7471488e07968599f1d2470c629f76af67145ca64428af.sig diff --git a/src/test/packages/13-find-images/helm-charts-find-images-why-expected.txt b/src/test/packages/13-find-images/helm-charts-find-images-why-expected.txt deleted file mode 100644 index 9140c95e5b..0000000000 --- a/src/test/packages/13-find-images/helm-charts-find-images-why-expected.txt +++ /dev/null @@ -1,186 +0,0 @@ -component: wordpress -chart: wordpress -resource: - -apiVersion: apps/v1 -kind: Deployment -metadata: - labels: - app.kubernetes.io/instance: wordpress - app.kubernetes.io/managed-by: Helm - app.kubernetes.io/name: wordpress - helm.sh/chart: wordpress-16.0.4 - name: wordpress - namespace: wordpress -spec: - replicas: 1 - selector: - matchLabels: - app.kubernetes.io/instance: wordpress - app.kubernetes.io/name: wordpress - strategy: - type: RollingUpdate - template: - metadata: - annotations: null - labels: - app.kubernetes.io/instance: wordpress - app.kubernetes.io/managed-by: Helm - app.kubernetes.io/name: wordpress - helm.sh/chart: wordpress-16.0.4 - spec: - affinity: - nodeAffinity: null - podAffinity: null - podAntiAffinity: - preferredDuringSchedulingIgnoredDuringExecution: - - podAffinityTerm: - labelSelector: - matchLabels: - app.kubernetes.io/instance: wordpress - app.kubernetes.io/name: wordpress - topologyKey: kubernetes.io/hostname - weight: 1 - containers: - - env: - - name: BITNAMI_DEBUG - value: "false" - - name: ALLOW_EMPTY_PASSWORD - value: "yes" - - name: MARIADB_HOST - value: wordpress-mariadb - - name: MARIADB_PORT_NUMBER - value: "3306" - - name: WORDPRESS_DATABASE_NAME - value: bitnami_wordpress - - name: WORDPRESS_DATABASE_USER - value: bn_wordpress - - name: WORDPRESS_DATABASE_PASSWORD - valueFrom: - secretKeyRef: - key: mariadb-password - name: wordpress-mariadb - - name: WORDPRESS_USERNAME - value: zarf - - name: WORDPRESS_PASSWORD - valueFrom: - secretKeyRef: - key: wordpress-password - name: wordpress - - name: WORDPRESS_EMAIL - value: hello@defenseunicorns.com - - name: WORDPRESS_FIRST_NAME - value: Zarf - - name: WORDPRESS_LAST_NAME - value: The Axolotl - - name: WORDPRESS_HTACCESS_OVERRIDE_NONE - value: "no" - - name: WORDPRESS_ENABLE_HTACCESS_PERSISTENCE - value: "no" - - name: WORDPRESS_BLOG_NAME - value: The Zarf Blog - - name: WORDPRESS_SKIP_BOOTSTRAP - value: "no" - - name: WORDPRESS_TABLE_PREFIX - value: wp_ - - name: WORDPRESS_SCHEME - value: http - - name: WORDPRESS_EXTRA_WP_CONFIG_CONTENT - value: "" - - name: WORDPRESS_PLUGINS - value: none - - name: APACHE_HTTP_PORT_NUMBER - value: "8080" - - name: APACHE_HTTPS_PORT_NUMBER - value: "8443" - envFrom: null - image: docker.io/bitnami/wordpress:6.2.0-debian-11-r18 - imagePullPolicy: IfNotPresent - livenessProbe: - failureThreshold: 6 - httpGet: - httpHeaders: [] - path: /wp-admin/install.php - port: http - scheme: HTTP - initialDelaySeconds: 120 - periodSeconds: 10 - successThreshold: 1 - timeoutSeconds: 5 - name: wordpress - ports: - - containerPort: 8080 - name: http - - containerPort: 8443 - name: https - readinessProbe: - failureThreshold: 6 - httpGet: - httpHeaders: [] - path: /wp-login.php - port: http - scheme: HTTP - initialDelaySeconds: 30 - periodSeconds: 10 - successThreshold: 1 - timeoutSeconds: 5 - resources: - limits: {} - requests: - cpu: 300m - memory: 512Mi - securityContext: - allowPrivilegeEscalation: false - capabilities: - drop: - - ALL - runAsNonRoot: true - runAsUser: 1001 - volumeMounts: - - mountPath: /bitnami/wordpress - name: wordpress-data - subPath: wordpress - - command: - - /bin/apache_exporter - - --scrape_uri - - http://status.localhost:8080/server-status/?auto - image: docker.io/bitnami/apache-exporter:0.13.3-debian-11-r2 - imagePullPolicy: IfNotPresent - livenessProbe: - failureThreshold: 3 - httpGet: - path: /metrics - port: metrics - initialDelaySeconds: 15 - periodSeconds: 10 - successThreshold: 1 - timeoutSeconds: 5 - name: metrics - ports: - - containerPort: 9117 - name: metrics - readinessProbe: - failureThreshold: 3 - httpGet: - path: /metrics - port: metrics - initialDelaySeconds: 5 - periodSeconds: 10 - successThreshold: 1 - timeoutSeconds: 3 - resources: - limits: {} - requests: {} - hostAliases: - - hostnames: - - status.localhost - ip: 127.0.0.1 - securityContext: - fsGroup: 1001 - seccompProfile: - type: RuntimeDefault - serviceAccountName: default - volumes: - - name: wordpress-data - persistentVolumeClaim: - claimName: wordpress diff --git a/src/test/packages/13-find-images/manifests-find-images-why-expected.txt b/src/test/packages/13-find-images/manifests-find-images-why-expected.txt deleted file mode 100644 index d3ed40d8ac..0000000000 --- a/src/test/packages/13-find-images/manifests-find-images-why-expected.txt +++ /dev/null @@ -1,24 +0,0 @@ -component: httpd-local -manifest: simple-httpd-deployment -resource: - -apiVersion: apps/v1 -kind: Deployment -metadata: - name: httpd-deployment -spec: - replicas: 2 - selector: - matchLabels: - app: httpd - template: - metadata: - labels: - app: httpd - spec: - containers: - - image: httpd:alpine3.18 - name: httpd - ports: - - containerPort: 80 - From a15ae57244a32c7425db18101ba311a52c3ac115 Mon Sep 17 00:00:00 2001 From: Austin Abro Date: Wed, 6 Mar 2024 21:44:25 +0000 Subject: [PATCH 66/68] de-parralizeing --- src/test/e2e/13_find_images_test.go | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/test/e2e/13_find_images_test.go b/src/test/e2e/13_find_images_test.go index 5b73a0bafe..47deb7fd51 100644 --- a/src/test/e2e/13_find_images_test.go +++ b/src/test/e2e/13_find_images_test.go @@ -12,7 +12,6 @@ func TestFindImages(t *testing.T) { t.Log("E2E: Find Images") t.Run("zarf prepare find-images", func(t *testing.T) { - t.Parallel() // Test `zarf prepare find-images` for a remote asset stdOut, stdErr, err := e2e.Zarf("prepare", "find-images", "examples/helm-charts") require.NoError(t, err, stdOut, stdErr) @@ -24,7 +23,6 @@ func TestFindImages(t *testing.T) { }) t.Run("zarf prepare find-images --kube-version", func(t *testing.T) { - t.Parallel() controllerImageWithTag := "quay.io/jetstack/cert-manager-controller:v1.11.1" controlImageWithSignature := "quay.io/jetstack/cert-manager-controller:sha256-4f1782c8316f34aae6b9ab823c3e6b7e6e4d92ec5dac21de6a17c3da44c364f1.sig" @@ -43,7 +41,6 @@ func TestFindImages(t *testing.T) { }) t.Run("zarf dev find-images with helm or manifest vars", func(t *testing.T) { - t.Parallel() registry := "coolregistry.gov" agentTag := "test" @@ -62,7 +59,6 @@ func TestFindImages(t *testing.T) { }) t.Run("zarf test find images --why w/ helm chart success", func(t *testing.T) { - t.Parallel() testPackagePath := filepath.Join("examples", "wordpress") stdOut, _, err := e2e.Zarf("dev", "find-images", testPackagePath, "--why", "docker.io/bitnami/apache-exporter:0.13.3-debian-11-r2") @@ -73,7 +69,6 @@ func TestFindImages(t *testing.T) { }) t.Run("zarf test find images --why w/ manifests success", func(t *testing.T) { - t.Parallel() testPackagePath := filepath.Join("examples", "manifests") From 5d2065b685d76e94ec72d9ebd4187d7fa16d8cfe Mon Sep 17 00:00:00 2001 From: Austin Abro Date: Wed, 6 Mar 2024 21:57:06 +0000 Subject: [PATCH 67/68] fix wordpress test --- src/pkg/packager/prepare.go | 1 - src/test/e2e/13_find_images_test.go | 9 ++++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/pkg/packager/prepare.go b/src/pkg/packager/prepare.go index 7d8ebabbc8..b2b77fd5b7 100644 --- a/src/pkg/packager/prepare.go +++ b/src/pkg/packager/prepare.go @@ -38,7 +38,6 @@ type imageMap map[string]bool // FindImages iterates over a Zarf.yaml and attempts to parse any images. func (p *Packager) FindImages() (imgMap map[string][]string, err error) { - config.CommonOptions.Confirm = true repoHelmChartPath := p.cfg.FindImagesOpts.RepoHelmChartPath kubeVersionOverride := p.cfg.FindImagesOpts.KubeVersionOverride whyImage := p.cfg.FindImagesOpts.Why diff --git a/src/test/e2e/13_find_images_test.go b/src/test/e2e/13_find_images_test.go index 47deb7fd51..f69d12ad0b 100644 --- a/src/test/e2e/13_find_images_test.go +++ b/src/test/e2e/13_find_images_test.go @@ -3,6 +3,7 @@ package test import ( "fmt" "path/filepath" + "strings" "testing" "github.com/stretchr/testify/require" @@ -58,17 +59,19 @@ func TestFindImages(t *testing.T) { require.Contains(t, stdOut, "busybox:earliest", "Values files aren't interpreting vars") }) - t.Run("zarf test find images --why w/ helm chart success", func(t *testing.T) { + t.Run("zarf test find images --why w/ helm chart success", func(t *testing.T) { testPackagePath := filepath.Join("examples", "wordpress") - stdOut, _, err := e2e.Zarf("dev", "find-images", testPackagePath, "--why", "docker.io/bitnami/apache-exporter:0.13.3-debian-11-r2") + sets := []string{"WORDPRESS_USERNAME=zarf", "WORDPRESS_PASSWORD=fake", "WORDPRESS_EMAIL=hello@defenseunicorns.com", "WORDPRESS_FIRST_NAME=zarf", "WORDPRESS_LAST_NAME=zarf", "WORDPRESS_BLOG_NAME=blog"} + deploysSet := strings.Join(sets, ",") + stdOut, _, err := e2e.Zarf("dev", "find-images", testPackagePath, "--why", "docker.io/bitnami/apache-exporter:0.13.3-debian-11-r2", "--deploy-set", deploysSet) require.NoError(t, err) require.Contains(t, stdOut, "component: wordpress") require.Contains(t, stdOut, "chart: wordpress") require.Contains(t, stdOut, "image: docker.io/bitnami/wordpress:6.2.0-debian-11-r18") }) - t.Run("zarf test find images --why w/ manifests success", func(t *testing.T) { + t.Run("zarf test find images --why w/ manifests success", func(t *testing.T) { testPackagePath := filepath.Join("examples", "manifests") From e4d45435463ab501d7568588266a722baa96a4c5 Mon Sep 17 00:00:00 2001 From: Austin Abro Date: Thu, 7 Mar 2024 14:14:32 +0000 Subject: [PATCH 68/68] adding back parrallel fixing lint test --- src/test/e2e/12_lint_test.go | 1 + src/test/e2e/13_find_images_test.go | 8 +++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/test/e2e/12_lint_test.go b/src/test/e2e/12_lint_test.go index cf132c4068..62b6964e88 100644 --- a/src/test/e2e/12_lint_test.go +++ b/src/test/e2e/12_lint_test.go @@ -28,6 +28,7 @@ func TestLint(t *testing.T) { configPath := filepath.Join(testPackagePath, "zarf-config.toml") os.Setenv("ZARF_CONFIG", configPath) _, stderr, err := e2e.Zarf("dev", "lint", testPackagePath, "-f", "good-flavor") + os.Unsetenv("ZARF_CONFIG") require.Error(t, err, "Require an exit code since there was warnings / errors") strippedStderr := e2e.StripMessageFormatting(stderr) diff --git a/src/test/e2e/13_find_images_test.go b/src/test/e2e/13_find_images_test.go index f69d12ad0b..3235d519f1 100644 --- a/src/test/e2e/13_find_images_test.go +++ b/src/test/e2e/13_find_images_test.go @@ -13,6 +13,7 @@ func TestFindImages(t *testing.T) { t.Log("E2E: Find Images") t.Run("zarf prepare find-images", func(t *testing.T) { + t.Parallel() // Test `zarf prepare find-images` for a remote asset stdOut, stdErr, err := e2e.Zarf("prepare", "find-images", "examples/helm-charts") require.NoError(t, err, stdOut, stdErr) @@ -24,6 +25,7 @@ func TestFindImages(t *testing.T) { }) t.Run("zarf prepare find-images --kube-version", func(t *testing.T) { + t.Parallel() controllerImageWithTag := "quay.io/jetstack/cert-manager-controller:v1.11.1" controlImageWithSignature := "quay.io/jetstack/cert-manager-controller:sha256-4f1782c8316f34aae6b9ab823c3e6b7e6e4d92ec5dac21de6a17c3da44c364f1.sig" @@ -42,7 +44,7 @@ func TestFindImages(t *testing.T) { }) t.Run("zarf dev find-images with helm or manifest vars", func(t *testing.T) { - + t.Parallel() registry := "coolregistry.gov" agentTag := "test" @@ -60,7 +62,7 @@ func TestFindImages(t *testing.T) { }) t.Run("zarf test find images --why w/ helm chart success", func(t *testing.T) { - + t.Parallel() testPackagePath := filepath.Join("examples", "wordpress") sets := []string{"WORDPRESS_USERNAME=zarf", "WORDPRESS_PASSWORD=fake", "WORDPRESS_EMAIL=hello@defenseunicorns.com", "WORDPRESS_FIRST_NAME=zarf", "WORDPRESS_LAST_NAME=zarf", "WORDPRESS_BLOG_NAME=blog"} deploysSet := strings.Join(sets, ",") @@ -72,7 +74,7 @@ func TestFindImages(t *testing.T) { }) t.Run("zarf test find images --why w/ manifests success", func(t *testing.T) { - + t.Parallel() testPackagePath := filepath.Join("examples", "manifests") stdOut, _, err := e2e.Zarf("dev", "find-images", testPackagePath, "--why", "httpd:alpine3.18")