From c77f4461ec611147b44871f3bd227bf6c05b7c83 Mon Sep 17 00:00:00 2001 From: Philip Laine Date: Tue, 23 Jul 2024 18:15:09 +0200 Subject: [PATCH 01/11] refactor: move setup CLI to only run once in root command (#2722) Signed-off-by: Philip Laine --- src/cmd/common/setup.go | 50 ++++++++++++++++---------------------- src/cmd/root.go | 41 ++++++++++++++++++++++++------- src/cmd/tools/common.go | 15 ++---------- src/cmd/version.go | 7 ++---- src/config/config.go | 6 ----- src/config/lang/english.go | 2 -- src/pkg/message/message.go | 8 ++++-- src/pkg/utils/yaml.go | 6 ++--- 8 files changed, 66 insertions(+), 69 deletions(-) diff --git a/src/cmd/common/setup.go b/src/cmd/common/setup.go index 703d9355bf..ac47d0c95d 100644 --- a/src/cmd/common/setup.go +++ b/src/cmd/common/setup.go @@ -5,43 +5,38 @@ package common import ( + "errors" "fmt" "io" "os" "time" "github.com/pterm/pterm" - "github.com/zarf-dev/zarf/src/config" - "github.com/zarf-dev/zarf/src/config/lang" + "github.com/zarf-dev/zarf/src/pkg/message" ) -// LogLevelCLI holds the log level as input from a command -var LogLevelCLI string - -// SetupCLI sets up the CLI logging, interrupt functions, and more -func SetupCLI() { - match := map[string]message.LogLevel{ - "warn": message.WarnLevel, - "info": message.InfoLevel, - "debug": message.DebugLevel, - "trace": message.TraceLevel, - } - - if config.NoColor { +// SetupCLI sets up the CLI logging +func SetupCLI(logLevel string, skipLogFile, noColor bool) error { + if noColor { message.DisableColor() } printViperConfigUsed() - // No log level set, so use the default - if LogLevelCLI != "" { - if lvl, ok := match[LogLevelCLI]; ok { - message.SetLogLevel(lvl) - message.Debug("Log level set to " + LogLevelCLI) - } else { - message.Warn(lang.RootCmdErrInvalidLogLevel) + if logLevel != "" { + match := map[string]message.LogLevel{ + "warn": message.WarnLevel, + "info": message.InfoLevel, + "debug": message.DebugLevel, + "trace": message.TraceLevel, } + lvl, ok := match[logLevel] + if !ok { + return errors.New("invalid log level, valid options are warn, info, debug, and trace") + } + message.SetLogLevel(lvl) + message.Debug("Log level set to " + logLevel) } // Disable progress bars for CI envs @@ -50,21 +45,18 @@ func SetupCLI() { message.NoProgress = true } - if !config.SkipLogFile { + if !skipLogFile { ts := time.Now().Format("2006-01-02-15-04-05") - f, err := os.CreateTemp("", fmt.Sprintf("zarf-%s-*.log", ts)) if err != nil { - message.WarnErr(err, "Error creating a log file in a temporary directory") - return + return fmt.Errorf("could not create a log file in a the temporary directory: %w", err) } logFile, err := message.UseLogFile(f) if err != nil { - message.WarnErr(err, "Error saving a log file to a temporary directory") - return + return fmt.Errorf("could not save a log file to the temporary directory: %w", err) } - pterm.SetDefaultOutput(io.MultiWriter(os.Stderr, logFile)) message.Notef("Saving log file to %s", f.Name()) } + return nil } diff --git a/src/cmd/root.go b/src/cmd/root.go index 086a1cab6c..876efdf20e 100644 --- a/src/cmd/root.go +++ b/src/cmd/root.go @@ -26,20 +26,43 @@ import ( var ( // Default global config for the packager pkgConfig = types.PackagerConfig{} + // LogLevelCLI holds the log level as input from a command + LogLevelCLI string + // SkipLogFile is a flag to skip logging to a file + SkipLogFile bool + // NoColor is a flag to disable colors in output + NoColor bool ) var rootCmd = &cobra.Command{ Use: "zarf COMMAND", - PersistentPreRun: func(cmd *cobra.Command, _ []string) { - // Skip for vendor-only commands + PersistentPreRunE: func(cmd *cobra.Command, _ []string) error { + // Skip for vendor only commands if common.CheckVendorOnlyFromPath(cmd) { - return + return nil } - // Don't log the help command + + skipLogFile := SkipLogFile + + // Dont write tool commands to file. + comps := strings.Split(cmd.CommandPath(), " ") + if len(comps) > 1 && comps[1] == "tools" { + skipLogFile = true + } + if len(comps) > 1 && comps[1] == "version" { + skipLogFile = true + } + + // Dont write help command to file. if cmd.Parent() == nil { - config.SkipLogFile = true + skipLogFile = true + } + + err := common.SetupCLI(LogLevelCLI, skipLogFile, NoColor) + if err != nil { + return err } - common.SetupCLI() + return nil }, Short: lang.RootCmdShort, Long: lang.RootCmdLong, @@ -89,11 +112,11 @@ func init() { v := common.InitViper() - rootCmd.PersistentFlags().StringVarP(&common.LogLevelCLI, "log-level", "l", v.GetString(common.VLogLevel), lang.RootCmdFlagLogLevel) + rootCmd.PersistentFlags().StringVarP(&LogLevelCLI, "log-level", "l", v.GetString(common.VLogLevel), lang.RootCmdFlagLogLevel) rootCmd.PersistentFlags().StringVarP(&config.CLIArch, "architecture", "a", v.GetString(common.VArchitecture), lang.RootCmdFlagArch) - rootCmd.PersistentFlags().BoolVar(&config.SkipLogFile, "no-log-file", v.GetBool(common.VNoLogFile), lang.RootCmdFlagSkipLogFile) + rootCmd.PersistentFlags().BoolVar(&SkipLogFile, "no-log-file", v.GetBool(common.VNoLogFile), lang.RootCmdFlagSkipLogFile) rootCmd.PersistentFlags().BoolVar(&message.NoProgress, "no-progress", v.GetBool(common.VNoProgress), lang.RootCmdFlagNoProgress) - rootCmd.PersistentFlags().BoolVar(&config.NoColor, "no-color", v.GetBool(common.VNoColor), lang.RootCmdFlagNoColor) + rootCmd.PersistentFlags().BoolVar(&NoColor, "no-color", v.GetBool(common.VNoColor), lang.RootCmdFlagNoColor) rootCmd.PersistentFlags().StringVar(&config.CommonOptions.CachePath, "zarf-cache", v.GetString(common.VZarfCache), lang.RootCmdFlagCachePath) rootCmd.PersistentFlags().StringVar(&config.CommonOptions.TempDirectory, "tmpdir", v.GetString(common.VTmpDir), lang.RootCmdFlagTempDir) rootCmd.PersistentFlags().BoolVar(&config.CommonOptions.Insecure, "insecure", v.GetBool(common.VInsecure), lang.RootCmdFlagInsecure) diff --git a/src/cmd/tools/common.go b/src/cmd/tools/common.go index 7f8f375be0..0aef6e95c5 100644 --- a/src/cmd/tools/common.go +++ b/src/cmd/tools/common.go @@ -8,25 +8,14 @@ import ( "fmt" "github.com/spf13/cobra" - "github.com/zarf-dev/zarf/src/cmd/common" - "github.com/zarf-dev/zarf/src/config" + "github.com/zarf-dev/zarf/src/config/lang" ) var toolsCmd = &cobra.Command{ Use: "tools", Aliases: []string{"t"}, - PersistentPreRun: func(cmd *cobra.Command, _ []string) { - config.SkipLogFile = true - - // Skip for vendor-only commands - if common.CheckVendorOnlyFromPath(cmd) { - return - } - - common.SetupCLI() - }, - Short: lang.CmdToolsShort, + Short: lang.CmdToolsShort, } // Include adds the tools command to the root command. diff --git a/src/cmd/version.go b/src/cmd/version.go index 26299c7db5..a08af2aaab 100644 --- a/src/cmd/version.go +++ b/src/cmd/version.go @@ -24,11 +24,8 @@ var outputFormat string var versionCmd = &cobra.Command{ Use: "version", Aliases: []string{"v"}, - PersistentPreRun: func(_ *cobra.Command, _ []string) { - config.SkipLogFile = true - }, - Short: lang.CmdVersionShort, - Long: lang.CmdVersionLong, + Short: lang.CmdVersionShort, + Long: lang.CmdVersionLong, RunE: func(_ *cobra.Command, _ []string) error { if outputFormat == "" { fmt.Println(config.CLIVersion) diff --git a/src/config/config.go b/src/config/config.go index 4f55f48e61..dc60ea2fd8 100644 --- a/src/config/config.go +++ b/src/config/config.go @@ -60,12 +60,6 @@ var ( // ZarfSeedPort is the NodePort Zarf uses for the 'seed registry' ZarfSeedPort string - // SkipLogFile is a flag to skip logging to a file - SkipLogFile bool - - // NoColor is a flag to disable colors in output - NoColor bool - CosignPublicKey string // Timestamp of when the CLI was started diff --git a/src/config/lang/english.go b/src/config/lang/english.go index df39428f48..9b90c23b22 100644 --- a/src/config/lang/english.go +++ b/src/config/lang/english.go @@ -58,8 +58,6 @@ const ( RootCmdDeprecatedDeploy = "Deprecated: Please use \"zarf package deploy %s\" to deploy this package. This warning will be removed in Zarf v1.0.0." RootCmdDeprecatedCreate = "Deprecated: Please use \"zarf package create\" to create this package. This warning will be removed in Zarf v1.0.0." - RootCmdErrInvalidLogLevel = "Invalid log level. Valid options are: warn, info, debug, trace." - // zarf connect CmdConnectShort = "Accesses services or pods deployed in the cluster" CmdConnectLong = "Uses a k8s port-forward to connect to resources within the cluster referenced by your kube-context.\n" + diff --git a/src/pkg/message/message.go b/src/pkg/message/message.go index f9d7d48c3c..e271cbf9d4 100644 --- a/src/pkg/message/message.go +++ b/src/pkg/message/message.go @@ -14,7 +14,6 @@ import ( "github.com/defenseunicorns/pkg/helpers/v2" "github.com/fatih/color" "github.com/pterm/pterm" - "github.com/zarf-dev/zarf/src/config" ) // LogLevel is the level of logging to display. @@ -99,6 +98,11 @@ func DisableColor() { pterm.DisableColor() } +// ColorEnabled returns true if color printing is enabled. +func ColorEnabled() bool { + return pterm.PrintColor +} + // ZarfCommand prints a zarf terminal command. func ZarfCommand(format string, a ...any) { Command("zarf "+format, a...) @@ -276,7 +280,7 @@ func Table(header []string, data [][]string) { // preventing future characters from taking on the given color // returns string as normal if color is disabled func ColorWrap(str string, attr color.Attribute) string { - if config.NoColor || str == "" { + if !ColorEnabled() || str == "" { return str } return fmt.Sprintf("\x1b[%dm%s\x1b[0m", attr, str) diff --git a/src/pkg/utils/yaml.go b/src/pkg/utils/yaml.go index e61083bc51..5f86202970 100644 --- a/src/pkg/utils/yaml.go +++ b/src/pkg/utils/yaml.go @@ -20,12 +20,12 @@ import ( "github.com/goccy/go-yaml/lexer" "github.com/goccy/go-yaml/printer" "github.com/pterm/pterm" - "github.com/zarf-dev/zarf/src/config" - "github.com/zarf-dev/zarf/src/pkg/message" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/runtime" kubeyaml "k8s.io/apimachinery/pkg/util/yaml" k8syaml "sigs.k8s.io/yaml" + + "github.com/zarf-dev/zarf/src/pkg/message" ) const yamlEscape = "\x1b" @@ -93,7 +93,7 @@ func ColorPrintYAML(data any, hints map[string]string, spaceRootLists bool) { outputYAML = strings.Replace(outputYAML, key, value, 1) } - if config.NoColor { + if !message.ColorEnabled() { // If no color is specified strip any color codes from the output - https://regex101.com/r/YFyIwC/2 ansiRegex := regexp.MustCompile(`\x1b\[(.*?)m`) outputYAML = ansiRegex.ReplaceAllString(outputYAML, "") From 5c74276d5c4fd1f6bf00f93347c469a0d90522e4 Mon Sep 17 00:00:00 2001 From: schristoff <28318173+schristoff@users.noreply.github.com> Date: Wed, 24 Jul 2024 17:00:00 -0600 Subject: [PATCH 02/11] chore: move context.TODO to context.Background() (3) (#2747) Signed-off-by: schristoff-du <167717759+schristoff-du@users.noreply.github.com> Co-authored-by: schristoff-du <167717759+schristoff-du@users.noreply.github.com> --- src/extensions/bigbang/bigbang.go | 2 +- src/internal/packager/helm/chart.go | 13 +++++++------ src/internal/packager/helm/post-render.go | 4 ++-- src/internal/packager/helm/zarf.go | 4 ++-- src/pkg/packager/deploy.go | 8 ++++---- src/pkg/packager/prepare.go | 2 +- 6 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/extensions/bigbang/bigbang.go b/src/extensions/bigbang/bigbang.go index e312f382f9..ebe068f003 100644 --- a/src/extensions/bigbang/bigbang.go +++ b/src/extensions/bigbang/bigbang.go @@ -107,7 +107,7 @@ func Run(ctx context.Context, YOLO bool, tmpPaths *layout.ComponentPaths, c type // Template the chart so we can see what GitRepositories are being referenced in the // manifests created with the provided Helm. - template, _, err := helmCfg.TemplateChart() + template, _, err := helmCfg.TemplateChart(ctx) if err != nil { return c, fmt.Errorf("unable to template Big Bang Chart: %w", err) } diff --git a/src/internal/packager/helm/chart.go b/src/internal/packager/helm/chart.go index f9ac5eefe0..0bd483df7f 100644 --- a/src/internal/packager/helm/chart.go +++ b/src/internal/packager/helm/chart.go @@ -5,6 +5,7 @@ package helm import ( + "context" "errors" "fmt" "time" @@ -30,7 +31,7 @@ import ( ) // InstallOrUpgradeChart performs a helm install of the given chart. -func (h *Helm) InstallOrUpgradeChart() (types.ConnectStrings, string, error) { +func (h *Helm) InstallOrUpgradeChart(ctx context.Context) (types.ConnectStrings, string, error) { fromMessage := h.chart.URL if fromMessage == "" { fromMessage = "Zarf-generated helm chart" @@ -52,7 +53,7 @@ func (h *Helm) InstallOrUpgradeChart() (types.ConnectStrings, string, error) { return nil, "", fmt.Errorf("unable to initialize the K8s client: %w", err) } - postRender, err := h.newRenderer() + postRender, err := h.newRenderer(ctx) if err != nil { return nil, "", fmt.Errorf("unable to create helm renderer: %w", err) } @@ -126,7 +127,7 @@ func (h *Helm) InstallOrUpgradeChart() (types.ConnectStrings, string, error) { } // TemplateChart generates a helm template from a given chart. -func (h *Helm) TemplateChart() (manifest string, chartValues chartutil.Values, err error) { +func (h *Helm) TemplateChart(ctx context.Context) (manifest string, chartValues chartutil.Values, err error) { message.Debugf("helm.TemplateChart()") spinner := message.NewProgressSpinner("Templating helm chart %s", h.chart.Name) defer spinner.Stop() @@ -170,7 +171,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.newRenderer() + client.PostRenderer, err = h.newRenderer(ctx) if err != nil { return "", nil, fmt.Errorf("unable to create helm renderer: %w", err) } @@ -204,7 +205,7 @@ func (h *Helm) RemoveChart(namespace string, name string, spinner *message.Spinn // UpdateReleaseValues updates values for a given chart release // (note: this only works on single-deep charts, charts with dependencies (like loki-stack) will not work) -func (h *Helm) UpdateReleaseValues(updatedValues map[string]interface{}) error { +func (h *Helm) UpdateReleaseValues(ctx context.Context, updatedValues map[string]interface{}) error { spinner := message.NewProgressSpinner("Updating values for helm release %s", h.chart.ReleaseName) defer spinner.Stop() @@ -213,7 +214,7 @@ func (h *Helm) UpdateReleaseValues(updatedValues map[string]interface{}) error { return fmt.Errorf("unable to initialize the K8s client: %w", err) } - postRender, err := h.newRenderer() + postRender, err := h.newRenderer(ctx) if err != nil { return fmt.Errorf("unable to create helm renderer: %w", err) } diff --git a/src/internal/packager/helm/post-render.go b/src/internal/packager/helm/post-render.go index 8d6c157427..9a514fc6a6 100644 --- a/src/internal/packager/helm/post-render.go +++ b/src/internal/packager/helm/post-render.go @@ -37,7 +37,7 @@ type renderer struct { namespaces map[string]*corev1.Namespace } -func (h *Helm) newRenderer() (*renderer, error) { +func (h *Helm) newRenderer(ctx context.Context) (*renderer, error) { message.Debugf("helm.NewRenderer()") rend := &renderer{ @@ -49,7 +49,7 @@ func (h *Helm) newRenderer() (*renderer, error) { return rend, nil } - namespace, err := h.cluster.Clientset.CoreV1().Namespaces().Get(context.TODO(), h.chart.Namespace, metav1.GetOptions{}) + namespace, err := h.cluster.Clientset.CoreV1().Namespaces().Get(ctx, h.chart.Namespace, metav1.GetOptions{}) if err != nil && !kerrors.IsNotFound(err) { return nil, fmt.Errorf("unable to check for existing namespace %q in cluster: %w", h.chart.Namespace, err) } diff --git a/src/internal/packager/helm/zarf.go b/src/internal/packager/helm/zarf.go index 0381ef4b52..8706fe2711 100644 --- a/src/internal/packager/helm/zarf.go +++ b/src/internal/packager/helm/zarf.go @@ -45,7 +45,7 @@ func (h *Helm) UpdateZarfRegistryValues(ctx context.Context) error { Namespace: "zarf", ReleaseName: "zarf-docker-registry", } - err = h.UpdateReleaseValues(registryValues) + err = h.UpdateReleaseValues(ctx, registryValues) if err != nil { return fmt.Errorf("error updating the release values: %w", err) } @@ -119,7 +119,7 @@ func (h *Helm) UpdateZarfAgentValues(ctx context.Context) error { } h.variableConfig.SetApplicationTemplates(applicationTemplates) - err = h.UpdateReleaseValues(map[string]interface{}{}) + err = h.UpdateReleaseValues(ctx, map[string]interface{}{}) if err != nil { return fmt.Errorf("error updating the release values: %w", err) } diff --git a/src/pkg/packager/deploy.go b/src/pkg/packager/deploy.go index 5c174a684f..73aec8f006 100644 --- a/src/pkg/packager/deploy.go +++ b/src/pkg/packager/deploy.go @@ -352,7 +352,7 @@ func (p *Packager) deployComponent(ctx context.Context, component types.ZarfComp } if hasCharts || hasManifests { - if charts, err = p.installChartAndManifests(componentPath, component); err != nil { + if charts, err = p.installChartAndManifests(ctx, componentPath, component); err != nil { return charts, err } } @@ -610,7 +610,7 @@ func (p *Packager) generateValuesOverrides(chart types.ZarfChart, componentName } // Install all Helm charts and raw k8s manifests into the k8s cluster. -func (p *Packager) installChartAndManifests(componentPaths *layout.ComponentPaths, component types.ZarfComponent) (installedCharts []types.InstalledChart, err error) { +func (p *Packager) installChartAndManifests(ctx context.Context, componentPaths *layout.ComponentPaths, component types.ZarfComponent) (installedCharts []types.InstalledChart, err error) { for _, chart := range component.Charts { // Do not wait for the chart to be ready if data injections are present. if len(component.DataInjections) > 0 { @@ -646,7 +646,7 @@ func (p *Packager) installChartAndManifests(componentPaths *layout.ComponentPath p.cfg.PkgOpts.Retries), ) - addedConnectStrings, installedChartName, err := helmCfg.InstallOrUpgradeChart() + addedConnectStrings, installedChartName, err := helmCfg.InstallOrUpgradeChart(ctx) if err != nil { return installedCharts, err } @@ -699,7 +699,7 @@ func (p *Packager) installChartAndManifests(componentPaths *layout.ComponentPath } // Install the chart. - addedConnectStrings, installedChartName, err := helmCfg.InstallOrUpgradeChart() + addedConnectStrings, installedChartName, err := helmCfg.InstallOrUpgradeChart(ctx) if err != nil { return installedCharts, err } diff --git a/src/pkg/packager/prepare.go b/src/pkg/packager/prepare.go index 340ac1c85a..2b888c3966 100644 --- a/src/pkg/packager/prepare.go +++ b/src/pkg/packager/prepare.go @@ -185,7 +185,7 @@ func (p *Packager) findImages(ctx context.Context) (imgMap map[string][]string, } // Generate helm templates for this chart - chartTemplate, chartValues, err := helmCfg.TemplateChart() + chartTemplate, chartValues, err := helmCfg.TemplateChart(ctx) if err != nil { message.WarnErrf(err, "Problem rendering the helm template for %s: %s", chart.Name, err.Error()) erroredCharts = append(erroredCharts, chart.Name) From 437e63ce6ac54b2c71ca4d837647646230c1500a Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Wed, 24 Jul 2024 18:13:34 -0600 Subject: [PATCH 03/11] fix(deps): update github.com/anchore/clio digest to ac88e09 (#2527) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- go.mod | 12 ++++++------ go.sum | 24 ++++++++++++------------ 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/go.mod b/go.mod index 9bf35fbbba..d69363783f 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,7 @@ require ( github.com/AlecAivazis/survey/v2 v2.3.7 github.com/Masterminds/semver/v3 v3.2.1 github.com/agnivade/levenshtein v1.1.1 - github.com/anchore/clio v0.0.0-20240408173007-3c4abf89e72f + github.com/anchore/clio v0.0.0-20240705045624-ac88e09ad9d0 github.com/anchore/stereoscope v0.0.1 github.com/anchore/syft v0.100.0 github.com/defenseunicorns/pkg/helpers/v2 v2.0.1 @@ -40,14 +40,14 @@ require ( github.com/sigstore/sigstore/pkg/signature/kms/azure v1.8.1 github.com/sigstore/sigstore/pkg/signature/kms/gcp v1.8.1 github.com/sigstore/sigstore/pkg/signature/kms/hashivault v1.8.1 - github.com/spf13/cobra v1.8.0 + github.com/spf13/cobra v1.8.1 github.com/spf13/pflag v1.0.5 github.com/spf13/viper v1.18.2 github.com/stretchr/testify v1.9.0 github.com/xeipuuv/gojsonschema v1.2.0 golang.org/x/crypto v0.24.0 golang.org/x/sync v0.7.0 - golang.org/x/term v0.21.0 + golang.org/x/term v0.22.0 helm.sh/helm/v3 v3.14.2 k8s.io/api v0.30.0 k8s.io/apimachinery v0.30.0 @@ -132,7 +132,7 @@ require ( github.com/alibabacloud-go/tea-xml v1.1.3 // indirect github.com/aliyun/credentials-go v1.3.1 // indirect github.com/anchore/bubbly v0.0.0-20231115134915-def0aba654a9 // indirect - github.com/anchore/fangs v0.0.0-20231201140849-5075d28d6d8b // indirect + github.com/anchore/fangs v0.0.0-20240508143433-f016b099950f // indirect github.com/anchore/go-logger v0.0.0-20230725134548-c21dafa1ec5a // indirect github.com/anchore/go-macholibre v0.0.0-20220308212642-53e6d0aaf6fb // indirect github.com/anchore/go-struct-converter v0.0.0-20221118182256-c68fdcfa2092 // indirect @@ -199,7 +199,7 @@ require ( github.com/containerd/ttrpc v1.2.2 // indirect github.com/containerd/typeurl/v2 v2.1.1 // indirect github.com/coreos/go-oidc/v3 v3.9.0 // indirect - github.com/cpuguy83/go-md2man/v2 v2.0.3 // indirect + github.com/cpuguy83/go-md2man/v2 v2.0.4 // indirect github.com/cyberphone/json-canonicalization v0.0.0-20231011164504-785e29786b46 // indirect github.com/cyphar/filepath-securejoin v0.2.4 // indirect github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect @@ -483,7 +483,7 @@ require ( golang.org/x/mod v0.17.0 // indirect golang.org/x/net v0.26.0 // indirect golang.org/x/oauth2 v0.21.0 // indirect - golang.org/x/sys v0.21.0 // indirect + golang.org/x/sys v0.22.0 // indirect golang.org/x/text v0.16.0 // indirect golang.org/x/time v0.5.0 // indirect golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect diff --git a/go.sum b/go.sum index 27f7af4f00..a0be8e7f61 100644 --- a/go.sum +++ b/go.sum @@ -372,10 +372,10 @@ github.com/aliyun/credentials-go v1.3.1 h1:uq/0v7kWrxmoLGpqjx7vtQ/s03f0zR//0br/x github.com/aliyun/credentials-go v1.3.1/go.mod h1:8jKYhQuDawt8x2+fusqa1Y6mPxemTsBEN04dgcAcYz0= github.com/anchore/bubbly v0.0.0-20231115134915-def0aba654a9 h1:p0ZIe0htYOX284Y4axJaGBvXHU0VCCzLN5Wf5XbKStU= github.com/anchore/bubbly v0.0.0-20231115134915-def0aba654a9/go.mod h1:3ZsFB9tzW3vl4gEiUeuSOMDnwroWxIxJelOOHUp8dSw= -github.com/anchore/clio v0.0.0-20240408173007-3c4abf89e72f h1:2xJPf4KWzxFDwZK/yax+h8QHP2Gnn4fgXUCCeizhbyU= -github.com/anchore/clio v0.0.0-20240408173007-3c4abf89e72f/go.mod h1:1k7cwq2CeVH9dgAl0X/JBBfJ4y/E8h2R9KqByDkrCA4= -github.com/anchore/fangs v0.0.0-20231201140849-5075d28d6d8b h1:L/djgY7ZbZ/38+wUtdkk398W3PIBJLkt1N8nU/7e47A= -github.com/anchore/fangs v0.0.0-20231201140849-5075d28d6d8b/go.mod h1:TLcE0RE5+8oIx2/NPWem/dq1DeaMoC+fPEH7hoSzPLo= +github.com/anchore/clio v0.0.0-20240705045624-ac88e09ad9d0 h1:rtO6Bcc5KX1i6Ndj4pFcFUkE5PaiKv0J4hKSlmbEIXQ= +github.com/anchore/clio v0.0.0-20240705045624-ac88e09ad9d0/go.mod h1:U3M+opzBUkSBUIRUXsQj6ZgrX9i7Nn0YLn4CjmhKMNI= +github.com/anchore/fangs v0.0.0-20240508143433-f016b099950f h1:NOhzafCyNYFi88qxkBFjMzQo4dRa1vDhBzx+0Uovx8Q= +github.com/anchore/fangs v0.0.0-20240508143433-f016b099950f/go.mod h1:sVpRS2yNCw6tLVpvA1QSDVWTJVpCuAm8JNZgn4Sjz/k= github.com/anchore/go-logger v0.0.0-20230725134548-c21dafa1ec5a h1:nJ2G8zWKASyVClGVgG7sfM5mwoZlZ2zYpIzN2OhjWkw= github.com/anchore/go-logger v0.0.0-20230725134548-c21dafa1ec5a/go.mod h1:ubLFmlsv8/DFUQrZwY5syT5/8Er3ugSr4rDFwHsE3hg= github.com/anchore/go-macholibre v0.0.0-20220308212642-53e6d0aaf6fb h1:iDMnx6LIjtjZ46C0akqveX83WFzhpTD3eqOthawb5vU= @@ -578,8 +578,8 @@ github.com/coreos/go-systemd/v22 v22.5.0 h1:RrqgGjYQKalulkV8NGVIfkXQf6YYmOyiJKk8 github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= github.com/cpuguy83/go-md2man/v2 v2.0.1/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= -github.com/cpuguy83/go-md2man/v2 v2.0.3 h1:qMCsGGgs+MAzDFyp9LpAe1Lqy/fY/qCovCm0qnXZOBM= -github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= +github.com/cpuguy83/go-md2man/v2 v2.0.4 h1:wfIWP927BUkWJb2NmU/kNDYIBTh/ziUX91+lVfRxZq4= +github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/creack/pty v1.1.17/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr4O4= github.com/creack/pty v1.1.21 h1:1/QdRyBaHHJP61QkWMXlOIBfsgdDeeKfK8SYVUWJKf0= github.com/creack/pty v1.1.21/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr4O4= @@ -1584,8 +1584,8 @@ github.com/spf13/cast v1.4.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkU github.com/spf13/cast v1.6.0 h1:GEiTHELF+vaR5dhz3VqZfFSzZjYbgeKDpBxQVS4GYJ0= github.com/spf13/cast v1.6.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo= github.com/spf13/cobra v1.3.0/go.mod h1:BrRVncBjOJa/eUcVVm9CE+oC6as8k+VYr4NY7WCi9V4= -github.com/spf13/cobra v1.8.0 h1:7aJaZx1B85qltLMc546zn58BxxfZdR/W22ej9CFoEf0= -github.com/spf13/cobra v1.8.0/go.mod h1:WXLWApfZ71AjXPya3WOlMsY9yMs7YeiHhFVlvLyhcho= +github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM= +github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y= github.com/spf13/jwalterweatherman v1.1.0/go.mod h1:aNWZUN0dPAAO/Ljvb5BEdw96iTZ0EXowPYD95IqWIGo= github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= @@ -2067,8 +2067,8 @@ golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.9.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws= -golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI= +golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= @@ -2082,8 +2082,8 @@ golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U= golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo= golang.org/x/term v0.9.0/go.mod h1:M6DEAAIenWoTxdKrOltXcmDY3rSplQUkrvaDU5FcQyo= golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk= -golang.org/x/term v0.21.0 h1:WVXCp+/EBEHOj53Rvu+7KiT/iElMrO8ACK16SMZ3jaA= -golang.org/x/term v0.21.0/go.mod h1:ooXLefLobQVslOqselCNF4SxFAaoS6KujMbsGzSDmX0= +golang.org/x/term v0.22.0 h1:BbsgPEJULsl2fV/AT3v15Mjva5yXKQDyKf+TbDz7QJk= +golang.org/x/term v0.22.0/go.mod h1:F3qCibpT5AMpCRfhfT53vVJwhLtIVHhB9XDjfFvnMI4= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= From b96446752706a9ffa4f02b0fcec6f657141f384d Mon Sep 17 00:00:00 2001 From: Philip Laine Date: Thu, 25 Jul 2024 10:21:45 +0200 Subject: [PATCH 04/11] refactor: add error handling to view SBOM files (#2752) Signed-off-by: Philip Laine --- src/internal/packager/sbom/tools.go | 43 ++++++++++++++++------------- src/pkg/packager/creator/normal.go | 5 +++- src/pkg/packager/inspect.go | 5 +++- 3 files changed, 32 insertions(+), 21 deletions(-) diff --git a/src/internal/packager/sbom/tools.go b/src/internal/packager/sbom/tools.go index 60aa998958..972b709906 100644 --- a/src/internal/packager/sbom/tools.go +++ b/src/internal/packager/sbom/tools.go @@ -14,26 +14,31 @@ import ( ) // ViewSBOMFiles opens a browser to view the SBOM files and pauses for user input. -func ViewSBOMFiles(directory string) { - sbomViewFiles, _ := filepath.Glob(filepath.Join(directory, "sbom-viewer-*")) - - if len(sbomViewFiles) > 0 { - link := sbomViewFiles[0] - msg := fmt.Sprintf("This package has %d images with software bill-of-materials (SBOM) included. If your browser did not open automatically you can copy and paste this file location into your browser address bar to view them: %s\n\n", len(sbomViewFiles), link) - message.Note(msg) - - if err := exec.LaunchURL(link); err != nil { - message.Debug(err) - } +func ViewSBOMFiles(directory string) error { + sbomViewFiles, err := filepath.Glob(filepath.Join(directory, "sbom-viewer-*")) + if err != nil { + return err + } - // Use survey.Input to hang until user input - var value string - prompt := &survey.Input{ - Message: "Hit the 'enter' key when you are done viewing the SBOM files", - Default: "", - } - _ = survey.AskOne(prompt, &value) - } else { + if len(sbomViewFiles) == 0 { message.Note("There were no images with software bill-of-materials (SBOM) included.") + return nil + } + + link := sbomViewFiles[0] + msg := fmt.Sprintf("This package has %d images with software bill-of-materials (SBOM) included. If your browser did not open automatically you can copy and paste this file location into your browser address bar to view them: %s\n\n", len(sbomViewFiles), link) + message.Note(msg) + if err := exec.LaunchURL(link); err != nil { + return err + } + var value string + prompt := &survey.Input{ + Message: "Hit the 'enter' key when you are done viewing the SBOM files", + Default: "", + } + err = survey.AskOne(prompt, &value) + if err != nil { + return err } + return nil } diff --git a/src/pkg/packager/creator/normal.go b/src/pkg/packager/creator/normal.go index 3b34b7e846..52baa708e4 100644 --- a/src/pkg/packager/creator/normal.go +++ b/src/pkg/packager/creator/normal.go @@ -321,7 +321,10 @@ func (pc *PackageCreator) Output(ctx context.Context, dst *layout.PackagePaths, } if pc.createOpts.ViewSBOM { - sbom.ViewSBOMFiles(sbomDir) + err := sbom.ViewSBOMFiles(sbomDir) + if err != nil { + return err + } } } return nil diff --git a/src/pkg/packager/inspect.go b/src/pkg/packager/inspect.go index bfa29d860b..88b1de88d8 100644 --- a/src/pkg/packager/inspect.go +++ b/src/pkg/packager/inspect.go @@ -47,7 +47,10 @@ func (p *Packager) Inspect(ctx context.Context) (err error) { } if p.cfg.InspectOpts.ViewSBOM { - sbom.ViewSBOMFiles(sbomDir) + err := sbom.ViewSBOMFiles(sbomDir) + if err != nil { + return err + } } return nil From 5058a673bef1496195afd9e193a64030df6f28ba Mon Sep 17 00:00:00 2001 From: Austin Abro <37223396+AustinAbro321@users.noreply.github.com> Date: Thu, 25 Jul 2024 04:44:50 -0400 Subject: [PATCH 05/11] feat: annotate image mutation (#2755) Signed-off-by: Austin Abro Signed-off-by: Philip Laine Co-authored-by: Philip Laine --- src/internal/agent/hooks/pods.go | 16 ++++++++++++++++ src/internal/agent/hooks/pods_test.go | 22 +++++++++++++++++++--- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/src/internal/agent/hooks/pods.go b/src/internal/agent/hooks/pods.go index 1eaccb5fbb..60362785a5 100644 --- a/src/internal/agent/hooks/pods.go +++ b/src/internal/agent/hooks/pods.go @@ -20,6 +20,8 @@ import ( corev1 "k8s.io/api/core/v1" ) +const annotationPrefix = "zarf.dev" + // NewPodMutationHook creates a new instance of pods mutation hook. func NewPodMutationHook(ctx context.Context, cluster *cluster.Cluster) operations.Hook { return operations.Hook{ @@ -40,6 +42,10 @@ func parsePod(object []byte) (*corev1.Pod, error) { return &pod, nil } +func getImageAnnotationKey(containerName string) string { + return fmt.Sprintf("%s/original-image-%s", annotationPrefix, containerName) +} + func mutatePod(ctx context.Context, r *v1.AdmissionRequest, cluster *cluster.Cluster) (*operations.Result, error) { pod, err := parsePod(r.Object.Raw) if err != nil { @@ -66,6 +72,11 @@ func mutatePod(ctx context.Context, r *v1.AdmissionRequest, cluster *cluster.Clu zarfSecret := []corev1.LocalObjectReference{{Name: config.ZarfImagePullSecretName}} patches = append(patches, operations.ReplacePatchOperation("/spec/imagePullSecrets", zarfSecret)) + updatedAnnotations := pod.Annotations + if updatedAnnotations == nil { + updatedAnnotations = make(map[string]string) + } + // update the image host for each init container for idx, container := range pod.Spec.InitContainers { path := fmt.Sprintf("/spec/initContainers/%d/image", idx) @@ -74,6 +85,7 @@ func mutatePod(ctx context.Context, r *v1.AdmissionRequest, cluster *cluster.Clu message.Warnf(lang.AgentErrImageSwap, container.Image) continue // Continue, because we might as well attempt to mutate the other containers for this pod } + updatedAnnotations[getImageAnnotationKey(container.Name)] = container.Image patches = append(patches, operations.ReplacePatchOperation(path, replacement)) } @@ -85,6 +97,7 @@ func mutatePod(ctx context.Context, r *v1.AdmissionRequest, cluster *cluster.Clu message.Warnf(lang.AgentErrImageSwap, container.Image) continue // Continue, because we might as well attempt to mutate the other containers for this pod } + updatedAnnotations[getImageAnnotationKey(container.Name)] = container.Image patches = append(patches, operations.ReplacePatchOperation(path, replacement)) } @@ -96,11 +109,14 @@ func mutatePod(ctx context.Context, r *v1.AdmissionRequest, cluster *cluster.Clu message.Warnf(lang.AgentErrImageSwap, container.Image) continue // Continue, because we might as well attempt to mutate the other containers for this pod } + updatedAnnotations[getImageAnnotationKey(container.Name)] = container.Image patches = append(patches, operations.ReplacePatchOperation(path, replacement)) } patches = append(patches, getLabelPatch(pod.Labels)) + patches = append(patches, operations.ReplacePatchOperation("/metadata/annotations", updatedAnnotations)) + return &operations.Result{ Allowed: true, PatchOps: patches, diff --git a/src/internal/agent/hooks/pods_test.go b/src/internal/agent/hooks/pods_test.go index dafa786f8c..60bd09d0f5 100644 --- a/src/internal/agent/hooks/pods_test.go +++ b/src/internal/agent/hooks/pods_test.go @@ -50,11 +50,12 @@ func TestPodMutationWebhook(t *testing.T) { Annotations: map[string]string{"should-be": "mutated"}, }, Spec: corev1.PodSpec{ - Containers: []corev1.Container{{Image: "nginx"}}, - InitContainers: []corev1.Container{{Image: "busybox"}}, + Containers: []corev1.Container{{Name: "nginx", Image: "nginx"}}, + InitContainers: []corev1.Container{{Name: "different", Image: "busybox"}}, EphemeralContainers: []corev1.EphemeralContainer{ { EphemeralContainerCommon: corev1.EphemeralContainerCommon{ + Name: "alpine", Image: "alpine", }, }, @@ -85,6 +86,15 @@ func TestPodMutationWebhook(t *testing.T) { "should-be": "mutated", }, ), + operations.ReplacePatchOperation( + "/metadata/annotations", + map[string]string{ + "zarf.dev/original-image-nginx": "nginx", + "zarf.dev/original-image-alpine": "alpine", + "zarf.dev/original-image-different": "busybox", + "should-be": "mutated", + }, + ), }, code: http.StatusOK, }, @@ -108,7 +118,7 @@ func TestPodMutationWebhook(t *testing.T) { Labels: nil, }, Spec: corev1.PodSpec{ - Containers: []corev1.Container{{Image: "nginx"}}, + Containers: []corev1.Container{{Name: "nginx", Image: "nginx"}}, }, }), patch: []operations.PatchOperation{ @@ -124,6 +134,12 @@ func TestPodMutationWebhook(t *testing.T) { "/metadata/labels", map[string]string{"zarf-agent": "patched"}, ), + operations.ReplacePatchOperation( + "/metadata/annotations", + map[string]string{ + "zarf.dev/original-image-nginx": "nginx", + }, + ), }, code: http.StatusOK, }, From 049fe2e110f16b050e1ebf6eb239e831b3275ee4 Mon Sep 17 00:00:00 2001 From: schristoff <28318173+schristoff@users.noreply.github.com> Date: Thu, 25 Jul 2024 02:50:59 -0600 Subject: [PATCH 06/11] chore: move context.TODO to context.Background() (2) (#2746) Signed-off-by: schristoff-du <167717759+schristoff-du@users.noreply.github.com> Co-authored-by: schristoff-du <167717759+schristoff-du@users.noreply.github.com> --- src/pkg/utils/exec/exec.go | 8 ++++ src/test/common.go | 11 ++--- src/test/e2e/00_use_cli_test.go | 44 ++++++++--------- src/test/e2e/01_component_choice_test.go | 6 +-- src/test/e2e/02_component_actions_test.go | 20 ++++---- src/test/e2e/03_deprecations_test.go | 14 +++--- src/test/e2e/04_create_templating_test.go | 10 ++-- src/test/e2e/05_tarball_test.go | 12 ++--- src/test/e2e/06_create_sbom_test.go | 10 ++-- src/test/e2e/07_create_git_test.go | 2 +- src/test/e2e/08_create_differential_test.go | 6 +-- src/test/e2e/09_component_compose_test.go | 6 +-- src/test/e2e/10_component_flavor_test.go | 8 ++-- src/test/e2e/11_oci_pull_inspect_test.go | 10 ++-- src/test/e2e/12_lint_test.go | 4 +- src/test/e2e/13_find_images_test.go | 16 +++---- src/test/e2e/13_zarf_package_generate_test.go | 2 +- src/test/e2e/14_create_sha_index_test.go | 2 +- src/test/e2e/20_zarf_init_test.go | 48 +++++++++---------- src/test/e2e/21_connect_creds_test.go | 14 +++--- src/test/e2e/22_git_and_gitops_test.go | 30 ++++++------ src/test/e2e/23_data_injection_test.go | 8 ++-- src/test/e2e/24_variables_test.go | 16 +++---- src/test/e2e/25_helm_test.go | 46 +++++++++--------- src/test/e2e/26_simple_packages_test.go | 16 +++---- src/test/e2e/27_deploy_regression_test.go | 9 ++-- src/test/e2e/28_wait_test.go | 12 ++--- src/test/e2e/29_config_file_test.go | 18 +++---- .../e2e/30_component_action_cluster_test.go | 8 ++-- .../e2e/31_checksum_and_signature_test.go | 12 ++--- src/test/e2e/32_component_webhooks_test.go | 16 +++---- src/test/e2e/33_manifest_with_symlink_test.go | 4 +- src/test/e2e/34_custom_init_package_test.go | 10 ++-- src/test/e2e/35_custom_retries_test.go | 6 +-- src/test/e2e/50_oci_publish_deploy_test.go | 22 ++++----- src/test/e2e/51_oci_compose_test.go | 26 +++++----- src/test/e2e/99_appliance_remove_test.go | 10 ++-- src/test/e2e/99_yolo_test.go | 10 ++-- src/test/external/common.go | 3 +- src/test/external/ext_in_cluster_test.go | 2 +- src/test/nightly/ecr_publish_test.go | 12 ++--- src/test/upgrade/previously_built_test.go | 37 +++++++------- 42 files changed, 295 insertions(+), 291 deletions(-) diff --git a/src/pkg/utils/exec/exec.go b/src/pkg/utils/exec/exec.go index 40b4023d50..a3957edd31 100644 --- a/src/pkg/utils/exec/exec.go +++ b/src/pkg/utils/exec/exec.go @@ -15,6 +15,7 @@ import ( "runtime" "strings" "sync" + "testing" ) // Config is a struct for configuring the Cmd function. @@ -50,6 +51,13 @@ func CmdWithPrint(command string, args ...string) error { return err } +// CmdWithTesting takes a *testing.T and generates a context the cancels on cleanup +func CmdWithTesting(t *testing.T, config Config, command string, args ...string) (string, string, error) { + ctx, cancel := context.WithCancel(context.Background()) + t.Cleanup(cancel) + return CmdWithContext(ctx, config, command, args...) +} + // CmdWithContext executes a given command with given config. func CmdWithContext(ctx context.Context, config Config, command string, args ...string) (string, string, error) { if command == "" { diff --git a/src/test/common.go b/src/test/common.go index 0339fe0f48..c75e71ec7c 100644 --- a/src/test/common.go +++ b/src/test/common.go @@ -6,7 +6,6 @@ package test import ( "bufio" - "context" "fmt" "os" "regexp" @@ -53,7 +52,7 @@ func GetCLIName() string { } // Zarf executes a Zarf command. -func (e2e *ZarfE2ETest) Zarf(args ...string) (string, string, error) { +func (e2e *ZarfE2ETest) Zarf(t *testing.T, args ...string) (string, string, error) { if !slices.Contains(args, "--tmpdir") && !slices.Contains(args, "tools") { tmpdir, err := os.MkdirTemp("", "zarf-") if err != nil { @@ -76,14 +75,14 @@ func (e2e *ZarfE2ETest) Zarf(args ...string) (string, string, error) { args = append(args, "--zarf-cache", cacheDir) defer os.RemoveAll(cacheDir) } - return exec.CmdWithContext(context.TODO(), exec.PrintCfg(), e2e.ZarfBinPath, args...) + return exec.CmdWithTesting(t, exec.PrintCfg(), e2e.ZarfBinPath, args...) } // Kubectl executes `zarf tools kubectl ...` -func (e2e *ZarfE2ETest) Kubectl(args ...string) (string, string, error) { +func (e2e *ZarfE2ETest) Kubectl(t *testing.T, args ...string) (string, string, error) { tk := []string{"tools", "kubectl"} args = append(tk, args...) - return e2e.Zarf(args...) + return e2e.Zarf(t, args...) } // CleanFiles removes files and directories that have been created during the test. @@ -132,7 +131,7 @@ func (e2e *ZarfE2ETest) TeardownRegistry(t *testing.T, port int) { // GetZarfVersion returns the current build/zarf version func (e2e *ZarfE2ETest) GetZarfVersion(t *testing.T) string { // Get the version of the CLI - stdOut, stdErr, err := e2e.Zarf("version") + stdOut, stdErr, err := e2e.Zarf(t, "version") require.NoError(t, err, stdOut, stdErr) return strings.Trim(stdOut, "\n") } diff --git a/src/test/e2e/00_use_cli_test.go b/src/test/e2e/00_use_cli_test.go index 93c5778c0c..ff8a07106b 100644 --- a/src/test/e2e/00_use_cli_test.go +++ b/src/test/e2e/00_use_cli_test.go @@ -35,7 +35,7 @@ func TestUseCLI(t *testing.T) { err := os.WriteFile(shasumTestFilePath, []byte("random test data 🦄\n"), helpers.ReadWriteUser) require.NoError(t, err) - stdOut, stdErr, err := e2e.Zarf("prepare", "sha256sum", shasumTestFilePath) + stdOut, stdErr, err := e2e.Zarf(t, "prepare", "sha256sum", shasumTestFilePath) require.NoError(t, err, stdOut, stdErr) require.Equal(t, expectedShasum, stdOut, "The expected SHASUM should equal the actual SHASUM") }) @@ -45,7 +45,7 @@ func TestUseCLI(t *testing.T) { // Test `zarf prepare sha256sum` for a remote asset expectedShasum := "c3cdea0573ba5a058ec090b5d2683bf398e8b1614c37ec81136ed03b78167617\n" - stdOut, stdErr, err := e2e.Zarf("prepare", "sha256sum", "https://zarf-public.s3-us-gov-west-1.amazonaws.com/pipelines/zarf-prepare-shasum-remote-test-file.txt") + stdOut, stdErr, err := e2e.Zarf(t, "prepare", "sha256sum", "https://zarf-public.s3-us-gov-west-1.amazonaws.com/pipelines/zarf-prepare-shasum-remote-test-file.txt") require.NoError(t, err, stdOut, stdErr) require.Contains(t, stdOut, expectedShasum, "The expected SHASUM should equal the actual SHASUM") }) @@ -53,19 +53,19 @@ func TestUseCLI(t *testing.T) { t.Run("zarf version", func(t *testing.T) { t.Parallel() // Test `zarf version` - version, _, err := e2e.Zarf("version") + version, _, err := e2e.Zarf(t, "version") require.NoError(t, err) require.NotEmpty(t, version, "Zarf version should not be an empty string") version = strings.Trim(version, "\n") // test `zarf version --output=json` - stdOut, _, err := e2e.Zarf("version", "--output=json") + stdOut, _, err := e2e.Zarf(t, "version", "--output=json") require.NoError(t, err) jsonVersion := fmt.Sprintf(",\"version\":\"%s\"}", version) require.Contains(t, stdOut, jsonVersion, "Zarf version should be the same in all formats") // test `zarf version --output=yaml` - stdOut, _, err = e2e.Zarf("version", "--output=yaml") + stdOut, _, err = e2e.Zarf(t, "version", "--output=yaml") require.NoError(t, err) yamlVersion := fmt.Sprintf("version: %s", version) require.Contains(t, stdOut, yamlVersion, "Zarf version should be the same in all formats") @@ -75,23 +75,23 @@ func TestUseCLI(t *testing.T) { t.Parallel() // Test for expected failure when given a bad component input path := fmt.Sprintf("build/zarf-package-component-actions-%s.tar.zst", e2e.Arch) - _, _, err := e2e.Zarf("package", "deploy", path, "--components=on-create,foo,git-server", "--confirm") + _, _, err := e2e.Zarf(t, "package", "deploy", path, "--components=on-create,foo,git-server", "--confirm") require.Error(t, err) }) t.Run("zarf deploy should return a warning when no components are deployed", func(t *testing.T) { t.Parallel() - _, _, err := e2e.Zarf("package", "create", "src/test/packages/00-no-components", "-o=build", "--confirm") + _, _, err := e2e.Zarf(t, "package", "create", "src/test/packages/00-no-components", "-o=build", "--confirm") require.NoError(t, err) path := fmt.Sprintf("build/zarf-package-no-components-%s.tar.zst", e2e.Arch) // Test that excluding all components with a leading dash results in a warning - _, stdErr, err := e2e.Zarf("package", "deploy", path, "--components=-deselect-me", "--confirm") + _, stdErr, err := e2e.Zarf(t, "package", "deploy", path, "--components=-deselect-me", "--confirm") require.NoError(t, err) require.Contains(t, stdErr, "No components were selected for deployment") // Test that excluding still works even if a wildcard is given - _, stdErr, err = e2e.Zarf("package", "deploy", path, "--components=*,-deselect-me", "--confirm") + _, stdErr, err = e2e.Zarf(t, "package", "deploy", path, "--components=*,-deselect-me", "--confirm") require.NoError(t, err) require.NotContains(t, stdErr, "DESELECT-ME COMPONENT") }) @@ -99,13 +99,13 @@ func TestUseCLI(t *testing.T) { t.Run("changing log level", func(t *testing.T) { t.Parallel() // Test that changing the log level actually applies the requested level - _, stdErr, _ := e2e.Zarf("internal", "crc32", "zarf", "--log-level=debug") + _, stdErr, _ := e2e.Zarf(t, "internal", "crc32", "zarf", "--log-level=debug") expectedOutString := "Log level set to debug" require.Contains(t, stdErr, expectedOutString, "The log level should be changed to 'debug'") }) t.Run("zarf package to test bad remote images", func(t *testing.T) { - _, stdErr, err := e2e.Zarf("package", "create", "src/test/packages/00-remote-pull-fail", "--confirm") + _, stdErr, err := e2e.Zarf(t, "package", "create", "src/test/packages/00-remote-pull-fail", "--confirm") // expecting zarf to have an error and output to stderr require.Error(t, err) // Make sure we print the get request error (only look for GET since the actual error changes based on login status) @@ -116,11 +116,11 @@ func TestUseCLI(t *testing.T) { t.Run("zarf package to test archive path", func(t *testing.T) { t.Parallel() - stdOut, stdErr, err := e2e.Zarf("package", "create", "packages/distros/eks", "--confirm") + stdOut, stdErr, err := e2e.Zarf(t, "package", "create", "packages/distros/eks", "--confirm") require.NoError(t, err, stdOut, stdErr) path := fmt.Sprintf("zarf-package-distro-eks-%s-0.0.3.tar.zst", e2e.Arch) - stdOut, stdErr, err = e2e.Zarf("package", "deploy", path, "--confirm") + stdOut, stdErr, err = e2e.Zarf(t, "package", "deploy", path, "--confirm") require.NoError(t, err, stdOut, stdErr) require.FileExists(t, "binaries/eksctl_Darwin_x86_64") @@ -134,7 +134,7 @@ func TestUseCLI(t *testing.T) { t.Parallel() tmpdir := t.TempDir() cacheDir := filepath.Join(t.TempDir(), ".cache-location") - stdOut, stdErr, err := e2e.Zarf("package", "create", "examples/dos-games", "--zarf-cache", cacheDir, "--tmpdir", tmpdir, "--log-level=debug", "-o=build", "--confirm") + stdOut, stdErr, err := e2e.Zarf(t, "package", "create", "examples/dos-games", "--zarf-cache", cacheDir, "--tmpdir", tmpdir, "--log-level=debug", "-o=build", "--confirm") require.Contains(t, stdErr, tmpdir, "The other tmp path should show as being created") require.NoError(t, err, stdOut, stdErr) @@ -147,7 +147,7 @@ func TestUseCLI(t *testing.T) { t.Parallel() path := fmt.Sprintf("build/zarf-package-component-actions-%s.tar.zst", e2e.Arch) tmpdir := t.TempDir() - stdOut, stdErr, err := e2e.Zarf("package", "inspect", path, "--tmpdir", tmpdir, "--log-level=debug") + stdOut, stdErr, err := e2e.Zarf(t, "package", "inspect", path, "--tmpdir", tmpdir, "--log-level=debug") require.Contains(t, stdErr, tmpdir, "The other tmp path should show as being created") require.NoError(t, err, stdOut, stdErr) }) @@ -164,7 +164,7 @@ func TestUseCLI(t *testing.T) { e2e.CleanFiles(firstFile, secondFile) }) path := fmt.Sprintf("build/zarf-package-component-choice-%s.tar.zst", e2e.Arch) - stdOut, stdErr, err := e2e.Zarf("package", "deploy", path, "--tmpdir", tmpdir, "--log-level=debug", "--confirm") + stdOut, stdErr, err := e2e.Zarf(t, "package", "deploy", path, "--tmpdir", tmpdir, "--log-level=debug", "--confirm") require.Contains(t, stdErr, tmpdir, "The other tmp path should show as being created") require.NoError(t, err, stdOut, stdErr) }) @@ -174,7 +174,7 @@ func TestUseCLI(t *testing.T) { tmpdir := t.TempDir() // Test removal of cache cachePath := filepath.Join(tmpdir, ".cache-location") - stdOut, stdErr, err := e2e.Zarf("tools", "clear-cache", "--zarf-cache", cachePath) + stdOut, stdErr, err := e2e.Zarf(t, "tools", "clear-cache", "--zarf-cache", cachePath) require.NoError(t, err, stdOut, stdErr) // Check that ReadDir returns no such file or directory for the cachePath _, err = os.ReadDir(cachePath) @@ -196,7 +196,7 @@ func TestUseCLI(t *testing.T) { t.Cleanup(func() { e2e.CleanFiles(tlsCA, tlsCert, tlsKey) }) - stdOut, stdErr, err := e2e.Zarf("tools", "gen-pki", "github.com", "--sub-alt-name", "google.com") + stdOut, stdErr, err := e2e.Zarf(t, "tools", "gen-pki", "github.com", "--sub-alt-name", "google.com") require.NoError(t, err, stdOut, stdErr) require.Contains(t, stdErr, "Successfully created a chain of trust for github.com") @@ -225,16 +225,16 @@ func TestUseCLI(t *testing.T) { require.NoError(t, err) // Test that yq can eval properly - _, stdErr, err := e2e.Zarf("tools", "yq", "eval", "-i", `.items[1].name = "renamed-item"`, file) + _, stdErr, err := e2e.Zarf(t, "tools", "yq", "eval", "-i", `.items[1].name = "renamed-item"`, file) require.NoError(t, err, stdErr) - stdOut, _, err := e2e.Zarf("tools", "yq", ".items[1].name", file) + stdOut, _, err := e2e.Zarf(t, "tools", "yq", ".items[1].name", file) require.NoError(t, err) require.Contains(t, stdOut, "renamed-item") // Test that yq ea can be used properly - _, _, err = e2e.Zarf("tools", "yq", "eval-all", "-i", `. as $doc ireduce ({}; .items += $doc.items)`, file, otherFile) + _, _, err = e2e.Zarf(t, "tools", "yq", "eval-all", "-i", `. as $doc ireduce ({}; .items += $doc.items)`, file, otherFile) require.NoError(t, err) - stdOut, _, err = e2e.Zarf("tools", "yq", "e", ".items | length", file) + stdOut, _, err = e2e.Zarf(t, "tools", "yq", "e", ".items | length", file) require.NoError(t, err) require.Equal(t, "4\n", stdOut) }) diff --git a/src/test/e2e/01_component_choice_test.go b/src/test/e2e/01_component_choice_test.go index 8930094f24..8668586956 100644 --- a/src/test/e2e/01_component_choice_test.go +++ b/src/test/e2e/01_component_choice_test.go @@ -26,11 +26,11 @@ func TestComponentChoice(t *testing.T) { // Try to deploy both and expect failure due to only one component allowed at a time // We currently don't have a pattern to actually test the interactive prompt, so just testing automation for now - stdOut, stdErr, err := e2e.Zarf("package", "deploy", path, "--components=first-choice,second-choice", "--confirm") + stdOut, stdErr, err := e2e.Zarf(t, "package", "deploy", path, "--components=first-choice,second-choice", "--confirm") require.Error(t, err, stdOut, stdErr) // Deploy a single choice and expect success - stdOut, stdErr, err = e2e.Zarf("package", "deploy", path, "--components=first-choice", "--confirm") + stdOut, stdErr, err = e2e.Zarf(t, "package", "deploy", path, "--components=first-choice", "--confirm") require.NoError(t, err, stdOut, stdErr) require.Contains(t, stdErr, "Component first-choice is using group which has been deprecated", "output should show a warning for group being deprecated.") @@ -40,7 +40,7 @@ func TestComponentChoice(t *testing.T) { require.NoFileExists(t, secondFile) // Deploy using default choice - stdOut, stdErr, err = e2e.Zarf("package", "deploy", path, "--confirm") + stdOut, stdErr, err = e2e.Zarf(t, "package", "deploy", path, "--confirm") require.NoError(t, err, stdOut, stdErr) // Verify the file was created diff --git a/src/test/e2e/02_component_actions_test.go b/src/test/e2e/02_component_actions_test.go index b709c0c267..94f9d997db 100644 --- a/src/test/e2e/02_component_actions_test.go +++ b/src/test/e2e/02_component_actions_test.go @@ -31,7 +31,7 @@ func TestComponentActions(t *testing.T) { /* Create */ // Try creating the package to test the onCreate actions. - stdOut, stdErr, err := e2e.Zarf("package", "create", "examples/component-actions", "--confirm") + stdOut, stdErr, err := e2e.Zarf(t, "package", "create", "examples/component-actions", "--confirm") require.NoError(t, err, stdOut, stdErr) require.Contains(t, stdErr, "Completed \"Create a test file\"") require.Contains(t, stdErr, "Completed \"touch test-create-after.txt\"") @@ -54,7 +54,7 @@ func TestComponentActions(t *testing.T) { t.Parallel() // Deploy the simple script that should pass. - stdOut, stdErr, err = e2e.Zarf("package", "deploy", path, "--components=on-deploy-and-remove", "--confirm") + stdOut, stdErr, err = e2e.Zarf(t, "package", "deploy", path, "--components=on-deploy-and-remove", "--confirm") require.NoError(t, err, stdOut, stdErr) // Check that the deploy artifacts were created. @@ -63,7 +63,7 @@ func TestComponentActions(t *testing.T) { } // Remove the simple script that should pass. - stdOut, stdErr, err = e2e.Zarf("package", "remove", path, "--components=on-deploy-and-remove", "--confirm") + stdOut, stdErr, err = e2e.Zarf(t, "package", "remove", path, "--components=on-deploy-and-remove", "--confirm") require.NoError(t, err, stdOut, stdErr) // Check that the deploy artifacts were removed. @@ -75,7 +75,7 @@ func TestComponentActions(t *testing.T) { t.Run("action on-deploy-with-timeout", func(t *testing.T) { t.Parallel() // Deploy the simple action that should fail the timeout. - stdOut, stdErr, err = e2e.Zarf("package", "deploy", path, "--components=on-deploy-with-timeout", "--confirm") + stdOut, stdErr, err = e2e.Zarf(t, "package", "deploy", path, "--components=on-deploy-with-timeout", "--confirm") require.Error(t, err, stdOut, stdErr) require.Contains(t, stdErr, "after 1 second") require.Contains(t, stdErr, "😭😭😭 this action failed because it took too long to run 😭😭😭") @@ -85,7 +85,7 @@ func TestComponentActions(t *testing.T) { t.Parallel() // Test using a Zarf Variable within the action - stdOut, stdErr, err = e2e.Zarf("package", "deploy", path, "--components=on-deploy-with-variable", "--confirm") + stdOut, stdErr, err = e2e.Zarf(t, "package", "deploy", path, "--components=on-deploy-with-variable", "--confirm") require.NoError(t, err, stdOut, stdErr) require.Contains(t, stdErr, "the dog says ruff") @@ -94,7 +94,7 @@ func TestComponentActions(t *testing.T) { t.Run("action on-deploy-with-dynamic-variable", func(t *testing.T) { t.Parallel() // Test using dynamic and multiple-variables - stdOut, stdErr, err = e2e.Zarf("package", "deploy", path, "--components=on-deploy-with-dynamic-variable,on-deploy-with-multiple-variables", "--confirm") + stdOut, stdErr, err = e2e.Zarf(t, "package", "deploy", path, "--components=on-deploy-with-dynamic-variable,on-deploy-with-multiple-variables", "--confirm") require.NoError(t, err, stdOut, stdErr) require.Contains(t, stdErr, "the cat says meow") require.Contains(t, stdErr, "the dog says ruff") @@ -108,7 +108,7 @@ func TestComponentActions(t *testing.T) { deployWithEnvVarArtifact := "test-filename-from-env.txt" // Test using environment variables - stdOut, stdErr, err = e2e.Zarf("package", "deploy", path, "--components=on-deploy-with-env-var", "--confirm") + stdOut, stdErr, err = e2e.Zarf(t, "package", "deploy", path, "--components=on-deploy-with-env-var", "--confirm") require.NoError(t, err, stdOut, stdErr) require.FileExists(t, deployWithEnvVarArtifact) @@ -121,7 +121,7 @@ func TestComponentActions(t *testing.T) { deployTemplatedArtifact := "test-templated.txt" // Test using a templated file but without dynamic variables - stdOut, stdErr, err = e2e.Zarf("package", "deploy", path, "--components=on-deploy-with-template-use-of-variable", "--confirm") + stdOut, stdErr, err = e2e.Zarf(t, "package", "deploy", path, "--components=on-deploy-with-template-use-of-variable", "--confirm") require.NoError(t, err, stdOut, stdErr) outTemplated, err := os.ReadFile(deployTemplatedArtifact) require.NoError(t, err) @@ -133,7 +133,7 @@ func TestComponentActions(t *testing.T) { e2e.CleanFiles(deployTemplatedArtifact) // Test using a templated file with dynamic variables - stdOut, stdErr, err = e2e.Zarf("package", "deploy", path, "--components=on-deploy-with-template-use-of-variable,on-deploy-with-dynamic-variable,on-deploy-with-multiple-variables", "--confirm") + stdOut, stdErr, err = e2e.Zarf(t, "package", "deploy", path, "--components=on-deploy-with-template-use-of-variable,on-deploy-with-dynamic-variable,on-deploy-with-multiple-variables", "--confirm") require.NoError(t, err, stdOut, stdErr) outTemplated, err = os.ReadFile(deployTemplatedArtifact) require.NoError(t, err) @@ -147,7 +147,7 @@ func TestComponentActions(t *testing.T) { t.Run("action on-deploy-immediate-failure", func(t *testing.T) { t.Parallel() - stdOut, stdErr, err = e2e.Zarf("package", "deploy", path, "--components=on-deploy-immediate-failure", "--confirm") + stdOut, stdErr, err = e2e.Zarf(t, "package", "deploy", path, "--components=on-deploy-immediate-failure", "--confirm") require.Error(t, err, stdOut, stdErr) require.Contains(t, stdErr, "failed to deploy package") // regression test to ensure that failed commands are not erroneously flagged as a timeout diff --git a/src/test/e2e/03_deprecations_test.go b/src/test/e2e/03_deprecations_test.go index 9d1c96b0c9..0414a3915e 100644 --- a/src/test/e2e/03_deprecations_test.go +++ b/src/test/e2e/03_deprecations_test.go @@ -30,7 +30,7 @@ func TestDeprecatedComponentScripts(t *testing.T) { // 1. Try creating the package to test the create scripts testPackagePath := fmt.Sprintf("%s/zarf-package-deprecated-component-scripts-%s.tar.zst", testPackageDirPath, e2e.Arch) outputFlag := fmt.Sprintf("-o=%s", testPackageDirPath) - stdOut, stdErr, err := e2e.Zarf("package", "create", testPackageDirPath, outputFlag, "--confirm") + stdOut, stdErr, err := e2e.Zarf(t, "package", "create", testPackageDirPath, outputFlag, "--confirm") defer e2e.CleanFiles(testPackagePath) require.NoError(t, err, stdOut, stdErr) require.Contains(t, stdErr, "Component '1-test-deprecated-prepare-scripts' is using scripts") @@ -46,7 +46,7 @@ func TestDeprecatedComponentScripts(t *testing.T) { } // 2. Deploy the simple script that should pass - stdOut, stdErr, err = e2e.Zarf("package", "deploy", testPackagePath, "--confirm", "--components=2-test-deprecated-deploy-scripts") + stdOut, stdErr, err = e2e.Zarf(t, "package", "deploy", testPackagePath, "--confirm", "--components=2-test-deprecated-deploy-scripts") require.NoError(t, err, stdOut, stdErr) // Check that the deploy artifacts were created @@ -55,7 +55,7 @@ func TestDeprecatedComponentScripts(t *testing.T) { } // 3. Deploy the simple script that should fail the timeout - stdOut, stdErr, err = e2e.Zarf("package", "deploy", testPackagePath, "--confirm", "--components=3-test-deprecated-timeout-scripts") + stdOut, stdErr, err = e2e.Zarf(t, "package", "deploy", testPackagePath, "--confirm", "--components=3-test-deprecated-timeout-scripts") require.Error(t, err, stdOut, stdErr) } @@ -79,24 +79,24 @@ func TestDeprecatedSetAndPackageVariables(t *testing.T) { outputFlag := fmt.Sprintf("-o=%s", testPackageDirPath) // Check that the command still errors out - stdOut, stdErr, err := e2e.Zarf("package", "create", testPackageDirPath, outputFlag, "--confirm") + stdOut, stdErr, err := e2e.Zarf(t, "package", "create", testPackageDirPath, outputFlag, "--confirm") require.Error(t, err, stdOut, stdErr) require.Contains(t, stdErr, "template \"ECHO\" must be '--set'") // Check that the command displays a warning on create - stdOut, stdErr, err = e2e.Zarf("package", "create", testPackageDirPath, outputFlag, "--confirm", "--set", "ECHO=Zarf-The-Axolotl") + stdOut, stdErr, err = e2e.Zarf(t, "package", "create", testPackageDirPath, outputFlag, "--confirm", "--set", "ECHO=Zarf-The-Axolotl") defer e2e.CleanFiles(testPackagePath) require.NoError(t, err, stdOut, stdErr) require.Contains(t, stdErr, "Component '1-test-deprecated-set-variable' is using setVariable") require.Contains(t, stdErr, "deprecated syntax ###ZARF_PKG_VAR_ECHO###") // 1. Deploy the setVariable action that should pass and output the variable - stdOut, stdErr, err = e2e.Zarf("package", "deploy", testPackagePath, "--confirm", "--components=1-test-deprecated-set-variable") + stdOut, stdErr, err = e2e.Zarf(t, "package", "deploy", testPackagePath, "--confirm", "--components=1-test-deprecated-set-variable") require.NoError(t, err, stdOut, stdErr) require.Contains(t, stdErr, "Hello from Hello Kitteh") // 2. Deploy the setVariable action that should pass and output the variable - stdOut, stdErr, err = e2e.Zarf("package", "deploy", testPackagePath, "--confirm", "--components=2-test-deprecated-pkg-var") + stdOut, stdErr, err = e2e.Zarf(t, "package", "deploy", testPackagePath, "--confirm", "--components=2-test-deprecated-pkg-var") require.NoError(t, err, stdOut, stdErr) require.Contains(t, stdErr, "Zarf-The-Axolotl") } diff --git a/src/test/e2e/04_create_templating_test.go b/src/test/e2e/04_create_templating_test.go index a77ba1abd6..d69839547b 100644 --- a/src/test/e2e/04_create_templating_test.go +++ b/src/test/e2e/04_create_templating_test.go @@ -24,15 +24,15 @@ func TestCreateTemplating(t *testing.T) { pkgName := fmt.Sprintf("zarf-package-variables-%s.tar.zst", e2e.Arch) // Test that not specifying a package variable results in an error - _, stdErr, _ := e2e.Zarf("package", "create", "examples/variables", "--confirm") + _, stdErr, _ := e2e.Zarf(t, "package", "create", "examples/variables", "--confirm") expectedOutString := "variable 'NGINX_VERSION' must be '--set' when using the '--confirm' flag" require.Contains(t, stdErr, "", expectedOutString) // Test a simple package variable example with `--set` (will fail to pull an image if this is not set correctly) - stdOut, stdErr, err := e2e.Zarf("package", "create", "examples/variables", "--set", "NGINX_VERSION=1.23.3", "--confirm") + stdOut, stdErr, err := e2e.Zarf(t, "package", "create", "examples/variables", "--set", "NGINX_VERSION=1.23.3", "--confirm") require.NoError(t, err, stdOut, stdErr) - stdOut, stdErr, err = e2e.Zarf("t", "archiver", "decompress", pkgName, decompressPath, "--unarchive-all") + stdOut, stdErr, err = e2e.Zarf(t, "t", "archiver", "decompress", pkgName, decompressPath, "--unarchive-all") require.NoError(t, err, stdOut, stdErr) // Check that the constant in the zarf.yaml is replaced correctly @@ -41,14 +41,14 @@ func TestCreateTemplating(t *testing.T) { require.Contains(t, string(builtConfig), "name: NGINX_VERSION\n value: 1.23.3") // Test that files and file folders template and handle SBOMs correctly - stdOut, stdErr, err = e2e.Zarf("package", "create", "src/test/packages/04-file-folders-templating-sbom/", "--sbom-out", sbomPath, "--confirm") + stdOut, stdErr, err = e2e.Zarf(t, "package", "create", "src/test/packages/04-file-folders-templating-sbom/", "--sbom-out", sbomPath, "--confirm") require.NoError(t, err, stdOut, stdErr) require.Contains(t, stdErr, "Creating SBOMs for 0 images and 2 components with files.") fileFoldersPkgName := fmt.Sprintf("zarf-package-file-folders-templating-sbom-%s.tar.zst", e2e.Arch) // Deploy the package and look for the variables in the output - stdOut, stdErr, err = e2e.Zarf("package", "deploy", fileFoldersPkgName, "--set", "DOGGO=doggy", "--set", "KITTEH=meowza", "--set", "PANDA=pandemonium", "--confirm") + stdOut, stdErr, err = e2e.Zarf(t, "package", "deploy", fileFoldersPkgName, "--set", "DOGGO=doggy", "--set", "KITTEH=meowza", "--set", "PANDA=pandemonium", "--confirm") require.NoError(t, err, stdOut, stdErr) require.Contains(t, stdErr, "A doggy barks!") require.Contains(t, stdErr, " - meowza") diff --git a/src/test/e2e/05_tarball_test.go b/src/test/e2e/05_tarball_test.go index ab91e06e4d..cac1a07582 100644 --- a/src/test/e2e/05_tarball_test.go +++ b/src/test/e2e/05_tarball_test.go @@ -30,7 +30,7 @@ func TestMultiPartPackage(t *testing.T) { e2e.CleanFiles(deployPath, outputFile) // Create the package with a max size of 20MB - stdOut, stdErr, err := e2e.Zarf("package", "create", createPath, "--max-package-size=20", "--confirm") + stdOut, stdErr, err := e2e.Zarf(t, "package", "create", createPath, "--max-package-size=20", "--confirm") require.NoError(t, err, stdOut, stdErr) parts, err := filepath.Glob("zarf-package-multi-part-*") @@ -53,7 +53,7 @@ func TestMultiPartPackage(t *testing.T) { require.Equal(t, 3, pkgData.Count) fmt.Printf("%#v", pkgData) - stdOut, stdErr, err = e2e.Zarf("package", "deploy", deployPath, "--confirm") + stdOut, stdErr, err = e2e.Zarf(t, "package", "deploy", deployPath, "--confirm") require.NoError(t, err, stdOut, stdErr) // Verify the package was deployed @@ -87,10 +87,10 @@ func TestReproducibleTarballs(t *testing.T) { unpack2 = filepath.Join(tmp, "unpack2") ) - stdOut, stdErr, err := e2e.Zarf("package", "create", createPath, "--confirm", "--output", tmp) + stdOut, stdErr, err := e2e.Zarf(t, "package", "create", createPath, "--confirm", "--output", tmp) require.NoError(t, err, stdOut, stdErr) - stdOut, stdErr, err = e2e.Zarf("tools", "archiver", "decompress", tb, unpack1) + stdOut, stdErr, err = e2e.Zarf(t, "tools", "archiver", "decompress", tb, unpack1) require.NoError(t, err, stdOut, stdErr) var pkg1 types.ZarfPackage @@ -99,10 +99,10 @@ func TestReproducibleTarballs(t *testing.T) { e2e.CleanFiles(unpack1, tb) - stdOut, stdErr, err = e2e.Zarf("package", "create", createPath, "--confirm", "--output", tmp) + stdOut, stdErr, err = e2e.Zarf(t, "package", "create", createPath, "--confirm", "--output", tmp) require.NoError(t, err, stdOut, stdErr) - stdOut, stdErr, err = e2e.Zarf("tools", "archiver", "decompress", tb, unpack2) + stdOut, stdErr, err = e2e.Zarf(t, "tools", "archiver", "decompress", tb, unpack2) require.NoError(t, err, stdOut, stdErr) var pkg2 types.ZarfPackage diff --git a/src/test/e2e/06_create_sbom_test.go b/src/test/e2e/06_create_sbom_test.go index d040ba2e05..75b1b309ff 100644 --- a/src/test/e2e/06_create_sbom_test.go +++ b/src/test/e2e/06_create_sbom_test.go @@ -20,7 +20,7 @@ func TestCreateSBOM(t *testing.T) { pkgName := fmt.Sprintf("zarf-package-dos-games-%s-1.0.0.tar.zst", e2e.Arch) - stdOut, stdErr, err := e2e.Zarf("package", "create", "examples/dos-games", "--sbom-out", sbomPath, "--confirm") + stdOut, stdErr, err := e2e.Zarf(t, "package", "create", "examples/dos-games", "--sbom-out", sbomPath, "--confirm") require.NoError(t, err, stdOut, stdErr) require.Contains(t, stdErr, "Creating SBOMs for 1 images and 0 components with files.") // Test that the game package generates the SBOMs we expect (images only) @@ -31,7 +31,7 @@ func TestCreateSBOM(t *testing.T) { // Clean the SBOM path so it is force to be recreated e2e.CleanFiles(sbomPath) - stdOut, stdErr, err = e2e.Zarf("package", "inspect", pkgName, "--sbom-out", sbomPath) + stdOut, stdErr, err = e2e.Zarf(t, "package", "inspect", pkgName, "--sbom-out", sbomPath) require.NoError(t, err, stdOut, stdErr) // Test that the game package generates the SBOMs we expect (images only) _, err = os.ReadFile(filepath.Join(sbomPath, "dos-games", "sbom-viewer-docker.io_defenseunicorns_zarf-game_multi-tile-dark.html")) @@ -41,17 +41,17 @@ func TestCreateSBOM(t *testing.T) { _, err = os.ReadFile(filepath.Join(sbomPath, "dos-games", "docker.io_defenseunicorns_zarf-game_multi-tile-dark.json")) require.NoError(t, err) - stdOut, _, err = e2e.Zarf("package", "inspect", pkgName, "--list-images") + stdOut, _, err = e2e.Zarf(t, "package", "inspect", pkgName, "--list-images") require.NoError(t, err) require.Equal(t, "- defenseunicorns/zarf-game:multi-tile-dark\n", stdOut) // Pull the current zarf binary version to find the corresponding init package - version, stdErr, err := e2e.Zarf("version") + version, stdErr, err := e2e.Zarf(t, "version") require.NoError(t, err, version, stdErr) initName := fmt.Sprintf("build/zarf-init-%s-%s.tar.zst", e2e.Arch, strings.TrimSpace(version)) - stdOut, stdErr, err = e2e.Zarf("package", "inspect", initName, "--sbom-out", sbomPath) + stdOut, stdErr, err = e2e.Zarf(t, "package", "inspect", initName, "--sbom-out", sbomPath) require.NoError(t, err, stdOut, stdErr) // Test that we preserve the filepath _, err = os.ReadFile(filepath.Join(sbomPath, "dos-games", "sbom-viewer-docker.io_defenseunicorns_zarf-game_multi-tile-dark.html")) diff --git a/src/test/e2e/07_create_git_test.go b/src/test/e2e/07_create_git_test.go index af475a3593..7a08043c1f 100644 --- a/src/test/e2e/07_create_git_test.go +++ b/src/test/e2e/07_create_git_test.go @@ -21,7 +21,7 @@ func TestCreateGit(t *testing.T) { // Extract the test package. path := fmt.Sprintf("build/zarf-package-git-data-%s-0.0.1.tar.zst", e2e.Arch) - stdOut, stdErr, err := e2e.Zarf("tools", "archiver", "decompress", path, extractDir, "--unarchive-all") + stdOut, stdErr, err := e2e.Zarf(t, "tools", "archiver", "decompress", path, extractDir, "--unarchive-all") require.NoError(t, err, stdOut, stdErr) defer e2e.CleanFiles(extractDir) diff --git a/src/test/e2e/08_create_differential_test.go b/src/test/e2e/08_create_differential_test.go index d692d1b9cc..97aaf40de2 100644 --- a/src/test/e2e/08_create_differential_test.go +++ b/src/test/e2e/08_create_differential_test.go @@ -28,17 +28,17 @@ func TestCreateDifferential(t *testing.T) { differentialFlag := fmt.Sprintf("--differential=%s", packageName) // Build the package a first time - stdOut, stdErr, err := e2e.Zarf("package", "create", packagePath, "--set=PACKAGE_VERSION=v0.25.0", "--confirm") + stdOut, stdErr, err := e2e.Zarf(t, "package", "create", packagePath, "--set=PACKAGE_VERSION=v0.25.0", "--confirm") require.NoError(t, err, stdOut, stdErr) defer e2e.CleanFiles(packageName) // Build the differential package without changing the version - _, stdErr, err = e2e.Zarf("package", "create", packagePath, "--set=PACKAGE_VERSION=v0.25.0", differentialFlag, "--confirm") + _, stdErr, err = e2e.Zarf(t, "package", "create", packagePath, "--set=PACKAGE_VERSION=v0.25.0", differentialFlag, "--confirm") require.Error(t, err, "zarf package create should have errored when a differential package was being created without updating the package version number") require.Contains(t, e2e.StripMessageFormatting(stdErr), lang.PkgCreateErrDifferentialSameVersion) // Build the differential package - stdOut, stdErr, err = e2e.Zarf("package", "create", packagePath, "--set=PACKAGE_VERSION=v0.26.0", differentialFlag, "--confirm") + stdOut, stdErr, err = e2e.Zarf(t, "package", "create", packagePath, "--set=PACKAGE_VERSION=v0.26.0", differentialFlag, "--confirm") require.NoError(t, err, stdOut, stdErr) defer e2e.CleanFiles(differentialPackageName) diff --git a/src/test/e2e/09_component_compose_test.go b/src/test/e2e/09_component_compose_test.go index 176b96207e..37a905456a 100644 --- a/src/test/e2e/09_component_compose_test.go +++ b/src/test/e2e/09_component_compose_test.go @@ -45,7 +45,7 @@ func (suite *CompositionSuite) TearDownSuite() { func (suite *CompositionSuite) Test_0_ComposabilityExample() { suite.T().Log("E2E: Package Compose Example") - _, stdErr, err := e2e.Zarf("package", "create", composeExample, "-o", "build", "--no-color", "--confirm") + _, stdErr, err := e2e.Zarf(suite.T(), "package", "create", composeExample, "-o", "build", "--no-color", "--confirm") suite.NoError(err) // Ensure that common names merge @@ -71,7 +71,7 @@ func (suite *CompositionSuite) Test_0_ComposabilityExample() { func (suite *CompositionSuite) Test_1_FullComposability() { suite.T().Log("E2E: Full Package Compose") - _, stdErr, err := e2e.Zarf("package", "create", composeTest, "-o", "build", "--no-color", "--confirm") + _, stdErr, err := e2e.Zarf(suite.T(), "package", "create", composeTest, "-o", "build", "--no-color", "--confirm") suite.NoError(err) // Ensure that names merge and that composition is added appropriately @@ -183,7 +183,7 @@ func (suite *CompositionSuite) Test_1_FullComposability() { func (suite *CompositionSuite) Test_2_ComposabilityBadLocalOS() { suite.T().Log("E2E: Package Compose Example") - _, stdErr, err := e2e.Zarf("package", "create", composeTestBadLocalOS, "-o", "build", "--no-color", "--confirm") + _, stdErr, err := e2e.Zarf(suite.T(), "package", "create", composeTestBadLocalOS, "-o", "build", "--no-color", "--confirm") suite.Error(err) suite.Contains(stdErr, "\"only.localOS\" \"linux\" cannot be redefined as \"windows\" during compose") } diff --git a/src/test/e2e/10_component_flavor_test.go b/src/test/e2e/10_component_flavor_test.go index 3ae8cfc234..a1f748bd22 100644 --- a/src/test/e2e/10_component_flavor_test.go +++ b/src/test/e2e/10_component_flavor_test.go @@ -46,7 +46,7 @@ func (suite *FlavorSuite) TearDownSuite() { func (suite *FlavorSuite) Test_0_FlavorExample() { suite.T().Log("E2E: Package Flavor Example") - _, stdErr, err := e2e.Zarf("package", "create", flavorExample, "-o", "build", "--flavor", "oracle-cookie-crunch", "--no-color", "--confirm") + _, stdErr, err := e2e.Zarf(suite.T(), "package", "create", flavorExample, "-o", "build", "--flavor", "oracle-cookie-crunch", "--no-color", "--confirm") suite.NoError(err) // Ensure that the oracle image is included @@ -64,7 +64,7 @@ func (suite *FlavorSuite) Test_0_FlavorExample() { func (suite *FlavorSuite) Test_1_FlavorArchFiltering() { suite.T().Log("E2E: Package Flavor + Arch Filtering") - _, stdErr, err := e2e.Zarf("package", "create", flavorTest, "-o", "build", "--flavor", "vanilla", "-a", "amd64", "--no-color", "--confirm") + _, stdErr, err := e2e.Zarf(suite.T(), "package", "create", flavorTest, "-o", "build", "--flavor", "vanilla", "-a", "amd64", "--no-color", "--confirm") suite.NoError(err) // Ensure that the initial filter was applied @@ -82,7 +82,7 @@ func (suite *FlavorSuite) Test_1_FlavorArchFiltering() { suite.NotContains(stdErr, `chocolate-amd`) suite.NotContains(stdErr, `chocolate-arm`) - _, stdErr, err = e2e.Zarf("package", "create", flavorTest, "-o", "build", "--flavor", "chocolate", "-a", "amd64", "--no-color", "--confirm") + _, stdErr, err = e2e.Zarf(suite.T(), "package", "create", flavorTest, "-o", "build", "--flavor", "chocolate", "-a", "amd64", "--no-color", "--confirm") suite.NoError(err) // Ensure that the initial filter was applied @@ -100,7 +100,7 @@ func (suite *FlavorSuite) Test_1_FlavorArchFiltering() { suite.NotContains(stdErr, `vanilla-amd`) suite.NotContains(stdErr, `chocolate-arm`) - _, stdErr, err = e2e.Zarf("package", "create", flavorTest, "-o", "build", "--flavor", "chocolate", "-a", "arm64", "--no-color", "--confirm") + _, stdErr, err = e2e.Zarf(suite.T(), "package", "create", flavorTest, "-o", "build", "--flavor", "chocolate", "-a", "arm64", "--no-color", "--confirm") suite.NoError(err) // Ensure that the initial filter was applied diff --git a/src/test/e2e/11_oci_pull_inspect_test.go b/src/test/e2e/11_oci_pull_inspect_test.go index 98e5e4ff52..a992a50f55 100644 --- a/src/test/e2e/11_oci_pull_inspect_test.go +++ b/src/test/e2e/11_oci_pull_inspect_test.go @@ -45,7 +45,7 @@ func (suite *PullInspectTestSuite) Test_0_Pull() { ref := fmt.Sprintf("oci://ghcr.io/zarf-dev/packages/dos-games:1.0.0-%s", e2e.Arch) // Pull the package via OCI. - stdOut, stdErr, err := e2e.Zarf("package", "pull", ref) + stdOut, stdErr, err := e2e.Zarf(suite.T(), "package", "pull", ref) suite.NoError(err, stdOut, stdErr) suite.Contains(stdErr, fmt.Sprintf("Pulling %q", ref)) suite.Contains(stdErr, "Validating full package checksums") @@ -55,13 +55,13 @@ func (suite *PullInspectTestSuite) Test_0_Pull() { // Verify the package was pulled correctly. suite.FileExists(out) - stdOut, stdErr, err = e2e.Zarf("package", "inspect", out, "--key", "https://zarf.dev/cosign.pub", "--sbom-out", sbomTmp) + stdOut, stdErr, err = e2e.Zarf(suite.T(), "package", "inspect", out, "--key", "https://zarf.dev/cosign.pub", "--sbom-out", sbomTmp) suite.NoError(err, stdOut, stdErr) suite.Contains(stdErr, "Validating SBOM checksums") suite.Contains(stdErr, "Package signature validated!") // Test pull w/ bad ref. - stdOut, stdErr, err = e2e.Zarf("package", "pull", "oci://"+badPullInspectRef.String(), "--insecure") + stdOut, stdErr, err = e2e.Zarf(suite.T(), "package", "pull", "oci://"+badPullInspectRef.String(), "--insecure") suite.Error(err, stdOut, stdErr) } @@ -69,13 +69,13 @@ func (suite *PullInspectTestSuite) Test_1_Remote_Inspect() { suite.T().Log("E2E: Package Inspect oci://") // Test inspect w/ bad ref. - _, stdErr, err := e2e.Zarf("package", "inspect", "oci://"+badPullInspectRef.String(), "--insecure") + _, stdErr, err := e2e.Zarf(suite.T(), "package", "inspect", "oci://"+badPullInspectRef.String(), "--insecure") suite.Error(err, stdErr) // Test inspect on a public package. // NOTE: This also makes sure that Zarf does not attempt auth when inspecting a public package. ref := fmt.Sprintf("oci://ghcr.io/zarf-dev/packages/dos-games:1.0.0-%s", e2e.Arch) - _, stdErr, err = e2e.Zarf("package", "inspect", ref) + _, stdErr, err = e2e.Zarf(suite.T(), "package", "inspect", ref) suite.NoError(err, stdErr) } diff --git a/src/test/e2e/12_lint_test.go b/src/test/e2e/12_lint_test.go index a577bb397f..6b7239a17a 100644 --- a/src/test/e2e/12_lint_test.go +++ b/src/test/e2e/12_lint_test.go @@ -20,7 +20,7 @@ func TestLint(t *testing.T) { t.Log("E2E: Test lint on schema success") // This runs lint on the zarf.yaml in the base directory of the repo - _, _, err := e2e.Zarf("dev", "lint") + _, _, err := e2e.Zarf(t, "dev", "lint") require.NoError(t, err, "Expect no error here because the yaml file is following schema") }) @@ -30,7 +30,7 @@ func TestLint(t *testing.T) { testPackagePath := filepath.Join("src", "test", "packages", "12-lint") configPath := filepath.Join(testPackagePath, "zarf-config.toml") os.Setenv("ZARF_CONFIG", configPath) - _, stderr, err := e2e.Zarf("dev", "lint", testPackagePath, "-f", "good-flavor") + _, stderr, err := e2e.Zarf(t, "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 27e7bbe715..a161ed15f6 100644 --- a/src/test/e2e/13_find_images_test.go +++ b/src/test/e2e/13_find_images_test.go @@ -18,11 +18,11 @@ func TestFindImages(t *testing.T) { 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") + stdOut, stdErr, err := e2e.Zarf(t, "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") + stdOut, stdErr, err = e2e.Zarf(t, "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") }) @@ -34,13 +34,13 @@ func TestFindImages(t *testing.T) { // 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") + stdOut, stdErr, err := e2e.Zarf(t, "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") + stdOut, stdErr, err = e2e.Zarf(t, "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") @@ -51,14 +51,14 @@ 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)) + stdOut, _, err := e2e.Zarf(t, "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, "zarf-dev/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") + stdOut, _, err = e2e.Zarf(t, "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") @@ -69,7 +69,7 @@ func TestFindImages(t *testing.T) { 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, ",") - stdOut, _, err := e2e.Zarf("dev", "find-images", testPackagePath, "--why", "docker.io/bitnami/apache-exporter:0.13.3-debian-11-r2", "--deploy-set", deploysSet) + stdOut, _, err := e2e.Zarf(t, "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") @@ -80,7 +80,7 @@ func TestFindImages(t *testing.T) { t.Parallel() testPackagePath := filepath.Join("examples", "manifests") - stdOut, _, err := e2e.Zarf("dev", "find-images", testPackagePath, "--why", "httpd:alpine3.18") + stdOut, _, err := e2e.Zarf(t, "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") diff --git a/src/test/e2e/13_zarf_package_generate_test.go b/src/test/e2e/13_zarf_package_generate_test.go index 305141739c..9d73747210 100644 --- a/src/test/e2e/13_zarf_package_generate_test.go +++ b/src/test/e2e/13_zarf_package_generate_test.go @@ -24,7 +24,7 @@ func TestZarfDevGenerate(t *testing.T) { version := "6.4.0" gitPath := "charts/podinfo" - stdOut, stdErr, err := e2e.Zarf("dev", "generate", "podinfo", "--url", url, "--version", version, "--gitPath", gitPath, "--output-directory", tmpDir) + stdOut, stdErr, err := e2e.Zarf(t, "dev", "generate", "podinfo", "--url", url, "--version", version, "--gitPath", gitPath, "--output-directory", tmpDir) require.NoError(t, err, stdOut, stdErr) zarfPackage := types.ZarfPackage{} diff --git a/src/test/e2e/14_create_sha_index_test.go b/src/test/e2e/14_create_sha_index_test.go index 59993c5874..eb2849975a 100644 --- a/src/test/e2e/14_create_sha_index_test.go +++ b/src/test/e2e/14_create_sha_index_test.go @@ -32,7 +32,7 @@ func TestCreateIndexShaErrors(t *testing.T) { for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { - _, stderr, err := e2e.Zarf("package", "create", tc.packagePath, "--confirm") + _, stderr, err := e2e.Zarf(t, "package", "create", tc.packagePath, "--confirm") require.Error(t, err) require.Contains(t, stderr, tc.expectedImageInStderr) }) diff --git a/src/test/e2e/20_zarf_init_test.go b/src/test/e2e/20_zarf_init_test.go index 572cedea0f..6f788ef3b1 100644 --- a/src/test/e2e/20_zarf_init_test.go +++ b/src/test/e2e/20_zarf_init_test.go @@ -37,25 +37,25 @@ func TestZarfInit(t *testing.T) { if runtime.GOOS == "linux" { // Build init package with different arch than the cluster arch. - stdOut, stdErr, err := e2e.Zarf("package", "create", "src/test/packages/20-mismatched-arch-init", "--architecture", mismatchedArch, "--confirm") + stdOut, stdErr, err := e2e.Zarf(t, "package", "create", "src/test/packages/20-mismatched-arch-init", "--architecture", mismatchedArch, "--confirm") require.NoError(t, err, stdOut, stdErr) // Check that `zarf init` returns an error because of the mismatched architectures. // We need to use the --architecture flag here to force zarf to find the package. - _, stdErr, err = e2e.Zarf("init", "--architecture", mismatchedArch, "--components=k3s", "--confirm") + _, stdErr, err = e2e.Zarf(t, "init", "--architecture", mismatchedArch, "--components=k3s", "--confirm") require.Error(t, err, stdErr) require.Contains(t, stdErr, expectedErrorMessage) } if !e2e.ApplianceMode { // throw a pending pod into the cluster to ensure we can properly ignore them when selecting images - _, _, err := e2e.Kubectl("apply", "-f", "https://raw.githubusercontent.com/kubernetes/website/main/content/en/examples/pods/pod-with-node-affinity.yaml") + _, _, err := e2e.Kubectl(t, "apply", "-f", "https://raw.githubusercontent.com/kubernetes/website/main/content/en/examples/pods/pod-with-node-affinity.yaml") require.NoError(t, err) } // Check for any old secrets to ensure that they don't get saved in the init log oldState := types.ZarfState{} - base64State, _, err := e2e.Kubectl("get", "secret", "zarf-state", "-n", "zarf", "-o", "jsonpath={.data.state}") + base64State, _, err := e2e.Kubectl(t, "get", "secret", "zarf-state", "-n", "zarf", "-o", "jsonpath={.data.state}") if err == nil { oldStateJSON, err := base64.StdEncoding.DecodeString(base64State) require.NoError(t, err) @@ -64,7 +64,7 @@ func TestZarfInit(t *testing.T) { } // run `zarf init` - _, initStdErr, err := e2e.Zarf("init", "--components="+initComponents, "--nodeport", "31337", "-l", "trace", "--confirm") + _, initStdErr, err := e2e.Zarf(t, "init", "--components="+initComponents, "--nodeport", "31337", "-l", "trace", "--confirm") require.NoError(t, err) require.Contains(t, initStdErr, "an inventory of all software contained in this package") require.NotContains(t, initStdErr, "This package does NOT contain an SBOM. If you require an SBOM, please contact the creator of this package to request a version that includes an SBOM.") @@ -73,7 +73,7 @@ func TestZarfInit(t *testing.T) { // Verify that any state secrets were not included in the log state := types.ZarfState{} - base64State, _, err = e2e.Kubectl("get", "secret", "zarf-state", "-n", "zarf", "-o", "jsonpath={.data.state}") + base64State, _, err = e2e.Kubectl(t, "get", "secret", "zarf-state", "-n", "zarf", "-o", "jsonpath={.data.state}") require.NoError(t, err) stateJSON, err := base64.StdEncoding.DecodeString(base64State) require.NoError(t, err) @@ -83,18 +83,18 @@ func TestZarfInit(t *testing.T) { if e2e.ApplianceMode { // make sure that we upgraded `k3s` correctly and are running the correct version - this should match that found in `packages/distros/k3s` - kubeletVersion, _, err := e2e.Kubectl("get", "nodes", "-o", "jsonpath={.items[0].status.nodeInfo.kubeletVersion}") + kubeletVersion, _, err := e2e.Kubectl(t, "get", "nodes", "-o", "jsonpath={.items[0].status.nodeInfo.kubeletVersion}") require.NoError(t, err) require.Contains(t, kubeletVersion, "v1.28.4+k3s2") } // Check that the registry is running on the correct NodePort - stdOut, _, err := e2e.Kubectl("get", "service", "-n", "zarf", "zarf-docker-registry", "-o=jsonpath='{.spec.ports[*].nodePort}'") + stdOut, _, err := e2e.Kubectl(t, "get", "service", "-n", "zarf", "zarf-docker-registry", "-o=jsonpath='{.spec.ports[*].nodePort}'") require.NoError(t, err) require.Contains(t, stdOut, "31337") // Check that the registry is running with the correct scale down policy - stdOut, _, err = e2e.Kubectl("get", "hpa", "-n", "zarf", "zarf-docker-registry", "-o=jsonpath='{.spec.behavior.scaleDown.selectPolicy}'") + stdOut, _, err = e2e.Kubectl(t, "get", "hpa", "-n", "zarf", "zarf-docker-registry", "-o=jsonpath='{.spec.behavior.scaleDown.selectPolicy}'") require.NoError(t, err) require.Contains(t, stdOut, "Min") @@ -104,8 +104,8 @@ func TestZarfInit(t *testing.T) { verifyZarfServiceLabels(t) // Special sizing-hacking for reducing resources where Kind + CI eats a lot of free cycles (ignore errors) - _, _, _ = e2e.Kubectl("scale", "deploy", "-n", "kube-system", "coredns", "--replicas=1") - _, _, _ = e2e.Kubectl("scale", "deploy", "-n", "zarf", "agent-hook", "--replicas=1") + _, _, _ = e2e.Kubectl(t, "scale", "deploy", "-n", "kube-system", "coredns", "--replicas=1") + _, _, _ = e2e.Kubectl(t, "scale", "deploy", "-n", "zarf", "agent-hook", "--replicas=1") } func checkLogForSensitiveState(t *testing.T, logText string, zarfState types.ZarfState) { @@ -129,7 +129,7 @@ func verifyZarfNamespaceLabels(t *testing.T) { t.Helper() expectedLabels := `'{"app.kubernetes.io/managed-by":"zarf","kubernetes.io/metadata.name":"zarf"}'` - actualLabels, _, err := e2e.Kubectl("get", "ns", "zarf", "-o=jsonpath='{.metadata.labels}'") + actualLabels, _, err := e2e.Kubectl(t, "get", "ns", "zarf", "-o=jsonpath='{.metadata.labels}'") require.NoError(t, err) require.Equal(t, expectedLabels, actualLabels) } @@ -139,19 +139,19 @@ func verifyZarfSecretLabels(t *testing.T) { // zarf state expectedLabels := `'{"app.kubernetes.io/managed-by":"zarf"}'` - actualLabels, _, err := e2e.Kubectl("get", "-n=zarf", "secret", "zarf-state", "-o=jsonpath='{.metadata.labels}'") + actualLabels, _, err := e2e.Kubectl(t, "get", "-n=zarf", "secret", "zarf-state", "-o=jsonpath='{.metadata.labels}'") require.NoError(t, err) require.Equal(t, expectedLabels, actualLabels) // init package secret expectedLabels = `'{"app.kubernetes.io/managed-by":"zarf","package-deploy-info":"init"}'` - actualLabels, _, err = e2e.Kubectl("get", "-n=zarf", "secret", "zarf-package-init", "-o=jsonpath='{.metadata.labels}'") + actualLabels, _, err = e2e.Kubectl(t, "get", "-n=zarf", "secret", "zarf-package-init", "-o=jsonpath='{.metadata.labels}'") require.NoError(t, err) require.Equal(t, expectedLabels, actualLabels) // registry expectedLabels = `'{"app.kubernetes.io/managed-by":"zarf"}'` - actualLabels, _, err = e2e.Kubectl("get", "-n=zarf", "secret", "private-registry", "-o=jsonpath='{.metadata.labels}'") + actualLabels, _, err = e2e.Kubectl(t, "get", "-n=zarf", "secret", "private-registry", "-o=jsonpath='{.metadata.labels}'") require.NoError(t, err) require.Equal(t, expectedLabels, actualLabels) @@ -160,13 +160,13 @@ func verifyZarfSecretLabels(t *testing.T) { // this secret does not have the managed by zarf label // because it is deployed as a helm chart rather than generated in Go code. expectedLabels = `'{"app.kubernetes.io/managed-by":"Helm"}'` - actualLabels, _, err = e2e.Kubectl("get", "-n=zarf", "secret", "agent-hook-tls", "-o=jsonpath='{.metadata.labels}'") + actualLabels, _, err = e2e.Kubectl(t, "get", "-n=zarf", "secret", "agent-hook-tls", "-o=jsonpath='{.metadata.labels}'") require.NoError(t, err) require.Equal(t, expectedLabels, actualLabels) // git server expectedLabels = `'{"app.kubernetes.io/managed-by":"zarf"}'` - actualLabels, _, err = e2e.Kubectl("get", "-n=zarf", "secret", "private-git-server", "-o=jsonpath='{.metadata.labels}'") + actualLabels, _, err = e2e.Kubectl(t, "get", "-n=zarf", "secret", "private-git-server", "-o=jsonpath='{.metadata.labels}'") require.NoError(t, err) require.Equal(t, expectedLabels, actualLabels) } @@ -175,24 +175,24 @@ func verifyZarfPodLabels(t *testing.T) { t.Helper() // registry - podHash, _, err := e2e.Kubectl("get", "-n=zarf", "--selector=app=docker-registry", "pods", `-o=jsonpath="{.items[0].metadata.labels['pod-template-hash']}"`) + podHash, _, err := e2e.Kubectl(t, "get", "-n=zarf", "--selector=app=docker-registry", "pods", `-o=jsonpath="{.items[0].metadata.labels['pod-template-hash']}"`) require.NoError(t, err) expectedLabels := fmt.Sprintf(`'{"app":"docker-registry","pod-template-hash":%s,"release":"zarf-docker-registry","zarf.dev/agent":"ignore"}'`, podHash) - actualLabels, _, err := e2e.Kubectl("get", "-n=zarf", "--selector=app=docker-registry", "pods", "-o=jsonpath='{.items[0].metadata.labels}'") + actualLabels, _, err := e2e.Kubectl(t, "get", "-n=zarf", "--selector=app=docker-registry", "pods", "-o=jsonpath='{.items[0].metadata.labels}'") require.NoError(t, err) require.Equal(t, expectedLabels, actualLabels) // agent - podHash, _, err = e2e.Kubectl("get", "-n=zarf", "--selector=app=agent-hook", "pods", `-o=jsonpath="{.items[0].metadata.labels['pod-template-hash']}"`) + podHash, _, err = e2e.Kubectl(t, "get", "-n=zarf", "--selector=app=agent-hook", "pods", `-o=jsonpath="{.items[0].metadata.labels['pod-template-hash']}"`) require.NoError(t, err) expectedLabels = fmt.Sprintf(`'{"app":"agent-hook","pod-template-hash":%s,"zarf.dev/agent":"ignore"}'`, podHash) - actualLabels, _, err = e2e.Kubectl("get", "-n=zarf", "--selector=app=agent-hook", "pods", "-o=jsonpath='{.items[0].metadata.labels}'") + actualLabels, _, err = e2e.Kubectl(t, "get", "-n=zarf", "--selector=app=agent-hook", "pods", "-o=jsonpath='{.items[0].metadata.labels}'") require.NoError(t, err) require.Equal(t, expectedLabels, actualLabels) // git server patchedLabel := `"zarf-agent":"patched"` - actualLabels, _, err = e2e.Kubectl("get", "-n=zarf", "--selector=app.kubernetes.io/instance=zarf-gitea ", "pods", "-o=jsonpath='{.items[0].metadata.labels}'") + actualLabels, _, err = e2e.Kubectl(t, "get", "-n=zarf", "--selector=app.kubernetes.io/instance=zarf-gitea ", "pods", "-o=jsonpath='{.items[0].metadata.labels}'") require.NoError(t, err) require.Contains(t, actualLabels, patchedLabel) } @@ -202,13 +202,13 @@ func verifyZarfServiceLabels(t *testing.T) { // registry expectedLabels := `'{"app.kubernetes.io/managed-by":"Helm","zarf.dev/connect-name":"registry"}'` - actualLabels, _, err := e2e.Kubectl("get", "-n=zarf", "service", "zarf-connect-registry", "-o=jsonpath='{.metadata.labels}'") + actualLabels, _, err := e2e.Kubectl(t, "get", "-n=zarf", "service", "zarf-connect-registry", "-o=jsonpath='{.metadata.labels}'") require.NoError(t, err) require.Equal(t, expectedLabels, actualLabels) // git server expectedLabels = `'{"app.kubernetes.io/managed-by":"Helm","zarf.dev/connect-name":"git"}'` - actualLabels, _, err = e2e.Kubectl("get", "-n=zarf", "service", "zarf-connect-git", "-o=jsonpath='{.metadata.labels}'") + actualLabels, _, err = e2e.Kubectl(t, "get", "-n=zarf", "service", "zarf-connect-git", "-o=jsonpath='{.metadata.labels}'") require.NoError(t, err) require.Equal(t, expectedLabels, actualLabels) } diff --git a/src/test/e2e/21_connect_creds_test.go b/src/test/e2e/21_connect_creds_test.go index b96d6c579b..e794de3f3e 100644 --- a/src/test/e2e/21_connect_creds_test.go +++ b/src/test/e2e/21_connect_creds_test.go @@ -24,17 +24,17 @@ type RegistryResponse struct { func TestConnectAndCreds(t *testing.T) { t.Log("E2E: Connect") - prevAgentSecretData, _, err := e2e.Kubectl("get", "secret", "agent-hook-tls", "-n", "zarf", "-o", "jsonpath={.data}") + prevAgentSecretData, _, err := e2e.Kubectl(t, "get", "secret", "agent-hook-tls", "-n", "zarf", "-o", "jsonpath={.data}") require.NoError(t, err) ctx := context.Background() connectToZarfServices(ctx, t) - stdOut, stdErr, err := e2e.Zarf("tools", "update-creds", "--confirm") + stdOut, stdErr, err := e2e.Zarf(t, "tools", "update-creds", "--confirm") require.NoError(t, err, stdOut, stdErr) - newAgentSecretData, _, err := e2e.Kubectl("get", "secret", "agent-hook-tls", "-n", "zarf", "-o", "jsonpath={.data}") + newAgentSecretData, _, err := e2e.Kubectl(t, "get", "secret", "agent-hook-tls", "-n", "zarf", "-o", "jsonpath={.data}") require.NoError(t, err) require.NotEqual(t, prevAgentSecretData, newAgentSecretData, "agent secrets should not be the same") @@ -81,7 +81,7 @@ func TestMetrics(t *testing.T) { func connectToZarfServices(ctx context.Context, t *testing.T) { // Make the Registry contains the images we expect - stdOut, stdErr, err := e2e.Zarf("tools", "registry", "catalog") + stdOut, stdErr, err := e2e.Zarf(t, "tools", "registry", "catalog") require.NoError(t, err, stdOut, stdErr) registryList := strings.Split(strings.Trim(stdOut, "\n "), "\n") @@ -93,13 +93,13 @@ func connectToZarfServices(ctx context.Context, t *testing.T) { require.Contains(t, stdOut, "library/registry") // Get the git credentials - stdOut, stdErr, err = e2e.Zarf("tools", "get-creds", "git") + stdOut, stdErr, err = e2e.Zarf(t, "tools", "get-creds", "git") require.NoError(t, err, stdOut, stdErr) gitPushPassword := strings.TrimSpace(stdOut) - stdOut, stdErr, err = e2e.Zarf("tools", "get-creds", "git-readonly") + stdOut, stdErr, err = e2e.Zarf(t, "tools", "get-creds", "git-readonly") require.NoError(t, err, stdOut, stdErr) gitPullPassword := strings.TrimSpace(stdOut) - stdOut, stdErr, err = e2e.Zarf("tools", "get-creds", "artifact") + stdOut, stdErr, err = e2e.Zarf(t, "tools", "get-creds", "artifact") require.NoError(t, err, stdOut, stdErr) gitArtifactToken := strings.TrimSpace(stdOut) diff --git a/src/test/e2e/22_git_and_gitops_test.go b/src/test/e2e/22_git_and_gitops_test.go index 559bb79e3f..363d5be1df 100644 --- a/src/test/e2e/22_git_and_gitops_test.go +++ b/src/test/e2e/22_git_and_gitops_test.go @@ -23,14 +23,14 @@ func TestGit(t *testing.T) { t.Log("E2E: Git") buildPath := filepath.Join("src", "test", "packages", "22-git-data") - stdOut, stdErr, err := e2e.Zarf("package", "create", buildPath, "-o=build", "--confirm") + stdOut, stdErr, err := e2e.Zarf(t, "package", "create", buildPath, "-o=build", "--confirm") require.NoError(t, err, stdOut, stdErr) path := fmt.Sprintf("build/zarf-package-git-data-test-%s-1.0.0.tar.zst", e2e.Arch) defer e2e.CleanFiles(path) // Deploy the git data example (with component globbing to test that as well) - stdOut, stdErr, err = e2e.Zarf("package", "deploy", path, "--components=full-repo,specific-*", "--confirm") + stdOut, stdErr, err = e2e.Zarf(t, "package", "deploy", path, "--components=full-repo,specific-*", "--confirm") require.NoError(t, err, stdOut, stdErr) c, err := cluster.NewCluster() @@ -135,54 +135,54 @@ func waitFluxPodInfoDeployment(t *testing.T) { require.NoError(t, err) // Deploy the flux example and verify that it works path := fmt.Sprintf("build/zarf-package-podinfo-flux-%s.tar.zst", e2e.Arch) - stdOut, stdErr, err := e2e.Zarf("package", "deploy", path, "--confirm") + stdOut, stdErr, err := e2e.Zarf(t, "package", "deploy", path, "--confirm") require.NoError(t, err, stdOut, stdErr) // Tests the URL mutation for GitRepository CRD for Flux. - stdOut, stdErr, err = e2e.Kubectl("get", "gitrepositories", "podinfo", "-n", "flux-system", "-o", "jsonpath={.spec.url}") + stdOut, stdErr, err = e2e.Kubectl(t, "get", "gitrepositories", "podinfo", "-n", "flux-system", "-o", "jsonpath={.spec.url}") require.NoError(t, err, stdOut, stdErr) expectedMutatedRepoURL := fmt.Sprintf("%s/%s/podinfo-1646971829.git", types.ZarfInClusterGitServiceURL, types.ZarfGitPushUser) require.Equal(t, expectedMutatedRepoURL, stdOut) // Tests the URL mutation for HelmRepository CRD for Flux. - stdOut, stdErr, err = e2e.Kubectl("get", "helmrepositories", "podinfo", "-n", "flux-system", "-o", "jsonpath={.spec.url}") + stdOut, stdErr, err = e2e.Kubectl(t, "get", "helmrepositories", "podinfo", "-n", "flux-system", "-o", "jsonpath={.spec.url}") require.NoError(t, err, stdOut, stdErr) expectedMutatedRepoURL = fmt.Sprintf("oci://%s/stefanprodan/charts", registryAddress) require.Equal(t, expectedMutatedRepoURL, stdOut) - stdOut, stdErr, err = e2e.Kubectl("get", "helmrelease", "podinfo", "-n", "flux-system", "-o", "jsonpath={.spec.chart.spec.version}") + stdOut, stdErr, err = e2e.Kubectl(t, "get", "helmrelease", "podinfo", "-n", "flux-system", "-o", "jsonpath={.spec.chart.spec.version}") require.NoError(t, err, stdOut, stdErr) expectedMutatedRepoTag := "6.4.0" require.Equal(t, expectedMutatedRepoTag, stdOut) // Tests the URL mutation for OCIRepository CRD for Flux. - stdOut, stdErr, err = e2e.Kubectl("get", "ocirepositories", "podinfo", "-n", "flux-system", "-o", "jsonpath={.spec.url}") + stdOut, stdErr, err = e2e.Kubectl(t, "get", "ocirepositories", "podinfo", "-n", "flux-system", "-o", "jsonpath={.spec.url}") require.NoError(t, err, stdOut, stdErr) expectedMutatedRepoURL = fmt.Sprintf("oci://%s/stefanprodan/manifests/podinfo", registryAddress) require.Equal(t, expectedMutatedRepoURL, stdOut) - stdOut, stdErr, err = e2e.Kubectl("get", "ocirepositories", "podinfo", "-n", "flux-system", "-o", "jsonpath={.spec.ref.tag}") + stdOut, stdErr, err = e2e.Kubectl(t, "get", "ocirepositories", "podinfo", "-n", "flux-system", "-o", "jsonpath={.spec.ref.tag}") require.NoError(t, err, stdOut, stdErr) expectedMutatedRepoTag = "6.4.0-zarf-2823281104" require.Equal(t, expectedMutatedRepoTag, stdOut) // Remove the flux example when deployment completes - stdOut, stdErr, err = e2e.Zarf("package", "remove", "podinfo-flux", "--confirm") + stdOut, stdErr, err = e2e.Zarf(t, "package", "remove", "podinfo-flux", "--confirm") require.NoError(t, err, stdOut, stdErr) // Prune the flux images to reduce disk pressure - stdOut, stdErr, err = e2e.Zarf("tools", "registry", "prune", "--confirm") + stdOut, stdErr, err = e2e.Zarf(t, "tools", "registry", "prune", "--confirm") require.NoError(t, err, stdOut, stdErr) } func waitArgoDeployment(t *testing.T) { // Deploy the argocd example and verify that it works path := fmt.Sprintf("build/zarf-package-argocd-%s.tar.zst", e2e.Arch) - stdOut, stdErr, err := e2e.Zarf("package", "deploy", path, "--components=argocd-apps", "--confirm") + stdOut, stdErr, err := e2e.Zarf(t, "package", "deploy", path, "--components=argocd-apps", "--confirm") require.NoError(t, err, stdOut, stdErr) 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}") + stdOut, stdErr, err = e2e.Kubectl(t, "get", "secret", "argocd-repo-github-podinfo", "-n", "argocd", "-o", "jsonpath={.data.url}") require.NoError(t, err, stdOut, stdErr) expectedMutatedPrivateRepoURLSecret, err := base64.StdEncoding.DecodeString(stdOut) @@ -190,15 +190,15 @@ func waitArgoDeployment(t *testing.T) { require.Equal(t, expectedMutatedRepoURL, string(expectedMutatedPrivateRepoURLSecret)) // Tests the mutation of the repoURL for Application CRD source(s) for ArgoCD. - stdOut, stdErr, err = e2e.Kubectl("get", "application", "apps", "-n", "argocd", "-o", "jsonpath={.spec.sources[0].repoURL}") + stdOut, stdErr, err = e2e.Kubectl(t, "get", "application", "apps", "-n", "argocd", "-o", "jsonpath={.spec.sources[0].repoURL}") require.NoError(t, err, stdOut, stdErr) require.Equal(t, expectedMutatedRepoURL, stdOut) // Remove the argocd example when deployment completes - stdOut, stdErr, err = e2e.Zarf("package", "remove", "argocd", "--confirm") + stdOut, stdErr, err = e2e.Zarf(t, "package", "remove", "argocd", "--confirm") require.NoError(t, err, stdOut, stdErr) // Prune the ArgoCD images to reduce disk pressure - stdOut, stdErr, err = e2e.Zarf("tools", "registry", "prune", "--confirm") + stdOut, stdErr, err = e2e.Zarf(t, "tools", "registry", "prune", "--confirm") require.NoError(t, err, stdOut, stdErr) } diff --git a/src/test/e2e/23_data_injection_test.go b/src/test/e2e/23_data_injection_test.go index 08f913fc41..c7400b240e 100644 --- a/src/test/e2e/23_data_injection_test.go +++ b/src/test/e2e/23_data_injection_test.go @@ -33,9 +33,9 @@ func TestDataInjection(t *testing.T) { } // Verify the file and injection marker were created - runningKiwixPod, _, err := e2e.Kubectl("--namespace=kiwix", "get", "pods", "--selector=app=kiwix-serve", "--field-selector=status.phase=Running", "--output=jsonpath={.items[0].metadata.name}") + runningKiwixPod, _, err := e2e.Kubectl(t, "--namespace=kiwix", "get", "pods", "--selector=app=kiwix-serve", "--field-selector=status.phase=Running", "--output=jsonpath={.items[0].metadata.name}") require.NoError(t, err) - stdOut, stdErr, err := e2e.Kubectl("--namespace=kiwix", "logs", runningKiwixPod, "--tail=5", "-c=kiwix-serve") + stdOut, stdErr, err := e2e.Kubectl(t, "--namespace=kiwix", "logs", runningKiwixPod, "--tail=5", "-c=kiwix-serve") require.NoError(t, err, stdOut, stdErr) require.Contains(t, stdOut, "devops.stackexchange.com_en_all_2023-05.zim") require.Contains(t, stdOut, ".zarf-injection-") @@ -53,11 +53,11 @@ func TestDataInjection(t *testing.T) { require.Equal(t, 200, resp.StatusCode) // Remove the data injection example - stdOut, stdErr, err = e2e.Zarf("package", "remove", path, "--confirm") + stdOut, stdErr, err = e2e.Zarf(t, "package", "remove", path, "--confirm") require.NoError(t, err, stdOut, stdErr) // Ensure that the `requirements.txt` file is discovered correctly - stdOut, stdErr, err = e2e.Zarf("package", "inspect", path, "--sbom-out", sbomPath) + stdOut, stdErr, err = e2e.Zarf(t, "package", "inspect", path, "--sbom-out", sbomPath) require.NoError(t, err, stdOut, stdErr) require.FileExists(t, filepath.Join(sbomPath, "kiwix", "compare.html"), "A compare.html file should have been made") diff --git a/src/test/e2e/24_variables_test.go b/src/test/e2e/24_variables_test.go index 765c8902bf..f5b06116d0 100644 --- a/src/test/e2e/24_variables_test.go +++ b/src/test/e2e/24_variables_test.go @@ -27,34 +27,34 @@ func TestVariables(t *testing.T) { e2e.CleanFiles(tfPath, evilPath) // Test that specifying an invalid setVariable value results in an error - stdOut, stdErr, err := e2e.Zarf("package", "create", evilSrc, "--set", "NUMB3R5=K1TT3H", "--confirm") + stdOut, stdErr, err := e2e.Zarf(t, "package", "create", evilSrc, "--set", "NUMB3R5=K1TT3H", "--confirm") require.NoError(t, err, stdOut, stdErr) expectedOutString := "\"K1TT3H\"" require.Contains(t, stdErr, "", expectedOutString) - stdOut, stdErr, err = e2e.Zarf("package", "deploy", evilPath, "--confirm") + stdOut, stdErr, err = e2e.Zarf(t, "package", "deploy", evilPath, "--confirm") require.Error(t, err, stdOut, stdErr) expectedOutString = "variable \"HELLO_KITTEH\" does not match pattern " require.Contains(t, stdErr, "", expectedOutString) // Test that specifying an invalid constant value results in an error - stdOut, stdErr, err = e2e.Zarf("package", "create", src, "--set", "NGINX_VERSION=", "--confirm") + stdOut, stdErr, err = e2e.Zarf(t, "package", "create", src, "--set", "NGINX_VERSION=", "--confirm") require.Error(t, err, stdOut, stdErr) expectedOutString = "constant \"NGINX_VERSION\" does not match pattern " require.Contains(t, stdErr, "", expectedOutString) // Test that not specifying a prompted variable results in an error - _, stdErr, _ = e2e.Zarf("package", "deploy", path, "--confirm") + _, stdErr, _ = e2e.Zarf(t, "package", "deploy", path, "--confirm") expectedOutString = "variable 'SITE_NAME' must be '--set' when using the '--confirm' flag" require.Contains(t, stdErr, "", expectedOutString) // Test that specifying an invalid variable value results in an error - stdOut, stdErr, err = e2e.Zarf("package", "deploy", path, "--set", "SITE_NAME=#INVALID", "--confirm") + stdOut, stdErr, err = e2e.Zarf(t, "package", "deploy", path, "--set", "SITE_NAME=#INVALID", "--confirm") require.Error(t, err, stdOut, stdErr) expectedOutString = "variable \"SITE_NAME\" does not match pattern " require.Contains(t, stdErr, "", expectedOutString) // Deploy nginx - stdOut, stdErr, err = e2e.Zarf("package", "deploy", path, "--confirm", "--set", "SITE_NAME=Lula Web", "--set", "AWS_REGION=unicorn-land", "-l", "trace") + stdOut, stdErr, err = e2e.Zarf(t, "package", "deploy", path, "--confirm", "--set", "SITE_NAME=Lula Web", "--set", "AWS_REGION=unicorn-land", "-l", "trace") require.NoError(t, err, stdOut, stdErr) // Verify that the variables were shown to the user in the formats we expect require.Contains(t, stdErr, "currently set to 'Defense Unicorns' (default)") @@ -73,7 +73,7 @@ func TestVariables(t *testing.T) { require.Contains(t, string(outputTF), "unicorn-land") // Verify the configmap was properly templated - kubectlOut, _, _ := e2e.Kubectl("-n", "nginx", "get", "configmap", "nginx-configmap", "-o", "jsonpath='{.data.index\\.html}' ") + kubectlOut, _, _ := e2e.Kubectl(t, "-n", "nginx", "get", "configmap", "nginx-configmap", "-o", "jsonpath='{.data.index\\.html}' ") // OPTIONAL_FOOTER should remain unset because it was not set during deploy require.Contains(t, string(kubectlOut), "\n \n ") // STYLE should take the default value @@ -88,7 +88,7 @@ func TestVariables(t *testing.T) { require.Contains(t, string(kubectlOut), "63af41aebec53e3679948b254073c3c0d603d47ab01b03ab14abd7d98234e101") // Remove the variables example - stdOut, stdErr, err = e2e.Zarf("package", "remove", path, "--confirm") + stdOut, stdErr, err = e2e.Zarf(t, "package", "remove", path, "--confirm") require.NoError(t, err, stdOut, stdErr) e2e.CleanFiles(tfPath, evilPath) diff --git a/src/test/e2e/25_helm_test.go b/src/test/e2e/25_helm_test.go index 071732da10..322d3c89dd 100644 --- a/src/test/e2e/25_helm_test.go +++ b/src/test/e2e/25_helm_test.go @@ -36,52 +36,52 @@ func testHelmChartsExample(t *testing.T) { // Create a package that has a tarball as a local chart localTgzChartPath := filepath.Join("src", "test", "packages", "25-local-tgz-chart") - stdOut, stdErr, err := e2e.Zarf("package", "create", localTgzChartPath, "--tmpdir", tmpdir, "--confirm") + stdOut, stdErr, err := e2e.Zarf(t, "package", "create", localTgzChartPath, "--tmpdir", tmpdir, "--confirm") require.NoError(t, err, stdOut, stdErr) defer e2e.CleanFiles(fmt.Sprintf("zarf-package-helm-charts-local-tgz-%s-0.0.1.tar.zst", e2e.Arch)) // Create a package that needs dependencies evilChartDepsPath := filepath.Join("src", "test", "packages", "25-evil-chart-deps") - stdOut, stdErr, err = e2e.Zarf("package", "create", evilChartDepsPath, "--tmpdir", tmpdir, "--confirm") + stdOut, stdErr, err = e2e.Zarf(t, "package", "create", evilChartDepsPath, "--tmpdir", tmpdir, "--confirm") require.Error(t, err, stdOut, stdErr) require.Contains(t, e2e.StripMessageFormatting(stdErr), "could not download https://charts.jetstack.io/charts/cert-manager-v1.11.1.tgz") require.FileExists(t, filepath.Join(evilChartDepsPath, "good-chart", "charts", "gitlab-runner-0.55.0.tgz")) // Create a package with a chart name that doesn't exist in a repo evilChartLookupPath := filepath.Join("src", "test", "packages", "25-evil-chart-lookup") - stdOut, stdErr, err = e2e.Zarf("package", "create", evilChartLookupPath, "--tmpdir", tmpdir, "--confirm") + stdOut, stdErr, err = e2e.Zarf(t, "package", "create", evilChartLookupPath, "--tmpdir", tmpdir, "--confirm") require.Error(t, err, stdOut, stdErr) require.Contains(t, e2e.StripMessageFormatting(stdErr), "chart \"asdf\" version \"6.4.0\" not found") require.Contains(t, e2e.StripMessageFormatting(stdErr), "Available charts and versions from \"https://stefanprodan.github.io/podinfo\":") // Create a test package (with a registry override (host+subpath to host+subpath) to test that as well) - stdOut, stdErr, err = e2e.Zarf("package", "create", "examples/helm-charts", "-o", "build", "--registry-override", "ghcr.io/stefanprodan=docker.io/stefanprodan", "--tmpdir", tmpdir, "--confirm") + stdOut, stdErr, err = e2e.Zarf(t, "package", "create", "examples/helm-charts", "-o", "build", "--registry-override", "ghcr.io/stefanprodan=docker.io/stefanprodan", "--tmpdir", tmpdir, "--confirm") 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 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") + stdOut, stdErr, err = e2e.Zarf(t, "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") // Create a test package (with a registry override (host+subpath to host) to test that as well) // works same as the above failing test - stdOut, stdErr, err = e2e.Zarf("package", "create", "examples/helm-charts", "-o", "build", "--registry-override", "ghcr.io/stefanprodan=localhost:555", "--tmpdir", tmpdir, "--confirm") + stdOut, stdErr, err = e2e.Zarf(t, "package", "create", "examples/helm-charts", "-o", "build", "--registry-override", "ghcr.io/stefanprodan=localhost:555", "--tmpdir", tmpdir, "--confirm") require.Error(t, err, stdOut, stdErr) require.Contains(t, string(stdErr), "localhost:555") // Create the package (with a registry override (host to host) to test that as well) - stdOut, stdErr, err = e2e.Zarf("package", "create", "examples/helm-charts", "-o", "build", "--registry-override", "ghcr.io=docker.io", "--tmpdir", tmpdir, "--confirm") + stdOut, stdErr, err = e2e.Zarf(t, "package", "create", "examples/helm-charts", "-o", "build", "--registry-override", "ghcr.io=docker.io", "--tmpdir", tmpdir, "--confirm") require.NoError(t, err, stdOut, stdErr) // Deploy the example package. - stdOut, stdErr, err = e2e.Zarf("package", "deploy", helmChartsPkg, "--confirm") + stdOut, stdErr, err = e2e.Zarf(t, "package", "deploy", helmChartsPkg, "--confirm") require.NoError(t, err, stdOut, stdErr) require.Contains(t, string(stdErr), "registryOverrides", "registry overrides was not saved to build data") require.Contains(t, string(stdErr), "docker.io", "docker.io not found in registry overrides") // Remove the example package. - stdOut, stdErr, err = e2e.Zarf("package", "remove", "helm-charts", "--confirm") + stdOut, stdErr, err = e2e.Zarf(t, "package", "remove", "helm-charts", "--confirm") require.NoError(t, err, stdOut, stdErr) } @@ -90,13 +90,13 @@ func testHelmEscaping(t *testing.T) { t.Log("E2E: Helm chart escaping") // Create the package. - stdOut, stdErr, err := e2e.Zarf("package", "create", "src/test/packages/25-evil-templates/", "--confirm") + stdOut, stdErr, err := e2e.Zarf(t, "package", "create", "src/test/packages/25-evil-templates/", "--confirm") require.NoError(t, err, stdOut, stdErr) path := fmt.Sprintf("zarf-package-evil-templates-%s.tar.zst", e2e.Arch) // Deploy the package. - stdOut, stdErr, err = e2e.Zarf("package", "deploy", path, "--confirm") + stdOut, stdErr, err = e2e.Zarf(t, "package", "deploy", path, "--confirm") require.NoError(t, err, stdOut, stdErr) // Verify the configmap was deployed, escaped, and contains all of its data @@ -108,7 +108,7 @@ func testHelmEscaping(t *testing.T) { require.Contains(t, string(kubectlOut), `TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVyIG`) // Remove the package. - stdOut, stdErr, err = e2e.Zarf("package", "remove", "evil-templates", "--confirm") + stdOut, stdErr, err = e2e.Zarf(t, "package", "remove", "evil-templates", "--confirm") require.NoError(t, err, stdOut, stdErr) } @@ -119,11 +119,11 @@ func testHelmUninstallRollback(t *testing.T) { evilPath := fmt.Sprintf("zarf-package-dos-games-%s.tar.zst", e2e.Arch) // Create the evil package (with the bad service). - stdOut, stdErr, err := e2e.Zarf("package", "create", "src/test/packages/25-evil-dos-games/", "--skip-sbom", "--confirm") + stdOut, stdErr, err := e2e.Zarf(t, "package", "create", "src/test/packages/25-evil-dos-games/", "--skip-sbom", "--confirm") require.NoError(t, err, stdOut, stdErr) // Deploy the evil package. - stdOut, stdErr, err = e2e.Zarf("package", "deploy", evilPath, "--timeout", "10s", "--confirm") + stdOut, stdErr, err = e2e.Zarf(t, "package", "deploy", evilPath, "--timeout", "10s", "--confirm") require.Error(t, err, stdOut, stdErr) // This package contains SBOMable things but was created with --skip-sbom @@ -138,7 +138,7 @@ func testHelmUninstallRollback(t *testing.T) { require.Contains(t, string(helmOut), "zarf-f53a99d4a4dd9a3575bedf59cd42d48d751ae866") // Deploy the good package. - stdOut, stdErr, err = e2e.Zarf("package", "deploy", goodPath, "--confirm") + stdOut, stdErr, err = e2e.Zarf(t, "package", "deploy", goodPath, "--confirm") require.NoError(t, err, stdOut, stdErr) // Ensure this upgrades/fixes the dos-games chart. @@ -147,7 +147,7 @@ func testHelmUninstallRollback(t *testing.T) { require.Contains(t, string(helmOut), "zarf-f53a99d4a4dd9a3575bedf59cd42d48d751ae866") // Deploy the evil package. - stdOut, stdErr, err = e2e.Zarf("package", "deploy", evilPath, "--timeout", "10s", "--confirm") + stdOut, stdErr, err = e2e.Zarf(t, "package", "deploy", evilPath, "--timeout", "10s", "--confirm") require.Error(t, err, stdOut, stdErr) // Ensure that we rollback properly @@ -156,7 +156,7 @@ func testHelmUninstallRollback(t *testing.T) { require.Contains(t, string(helmOut), "Rollback to 4") // Deploy the evil package (again to ensure we check full history) - stdOut, stdErr, err = e2e.Zarf("package", "deploy", evilPath, "--timeout", "10s", "--confirm") + stdOut, stdErr, err = e2e.Zarf(t, "package", "deploy", evilPath, "--timeout", "10s", "--confirm") require.Error(t, err, stdOut, stdErr) // Ensure that we rollback properly @@ -165,7 +165,7 @@ func testHelmUninstallRollback(t *testing.T) { require.Contains(t, string(helmOut), "Rollback to 8") // Remove the package. - stdOut, stdErr, err = e2e.Zarf("package", "remove", "dos-games", "--confirm") + stdOut, stdErr, err = e2e.Zarf(t, "package", "remove", "dos-games", "--confirm") require.NoError(t, err, stdOut, stdErr) } @@ -176,11 +176,11 @@ func testHelmAdoption(t *testing.T) { deploymentManifest := "src/test/packages/25-manifest-adoption/deployment.yaml" // Deploy dos-games manually into the cluster without Zarf - kubectlOut, _, _ := e2e.Kubectl("apply", "-f", deploymentManifest) + kubectlOut, _, _ := e2e.Kubectl(t, "apply", "-f", deploymentManifest) require.Contains(t, string(kubectlOut), "deployment.apps/game created") // Deploy dos-games into the cluster with Zarf - stdOut, stdErr, err := e2e.Zarf("package", "deploy", packagePath, "--confirm", "--adopt-existing-resources") + stdOut, stdErr, err := e2e.Zarf(t, "package", "deploy", packagePath, "--confirm", "--adopt-existing-resources") require.NoError(t, err, stdOut, stdErr) // Ensure that this does create a dos-games chart @@ -188,14 +188,14 @@ func testHelmAdoption(t *testing.T) { require.NoError(t, err) require.Contains(t, string(helmOut), "zarf-f53a99d4a4dd9a3575bedf59cd42d48d751ae866") - existingLabel, _, err := e2e.Kubectl("get", "ns", "dos-games", "-o=jsonpath={.metadata.labels.keep-this}") + existingLabel, _, err := e2e.Kubectl(t, "get", "ns", "dos-games", "-o=jsonpath={.metadata.labels.keep-this}") require.Equal(t, "label", existingLabel) require.NoError(t, err) - existingAnnotation, _, err := e2e.Kubectl("get", "ns", "dos-games", "-o=jsonpath={.metadata.annotations.keep-this}") + existingAnnotation, _, err := e2e.Kubectl(t, "get", "ns", "dos-games", "-o=jsonpath={.metadata.annotations.keep-this}") require.Equal(t, "annotation", existingAnnotation) require.NoError(t, err) // Remove the package. - stdOut, stdErr, err = e2e.Zarf("package", "remove", "dos-games", "--confirm") + stdOut, stdErr, err = e2e.Zarf(t, "package", "remove", "dos-games", "--confirm") require.NoError(t, err, stdOut, stdErr) } diff --git a/src/test/e2e/26_simple_packages_test.go b/src/test/e2e/26_simple_packages_test.go index 05a95d97d2..6e4c20bd8a 100644 --- a/src/test/e2e/26_simple_packages_test.go +++ b/src/test/e2e/26_simple_packages_test.go @@ -21,7 +21,7 @@ func TestDosGames(t *testing.T) { path := filepath.Join("build", fmt.Sprintf("zarf-package-dos-games-%s-1.0.0.tar.zst", e2e.Arch)) // Deploy the game - stdOut, stdErr, err := e2e.Zarf("package", "deploy", path, "--confirm") + stdOut, stdErr, err := e2e.Zarf(t, "package", "deploy", path, "--confirm") require.NoError(t, err, stdOut, stdErr) c, err := cluster.NewCluster() @@ -35,18 +35,18 @@ func TestDosGames(t *testing.T) { require.NoError(t, err, resp) require.Equal(t, 200, resp.StatusCode) - stdOut, stdErr, err = e2e.Zarf("package", "remove", "dos-games", "--confirm") + stdOut, stdErr, err = e2e.Zarf(t, "package", "remove", "dos-games", "--confirm") require.NoError(t, err, stdOut, stdErr) testCreate := filepath.Join("src", "test", "packages", "26-image-dos-games") testDeploy := filepath.Join("build", fmt.Sprintf("zarf-package-dos-games-images-%s.tar.zst", e2e.Arch)) // Create the game image test package - stdOut, stdErr, err = e2e.Zarf("package", "create", testCreate, "-o", "build", "--confirm") + stdOut, stdErr, err = e2e.Zarf(t, "package", "create", testCreate, "-o", "build", "--confirm") require.NoError(t, err, stdOut, stdErr) // Deploy the game image test package - stdOut, stdErr, err = e2e.Zarf("package", "deploy", testDeploy, "--confirm") + stdOut, stdErr, err = e2e.Zarf(t, "package", "deploy", testDeploy, "--confirm") require.NoError(t, err, stdOut, stdErr) } @@ -56,11 +56,11 @@ func TestManifests(t *testing.T) { path := filepath.Join("build", fmt.Sprintf("zarf-package-manifests-%s-0.0.1.tar.zst", e2e.Arch)) // Deploy the package - stdOut, stdErr, err := e2e.Zarf("package", "deploy", path, "--confirm") + stdOut, stdErr, err := e2e.Zarf(t, "package", "deploy", path, "--confirm") require.NoError(t, err, stdOut, stdErr) // Remove the package - stdOut, stdErr, err = e2e.Zarf("package", "remove", "manifests", "--confirm") + stdOut, stdErr, err = e2e.Zarf(t, "package", "remove", "manifests", "--confirm") require.NoError(t, err, stdOut, stdErr) } @@ -71,10 +71,10 @@ func TestAgentIgnore(t *testing.T) { testDeploy := filepath.Join("build", fmt.Sprintf("zarf-package-agent-ignore-namespace-%s.tar.zst", e2e.Arch)) // Create the agent ignore test package - stdOut, stdErr, err := e2e.Zarf("package", "create", testCreate, "-o", "build", "--confirm") + stdOut, stdErr, err := e2e.Zarf(t, "package", "create", testCreate, "-o", "build", "--confirm") require.NoError(t, err, stdOut, stdErr) // Deploy the agent ignore test package - stdOut, stdErr, err = e2e.Zarf("package", "deploy", testDeploy, "--confirm") + stdOut, stdErr, err = e2e.Zarf(t, "package", "deploy", testDeploy, "--confirm") require.NoError(t, err, stdOut, stdErr) } diff --git a/src/test/e2e/27_deploy_regression_test.go b/src/test/e2e/27_deploy_regression_test.go index 49808addff..f16c3d243a 100644 --- a/src/test/e2e/27_deploy_regression_test.go +++ b/src/test/e2e/27_deploy_regression_test.go @@ -5,7 +5,6 @@ package test import ( - "context" "fmt" "testing" @@ -26,10 +25,10 @@ func TestGHCRDeploy(t *testing.T) { } // Test with command from https://docs.zarf.dev/getting-started/install/ - stdOut, stdErr, err := e2e.Zarf("package", "deploy", fmt.Sprintf("oci://🦄/dos-games:1.0.0-%s@sha256:%s", e2e.Arch, sha), "--key=https://zarf.dev/cosign.pub", "--confirm") + stdOut, stdErr, err := e2e.Zarf(t, "package", "deploy", fmt.Sprintf("oci://🦄/dos-games:1.0.0-%s@sha256:%s", e2e.Arch, sha), "--key=https://zarf.dev/cosign.pub", "--confirm") require.NoError(t, err, stdOut, stdErr) - stdOut, stdErr, err = e2e.Zarf("package", "remove", "dos-games", "--confirm") + stdOut, stdErr, err = e2e.Zarf(t, "package", "remove", "dos-games", "--confirm") require.NoError(t, err, stdOut, stdErr) } @@ -39,9 +38,9 @@ func TestCosignDeploy(t *testing.T) { // Test with command from https://docs.zarf.dev/getting-started/install/ command := fmt.Sprintf("%s package deploy sget://defenseunicorns/zarf-hello-world:$(uname -m) --confirm", e2e.ZarfBinPath) - stdOut, stdErr, err := exec.CmdWithContext(context.TODO(), exec.PrintCfg(), "sh", "-c", command) + stdOut, stdErr, err := exec.CmdWithTesting(t, exec.PrintCfg(), "sh", "-c", command) require.NoError(t, err, stdOut, stdErr) - stdOut, stdErr, err = e2e.Zarf("package", "remove", "dos-games", "--confirm") + stdOut, stdErr, err = e2e.Zarf(t, "package", "remove", "dos-games", "--confirm") require.NoError(t, err, stdOut, stdErr) } diff --git a/src/test/e2e/28_wait_test.go b/src/test/e2e/28_wait_test.go index e1b22b4f28..e150d163fd 100644 --- a/src/test/e2e/28_wait_test.go +++ b/src/test/e2e/28_wait_test.go @@ -20,22 +20,22 @@ type zarfCommandResult struct { err error } -func zarfCommandWStruct(e2e test.ZarfE2ETest, path string) (result zarfCommandResult) { - result.stdOut, result.stdErr, result.err = e2e.Zarf("package", "deploy", path, "--confirm") +func zarfCommandWStruct(t *testing.T, e2e test.ZarfE2ETest, path string) (result zarfCommandResult) { + result.stdOut, result.stdErr, result.err = e2e.Zarf(t, "package", "deploy", path, "--confirm") return result } func TestNoWait(t *testing.T) { t.Log("E2E: Helm Wait") - stdOut, stdErr, err := e2e.Zarf("package", "create", "src/test/packages/28-helm-no-wait", "-o=build", "--confirm") + stdOut, stdErr, err := e2e.Zarf(t, "package", "create", "src/test/packages/28-helm-no-wait", "-o=build", "--confirm") require.NoError(t, err, stdOut, stdErr) path := fmt.Sprintf("build/zarf-package-helm-no-wait-%s.tar.zst", e2e.Arch) zarfChannel := make(chan zarfCommandResult, 1) go func() { - zarfChannel <- zarfCommandWStruct(e2e, path) + zarfChannel <- zarfCommandWStruct(t, e2e, path) }() stdOut = "" @@ -50,10 +50,10 @@ func TestNoWait(t *testing.T) { case <-time.After(30 * time.Second): t.Error("Timeout waiting for zarf deploy (it tried to wait)") t.Log("Removing hanging namespace...") - _, _, _ = e2e.Kubectl("delete", "namespace", "no-wait", "--force=true", "--wait=false", "--grace-period=0") + _, _, _ = e2e.Kubectl(t, "delete", "namespace", "no-wait", "--force=true", "--wait=false", "--grace-period=0") } require.NoError(t, err, stdOut, stdErr) - stdOut, stdErr, err = e2e.Zarf("package", "remove", "helm-no-wait", "--confirm") + stdOut, stdErr, err = e2e.Zarf(t, "package", "remove", "helm-no-wait", "--confirm") require.NoError(t, err, stdOut, stdErr) } diff --git a/src/test/e2e/29_config_file_test.go b/src/test/e2e/29_config_file_test.go index 40c66b4204..e947621518 100644 --- a/src/test/e2e/29_config_file_test.go +++ b/src/test/e2e/29_config_file_test.go @@ -31,7 +31,7 @@ func TestConfigFile(t *testing.T) { configFileDefaultTests(t) - stdOut, stdErr, err := e2e.Zarf("package", "remove", path, "--confirm") + stdOut, stdErr, err := e2e.Zarf(t, "package", "remove", path, "--confirm") require.NoError(t, err, stdOut, stdErr) e2e.CleanFiles(path) @@ -40,12 +40,12 @@ func TestConfigFile(t *testing.T) { func configFileTests(t *testing.T, dir, path string) { t.Helper() - _, stdErr, err := e2e.Zarf("package", "create", dir, "--confirm") + _, stdErr, err := e2e.Zarf(t, "package", "create", dir, "--confirm") require.NoError(t, err) require.Contains(t, string(stdErr), "This is a zebra and they have stripes") require.Contains(t, string(stdErr), "This is a leopard and they have spots") - _, stdErr, err = e2e.Zarf("package", "deploy", path, "--confirm") + _, stdErr, err = e2e.Zarf(t, "package", "deploy", path, "--confirm") require.NoError(t, err) require.Contains(t, string(stdErr), "📦 LION COMPONENT") require.NotContains(t, string(stdErr), "📦 LEOPARD COMPONENT") @@ -55,7 +55,7 @@ func configFileTests(t *testing.T, dir, path string) { require.NotContains(t, string(stdErr), "This package does NOT contain an SBOM.") // Verify the configmap was properly templated - kubectlOut, _, err := e2e.Kubectl("-n", "zarf", "get", "configmap", "simple-configmap", "-o", "jsonpath={.data.templateme\\.properties}") + kubectlOut, _, err := e2e.Kubectl(t, "-n", "zarf", "get", "configmap", "simple-configmap", "-o", "jsonpath={.data.templateme\\.properties}") require.NoError(t, err) require.Contains(t, string(kubectlOut), "scorpion=iridescent") require.Contains(t, string(kubectlOut), "camel_spider=matte") @@ -89,7 +89,7 @@ b42JLSKqwpvVjQDiFZPI/0wZTo3WkWm9Rd7CAACheb8S70K1r/JIzsmIcnj0v4xs sfd+R35UE+m8MExbDP4lKFParmvi2/UZfb3VFNMmMPTV6AEIBl6N4PmhHMZOsIRs H4RxbE+FpmsMAUCpdrzvFkc= -----END PRIVATE KEY-----` - kubectlOut, _, err = e2e.Kubectl("-n", "zarf", "get", "configmap", "simple-configmap", "-o", "jsonpath={.data.tls-key}") + kubectlOut, _, err = e2e.Kubectl(t, "-n", "zarf", "get", "configmap", "simple-configmap", "-o", "jsonpath={.data.tls-key}") require.NoError(t, err) require.Equal(t, tlsKey, kubectlOut) } @@ -142,25 +142,25 @@ func configFileDefaultTests(t *testing.T) { defer os.Unsetenv("ZARF_CONFIG") // Test global flags - stdOut, _, _ := e2e.Zarf("--help") + stdOut, _, _ := e2e.Zarf(t, "--help") for _, test := range globalFlags { require.Contains(t, string(stdOut), test) } // Test init flags - stdOut, _, _ = e2e.Zarf("init", "--help") + stdOut, _, _ = e2e.Zarf(t, "init", "--help") for _, test := range initFlags { require.Contains(t, string(stdOut), test) } // Test package create flags - stdOut, _, _ = e2e.Zarf("package", "create", "--help") + stdOut, _, _ = e2e.Zarf(t, "package", "create", "--help") for _, test := range packageCreateFlags { require.Contains(t, string(stdOut), test) } // Test package deploy flags - stdOut, _, _ = e2e.Zarf("package", "deploy", "--help") + stdOut, _, _ = e2e.Zarf(t, "package", "deploy", "--help") for _, test := range packageDeployFlags { require.Contains(t, string(stdOut), test) } diff --git a/src/test/e2e/30_component_action_cluster_test.go b/src/test/e2e/30_component_action_cluster_test.go index 5d6658152f..6763a042dc 100644 --- a/src/test/e2e/30_component_action_cluster_test.go +++ b/src/test/e2e/30_component_action_cluster_test.go @@ -17,10 +17,10 @@ func TestComponentActionRemove(t *testing.T) { packagePath := filepath.Join("build", fmt.Sprintf("zarf-package-component-actions-%s.tar.zst", e2e.Arch)) - stdOut, stdErr, err := e2e.Zarf("package", "deploy", packagePath, "--confirm", "--components=on-remove") + stdOut, stdErr, err := e2e.Zarf(t, "package", "deploy", packagePath, "--confirm", "--components=on-remove") require.NoError(t, err, stdOut, stdErr) - stdOut, stdErr, err = e2e.Zarf("package", "remove", packagePath, "--confirm", "--components=on-remove") + stdOut, stdErr, err = e2e.Zarf(t, "package", "remove", packagePath, "--confirm", "--components=on-remove") require.NoError(t, err, stdOut, stdErr) require.Contains(t, stdErr, "NAME") require.Contains(t, stdErr, "DATA") @@ -34,10 +34,10 @@ func TestComponentActionEdgeCases(t *testing.T) { sourcePath := filepath.Join("src", "test", "packages", "31-component-actions-edgecases") packagePath := fmt.Sprintf("zarf-package-component-actions-edgecases-%s.tar.zst", e2e.Arch) - stdOut, stdErr, err := e2e.Zarf("package", "create", sourcePath, "--confirm") + stdOut, stdErr, err := e2e.Zarf(t, "package", "create", sourcePath, "--confirm") require.NoError(t, err, stdOut, stdErr) defer e2e.CleanFiles(packagePath) - stdOut, stdErr, err = e2e.Zarf("package", "deploy", packagePath, "--confirm") + stdOut, stdErr, err = e2e.Zarf(t, "package", "deploy", packagePath, "--confirm") require.NoError(t, err, stdOut, stdErr) } diff --git a/src/test/e2e/31_checksum_and_signature_test.go b/src/test/e2e/31_checksum_and_signature_test.go index 2b3856779f..e8aed4c1cb 100644 --- a/src/test/e2e/31_checksum_and_signature_test.go +++ b/src/test/e2e/31_checksum_and_signature_test.go @@ -19,32 +19,32 @@ func TestChecksumAndSignature(t *testing.T) { privateKeyFlag := "--signing-key=src/test/packages/zarf-test.prv-key" publicKeyFlag := "--key=src/test/packages/zarf-test.pub" - stdOut, stdErr, err := e2e.Zarf("package", "create", testPackageDirPath, privateKeyFlag, "--confirm") + stdOut, stdErr, err := e2e.Zarf(t, "package", "create", testPackageDirPath, privateKeyFlag, "--confirm") require.NoError(t, err, stdOut, stdErr) defer e2e.CleanFiles(pkgName) /* Test operations during package inspect */ // Test that we can inspect the yaml of the package without the private key - stdOut, stdErr, err = e2e.Zarf("package", "inspect", pkgName) + stdOut, stdErr, err = e2e.Zarf(t, "package", "inspect", pkgName) require.NoError(t, err, stdOut, stdErr) // Test that we don't get an error when we remember to provide the public key - stdOut, stdErr, err = e2e.Zarf("package", "inspect", pkgName, publicKeyFlag) + stdOut, stdErr, err = e2e.Zarf(t, "package", "inspect", pkgName, publicKeyFlag) require.NoError(t, err, stdOut, stdErr) require.Contains(t, stdErr, "Verified OK") /* Test operations during package deploy */ // Test that we get an error when trying to deploy a package without providing the public key - stdOut, stdErr, err = e2e.Zarf("package", "deploy", pkgName, "--confirm") + stdOut, stdErr, err = e2e.Zarf(t, "package", "deploy", pkgName, "--confirm") require.Error(t, err, stdOut, stdErr) require.Contains(t, stdErr, "failed to deploy package: unable to load the package: package is signed but no key was provided - add a key with the --key flag or use the --insecure flag and run the command again") // Test that we don't get an error when we remember to provide the public key - stdOut, stdErr, err = e2e.Zarf("package", "deploy", pkgName, publicKeyFlag, "--confirm") + stdOut, stdErr, err = e2e.Zarf(t, "package", "deploy", pkgName, publicKeyFlag, "--confirm") require.NoError(t, err, stdOut, stdErr) require.Contains(t, stdErr, "Zarf deployment complete") // Remove the package - stdOut, stdErr, err = e2e.Zarf("package", "remove", pkgName, publicKeyFlag, "--confirm") + stdOut, stdErr, err = e2e.Zarf(t, "package", "remove", pkgName, publicKeyFlag, "--confirm") require.NoError(t, err, stdOut, stdErr) } diff --git a/src/test/e2e/32_component_webhooks_test.go b/src/test/e2e/32_component_webhooks_test.go index d409e62521..7d6d761835 100644 --- a/src/test/e2e/32_component_webhooks_test.go +++ b/src/test/e2e/32_component_webhooks_test.go @@ -16,32 +16,32 @@ func TestComponentWebhooks(t *testing.T) { // Deploy example Pepr webhook. webhookPath := fmt.Sprintf("build/zarf-package-component-webhooks-%s-0.0.1.tar.zst", e2e.Arch) - stdOut, stdErr, err := e2e.Zarf("package", "deploy", webhookPath, "--confirm") + stdOut, stdErr, err := e2e.Zarf(t, "package", "deploy", webhookPath, "--confirm") require.NoError(t, err, stdOut, stdErr) - stdOut, stdErr, err = e2e.Zarf("tools", "wait-for", "deployment", "pepr-cb5693ef-d13c-5fe1-b5ad-c870fd911b3b", "available", "-n=pepr-system") + stdOut, stdErr, err = e2e.Zarf(t, "tools", "wait-for", "deployment", "pepr-cb5693ef-d13c-5fe1-b5ad-c870fd911b3b", "available", "-n=pepr-system") require.NoError(t, err, stdOut, stdErr) defer e2e.CleanFiles(webhookPath) // Ensure package deployments wait for webhooks to complete. gamesPath := fmt.Sprintf("build/zarf-package-dos-games-%s-1.0.0.tar.zst", e2e.Arch) - stdOut, stdErr, err = e2e.Zarf("package", "deploy", gamesPath, "--confirm") + stdOut, stdErr, err = e2e.Zarf(t, "package", "deploy", gamesPath, "--confirm") require.NoError(t, err, stdOut, stdErr) require.Contains(t, stdErr, "Waiting for webhook \"test-webhook\" to complete for component \"baseline\"") // Ensure package deployments with the '--skip-webhooks' flag do not wait on webhooks to complete. - stdOut, stdErr, err = e2e.Zarf("package", "deploy", gamesPath, "--skip-webhooks", "--confirm") + stdOut, stdErr, err = e2e.Zarf(t, "package", "deploy", gamesPath, "--skip-webhooks", "--confirm") require.NoError(t, err, stdOut, stdErr) require.NotContains(t, stdErr, "Waiting for webhook \"test-webhook\" to complete for component \"baseline\"") // Remove the Pepr webhook package. - stdOut, stdErr, err = e2e.Zarf("package", "remove", "component-webhooks", "--confirm") + stdOut, stdErr, err = e2e.Zarf(t, "package", "remove", "component-webhooks", "--confirm") require.NoError(t, err, stdOut, stdErr) - stdOut, stdErr, err = e2e.Kubectl("delete", "namespace", "pepr-system") + stdOut, stdErr, err = e2e.Kubectl(t, "delete", "namespace", "pepr-system") require.NoError(t, err, stdOut, stdErr) // Remove the dos-games package. - stdOut, stdErr, err = e2e.Zarf("package", "remove", "dos-games", "--confirm") + stdOut, stdErr, err = e2e.Zarf(t, "package", "remove", "dos-games", "--confirm") require.NoError(t, err, stdOut, stdErr) - stdOut, stdErr, err = e2e.Kubectl("delete", "namespace", "dos-games") + stdOut, stdErr, err = e2e.Kubectl(t, "delete", "namespace", "dos-games") require.NoError(t, err, stdOut, stdErr) } diff --git a/src/test/e2e/33_manifest_with_symlink_test.go b/src/test/e2e/33_manifest_with_symlink_test.go index 4664189636..9748154dc7 100644 --- a/src/test/e2e/33_manifest_with_symlink_test.go +++ b/src/test/e2e/33_manifest_with_symlink_test.go @@ -17,14 +17,14 @@ func TestManifestWithSymlink(t *testing.T) { // Build the package, should succeed, even though there is a symlink in the package. buildPath := filepath.Join("src", "test", "packages", "34-manifest-with-symlink") - stdOut, stdErr, err := e2e.Zarf("package", "create", buildPath, "-o=build", "--confirm") + stdOut, stdErr, err := e2e.Zarf(t, "package", "create", buildPath, "-o=build", "--confirm") require.NoError(t, err, stdOut, stdErr) path := fmt.Sprintf("build/zarf-package-manifest-with-symlink-%s-0.0.1.tar.zst", e2e.Arch) require.FileExists(t, path) defer e2e.CleanFiles(path) - stdOut, stdErr, err = e2e.Zarf("package", "deploy", path, "--confirm") + stdOut, stdErr, err = e2e.Zarf(t, "package", "deploy", path, "--confirm") defer e2e.CleanFiles("temp/manifests") require.NoError(t, err, stdOut, stdErr) require.FileExists(t, "temp/manifests/resources/img", "Symlink does not exist in the package as expected.") diff --git a/src/test/e2e/34_custom_init_package_test.go b/src/test/e2e/34_custom_init_package_test.go index 6229255aca..c61cf91e2d 100644 --- a/src/test/e2e/34_custom_init_package_test.go +++ b/src/test/e2e/34_custom_init_package_test.go @@ -20,28 +20,28 @@ func TestCustomInit(t *testing.T) { privateKeyFlag := "--signing-key=src/test/packages/zarf-test.prv-key" publicKeyFlag := "--key=src/test/packages/zarf-test.pub" - stdOut, stdErr, err := e2e.Zarf("package", "create", buildPath, privateKeyFlag, "--confirm") + stdOut, stdErr, err := e2e.Zarf(t, "package", "create", buildPath, privateKeyFlag, "--confirm") require.NoError(t, err, stdOut, stdErr) defer e2e.CleanFiles(pkgName) /* Test operations during package inspect */ // Test that we can inspect the yaml of the package without the private key - stdOut, stdErr, err = e2e.Zarf("package", "inspect", pkgName) + stdOut, stdErr, err = e2e.Zarf(t, "package", "inspect", pkgName) require.NoError(t, err, stdOut, stdErr) // Test that we don't get an error when we remember to provide the public key - stdOut, stdErr, err = e2e.Zarf("package", "inspect", pkgName, publicKeyFlag) + stdOut, stdErr, err = e2e.Zarf(t, "package", "inspect", pkgName, publicKeyFlag) require.NoError(t, err, stdOut, stdErr) require.Contains(t, stdErr, "Verified OK") /* Test operations during package deploy */ // Test that we get an error when trying to deploy a package without providing the public key - stdOut, stdErr, err = e2e.Zarf("init", "--confirm") + stdOut, stdErr, err = e2e.Zarf(t, "init", "--confirm") require.Error(t, err, stdOut, stdErr) require.Contains(t, stdErr, "unable to load the package: package is signed but no key was provided - add a key with the --key flag or use the --insecure flag and run the command again") /* Test operations during package deploy */ // Test that we can deploy the package with the public key - stdOut, stdErr, err = e2e.Zarf("init", "--confirm", publicKeyFlag) + stdOut, stdErr, err = e2e.Zarf(t, "init", "--confirm", publicKeyFlag) require.NoError(t, err, stdOut, stdErr) } diff --git a/src/test/e2e/35_custom_retries_test.go b/src/test/e2e/35_custom_retries_test.go index 92d7e2fffe..e6a87ff5e1 100644 --- a/src/test/e2e/35_custom_retries_test.go +++ b/src/test/e2e/35_custom_retries_test.go @@ -21,14 +21,14 @@ func TestRetries(t *testing.T) { buildPath := filepath.Join("src", "test", "packages", "25-evil-dos-games") pkgName := fmt.Sprintf("zarf-package-dos-games-%s.tar.zst", e2e.Arch) - stdOut, stdErr, err := e2e.Zarf("package", "create", buildPath, "--tmpdir", tmpDir, "--output", tmpDir, "--confirm") + stdOut, stdErr, err := e2e.Zarf(t, "package", "create", buildPath, "--tmpdir", tmpDir, "--output", tmpDir, "--confirm") require.NoError(t, err, stdOut, stdErr) - stdOut, stdErr, err = e2e.Zarf("package", "deploy", path.Join(tmpDir, pkgName), "--retries", "2", "--timeout", "3s", "--tmpdir", tmpDir, "--confirm") + stdOut, stdErr, err = e2e.Zarf(t, "package", "deploy", path.Join(tmpDir, pkgName), "--retries", "2", "--timeout", "3s", "--tmpdir", tmpDir, "--confirm") require.Error(t, err, stdOut, stdErr) require.Contains(t, stdErr, "Retrying in 5s") require.Contains(t, e2e.StripMessageFormatting(stdErr), "unable to install chart after 2 attempts") - _, _, err = e2e.Zarf("package", "remove", "dos-games", "--confirm") + _, _, err = e2e.Zarf(t, "package", "remove", "dos-games", "--confirm") require.NoError(t, err) } diff --git a/src/test/e2e/50_oci_publish_deploy_test.go b/src/test/e2e/50_oci_publish_deploy_test.go index 81e5e39f54..f72fbb28b5 100644 --- a/src/test/e2e/50_oci_publish_deploy_test.go +++ b/src/test/e2e/50_oci_publish_deploy_test.go @@ -54,35 +54,35 @@ func (suite *PublishDeploySuiteTestSuite) Test_0_Publish() { // Publish package. example := filepath.Join(suite.PackagesDir, fmt.Sprintf("zarf-package-helm-charts-%s-0.0.1.tar.zst", e2e.Arch)) ref := suite.Reference.String() - stdOut, stdErr, err := e2e.Zarf("package", "publish", example, "oci://"+ref, "--insecure") + stdOut, stdErr, err := e2e.Zarf(suite.T(), "package", "publish", example, "oci://"+ref, "--insecure") suite.NoError(err, stdOut, stdErr) suite.Contains(stdErr, "Published "+ref) // Pull the package via OCI. - stdOut, stdErr, err = e2e.Zarf("package", "pull", "oci://"+ref+"/helm-charts:0.0.1", "--insecure") + stdOut, stdErr, err = e2e.Zarf(suite.T(), "package", "pull", "oci://"+ref+"/helm-charts:0.0.1", "--insecure") suite.NoError(err, stdOut, stdErr) // Publish w/ package missing `metadata.version` field. example = filepath.Join(suite.PackagesDir, fmt.Sprintf("zarf-package-component-actions-%s.tar.zst", e2e.Arch)) - _, stdErr, err = e2e.Zarf("package", "publish", example, "oci://"+ref, "--insecure") + _, stdErr, err = e2e.Zarf(suite.T(), "package", "publish", example, "oci://"+ref, "--insecure") suite.Error(err, stdErr) // Inline publish package. dir := filepath.Join("examples", "helm-charts") - stdOut, stdErr, err = e2e.Zarf("package", "create", dir, "-o", "oci://"+ref, "--insecure", "--oci-concurrency=5", "--confirm") + stdOut, stdErr, err = e2e.Zarf(suite.T(), "package", "create", dir, "-o", "oci://"+ref, "--insecure", "--oci-concurrency=5", "--confirm") suite.NoError(err, stdOut, stdErr) // Inline publish flavor. dir = filepath.Join("examples", "package-flavors") - stdOut, stdErr, err = e2e.Zarf("package", "create", dir, "-o", "oci://"+ref, "--flavor", "oracle-cookie-crunch", "--insecure", "--confirm") + stdOut, stdErr, err = e2e.Zarf(suite.T(), "package", "create", dir, "-o", "oci://"+ref, "--flavor", "oracle-cookie-crunch", "--insecure", "--confirm") suite.NoError(err, stdOut, stdErr) // Inspect published flavor. - stdOut, stdErr, err = e2e.Zarf("package", "inspect", "oci://"+ref+"/package-flavors:1.0.0-oracle-cookie-crunch", "--insecure") + stdOut, stdErr, err = e2e.Zarf(suite.T(), "package", "inspect", "oci://"+ref+"/package-flavors:1.0.0-oracle-cookie-crunch", "--insecure") suite.NoError(err, stdOut, stdErr) // Inspect the published package. - stdOut, stdErr, err = e2e.Zarf("package", "inspect", "oci://"+ref+"/helm-charts:0.0.1", "--insecure") + stdOut, stdErr, err = e2e.Zarf(suite.T(), "package", "inspect", "oci://"+ref+"/helm-charts:0.0.1", "--insecure") suite.NoError(err, stdOut, stdErr) } @@ -95,15 +95,15 @@ func (suite *PublishDeploySuiteTestSuite) Test_1_Deploy() { ref := suite.Reference.String() // Deploy the package via OCI. - stdOut, stdErr, err := e2e.Zarf("package", "deploy", "oci://"+ref, "--insecure", "--confirm") + stdOut, stdErr, err := e2e.Zarf(suite.T(), "package", "deploy", "oci://"+ref, "--insecure", "--confirm") suite.NoError(err, stdOut, stdErr) // Remove the package via OCI. - stdOut, stdErr, err = e2e.Zarf("package", "remove", "oci://"+ref, "--insecure", "--confirm") + stdOut, stdErr, err = e2e.Zarf(suite.T(), "package", "remove", "oci://"+ref, "--insecure", "--confirm") suite.NoError(err, stdOut, stdErr) // Test deploy w/ bad ref. - _, stdErr, err = e2e.Zarf("package", "deploy", "oci://"+badDeployRef.String(), "--insecure", "--confirm") + _, stdErr, err = e2e.Zarf(suite.T(), "package", "deploy", "oci://"+badDeployRef.String(), "--insecure", "--confirm") suite.Error(err, stdErr) } @@ -116,7 +116,7 @@ func (suite *PublishDeploySuiteTestSuite) Test_2_Pull_And_Deploy() { suite.FileExists(local) // Deploy the local package. - stdOut, stdErr, err := e2e.Zarf("package", "deploy", local, "--confirm") + stdOut, stdErr, err := e2e.Zarf(suite.T(), "package", "deploy", local, "--confirm") suite.NoError(err, stdOut, stdErr) } diff --git a/src/test/e2e/51_oci_compose_test.go b/src/test/e2e/51_oci_compose_test.go index b38db002a6..0d98d13c8b 100644 --- a/src/test/e2e/51_oci_compose_test.go +++ b/src/test/e2e/51_oci_compose_test.go @@ -63,50 +63,50 @@ func (suite *SkeletonSuite) Test_0_Publish_Skeletons() { ref := suite.Reference.String() helmCharts := filepath.Join("examples", "helm-charts") - _, stdErr, err := e2e.Zarf("package", "publish", helmCharts, "oci://"+ref, "--insecure") + _, stdErr, err := e2e.Zarf(suite.T(), "package", "publish", helmCharts, "oci://"+ref, "--insecure") suite.NoError(err) suite.Contains(stdErr, "Published "+ref) bigBang := filepath.Join("src", "test", "packages", "51-import-everything", "big-bang-min") - _, stdErr, err = e2e.Zarf("package", "publish", bigBang, "oci://"+ref, "--insecure") + _, stdErr, err = e2e.Zarf(suite.T(), "package", "publish", bigBang, "oci://"+ref, "--insecure") suite.NoError(err) suite.Contains(stdErr, "Published "+ref) composable := filepath.Join("src", "test", "packages", "09-composable-packages") - _, stdErr, err = e2e.Zarf("package", "publish", composable, "oci://"+ref, "--insecure") + _, stdErr, err = e2e.Zarf(suite.T(), "package", "publish", composable, "oci://"+ref, "--insecure") suite.NoError(err) suite.Contains(stdErr, "Published "+ref) - _, stdErr, err = e2e.Zarf("package", "publish", importEverything, "oci://"+ref, "--insecure") + _, stdErr, err = e2e.Zarf(suite.T(), "package", "publish", importEverything, "oci://"+ref, "--insecure") suite.NoError(err) suite.Contains(stdErr, "Published "+ref) - _, _, err = e2e.Zarf("package", "inspect", "oci://"+ref+"/import-everything:0.0.1", "--insecure", "-a", "skeleton") + _, _, err = e2e.Zarf(suite.T(), "package", "inspect", "oci://"+ref+"/import-everything:0.0.1", "--insecure", "-a", "skeleton") suite.NoError(err) - _, _, err = e2e.Zarf("package", "pull", "oci://"+ref+"/import-everything:0.0.1", "-o", "build", "--insecure", "-a", "skeleton") + _, _, err = e2e.Zarf(suite.T(), "package", "pull", "oci://"+ref+"/import-everything:0.0.1", "-o", "build", "--insecure", "-a", "skeleton") suite.NoError(err) - _, _, err = e2e.Zarf("package", "pull", "oci://"+ref+"/helm-charts:0.0.1", "-o", "build", "--insecure", "-a", "skeleton") + _, _, err = e2e.Zarf(suite.T(), "package", "pull", "oci://"+ref+"/helm-charts:0.0.1", "-o", "build", "--insecure", "-a", "skeleton") suite.NoError(err) - _, _, err = e2e.Zarf("package", "pull", "oci://"+ref+"/big-bang-min:2.10.0", "-o", "build", "--insecure", "-a", "skeleton") + _, _, err = e2e.Zarf(suite.T(), "package", "pull", "oci://"+ref+"/big-bang-min:2.10.0", "-o", "build", "--insecure", "-a", "skeleton") suite.NoError(err) - _, _, err = e2e.Zarf("package", "pull", "oci://"+ref+"/test-compose-package:0.0.1", "-o", "build", "--insecure", "-a", "skeleton") + _, _, err = e2e.Zarf(suite.T(), "package", "pull", "oci://"+ref+"/test-compose-package:0.0.1", "-o", "build", "--insecure", "-a", "skeleton") suite.NoError(err) } func (suite *SkeletonSuite) Test_1_Compose_Everything_Inception() { suite.T().Log("E2E: Skeleton Package Compose oci://") - _, _, err := e2e.Zarf("package", "create", importEverything, "-o", "build", "--insecure", "--confirm") + _, _, err := e2e.Zarf(suite.T(), "package", "create", importEverything, "-o", "build", "--insecure", "--confirm") suite.NoError(err) - _, _, err = e2e.Zarf("package", "create", importception, "-o", "build", "--insecure", "--confirm") + _, _, err = e2e.Zarf(suite.T(), "package", "create", importception, "-o", "build", "--insecure", "--confirm") suite.NoError(err) - _, stdErr, err := e2e.Zarf("package", "inspect", importEverythingPath) + _, stdErr, err := e2e.Zarf(suite.T(), "package", "inspect", importEverythingPath) suite.NoError(err) targets := []string{ @@ -140,7 +140,7 @@ func (suite *SkeletonSuite) Test_2_FilePaths() { unpacked := strings.TrimSuffix(pkgTar, ".tar.zst") defer os.RemoveAll(unpacked) defer os.RemoveAll(pkgTar) - _, _, err := e2e.Zarf("tools", "archiver", "decompress", pkgTar, unpacked, "--unarchive-all") + _, _, err := e2e.Zarf(suite.T(), "tools", "archiver", "decompress", pkgTar, unpacked, "--unarchive-all") suite.NoError(err) suite.DirExists(unpacked) diff --git a/src/test/e2e/99_appliance_remove_test.go b/src/test/e2e/99_appliance_remove_test.go index 321f353228..1cd25d41e4 100644 --- a/src/test/e2e/99_appliance_remove_test.go +++ b/src/test/e2e/99_appliance_remove_test.go @@ -24,23 +24,23 @@ func TestApplianceRemove(t *testing.T) { path := fmt.Sprintf("build/zarf-init-%s-%s.tar.zst", e2e.Arch, initPackageVersion) // Package remove the cluster to test Zarf cleaning up after itself - stdOut, stdErr, err := e2e.Zarf("package", "remove", path, "--confirm") + stdOut, stdErr, err := e2e.Zarf(t, "package", "remove", path, "--confirm") require.NoError(t, err, stdOut, stdErr) // Check that the cluster is now gone - _, _, err = e2e.Kubectl("get", "nodes") + _, _, err = e2e.Kubectl(t, "get", "nodes") require.Error(t, err) // TODO (@WSTARR) - This needs to be refactored to use the remove logic instead of reaching into a magic directory // Re-init the cluster so that we can test if the destroy scripts run - stdOut, stdErr, err = e2e.Zarf("init", "--components=k3s", "--confirm") + stdOut, stdErr, err = e2e.Zarf(t, "init", "--components=k3s", "--confirm") require.NoError(t, err, stdOut, stdErr) // Destroy the cluster to test Zarf cleaning up after itself - stdOut, stdErr, err = e2e.Zarf("destroy", "--confirm") + stdOut, stdErr, err = e2e.Zarf(t, "destroy", "--confirm") require.NoError(t, err, stdOut, stdErr) // Check that the cluster gone again - _, _, err = e2e.Kubectl("get", "nodes") + _, _, err = e2e.Kubectl(t, "get", "nodes") require.Error(t, err) } diff --git a/src/test/e2e/99_yolo_test.go b/src/test/e2e/99_yolo_test.go index 93a9b9ed60..03281df1a7 100644 --- a/src/test/e2e/99_yolo_test.go +++ b/src/test/e2e/99_yolo_test.go @@ -23,13 +23,13 @@ func TestYOLOMode(t *testing.T) { } // Destroy the cluster to test Zarf cleaning up after itself - stdOut, stdErr, err := e2e.Zarf("destroy", "--confirm", "--remove-components") + stdOut, stdErr, err := e2e.Zarf(t, "destroy", "--confirm", "--remove-components") require.NoError(t, err, stdOut, stdErr) path := fmt.Sprintf("build/zarf-package-yolo-%s.tar.zst", e2e.Arch) // Deploy the YOLO package - stdOut, stdErr, err = e2e.Zarf("package", "deploy", path, "--confirm") + stdOut, stdErr, err = e2e.Zarf(t, "package", "deploy", path, "--confirm") require.NoError(t, err, stdOut, stdErr) c, err := cluster.NewCluster() @@ -43,7 +43,7 @@ func TestYOLOMode(t *testing.T) { require.NoError(t, err, resp) require.Equal(t, 200, resp.StatusCode) - stdOut, stdErr, err = e2e.Zarf("package", "remove", "yolo", "--confirm") + stdOut, stdErr, err = e2e.Zarf(t, "package", "remove", "yolo", "--confirm") require.NoError(t, err, stdOut, stdErr) } @@ -53,9 +53,9 @@ func TestDevDeploy(t *testing.T) { return } - stdOut, stdErr, err := e2e.Zarf("dev", "deploy", "examples/dos-games") + stdOut, stdErr, err := e2e.Zarf(t, "dev", "deploy", "examples/dos-games") require.NoError(t, err, stdOut, stdErr) - stdOut, stdErr, err = e2e.Zarf("package", "remove", "dos-games", "--confirm") + stdOut, stdErr, err = e2e.Zarf(t, "package", "remove", "dos-games", "--confirm") require.NoError(t, err, stdOut, stdErr) } diff --git a/src/test/external/common.go b/src/test/external/common.go index 36e8405a25..0209ddadb2 100644 --- a/src/test/external/common.go +++ b/src/test/external/common.go @@ -5,7 +5,6 @@ package external import ( - "context" "path" "path/filepath" "strings" @@ -47,7 +46,7 @@ func verifyWaitSuccess(t *testing.T, timeoutMinutes time.Duration, cmd string, a // after delay, try running default: // Check information from the given command - stdOut, _, err := exec.CmdWithContext(context.TODO(), exec.PrintCfg(), cmd, args...) + stdOut, _, err := exec.CmdWithTesting(t, exec.PrintCfg(), cmd, args...) // Log error if err != nil { t.Log(string(stdOut), err) diff --git a/src/test/external/ext_in_cluster_test.go b/src/test/external/ext_in_cluster_test.go index 97a52fda0a..bddc84fbf6 100644 --- a/src/test/external/ext_in_cluster_test.go +++ b/src/test/external/ext_in_cluster_test.go @@ -187,7 +187,7 @@ func (suite *ExtInClusterTestSuite) Test_1_Deploy() { err = pkgkubernetes.WaitForReady(waitCtx, c.Watcher, objs) suite.NoError(err) - _, _, err = exec.CmdWithContext(context.TODO(), exec.PrintCfg(), zarfBinPath, "destroy", "--confirm") + _, _, err = exec.CmdWithTesting(suite.T(), exec.PrintCfg(), zarfBinPath, "destroy", "--confirm") suite.NoError(err, "unable to teardown zarf") } diff --git a/src/test/nightly/ecr_publish_test.go b/src/test/nightly/ecr_publish_test.go index 2d872c16e1..ea58faa677 100644 --- a/src/test/nightly/ecr_publish_test.go +++ b/src/test/nightly/ecr_publish_test.go @@ -50,33 +50,33 @@ func TestECRPublishing(t *testing.T) { keyFlag := fmt.Sprintf("--key=%s", "./src/test/packages/zarf-test.pub") // Build the package with our test signature - stdOut, stdErr, err := e2e.Zarf("package", "create", "examples/helm-charts", "--signing-key=./src/test/packages/zarf-test.prv-key", "--confirm", fmt.Sprintf("-o=%s", tmpDir)) + stdOut, stdErr, err := e2e.Zarf(t, "package", "create", "examples/helm-charts", "--signing-key=./src/test/packages/zarf-test.prv-key", "--confirm", fmt.Sprintf("-o=%s", tmpDir)) require.NoError(t, err, stdOut, stdErr) require.FileExists(t, testPackageLocation) // Validate that we can publish the package to ECR without an issue - stdOut, stdErr, err = e2e.Zarf("package", "publish", testPackageLocation, registryURL, keyFlag) + stdOut, stdErr, err = e2e.Zarf(t, "package", "publish", testPackageLocation, registryURL, keyFlag) require.NoError(t, err, stdOut, stdErr) // Ensure we get a warning when trying to inspect the online published package - stdOut, stdErr, err = e2e.Zarf("package", "inspect", upstreamPackageURL, keyFlag, "--sbom-out", tmpDir) + stdOut, stdErr, err = e2e.Zarf(t, "package", "inspect", upstreamPackageURL, keyFlag, "--sbom-out", tmpDir) require.NoError(t, err, stdOut, stdErr) require.Contains(t, stdErr, "Validating SBOM checksums") require.Contains(t, stdErr, "Package signature validated!") // Validate that we can pull the package down from ECR - stdOut, stdErr, err = e2e.Zarf("package", "pull", upstreamPackageURL) + stdOut, stdErr, err = e2e.Zarf(t, "package", "pull", upstreamPackageURL) require.NoError(t, err, stdOut, stdErr) defer e2e.CleanFiles(testPackageFileName) // Ensure we get a warning when trying to inspect the package without providing the public key - stdOut, stdErr, err = e2e.Zarf("package", "inspect", testPackageFileName) + stdOut, stdErr, err = e2e.Zarf(t, "package", "inspect", testPackageFileName) require.NoError(t, err, stdOut, stdErr) require.NotContains(t, stdErr, "Validating SBOM checksums") require.Contains(t, stdErr, "The package was signed but no public key was provided, skipping signature validation") // Validate that we get no warnings when inspecting the package while providing the public key - stdOut, stdErr, err = e2e.Zarf("package", "inspect", testPackageFileName, keyFlag) + stdOut, stdErr, err = e2e.Zarf(t, "package", "inspect", testPackageFileName, keyFlag) require.NoError(t, err, stdOut, stdErr) require.NotContains(t, stdErr, "Validating SBOM checksums") require.Contains(t, stdErr, "Package signature validated!") diff --git a/src/test/upgrade/previously_built_test.go b/src/test/upgrade/previously_built_test.go index a7c42e87a1..0b59761d6d 100644 --- a/src/test/upgrade/previously_built_test.go +++ b/src/test/upgrade/previously_built_test.go @@ -5,7 +5,6 @@ package upgrade import ( - "context" "path" "testing" @@ -14,15 +13,15 @@ import ( test "github.com/zarf-dev/zarf/src/test" ) -func kubectl(args ...string) (string, string, error) { +func kubectl(t *testing.T, args ...string) (string, string, error) { tk := []string{"tools", "kubectl"} args = append(tk, args...) - return zarf(args...) + return zarf(t, args...) } -func zarf(args ...string) (string, string, error) { +func zarf(t *testing.T, args ...string) (string, string, error) { zarfBinPath := path.Join("../../../build", test.GetCLIName()) - return exec.CmdWithContext(context.TODO(), exec.PrintCfg(), zarfBinPath, args...) + return exec.CmdWithTesting(t, exec.PrintCfg(), zarfBinPath, args...) } func TestPreviouslyBuiltZarfPackage(t *testing.T) { @@ -30,18 +29,18 @@ func TestPreviouslyBuiltZarfPackage(t *testing.T) { t.Log("Upgrade: Previously Built Zarf Package") // For the upgrade test, podinfo-upgrade should already be in the cluster (version 6.3.3) (see .github/workflows/test-upgrade.yml) - kubectlOut, _, _ := kubectl("-n=podinfo-upgrade", "rollout", "status", "deployment/podinfo-upgrade") + kubectlOut, _, _ := kubectl(t, "-n=podinfo-upgrade", "rollout", "status", "deployment/podinfo-upgrade") require.Contains(t, kubectlOut, "successfully rolled out") - kubectlOut, _, _ = kubectl("-n=podinfo-upgrade", "get", "deployment", "podinfo-upgrade", "-o=jsonpath={.metadata.labels}}") + kubectlOut, _, _ = kubectl(t, "-n=podinfo-upgrade", "get", "deployment", "podinfo-upgrade", "-o=jsonpath={.metadata.labels}}") require.Contains(t, kubectlOut, "6.3.3") // Verify that the private-registry secret and private-git-server secret in the podinfo-upgrade namespace are the same after re-init // This tests that `zarf tools update-creds` successfully updated the other namespace - zarfRegistrySecret, _, _ := kubectl("-n=zarf", "get", "secret", "private-registry", "-o", "jsonpath={.data}") - podinfoRegistrySecret, _, _ := kubectl("-n=podinfo-upgrade", "get", "secret", "private-registry", "-o", "jsonpath={.data}") + zarfRegistrySecret, _, _ := kubectl(t, "-n=zarf", "get", "secret", "private-registry", "-o", "jsonpath={.data}") + podinfoRegistrySecret, _, _ := kubectl(t, "-n=podinfo-upgrade", "get", "secret", "private-registry", "-o", "jsonpath={.data}") require.Equal(t, zarfRegistrySecret, podinfoRegistrySecret, "the zarf registry secret and podinfo-upgrade registry secret did not match") - zarfGitServerSecret, _, _ := kubectl("-n=zarf", "get", "secret", "private-git-server", "-o", "jsonpath={.data}") - podinfoGitServerSecret, _, _ := kubectl("-n=podinfo-upgrade", "get", "secret", "private-git-server", "-o", "jsonpath={.data}") + zarfGitServerSecret, _, _ := kubectl(t, "-n=zarf", "get", "secret", "private-git-server", "-o", "jsonpath={.data}") + podinfoGitServerSecret, _, _ := kubectl(t, "-n=podinfo-upgrade", "get", "secret", "private-git-server", "-o", "jsonpath={.data}") require.Equal(t, zarfGitServerSecret, podinfoGitServerSecret, "the zarf git server secret and podinfo-upgrade git server secret did not match") // We also expect a 6.3.4 package to have been previously built @@ -49,7 +48,7 @@ func TestPreviouslyBuiltZarfPackage(t *testing.T) { // Deploy the package. zarfDeployArgs := []string{"package", "deploy", previouslyBuiltPackage, "--confirm"} - stdOut, stdErr, err := zarf(zarfDeployArgs...) + stdOut, stdErr, err := zarf(t, zarfDeployArgs...) require.NoError(t, err, stdOut, stdErr) // [DEPRECATIONS] We expect any deprecated things to work from the old package @@ -57,18 +56,18 @@ func TestPreviouslyBuiltZarfPackage(t *testing.T) { require.Contains(t, stdErr, "-----BEGIN PUBLIC KEY-----") // Verify that podinfo-upgrade successfully deploys in the cluster (version 6.3.4) - kubectlOut, _, _ = kubectl("-n=podinfo-upgrade", "rollout", "status", "deployment/podinfo-upgrade") + kubectlOut, _, _ = kubectl(t, "-n=podinfo-upgrade", "rollout", "status", "deployment/podinfo-upgrade") require.Contains(t, kubectlOut, "successfully rolled out") - kubectlOut, _, _ = kubectl("-n=podinfo-upgrade", "get", "deployment", "podinfo-upgrade", "-o=jsonpath={.metadata.labels}}") + kubectlOut, _, _ = kubectl(t, "-n=podinfo-upgrade", "get", "deployment", "podinfo-upgrade", "-o=jsonpath={.metadata.labels}}") require.Contains(t, kubectlOut, "6.3.4") // We also want to build a new package. - stdOut, stdErr, err = zarf("package", "create", "../../../src/test/upgrade", "--set", "PODINFO_VERSION=6.3.5", "--confirm") + stdOut, stdErr, err = zarf(t, "package", "create", "../../../src/test/upgrade", "--set", "PODINFO_VERSION=6.3.5", "--confirm") require.NoError(t, err, stdOut, stdErr) newlyBuiltPackage := "zarf-package-test-upgrade-package-amd64-6.3.5.tar.zst" // Deploy the package. - stdOut, stdErr, err = zarf("package", "deploy", newlyBuiltPackage, "--confirm") + stdOut, stdErr, err = zarf(t, "package", "deploy", newlyBuiltPackage, "--confirm") require.NoError(t, err, stdOut, stdErr) // [DEPRECATIONS] We expect any deprecated things to work from the new package @@ -76,12 +75,12 @@ func TestPreviouslyBuiltZarfPackage(t *testing.T) { require.Contains(t, stdErr, "-----BEGIN PUBLIC KEY-----") // Verify that podinfo-upgrade successfully deploys in the cluster (version 6.3.5) - kubectlOut, _, _ = kubectl("-n=podinfo-upgrade", "rollout", "status", "deployment/podinfo-upgrade") + kubectlOut, _, _ = kubectl(t, "-n=podinfo-upgrade", "rollout", "status", "deployment/podinfo-upgrade") require.Contains(t, kubectlOut, "successfully rolled out") - kubectlOut, _, _ = kubectl("-n=podinfo-upgrade", "get", "deployment", "podinfo-upgrade", "-o=jsonpath={.metadata.labels}}") + kubectlOut, _, _ = kubectl(t, "-n=podinfo-upgrade", "get", "deployment", "podinfo-upgrade", "-o=jsonpath={.metadata.labels}}") require.Contains(t, kubectlOut, "6.3.5") // Remove the package. - stdOut, stdErr, err = zarf("package", "remove", "test-upgrade-package", "--confirm") + stdOut, stdErr, err = zarf(t, "package", "remove", "test-upgrade-package", "--confirm") require.NoError(t, err, stdOut, stdErr) } From 1c8e55f265ed8bb57cf1ee7008956725be42451f Mon Sep 17 00:00:00 2001 From: Xander Grzywinski Date: Thu, 25 Jul 2024 01:53:12 -0700 Subject: [PATCH 07/11] docs: update repo name across docs (#2735) Signed-off-by: Xander Grzywinski Co-authored-by: Austin Abro <37223396+AustinAbro321@users.noreply.github.com> --- site/public/tutorials/package_create_wordpress.html | 2 +- site/src/content/docs/ref/deploy.mdx | 2 +- site/src/content/docs/ref/deployment-ui.mdx | 2 +- site/src/content/docs/roadmap.mdx | 2 +- site/src/content/docs/tutorials/3-deploy-a-retro-arcade.mdx | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/site/public/tutorials/package_create_wordpress.html b/site/public/tutorials/package_create_wordpress.html index abb216bb08..940bd94cc9 100644 --- a/site/public/tutorials/package_create_wordpress.html +++ b/site/public/tutorials/package_create_wordpress.html @@ -91,7 +91,7 @@ sensitive: true - name: WORDPRESS_EMAIL description: The email that is used for the WordPress admin account - default: hello@defenseunicorns.com + default: hello@zarf-dev.com prompt: true - name: WORDPRESS_FIRST_NAME description: The first name that is used for the WordPress admin account diff --git a/site/src/content/docs/ref/deploy.mdx b/site/src/content/docs/ref/deploy.mdx index 28e61f7114..dbb5dc1679 100644 --- a/site/src/content/docs/ref/deploy.mdx +++ b/site/src/content/docs/ref/deploy.mdx @@ -117,7 +117,7 @@ $ zarf connect [service name] :::note -You can also specify a package locally, or via oci such as `zarf package deploy oci://defenseunicorns/dos-games:1.0.0-$(uname -m) --key=https://zarf.dev/cosign.pub` +You can also specify a package locally, or via oci such as `zarf package deploy oci://defenseunicorns/dos-games:1.0.0 --key=https://zarf.dev/cosign.pub` ::: diff --git a/site/src/content/docs/ref/deployment-ui.mdx b/site/src/content/docs/ref/deployment-ui.mdx index c560a4fc92..b21f028a51 100644 --- a/site/src/content/docs/ref/deployment-ui.mdx +++ b/site/src/content/docs/ref/deployment-ui.mdx @@ -24,7 +24,7 @@ The Zarf Deployment Web UI can easily be downloaded from the [Zarf UI Github Pro Follow these steps to get started using the Web UI -1. Step one: [Download the Zarf UI](https://github.com/defenseunicorns/zarf-ui/releases/latest) version that matches your system (i.e. `zarf-ui_v0.1.0-Darwin_arm64`) +1. Step one: [Download the Zarf UI](https://github.com/zarf-dev/zarf-ui/releases/latest) version that matches your system (i.e. `zarf-ui_v0.1.0-Darwin_arm64`) 2. Step two: (if applicable) Mark the file as executable with `chmod +x zarf-ui_v0.1.0-Darwin_arm64` 3. Step three: Run the binary with `./zarf-ui_v0.1.0-Darwin_arm64` or by double clicking the file in your file browser diff --git a/site/src/content/docs/roadmap.mdx b/site/src/content/docs/roadmap.mdx index 43a80e41ad..f0a9244752 100644 --- a/site/src/content/docs/roadmap.mdx +++ b/site/src/content/docs/roadmap.mdx @@ -4,7 +4,7 @@ title: Roadmap ## Issue Tracking -The issue board for Zarf is hosted on a [GitHub Project Board](https://github.com/orgs/defenseunicorns/projects/1) that tracks the issues the Zarf team is working along with future work we are prioritizing. +The issue board for Zarf is hosted on a [GitHub Project Board](https://github.com/orgs/zarf-dev/projects/1) that tracks the issues the Zarf team is working along with future work we are prioritizing. If you would like to add bug reports or feature requests, please [add an issue](https://github.com/zarf-dev/zarf/issues) to the GitHub repository under the appropriate template. If you have a more general question about a feature, feel free to ask the team in the [Zarf Kubernetes Slack Channel](https://kubernetes.slack.com/archives/C03B6BJAUJ3). diff --git a/site/src/content/docs/tutorials/3-deploy-a-retro-arcade.mdx b/site/src/content/docs/tutorials/3-deploy-a-retro-arcade.mdx index abfcd55b42..ebb499ffbb 100644 --- a/site/src/content/docs/tutorials/3-deploy-a-retro-arcade.mdx +++ b/site/src/content/docs/tutorials/3-deploy-a-retro-arcade.mdx @@ -22,7 +22,7 @@ Before beginning this tutorial you will need the following: ## Deploying the Arcade -1. The `dos-games` package is easily deployable via `oci://` by running `zarf package deploy oci://defenseunicorns/dos-games:1.0.0-$(uname -m) --key=https://zarf.dev/cosign.pub`. +1. The `dos-games` package is easily deployable via `oci://` by running `zarf package deploy oci://defenseunicorns/dos-games:1.0.0 --key=https://zarf.dev/cosign.pub`. :::tip From 5f91e88d4036e05de4dd822d882a3775f94fa48a Mon Sep 17 00:00:00 2001 From: Philip Laine Date: Thu, 25 Jul 2024 15:38:54 +0200 Subject: [PATCH 08/11] fix: add whitespace linter and fix all warnings (#2764) Signed-off-by: Philip Laine --- .golangci.yaml | 1 + src/cmd/tools/yq.go | 1 - src/extensions/bigbang/flux.go | 1 - src/internal/agent/hooks/flux-gitrepo.go | 1 - src/internal/agent/hooks/flux-helmrepo.go | 1 - src/internal/agent/hooks/flux-ocirepo.go | 1 - src/internal/packager/git/gitea.go | 1 - src/internal/packager/helm/post-render.go | 2 -- src/internal/packager/helm/repo.go | 1 - src/pkg/cluster/zarf.go | 1 - src/pkg/interactive/prompt.go | 1 - src/pkg/message/credentials.go | 1 - src/pkg/packager/actions/actions.go | 1 - src/pkg/packager/common.go | 1 - src/pkg/packager/composer/oci.go | 1 - src/pkg/packager/creator/skeleton.go | 1 - src/pkg/packager/deploy.go | 2 -- src/pkg/packager/filters/deploy_test.go | 1 - src/pkg/packager/filters/os_test.go | 1 - src/pkg/packager/prepare.go | 2 -- src/pkg/utils/bytes.go | 1 - src/pkg/utils/image.go | 1 - src/pkg/utils/wait.go | 3 --- src/pkg/zoci/copier.go | 1 - src/test/e2e/02_component_actions_test.go | 2 -- src/test/e2e/12_lint_test.go | 2 -- src/test/e2e/13_find_images_test.go | 2 -- src/test/e2e/14_create_sha_index_test.go | 1 - src/test/e2e/50_oci_publish_deploy_test.go | 1 - src/test/e2e/51_oci_compose_test.go | 3 --- src/test/external/ext_out_cluster_test.go | 1 - src/types/validate.go | 1 - 32 files changed, 1 insertion(+), 41 deletions(-) diff --git a/.golangci.yaml b/.golangci.yaml index ab7cc77904..37d811f119 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -14,6 +14,7 @@ linters: - goimports - nolintlint - testifylint + - whitespace linters-settings: govet: enable-all: true diff --git a/src/cmd/tools/yq.go b/src/cmd/tools/yq.go index 85d72ab767..41839f568b 100644 --- a/src/cmd/tools/yq.go +++ b/src/cmd/tools/yq.go @@ -10,7 +10,6 @@ import ( ) func init() { - yqCmd := yq.New() yqCmd.Example = lang.CmdToolsYqExample yqCmd.Use = "yq" diff --git a/src/extensions/bigbang/flux.go b/src/extensions/bigbang/flux.go index d67097f26c..91680970e9 100644 --- a/src/extensions/bigbang/flux.go +++ b/src/extensions/bigbang/flux.go @@ -120,7 +120,6 @@ func readFluxImages(localPath string) (images []string, err error) { for _, container := range pod.Containers { images = append(images, container.Image) } - } } diff --git a/src/internal/agent/hooks/flux-gitrepo.go b/src/internal/agent/hooks/flux-gitrepo.go index 079ee6a8e0..38a5aedadb 100644 --- a/src/internal/agent/hooks/flux-gitrepo.go +++ b/src/internal/agent/hooks/flux-gitrepo.go @@ -38,7 +38,6 @@ func NewGitRepositoryMutationHook(ctx context.Context, cluster *cluster.Cluster) // mutateGitRepoCreate mutates the git repository url to point to the repository URL defined in the ZarfState. func mutateGitRepo(ctx context.Context, r *v1.AdmissionRequest, cluster *cluster.Cluster) (result *operations.Result, err error) { - var ( patches []operations.PatchOperation isPatched bool diff --git a/src/internal/agent/hooks/flux-helmrepo.go b/src/internal/agent/hooks/flux-helmrepo.go index 90aab22f7a..c053bb669b 100644 --- a/src/internal/agent/hooks/flux-helmrepo.go +++ b/src/internal/agent/hooks/flux-helmrepo.go @@ -36,7 +36,6 @@ func NewHelmRepositoryMutationHook(ctx context.Context, cluster *cluster.Cluster // mutateHelmRepo mutates the repository url to point to the repository URL defined in the ZarfState. func mutateHelmRepo(ctx context.Context, r *v1.AdmissionRequest, cluster *cluster.Cluster) (*operations.Result, error) { - src := &flux.HelmRepository{} if err := json.Unmarshal(r.Object.Raw, &src); err != nil { return nil, fmt.Errorf(lang.ErrUnmarshal, err) diff --git a/src/internal/agent/hooks/flux-ocirepo.go b/src/internal/agent/hooks/flux-ocirepo.go index 045b315e3a..021a0a619d 100644 --- a/src/internal/agent/hooks/flux-ocirepo.go +++ b/src/internal/agent/hooks/flux-ocirepo.go @@ -35,7 +35,6 @@ func NewOCIRepositoryMutationHook(ctx context.Context, cluster *cluster.Cluster) // mutateOCIRepo mutates the oci repository url to point to the repository URL defined in the ZarfState. func mutateOCIRepo(ctx context.Context, r *v1.AdmissionRequest, cluster *cluster.Cluster) (*operations.Result, error) { - src := &flux.OCIRepository{} if err := json.Unmarshal(r.Object.Raw, &src); err != nil { return nil, fmt.Errorf(lang.ErrUnmarshal, err) diff --git a/src/internal/packager/git/gitea.go b/src/internal/packager/git/gitea.go index a6c2f4b48a..4bfbcf60ab 100644 --- a/src/internal/packager/git/gitea.go +++ b/src/internal/packager/git/gitea.go @@ -103,7 +103,6 @@ func (g *Git) CreateReadOnlyUser(ctx context.Context) error { // UpdateZarfGiteaUsers updates Zarf gitea users func (g *Git) UpdateZarfGiteaUsers(ctx context.Context, oldState *types.ZarfState) error { - //Update git read only user password err := g.UpdateGitUser(ctx, oldState.GitServer.PushPassword, g.Server.PullUsername, g.Server.PullPassword) if err != nil { diff --git a/src/internal/packager/helm/post-render.go b/src/internal/packager/helm/post-render.go index 9a514fc6a6..60d8fde0e3 100644 --- a/src/internal/packager/helm/post-render.go +++ b/src/internal/packager/helm/post-render.go @@ -125,7 +125,6 @@ func (r *renderer) adoptAndUpdateNamespaces(ctx context.Context) error { return err } for name, namespace := range r.namespaces { - // Check to see if this namespace already exists var existingNamespace bool for _, serverNamespace := range namespaceList.Items { @@ -205,7 +204,6 @@ func (r *renderer) adoptAndUpdateNamespaces(ctx context.Context) error { if err != nil { message.WarnErrf(err, "Problem creating git server secret for the %s namespace", name) } - } } return nil diff --git a/src/internal/packager/helm/repo.go b/src/internal/packager/helm/repo.go index 148a4176a4..1e47b6e6bf 100644 --- a/src/internal/packager/helm/repo.go +++ b/src/internal/packager/helm/repo.go @@ -58,7 +58,6 @@ func (h *Helm) PackageChart(ctx context.Context, cosignKeyPath string) error { return fmt.Errorf("unable to download the published chart %q: %w", h.chart.Name, err) } } - } else { err := h.PackageChartFromLocalFiles(cosignKeyPath) if err != nil { diff --git a/src/pkg/cluster/zarf.go b/src/pkg/cluster/zarf.go index 7320e4610b..71d6f73c9e 100644 --- a/src/pkg/cluster/zarf.go +++ b/src/pkg/cluster/zarf.go @@ -105,7 +105,6 @@ func (c *Cluster) StripZarfLabelsAndSecretsFromNamespaces(ctx context.Context) { // PackageSecretNeedsWait checks if a package component has a running webhook that needs to be waited on. func (c *Cluster) PackageSecretNeedsWait(deployedPackage *types.DeployedPackage, component types.ZarfComponent, skipWebhooks bool) (needsWait bool, waitSeconds int, hookName string) { - // Skip checking webhook status when '--skip-webhooks' flag is provided and for YOLO packages if skipWebhooks || deployedPackage == nil || deployedPackage.Data.Metadata.YOLO { return false, 0, "" diff --git a/src/pkg/interactive/prompt.go b/src/pkg/interactive/prompt.go index 759f520948..c22b05e449 100644 --- a/src/pkg/interactive/prompt.go +++ b/src/pkg/interactive/prompt.go @@ -24,7 +24,6 @@ func PromptSigPassword() ([]byte, error) { // PromptVariable prompts the user for a value for a variable func PromptVariable(variable variables.InteractiveVariable) (value string, err error) { - if variable.Description != "" { message.Question(variable.Description) } diff --git a/src/pkg/message/credentials.go b/src/pkg/message/credentials.go index 74b127a1c6..34134e6484 100644 --- a/src/pkg/message/credentials.go +++ b/src/pkg/message/credentials.go @@ -91,7 +91,6 @@ func PrintCredentialUpdates(oldState *types.ZarfState, newState *types.ZarfState } for _, service := range services { - HorizontalRule() switch service { diff --git a/src/pkg/packager/actions/actions.go b/src/pkg/packager/actions/actions.go index c92457675c..541c73b0fe 100644 --- a/src/pkg/packager/actions/actions.go +++ b/src/pkg/packager/actions/actions.go @@ -97,7 +97,6 @@ func runAction(defaultCfg types.ZarfComponentActionDefaults, action types.ZarfCo // Keep trying until the max retries is reached. retryCmd: for remaining := actionDefaults.MaxRetries + 1; remaining > 0; remaining-- { - // Perform the action run. tryCmd := func(ctx context.Context) error { // Try running the command and continue the retry loop if it fails. diff --git a/src/pkg/packager/common.go b/src/pkg/packager/common.go index d790275d12..a5b77ff9d1 100644 --- a/src/pkg/packager/common.go +++ b/src/pkg/packager/common.go @@ -170,7 +170,6 @@ func (p *Packager) hasImages() bool { // attemptClusterChecks attempts to connect to the cluster and check for useful metadata and config mismatches. // NOTE: attemptClusterChecks should only return an error if there is a problem significant enough to halt a deployment, otherwise it should return nil and print a warning message. func (p *Packager) attemptClusterChecks(ctx context.Context) (err error) { - spinner := message.NewProgressSpinner("Gathering additional cluster information (if available)") defer spinner.Stop() diff --git a/src/pkg/packager/composer/oci.go b/src/pkg/packager/composer/oci.go index 129013d487..2541e45f32 100644 --- a/src/pkg/packager/composer/oci.go +++ b/src/pkg/packager/composer/oci.go @@ -104,7 +104,6 @@ func (ic *ImportChain) fetchOCISkeleton(ctx context.Context) error { if err != nil { return err } - } } diff --git a/src/pkg/packager/creator/skeleton.go b/src/pkg/packager/creator/skeleton.go index 091874c84f..3c95623542 100644 --- a/src/pkg/packager/creator/skeleton.go +++ b/src/pkg/packager/creator/skeleton.go @@ -182,7 +182,6 @@ func (sc *SkeletonCreator) addComponent(component types.ZarfComponent, dst *layo // If any helm charts are defined, process them. for chartIdx, chart := range component.Charts { - if chart.LocalPath != "" { rel := filepath.Join(layout.ChartsDir, fmt.Sprintf("%s-%d", chart.Name, chartIdx)) dst := filepath.Join(componentPaths.Base, rel) diff --git a/src/pkg/packager/deploy.go b/src/pkg/packager/deploy.go index 73aec8f006..735a0b69db 100644 --- a/src/pkg/packager/deploy.go +++ b/src/pkg/packager/deploy.go @@ -142,7 +142,6 @@ func (p *Packager) deployComponents(ctx context.Context) (deployedComponents []t // Process all the components we are deploying for _, component := range p.cfg.Pkg.Components { - deployedComponent := types.DeployedComponent{ Name: component.Name, Status: types.ComponentStatusDeploying, @@ -716,7 +715,6 @@ func (p *Packager) installChartAndManifests(ctx context.Context, componentPaths } func (p *Packager) printTablesForDeployment(ctx context.Context, componentsToDeploy []types.DeployedComponent) { - // If not init config, print the application connection table if !p.cfg.Pkg.IsInitConfig() { message.PrintConnectStringTable(p.connectStrings) diff --git a/src/pkg/packager/filters/deploy_test.go b/src/pkg/packager/filters/deploy_test.go index 5b31a2269e..7c69007223 100644 --- a/src/pkg/packager/filters/deploy_test.go +++ b/src/pkg/packager/filters/deploy_test.go @@ -111,7 +111,6 @@ func componentMatrix(_ *testing.T) []types.ZarfComponent { } func TestDeployFilter_Apply(t *testing.T) { - possibilities := componentMatrix(t) tests := map[string]struct { diff --git a/src/pkg/packager/filters/os_test.go b/src/pkg/packager/filters/os_test.go index 4dcc4b5279..98c5678c96 100644 --- a/src/pkg/packager/filters/os_test.go +++ b/src/pkg/packager/filters/os_test.go @@ -12,7 +12,6 @@ import ( ) func TestLocalOSFilter(t *testing.T) { - pkg := types.ZarfPackage{} for _, os := range types.SupportedOS() { pkg.Components = append(pkg.Components, types.ZarfComponent{ diff --git a/src/pkg/packager/prepare.go b/src/pkg/packager/prepare.go index 2b888c3966..ea883d6970 100644 --- a/src/pkg/packager/prepare.go +++ b/src/pkg/packager/prepare.go @@ -118,7 +118,6 @@ func (p *Packager) findImages(ctx context.Context) (imgMap map[string][]string, } for _, component := range p.cfg.Pkg.Components { - if len(component.Charts)+len(component.Manifests)+len(component.Repos) < 1 { // Skip if it doesn't have what we need continue @@ -163,7 +162,6 @@ func (p *Packager) findImages(ctx context.Context) (imgMap map[string][]string, } for _, chart := range component.Charts { - helmCfg := helm.New( chart, componentPaths.Charts, diff --git a/src/pkg/utils/bytes.go b/src/pkg/utils/bytes.go index 032cc65334..7dd159b91f 100644 --- a/src/pkg/utils/bytes.go +++ b/src/pkg/utils/bytes.go @@ -60,7 +60,6 @@ func ByteFormat(inputNum float64, precision int) string { // RenderProgressBarForLocalDirWrite creates a progress bar that continuously tracks the progress of writing files to a local directory and all of its subdirectories. // NOTE: This function runs infinitely until either completeChan or errChan is triggered, this function should be run in a goroutine while a different thread/process is writing to the directory. func RenderProgressBarForLocalDirWrite(filepath string, expectedTotal int64, completeChan chan error, updateText string, successText string) { - // Create a progress bar title := fmt.Sprintf("%s (%s of %s)", updateText, ByteFormat(float64(0), 2), ByteFormat(float64(expectedTotal), 2)) progressBar := message.NewProgressBar(expectedTotal, title) diff --git a/src/pkg/utils/image.go b/src/pkg/utils/image.go index 828fea84ad..3756a759e1 100644 --- a/src/pkg/utils/image.go +++ b/src/pkg/utils/image.go @@ -35,7 +35,6 @@ func LoadOCIImage(imgPath string, refInfo transform.Image) (v1.Image, error) { if manifest.Annotations[ocispec.AnnotationBaseImageName] == refInfo.Reference || // A backwards compatibility shim for older Zarf versions that would leave docker.io off of image annotations (manifest.Annotations[ocispec.AnnotationBaseImageName] == refInfo.Path+refInfo.TagOrDigest && refInfo.Host == "docker.io") { - // This is the image we are looking for, load it and then return return layoutPath.Image(manifest.Digest) } diff --git a/src/pkg/utils/wait.go b/src/pkg/utils/wait.go index fd2d7f1422..a6727d9e35 100644 --- a/src/pkg/utils/wait.go +++ b/src/pkg/utils/wait.go @@ -153,10 +153,8 @@ func waitForNetworkEndpoint(resource, name, condition string, timeout time.Durat select { case <-expired: return errors.New("wait timed out") - default: switch resource { - case "http", "https": // Handle HTTP and HTTPS endpoints. url := fmt.Sprintf("%s://%s", resource, name) @@ -191,7 +189,6 @@ func waitForNetworkEndpoint(resource, name, condition string, timeout time.Durat message.Debug(err) continue } - default: // Fallback to any generic protocol using net.Dial conn, err := net.Dial(resource, name) diff --git a/src/pkg/zoci/copier.go b/src/pkg/zoci/copier.go index 74c8636a74..f1564bfaed 100644 --- a/src/pkg/zoci/copier.go +++ b/src/pkg/zoci/copier.go @@ -17,7 +17,6 @@ import ( // CopyPackage copies a zarf package from one OCI registry to another func CopyPackage(ctx context.Context, src *Remote, dst *Remote, concurrency int) error { - srcManifest, err := src.FetchRoot(ctx) if err != nil { return err diff --git a/src/test/e2e/02_component_actions_test.go b/src/test/e2e/02_component_actions_test.go index 94f9d997db..8ef710ee90 100644 --- a/src/test/e2e/02_component_actions_test.go +++ b/src/test/e2e/02_component_actions_test.go @@ -88,7 +88,6 @@ func TestComponentActions(t *testing.T) { stdOut, stdErr, err = e2e.Zarf(t, "package", "deploy", path, "--components=on-deploy-with-variable", "--confirm") require.NoError(t, err, stdOut, stdErr) require.Contains(t, stdErr, "the dog says ruff") - }) t.Run("action on-deploy-with-dynamic-variable", func(t *testing.T) { @@ -100,7 +99,6 @@ func TestComponentActions(t *testing.T) { require.Contains(t, stdErr, "the dog says ruff") require.Contains(t, stdErr, "the snake says hiss") require.Contains(t, stdErr, "with a TF_VAR, the snake also says hiss") - }) t.Run("action on-deploy-with-env-var", func(t *testing.T) { diff --git a/src/test/e2e/12_lint_test.go b/src/test/e2e/12_lint_test.go index 6b7239a17a..58e19536ce 100644 --- a/src/test/e2e/12_lint_test.go +++ b/src/test/e2e/12_lint_test.go @@ -55,7 +55,5 @@ func TestLint(t *testing.T) { // Check reported filepaths require.Contains(t, strippedStderr, "Linting package \"dos-games\" at oci://🦄/dos-games:1.0.0") require.Contains(t, strippedStderr, fmt.Sprintf("Linting package \"lint\" at %s", testPackagePath)) - }) - } diff --git a/src/test/e2e/13_find_images_test.go b/src/test/e2e/13_find_images_test.go index a161ed15f6..474aa27eb8 100644 --- a/src/test/e2e/13_find_images_test.go +++ b/src/test/e2e/13_find_images_test.go @@ -85,7 +85,5 @@ func TestFindImages(t *testing.T) { 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/e2e/14_create_sha_index_test.go b/src/test/e2e/14_create_sha_index_test.go index eb2849975a..40b198738b 100644 --- a/src/test/e2e/14_create_sha_index_test.go +++ b/src/test/e2e/14_create_sha_index_test.go @@ -37,5 +37,4 @@ func TestCreateIndexShaErrors(t *testing.T) { require.Contains(t, stderr, tc.expectedImageInStderr) }) } - } diff --git a/src/test/e2e/50_oci_publish_deploy_test.go b/src/test/e2e/50_oci_publish_deploy_test.go index f72fbb28b5..905a5f7ed7 100644 --- a/src/test/e2e/50_oci_publish_deploy_test.go +++ b/src/test/e2e/50_oci_publish_deploy_test.go @@ -164,6 +164,5 @@ func (suite *PublishDeploySuiteTestSuite) Test_3_Copy() { } func TestPublishDeploySuite(t *testing.T) { - suite.Run(t, new(PublishDeploySuiteTestSuite)) } diff --git a/src/test/e2e/51_oci_compose_test.go b/src/test/e2e/51_oci_compose_test.go index 0d98d13c8b..034fc0e15a 100644 --- a/src/test/e2e/51_oci_compose_test.go +++ b/src/test/e2e/51_oci_compose_test.go @@ -185,7 +185,6 @@ func (suite *SkeletonSuite) DirOrFileExists(path string) { } func (suite *SkeletonSuite) verifyComponentPaths(unpackedPath string, components []types.ZarfComponent, isSkeleton bool) { - if isSkeleton { suite.NoDirExists(filepath.Join(unpackedPath, "images")) suite.NoDirExists(filepath.Join(unpackedPath, "sboms")) @@ -280,10 +279,8 @@ func (suite *SkeletonSuite) verifyComponentPaths(unpackedPath string, components } } } - } func TestSkeletonSuite(t *testing.T) { - suite.Run(t, new(SkeletonSuite)) } diff --git a/src/test/external/ext_out_cluster_test.go b/src/test/external/ext_out_cluster_test.go index dfcc9da580..86f2ef0edd 100644 --- a/src/test/external/ext_out_cluster_test.go +++ b/src/test/external/ext_out_cluster_test.go @@ -54,7 +54,6 @@ type ExtOutClusterTestSuite struct { } func (suite *ExtOutClusterTestSuite) SetupSuite() { - suite.Assertions = require.New(suite.T()) // Teardown any leftovers from previous tests diff --git a/src/types/validate.go b/src/types/validate.go index 4d39d36b23..63ee4584d9 100644 --- a/src/types/validate.go +++ b/src/types/validate.go @@ -241,7 +241,6 @@ func (as ZarfComponentActionSet) Validate() error { if actionErr := action.Validate(); actionErr != nil { err = errors.Join(err, fmt.Errorf(lang.PkgValidateErrAction, actionErr)) } - } } From 3d6c3423975b6d2fdc13646be37396ee7e8937c0 Mon Sep 17 00:00:00 2001 From: schristoff <28318173+schristoff@users.noreply.github.com> Date: Thu, 25 Jul 2024 07:42:09 -0600 Subject: [PATCH 09/11] chore: move context.TODO to context.Background() (5) (#2750) Signed-off-by: schristoff-du <167717759+schristoff-du@users.noreply.github.com> Co-authored-by: schristoff-du <167717759+schristoff-du@users.noreply.github.com> --- src/cmd/dev.go | 4 ++-- src/internal/packager/helm/repo.go | 22 +++++++++++----------- src/pkg/packager/creator/normal.go | 8 ++++---- src/pkg/packager/prepare.go | 2 +- src/pkg/packager/sources/url.go | 4 ++-- src/pkg/utils/network.go | 4 ++-- src/pkg/utils/network_test.go | 4 +++- src/test/e2e/50_oci_publish_deploy_test.go | 4 ++-- src/test/external/ext_in_cluster_test.go | 3 ++- src/test/external/ext_out_cluster_test.go | 3 ++- src/test/testutil/testutil.go | 18 ++++++++++++++++++ 11 files changed, 49 insertions(+), 27 deletions(-) create mode 100644 src/test/testutil/testutil.go diff --git a/src/cmd/dev.go b/src/cmd/dev.go index b10f2dde51..80a602afdb 100644 --- a/src/cmd/dev.go +++ b/src/cmd/dev.go @@ -142,7 +142,7 @@ var devSha256SumCmd = &cobra.Command{ Aliases: []string{"s"}, Short: lang.CmdDevSha256sumShort, Args: cobra.ExactArgs(1), - RunE: func(_ *cobra.Command, args []string) error { + RunE: func(cmd *cobra.Command, args []string) error { hashErr := errors.New("unable to compute the SHA256SUM hash") fileName := args[0] @@ -169,7 +169,7 @@ var devSha256SumCmd = &cobra.Command{ } downloadPath := filepath.Join(tmp, fileBase) - err = utils.DownloadToFile(fileName, downloadPath, "") + err = utils.DownloadToFile(cmd.Context(), fileName, downloadPath, "") if err != nil { return errors.Join(hashErr, err) } diff --git a/src/internal/packager/helm/repo.go b/src/internal/packager/helm/repo.go index 1e47b6e6bf..9397a7f760 100644 --- a/src/internal/packager/helm/repo.go +++ b/src/internal/packager/helm/repo.go @@ -53,13 +53,13 @@ func (h *Helm) PackageChart(ctx context.Context, cosignKeyPath string) error { return fmt.Errorf("unable to pull the chart %q from git: %w", h.chart.Name, err) } } else { - err = h.DownloadPublishedChart(cosignKeyPath) + err = h.DownloadPublishedChart(ctx, cosignKeyPath) if err != nil { return fmt.Errorf("unable to download the published chart %q: %w", h.chart.Name, err) } } } else { - err := h.PackageChartFromLocalFiles(cosignKeyPath) + err := h.PackageChartFromLocalFiles(ctx, cosignKeyPath) if err != nil { return fmt.Errorf("unable to package the %q chart: %w", h.chart.Name, err) } @@ -68,7 +68,7 @@ func (h *Helm) PackageChart(ctx context.Context, cosignKeyPath string) error { } // PackageChartFromLocalFiles creates a chart archive from a path to a chart on the host os. -func (h *Helm) PackageChartFromLocalFiles(cosignKeyPath string) error { +func (h *Helm) PackageChartFromLocalFiles(ctx context.Context, cosignKeyPath string) error { spinner := message.NewProgressSpinner("Processing helm chart %s:%s from %s", h.chart.Name, h.chart.Version, h.chart.LocalPath) defer spinner.Stop() @@ -102,7 +102,7 @@ func (h *Helm) PackageChartFromLocalFiles(cosignKeyPath string) error { } // Finalize the chart - err = h.finalizeChartPackage(saved, cosignKeyPath) + err = h.finalizeChartPackage(ctx, saved, cosignKeyPath) if err != nil { return err } @@ -126,11 +126,11 @@ func (h *Helm) PackageChartFromGit(ctx context.Context, cosignKeyPath string) er // Set the directory for the chart and package it h.chart.LocalPath = filepath.Join(gitPath, h.chart.GitPath) - return h.PackageChartFromLocalFiles(cosignKeyPath) + return h.PackageChartFromLocalFiles(ctx, cosignKeyPath) } // DownloadPublishedChart loads a specific chart version from a remote repo. -func (h *Helm) DownloadPublishedChart(cosignKeyPath string) error { +func (h *Helm) DownloadPublishedChart(ctx context.Context, cosignKeyPath string) error { spinner := message.NewProgressSpinner("Processing helm chart %s:%s from repo %s", h.chart.Name, h.chart.Version, h.chart.URL) defer spinner.Stop() @@ -221,7 +221,7 @@ func (h *Helm) DownloadPublishedChart(cosignKeyPath string) error { } // Finalize the chart - err = h.finalizeChartPackage(saved, cosignKeyPath) + err = h.finalizeChartPackage(ctx, saved, cosignKeyPath) if err != nil { return err } @@ -245,7 +245,7 @@ func DownloadChartFromGitToTemp(ctx context.Context, url string, spinner *messag return gitCfg.GitPath, nil } -func (h *Helm) finalizeChartPackage(saved, cosignKeyPath string) error { +func (h *Helm) finalizeChartPackage(ctx context.Context, saved, cosignKeyPath string) error { // Ensure the name is consistent for deployments destinationTarball := StandardName(h.chartPath, h.chart) + ".tgz" err := os.Rename(saved, destinationTarball) @@ -253,19 +253,19 @@ func (h *Helm) finalizeChartPackage(saved, cosignKeyPath string) error { return fmt.Errorf("unable to save the final chart tarball: %w", err) } - err = h.packageValues(cosignKeyPath) + err = h.packageValues(ctx, cosignKeyPath) if err != nil { return fmt.Errorf("unable to process the values for the package: %w", err) } return nil } -func (h *Helm) packageValues(cosignKeyPath string) error { +func (h *Helm) packageValues(ctx context.Context, cosignKeyPath string) error { for valuesIdx, path := range h.chart.ValuesFiles { dst := StandardValuesName(h.valuesPath, h.chart, valuesIdx) if helpers.IsURL(path) { - if err := utils.DownloadToFile(path, dst, cosignKeyPath); err != nil { + if err := utils.DownloadToFile(ctx, path, dst, cosignKeyPath); err != nil { return fmt.Errorf(lang.ErrDownloading, path, err.Error()) } } else { diff --git a/src/pkg/packager/creator/normal.go b/src/pkg/packager/creator/normal.go index 52baa708e4..32e2ea1bbb 100644 --- a/src/pkg/packager/creator/normal.go +++ b/src/pkg/packager/creator/normal.go @@ -390,7 +390,7 @@ func (pc *PackageCreator) addComponent(ctx context.Context, component types.Zarf compressedFile := filepath.Join(componentPaths.Temp, compressedFileName) // If the file is an archive, download it to the componentPath.Temp - if err := utils.DownloadToFile(file.Source, compressedFile, component.DeprecatedCosignKeyPath); err != nil { + if err := utils.DownloadToFile(ctx, file.Source, compressedFile, component.DeprecatedCosignKeyPath); err != nil { return fmt.Errorf(lang.ErrDownloading, file.Source, err.Error()) } @@ -399,7 +399,7 @@ func (pc *PackageCreator) addComponent(ctx context.Context, component types.Zarf return fmt.Errorf(lang.ErrFileExtract, file.ExtractPath, compressedFileName, err.Error()) } } else { - if err := utils.DownloadToFile(file.Source, dst, component.DeprecatedCosignKeyPath); err != nil { + if err := utils.DownloadToFile(ctx, file.Source, dst, component.DeprecatedCosignKeyPath); err != nil { return fmt.Errorf(lang.ErrDownloading, file.Source, err.Error()) } } @@ -450,7 +450,7 @@ func (pc *PackageCreator) addComponent(ctx context.Context, component types.Zarf dst := filepath.Join(componentPaths.Base, rel) if helpers.IsURL(data.Source) { - if err := utils.DownloadToFile(data.Source, dst, component.DeprecatedCosignKeyPath); err != nil { + if err := utils.DownloadToFile(ctx, data.Source, dst, component.DeprecatedCosignKeyPath); err != nil { return fmt.Errorf(lang.ErrDownloading, data.Source, err.Error()) } } else { @@ -483,7 +483,7 @@ func (pc *PackageCreator) addComponent(ctx context.Context, component types.Zarf // Copy manifests without any processing. spinner.Updatef("Copying manifest %s", path) if helpers.IsURL(path) { - if err := utils.DownloadToFile(path, dst, component.DeprecatedCosignKeyPath); err != nil { + if err := utils.DownloadToFile(ctx, path, dst, component.DeprecatedCosignKeyPath); err != nil { return fmt.Errorf(lang.ErrDownloading, path, err.Error()) } } else { diff --git a/src/pkg/packager/prepare.go b/src/pkg/packager/prepare.go index ea883d6970..0ca1f35f91 100644 --- a/src/pkg/packager/prepare.go +++ b/src/pkg/packager/prepare.go @@ -231,7 +231,7 @@ func (p *Packager) findImages(ctx context.Context) (imgMap map[string][]string, if helpers.IsURL(f) { mname := fmt.Sprintf("manifest-%s-%d.yaml", manifest.Name, idx) destination := filepath.Join(componentPaths.Manifests, mname) - if err := utils.DownloadToFile(f, destination, component.DeprecatedCosignKeyPath); err != nil { + if err := utils.DownloadToFile(ctx, f, destination, component.DeprecatedCosignKeyPath); err != nil { return nil, fmt.Errorf(lang.ErrDownloading, f, err.Error()) } f = destination diff --git a/src/pkg/packager/sources/url.go b/src/pkg/packager/sources/url.go index 02fc785d81..d3d79af237 100644 --- a/src/pkg/packager/sources/url.go +++ b/src/pkg/packager/sources/url.go @@ -30,7 +30,7 @@ type URLSource struct { } // Collect downloads a package from the source URL. -func (s *URLSource) Collect(_ context.Context, dir string) (string, error) { +func (s *URLSource) Collect(ctx context.Context, dir string) (string, error) { if !config.CommonOptions.Insecure && s.Shasum == "" && !strings.HasPrefix(s.PackageSource, helpers.SGETURLPrefix) { return "", fmt.Errorf("remote package provided without a shasum, use --insecure to ignore, or provide one w/ --shasum") } @@ -43,7 +43,7 @@ func (s *URLSource) Collect(_ context.Context, dir string) (string, error) { dstTarball := filepath.Join(dir, "zarf-package-url-unknown") - if err := utils.DownloadToFile(packageURL, dstTarball, s.SGetKeyPath); err != nil { + if err := utils.DownloadToFile(ctx, packageURL, dstTarball, s.SGetKeyPath); err != nil { return "", err } diff --git a/src/pkg/utils/network.go b/src/pkg/utils/network.go index e17c086161..4bd6945f36 100644 --- a/src/pkg/utils/network.go +++ b/src/pkg/utils/network.go @@ -39,7 +39,7 @@ func parseChecksum(src string) (string, string, error) { } // DownloadToFile downloads a given URL to the target filepath (including the cosign key if necessary). -func DownloadToFile(src string, dst string, cosignKeyPath string) (err error) { +func DownloadToFile(ctx context.Context, src string, dst string, cosignKeyPath string) (err error) { message.Debugf("Downloading %s to %s", src, dst) // check if the parsed URL has a checksum // if so, remove it and use the checksum to validate the file @@ -66,7 +66,7 @@ func DownloadToFile(src string, dst string, cosignKeyPath string) (err error) { } // If the source url starts with the sget protocol use that, otherwise do a typical GET call if parsed.Scheme == helpers.SGETURLScheme { - err = Sget(context.TODO(), src, cosignKeyPath, file) + err = Sget(ctx, src, cosignKeyPath, file) if err != nil { return fmt.Errorf("unable to download file with sget: %s: %w", src, err) } diff --git a/src/pkg/utils/network_test.go b/src/pkg/utils/network_test.go index d2357f907d..02e308f170 100644 --- a/src/pkg/utils/network_test.go +++ b/src/pkg/utils/network_test.go @@ -13,6 +13,8 @@ import ( "strings" "testing" + "github.com/zarf-dev/zarf/src/test/testutil" + "github.com/stretchr/testify/require" "github.com/defenseunicorns/pkg/helpers/v2" @@ -136,7 +138,7 @@ func TestDownloadToFile(t *testing.T) { } fmt.Println(src) dst := filepath.Join(t.TempDir(), tt.fileName) - err := DownloadToFile(src, dst, "") + err := DownloadToFile(testutil.TestContext(t), src, dst, "") if tt.expectedErr != "" { require.ErrorContains(t, err, tt.expectedErr) return diff --git a/src/test/e2e/50_oci_publish_deploy_test.go b/src/test/e2e/50_oci_publish_deploy_test.go index 905a5f7ed7..217c1b2de6 100644 --- a/src/test/e2e/50_oci_publish_deploy_test.go +++ b/src/test/e2e/50_oci_publish_deploy_test.go @@ -5,7 +5,6 @@ package test import ( - "context" "fmt" "path/filepath" "strings" @@ -16,6 +15,7 @@ import ( "github.com/stretchr/testify/require" "github.com/stretchr/testify/suite" "github.com/zarf-dev/zarf/src/pkg/zoci" + "github.com/zarf-dev/zarf/src/test/testutil" "oras.land/oras-go/v2/registry" "oras.land/oras-go/v2/registry/remote" ) @@ -139,7 +139,7 @@ func (suite *PublishDeploySuiteTestSuite) Test_3_Copy() { suite.NoError(err) reg.PlainHTTP = true attempt := 0 - ctx := context.TODO() + ctx := testutil.TestContext(t) for attempt <= 5 { err = reg.Ping(ctx) if err == nil { diff --git a/src/test/external/ext_in_cluster_test.go b/src/test/external/ext_in_cluster_test.go index bddc84fbf6..ffe5a08b73 100644 --- a/src/test/external/ext_in_cluster_test.go +++ b/src/test/external/ext_in_cluster_test.go @@ -19,6 +19,7 @@ import ( "github.com/stretchr/testify/suite" "github.com/zarf-dev/zarf/src/pkg/cluster" "github.com/zarf-dev/zarf/src/pkg/utils/exec" + "github.com/zarf-dev/zarf/src/test/testutil" "k8s.io/apimachinery/pkg/runtime/schema" "sigs.k8s.io/cli-utils/pkg/object" ) @@ -103,7 +104,7 @@ func (suite *ExtInClusterTestSuite) Test_0_Mirror() { c, err := cluster.NewCluster() suite.NoError(err) - ctx := context.TODO() + ctx := testutil.TestContext(suite.T()) // Check that the registry contains the images we want tunnelReg, err := c.NewTunnel("external-registry", "svc", "external-registry-docker-registry", "", 0, 5000) diff --git a/src/test/external/ext_out_cluster_test.go b/src/test/external/ext_out_cluster_test.go index 86f2ef0edd..e2cbaccefb 100644 --- a/src/test/external/ext_out_cluster_test.go +++ b/src/test/external/ext_out_cluster_test.go @@ -20,6 +20,7 @@ import ( "github.com/stretchr/testify/suite" "github.com/zarf-dev/zarf/src/pkg/utils" "github.com/zarf-dev/zarf/src/pkg/utils/exec" + "github.com/zarf-dev/zarf/src/test/testutil" "helm.sh/helm/v3/pkg/repo" ) @@ -206,7 +207,7 @@ func (suite *ExtOutClusterTestSuite) createHelmChartInGitea(baseURL string, user podinfoTarballPath := filepath.Join(tempDir, fmt.Sprintf("podinfo-%s.tgz", podInfoVersion)) suite.NoError(err, "Unable to package chart") - err = utils.DownloadToFile(fmt.Sprintf("https://stefanprodan.github.io/podinfo/podinfo-%s.tgz", podInfoVersion), podinfoTarballPath, "") + err = utils.DownloadToFile(testutil.TestContext(suite.T()), fmt.Sprintf("https://stefanprodan.github.io/podinfo/podinfo-%s.tgz", podInfoVersion), podinfoTarballPath, "") suite.NoError(err) url := fmt.Sprintf("%s/api/packages/%s/helm/api/charts", baseURL, username) diff --git a/src/test/testutil/testutil.go b/src/test/testutil/testutil.go new file mode 100644 index 0000000000..862bca937d --- /dev/null +++ b/src/test/testutil/testutil.go @@ -0,0 +1,18 @@ +// SPDX-License-Identifier: Apache-2.0 +// SPDX-FileCopyrightText: 2021-Present The Zarf Authors + +// Package testutil provides global testing helper functions +package testutil + +import ( + "context" + "testing" +) + +// TestContext takes a testing.T and returns a context that is +// attached to the test by t.Cleanup() +func TestContext(t *testing.T) context.Context { + ctx, cancel := context.WithCancel(context.Background()) + t.Cleanup(cancel) + return ctx +} From 70e8b8def7a91e054f9763250cd464877f5e6fc7 Mon Sep 17 00:00:00 2001 From: Austin Abro <37223396+AustinAbro321@users.noreply.github.com> Date: Thu, 25 Jul 2024 09:48:27 -0400 Subject: [PATCH 10/11] feat: run schema validation on create (#2585) Signed-off-by: Austin Abro --- main.go | 2 +- src/cmd/dev.go | 4 +- src/config/lang/english.go | 7 - src/pkg/lint/findings.go | 115 ++++++++ src/pkg/lint/findings_test.go | 105 +++++++ src/pkg/lint/lint.go | 136 +++++++++ src/pkg/lint/lint_test.go | 71 +++++ src/pkg/lint/rules.go | 108 +++++++ src/pkg/lint/rules_test.go | 137 +++++++++ src/pkg/lint/schema.go | 79 +++++ .../lint/lint_test.go => lint/schema_test.go} | 164 +---------- src/pkg/packager/creator/creator_test.go | 38 ++- src/pkg/packager/creator/normal.go | 3 +- src/pkg/packager/creator/skeleton.go | 2 +- src/pkg/packager/creator/utils.go | 22 ++ src/pkg/packager/dev.go | 75 +---- src/pkg/packager/lint/findings.go | 41 --- src/pkg/packager/lint/findings_test.go | 122 -------- src/pkg/packager/lint/lint.go | 278 ------------------ src/pkg/variables/types.go | 13 - src/types/package.go | 2 + src/types/validate.go | 34 --- src/types/validate_test.go | 45 +-- 23 files changed, 825 insertions(+), 778 deletions(-) create mode 100644 src/pkg/lint/findings.go create mode 100644 src/pkg/lint/findings_test.go create mode 100644 src/pkg/lint/lint.go create mode 100644 src/pkg/lint/lint_test.go create mode 100644 src/pkg/lint/rules.go create mode 100644 src/pkg/lint/rules_test.go create mode 100644 src/pkg/lint/schema.go rename src/pkg/{packager/lint/lint_test.go => lint/schema_test.go} (56%) delete mode 100644 src/pkg/packager/lint/findings.go delete mode 100644 src/pkg/packager/lint/findings_test.go delete mode 100644 src/pkg/packager/lint/lint.go diff --git a/main.go b/main.go index 70feb480f4..f424789b54 100644 --- a/main.go +++ b/main.go @@ -13,7 +13,7 @@ import ( "github.com/zarf-dev/zarf/src/cmd" "github.com/zarf-dev/zarf/src/config" - "github.com/zarf-dev/zarf/src/pkg/packager/lint" + "github.com/zarf-dev/zarf/src/pkg/lint" ) //go:embed cosign.pub diff --git a/src/cmd/dev.go b/src/cmd/dev.go index 80a602afdb..322b82fb84 100644 --- a/src/cmd/dev.go +++ b/src/cmd/dev.go @@ -22,6 +22,7 @@ import ( "github.com/zarf-dev/zarf/src/cmd/common" "github.com/zarf-dev/zarf/src/config" "github.com/zarf-dev/zarf/src/config/lang" + "github.com/zarf-dev/zarf/src/pkg/lint" "github.com/zarf-dev/zarf/src/pkg/message" "github.com/zarf-dev/zarf/src/pkg/packager" "github.com/zarf-dev/zarf/src/pkg/transform" @@ -269,6 +270,7 @@ var devLintCmd = &cobra.Command{ Short: lang.CmdDevLintShort, Long: lang.CmdDevLintLong, RunE: func(cmd *cobra.Command, args []string) error { + config.CommonOptions.Confirm = true pkgConfig.CreateOpts.BaseDir = common.SetBaseDirectory(args) v := common.GetViper() pkgConfig.CreateOpts.SetVariables = helpers.TransformAndMergeMap( @@ -280,7 +282,7 @@ var devLintCmd = &cobra.Command{ } defer pkgClient.ClearTempPaths() - return pkgClient.Lint(cmd.Context()) + return lint.Validate(cmd.Context(), pkgConfig.CreateOpts) }, } diff --git a/src/config/lang/english.go b/src/config/lang/english.go index 9b90c23b22..33698de7a5 100644 --- a/src/config/lang/english.go +++ b/src/config/lang/english.go @@ -630,19 +630,15 @@ const ( // Package validate const ( PkgValidateTemplateDeprecation = "Package template %q is using the deprecated syntax ###ZARF_PKG_VAR_%s###. This will be removed in Zarf v1.0.0. Please update to ###ZARF_PKG_TMPL_%s###." - PkgValidateMustBeUppercase = "variable name %q must be all uppercase and contain no special characters except _" PkgValidateErrAction = "invalid action: %w" PkgValidateErrActionCmdWait = "action %q cannot be both a command and wait action" PkgValidateErrActionClusterNetwork = "a single wait action must contain only one of cluster or network" PkgValidateErrChart = "invalid chart definition: %w" PkgValidateErrChartName = "chart %q exceed the maximum length of %d characters" - PkgValidateErrChartNameMissing = "chart must include a name" PkgValidateErrChartNameNotUnique = "chart name %q is not unique" PkgValidateErrChartNamespaceMissing = "chart %q must include a namespace" PkgValidateErrChartURLOrPath = "chart %q must have either a url or localPath" PkgValidateErrChartVersion = "chart %q must include a chart version" - PkgValidateErrComponentName = "component name %q must be all lowercase and contain no special characters except '-' and cannot start with a '-'" - PkgValidateErrComponentLocalOS = "component %q contains a localOS value that is not supported: %s (supported: %s)" PkgValidateErrComponentNameNotUnique = "component name %q is not unique" PkgValidateErrComponentReqDefault = "component %q cannot be both required and default" PkgValidateErrComponentReqGrouped = "component %q cannot be both required and grouped" @@ -654,11 +650,8 @@ const ( PkgValidateErrManifest = "invalid manifest definition: %w" PkgValidateErrManifestFileOrKustomize = "manifest %q must have at least one file or kustomization" PkgValidateErrManifestNameLength = "manifest %q exceed the maximum length of %d characters" - PkgValidateErrManifestNameMissing = "manifest must include a name" PkgValidateErrManifestNameNotUnique = "manifest name %q is not unique" - PkgValidateErrPkgConstantName = "constant name %q must be all uppercase and contain no special characters except _" PkgValidateErrPkgConstantPattern = "provided value for constant %q does not match pattern %q" - PkgValidateErrPkgName = "package name %q must be all lowercase and contain no special characters except '-' and cannot start with a '-'" PkgValidateErrVariable = "invalid package variable: %w" PkgValidateErrYOLONoArch = "cluster architecture not allowed in YOLO" PkgValidateErrYOLONoDistro = "cluster distros not allowed in YOLO" diff --git a/src/pkg/lint/findings.go b/src/pkg/lint/findings.go new file mode 100644 index 0000000000..a8ad9b5eac --- /dev/null +++ b/src/pkg/lint/findings.go @@ -0,0 +1,115 @@ +// SPDX-License-Identifier: Apache-2.0 +// SPDX-FileCopyrightText: 2021-Present The Zarf Authors + +// Package lint contains functions for verifying zarf yaml files are valid +package lint + +import ( + "fmt" + "path/filepath" + + "github.com/defenseunicorns/pkg/helpers/v2" + "github.com/fatih/color" + "github.com/zarf-dev/zarf/src/pkg/message" +) + +// PackageFinding is a struct that contains a finding about something wrong with a package +type PackageFinding struct { + // YqPath is the path to the key where the error originated from, this is sometimes empty in the case of a general error + YqPath string + Description string + // Item is the value of a key that is causing an error, for example a bad image name + Item string + // PackageNameOverride shows the name of the package that the error originated from + // If it is not set the base package will be used when displaying the error + PackageNameOverride string + // PackagePathOverride shows the path to the package that the error originated from + // If it is not set the base package will be used when displaying the error + PackagePathOverride string + Severity Severity +} + +// Severity is the type of finding +type Severity int + +// different severities of package errors +const ( + SevErr Severity = iota + 1 + SevWarn +) + +func (f PackageFinding) itemizedDescription() string { + if f.Item == "" { + return f.Description + } + return fmt.Sprintf("%s - %s", f.Description, f.Item) +} + +func colorWrapSev(s Severity) string { + if s == SevErr { + return message.ColorWrap("Error", color.FgRed) + } else if s == SevWarn { + return message.ColorWrap("Warning", color.FgYellow) + } + return "unknown" +} + +func filterLowerSeverity(findings []PackageFinding, severity Severity) []PackageFinding { + findings = helpers.RemoveMatches(findings, func(finding PackageFinding) bool { + return finding.Severity > severity + }) + return findings +} + +// PrintFindings prints the findings of the given severity in a table +func PrintFindings(findings []PackageFinding, severity Severity, baseDir string, packageName string) { + findings = filterLowerSeverity(findings, severity) + if len(findings) == 0 { + return + } + mapOfFindingsByPath := GroupFindingsByPath(findings, packageName) + + header := []string{"Type", "Path", "Message"} + + for _, findings := range mapOfFindingsByPath { + lintData := [][]string{} + for _, finding := range findings { + lintData = append(lintData, []string{ + colorWrapSev(finding.Severity), + message.ColorWrap(finding.YqPath, color.FgCyan), + finding.itemizedDescription(), + }) + } + var packagePathFromUser string + if helpers.IsOCIURL(findings[0].PackagePathOverride) { + packagePathFromUser = findings[0].PackagePathOverride + } else { + packagePathFromUser = filepath.Join(baseDir, findings[0].PackagePathOverride) + } + message.Notef("Linting package %q at %s", findings[0].PackageNameOverride, packagePathFromUser) + message.Table(header, lintData) + } +} + +// GroupFindingsByPath groups findings by their package path +func GroupFindingsByPath(findings []PackageFinding, packageName string) map[string][]PackageFinding { + for i := range findings { + if findings[i].PackageNameOverride == "" { + findings[i].PackageNameOverride = packageName + } + if findings[i].PackagePathOverride == "" { + findings[i].PackagePathOverride = "." + } + } + + mapOfFindingsByPath := make(map[string][]PackageFinding) + for _, finding := range findings { + mapOfFindingsByPath[finding.PackagePathOverride] = append(mapOfFindingsByPath[finding.PackagePathOverride], finding) + } + return mapOfFindingsByPath +} + +// HasSevOrHigher returns true if the findings contain a severity equal to or greater than the given severity +func HasSevOrHigher(findings []PackageFinding, severity Severity) bool { + return len(filterLowerSeverity(findings, severity)) > 0 +} diff --git a/src/pkg/lint/findings_test.go b/src/pkg/lint/findings_test.go new file mode 100644 index 0000000000..f3c09673c8 --- /dev/null +++ b/src/pkg/lint/findings_test.go @@ -0,0 +1,105 @@ +// SPDX-License-Identifier: Apache-2.0 +// SPDX-FileCopyrightText: 2021-Present The Zarf Authors + +// Package lint contains functions for verifying zarf yaml files are valid +package lint + +import ( + "testing" + + "github.com/stretchr/testify/require" +) + +func TestGroupFindingsByPath(t *testing.T) { + t.Parallel() + tests := []struct { + name string + findings []PackageFinding + severity Severity + packageName string + want map[string][]PackageFinding + }{ + { + name: "same package multiple findings", + findings: []PackageFinding{ + {Severity: SevWarn, PackageNameOverride: "import", PackagePathOverride: "path"}, + {Severity: SevWarn, PackageNameOverride: "import", PackagePathOverride: "path"}, + }, + packageName: "testPackage", + want: map[string][]PackageFinding{ + "path": { + {Severity: SevWarn, PackageNameOverride: "import", PackagePathOverride: "path"}, + {Severity: SevWarn, PackageNameOverride: "import", PackagePathOverride: "path"}, + }, + }, + }, + { + name: "different packages single finding", + findings: []PackageFinding{ + {Severity: SevWarn, PackageNameOverride: "import", PackagePathOverride: "path"}, + {Severity: SevErr, PackageNameOverride: "", PackagePathOverride: ""}, + }, + packageName: "testPackage", + want: map[string][]PackageFinding{ + "path": {{Severity: SevWarn, PackageNameOverride: "import", PackagePathOverride: "path"}}, + ".": {{Severity: SevErr, PackageNameOverride: "testPackage", PackagePathOverride: "."}}, + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + require.Equal(t, tt.want, GroupFindingsByPath(tt.findings, tt.packageName)) + }) + } +} + +func TestHasSeverity(t *testing.T) { + t.Parallel() + tests := []struct { + name string + severity Severity + expected bool + findings []PackageFinding + }{ + { + name: "error severity present", + findings: []PackageFinding{ + { + Severity: SevErr, + }, + }, + severity: SevErr, + expected: true, + }, + { + name: "error severity not present", + findings: []PackageFinding{ + { + Severity: SevWarn, + }, + }, + severity: SevErr, + expected: false, + }, + { + name: "err and warning severity present", + findings: []PackageFinding{ + { + Severity: SevWarn, + }, + { + Severity: SevErr, + }, + }, + severity: SevErr, + expected: true, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + require.Equal(t, tt.expected, HasSevOrHigher(tt.findings, tt.severity)) + }) + } +} diff --git a/src/pkg/lint/lint.go b/src/pkg/lint/lint.go new file mode 100644 index 0000000000..fda3da01f9 --- /dev/null +++ b/src/pkg/lint/lint.go @@ -0,0 +1,136 @@ +// SPDX-License-Identifier: Apache-2.0 +// SPDX-FileCopyrightText: 2021-Present The Zarf Authors + +// Package lint contains functions for verifying zarf yaml files are valid +package lint + +import ( + "context" + "errors" + "fmt" + "os" + + "github.com/zarf-dev/zarf/src/config" + "github.com/zarf-dev/zarf/src/config/lang" + "github.com/zarf-dev/zarf/src/pkg/layout" + "github.com/zarf-dev/zarf/src/pkg/message" + "github.com/zarf-dev/zarf/src/pkg/packager/composer" + "github.com/zarf-dev/zarf/src/pkg/utils" + "github.com/zarf-dev/zarf/src/types" +) + +// Validate lints the given Zarf package +func Validate(ctx context.Context, createOpts types.ZarfCreateOptions) error { + var findings []PackageFinding + if err := os.Chdir(createOpts.BaseDir); err != nil { + return fmt.Errorf("unable to access directory %q: %w", createOpts.BaseDir, err) + } + var pkg types.ZarfPackage + if err := utils.ReadYaml(layout.ZarfYAML, &pkg); err != nil { + return err + } + + compFindings, err := lintComponents(ctx, pkg, createOpts) + if err != nil { + return err + } + findings = append(findings, compFindings...) + schemaFindings, err := ValidatePackageSchema() + if err != nil { + return err + } + findings = append(findings, schemaFindings...) + + if len(findings) == 0 { + message.Successf("0 findings for %q", pkg.Metadata.Name) + return nil + } + PrintFindings(findings, SevWarn, createOpts.BaseDir, pkg.Metadata.Name) + if HasSevOrHigher(findings, SevErr) { + return errors.New("errors during lint") + } + return nil +} + +func lintComponents(ctx context.Context, pkg types.ZarfPackage, createOpts types.ZarfCreateOptions) ([]PackageFinding, error) { + var findings []PackageFinding + + for i, component := range pkg.Components { + arch := config.GetArch(pkg.Metadata.Architecture) + if !composer.CompatibleComponent(component, arch, createOpts.Flavor) { + continue + } + + chain, err := composer.NewImportChain(ctx, component, i, pkg.Metadata.Name, arch, createOpts.Flavor) + + if err != nil { + return nil, err + } + + node := chain.Head() + for node != nil { + component := node.ZarfComponent + compFindings, err := fillComponentTemplate(&component, createOpts) + if err != nil { + return nil, err + } + compFindings = append(compFindings, CheckComponentValues(component, node.Index())...) + for i := range compFindings { + compFindings[i].PackagePathOverride = node.ImportLocation() + compFindings[i].PackageNameOverride = node.OriginalPackageName() + } + findings = append(findings, compFindings...) + node = node.Next() + } + } + return findings, nil +} + +func fillComponentTemplate(c *types.ZarfComponent, createOpts types.ZarfCreateOptions) ([]PackageFinding, error) { + var findings []PackageFinding + templateMap := map[string]string{} + + setVarsAndWarn := func(templatePrefix string, deprecated bool) error { + yamlTemplates, err := utils.FindYamlTemplates(c, templatePrefix, "###") + if err != nil { + return err + } + + var unSetTemplates bool + for key := range yamlTemplates { + if deprecated { + findings = append(findings, PackageFinding{ + Description: fmt.Sprintf(lang.PkgValidateTemplateDeprecation, key, key, key), + Severity: SevWarn, + }) + } + if _, present := createOpts.SetVariables[key]; !present { + unSetTemplates = true + } + } + if unSetTemplates { + findings = append(findings, PackageFinding{ + Description: lang.UnsetVarLintWarning, + Severity: SevWarn, + }) + } + for key, value := range createOpts.SetVariables { + templateMap[fmt.Sprintf("%s%s###", templatePrefix, key)] = value + } + return nil + } + + if err := setVarsAndWarn(types.ZarfPackageTemplatePrefix, false); err != nil { + return nil, err + } + + // [DEPRECATION] Set the Package Variable syntax as well for backward compatibility + if err := setVarsAndWarn(types.ZarfPackageVariablePrefix, true); err != nil { + return nil, err + } + + if err := utils.ReloadYamlTemplate(c, templateMap); err != nil { + return nil, err + } + return findings, nil +} diff --git a/src/pkg/lint/lint_test.go b/src/pkg/lint/lint_test.go new file mode 100644 index 0000000000..d5c5a03495 --- /dev/null +++ b/src/pkg/lint/lint_test.go @@ -0,0 +1,71 @@ +// SPDX-License-Identifier: Apache-2.0 +// SPDX-FileCopyrightText: 2021-Present The Zarf Authors + +// Package lint contains functions for verifying zarf yaml files are valid +package lint + +import ( + "context" + "fmt" + "testing" + + "github.com/stretchr/testify/require" + "github.com/zarf-dev/zarf/src/config/lang" + "github.com/zarf-dev/zarf/src/types" +) + +func TestLintComponents(t *testing.T) { + t.Run("Test composable components with bad path", func(t *testing.T) { + t.Parallel() + zarfPackage := types.ZarfPackage{ + Components: []types.ZarfComponent{ + { + Import: types.ZarfComponentImport{Path: "bad-path"}, + }, + }, + Metadata: types.ZarfMetadata{Name: "test-zarf-package"}, + } + + createOpts := types.ZarfCreateOptions{Flavor: "", BaseDir: "."} + _, err := lintComponents(context.Background(), zarfPackage, createOpts) + require.Error(t, err) + }) +} +func TestFillComponentTemplate(t *testing.T) { + createOpts := types.ZarfCreateOptions{ + SetVariables: map[string]string{ + "KEY1": "value1", + "KEY2": "value2", + }, + } + + component := types.ZarfComponent{ + Images: []string{ + fmt.Sprintf("%s%s###", types.ZarfPackageTemplatePrefix, "KEY1"), + fmt.Sprintf("%s%s###", types.ZarfPackageVariablePrefix, "KEY2"), + fmt.Sprintf("%s%s###", types.ZarfPackageTemplatePrefix, "KEY3"), + }, + } + + findings, err := fillComponentTemplate(&component, createOpts) + require.NoError(t, err) + expectedFindings := []PackageFinding{ + { + Severity: SevWarn, + Description: "There are templates that are not set and won't be evaluated during lint", + }, + { + Severity: SevWarn, + Description: fmt.Sprintf(lang.PkgValidateTemplateDeprecation, "KEY2", "KEY2", "KEY2"), + }, + } + expectedComponent := types.ZarfComponent{ + Images: []string{ + "value1", + "value2", + fmt.Sprintf("%s%s###", types.ZarfPackageTemplatePrefix, "KEY3"), + }, + } + require.ElementsMatch(t, expectedFindings, findings) + require.Equal(t, expectedComponent, component) +} diff --git a/src/pkg/lint/rules.go b/src/pkg/lint/rules.go new file mode 100644 index 0000000000..17c22256a4 --- /dev/null +++ b/src/pkg/lint/rules.go @@ -0,0 +1,108 @@ +// SPDX-License-Identifier: Apache-2.0 +// SPDX-FileCopyrightText: 2021-Present The Zarf Authors + +// Package lint contains functions for verifying zarf yaml files are valid +package lint + +import ( + "fmt" + "strings" + + "github.com/defenseunicorns/pkg/helpers/v2" + "github.com/zarf-dev/zarf/src/pkg/transform" + "github.com/zarf-dev/zarf/src/types" +) + +func isPinnedImage(image string) (bool, error) { + transformedImage, err := transform.ParseImageRef(image) + if err != nil { + if strings.Contains(image, types.ZarfPackageTemplatePrefix) || + strings.Contains(image, types.ZarfPackageVariablePrefix) { + return true, nil + } + return false, err + } + if isCosignSignature(transformedImage.Tag) || isCosignAttestation(transformedImage.Tag) { + return true, nil + } + return (transformedImage.Digest != ""), err +} + +func isCosignSignature(image string) bool { + return strings.HasSuffix(image, ".sig") +} + +func isCosignAttestation(image string) bool { + return strings.HasSuffix(image, ".att") +} + +func isPinnedRepo(repo string) bool { + return (strings.Contains(repo, "@")) +} + +// CheckComponentValues runs lint rules validating values on component keys, should be run after templating +func CheckComponentValues(c types.ZarfComponent, i int) []PackageFinding { + var findings []PackageFinding + findings = append(findings, checkForUnpinnedRepos(c, i)...) + findings = append(findings, checkForUnpinnedImages(c, i)...) + findings = append(findings, checkForUnpinnedFiles(c, i)...) + return findings +} + +func checkForUnpinnedRepos(c types.ZarfComponent, i int) []PackageFinding { + var findings []PackageFinding + for j, repo := range c.Repos { + repoYqPath := fmt.Sprintf(".components.[%d].repos.[%d]", i, j) + if !isPinnedRepo(repo) { + findings = append(findings, PackageFinding{ + YqPath: repoYqPath, + Description: "Unpinned repository", + Item: repo, + Severity: SevWarn, + }) + } + } + return findings +} + +func checkForUnpinnedImages(c types.ZarfComponent, i int) []PackageFinding { + var findings []PackageFinding + for j, image := range c.Images { + imageYqPath := fmt.Sprintf(".components.[%d].images.[%d]", i, j) + pinnedImage, err := isPinnedImage(image) + if err != nil { + findings = append(findings, PackageFinding{ + YqPath: imageYqPath, + Description: "Failed to parse image reference", + Item: image, + Severity: SevWarn, + }) + continue + } + if !pinnedImage { + findings = append(findings, PackageFinding{ + YqPath: imageYqPath, + Description: "Image not pinned with digest", + Item: image, + Severity: SevWarn, + }) + } + } + return findings +} + +func checkForUnpinnedFiles(c types.ZarfComponent, i int) []PackageFinding { + var findings []PackageFinding + for j, file := range c.Files { + fileYqPath := fmt.Sprintf(".components.[%d].files.[%d]", i, j) + if file.Shasum == "" && helpers.IsURL(file.Source) { + findings = append(findings, PackageFinding{ + YqPath: fileYqPath, + Description: "No shasum for remote file", + Item: file.Source, + Severity: SevWarn, + }) + } + } + return findings +} diff --git a/src/pkg/lint/rules_test.go b/src/pkg/lint/rules_test.go new file mode 100644 index 0000000000..bf080ac506 --- /dev/null +++ b/src/pkg/lint/rules_test.go @@ -0,0 +1,137 @@ +// SPDX-License-Identifier: Apache-2.0 +// SPDX-FileCopyrightText: 2021-Present The Zarf Authors + +// Package lint contains functions for verifying zarf yaml files are valid +package lint + +import ( + "errors" + "testing" + + "github.com/stretchr/testify/require" + "github.com/zarf-dev/zarf/src/types" +) + +func TestUnpinnedRepo(t *testing.T) { + t.Parallel() + unpinnedRepo := "https://github.com/zarf-dev/zarf-public-test.git" + component := types.ZarfComponent{Repos: []string{ + unpinnedRepo, + "https://dev.azure.com/zarf-dev/zarf-public-test/_git/zarf-public-test@v0.0.1", + }} + findings := checkForUnpinnedRepos(component, 0) + expected := []PackageFinding{ + { + Item: unpinnedRepo, + Description: "Unpinned repository", + Severity: SevWarn, + YqPath: ".components.[0].repos.[0]", + }, + } + require.Equal(t, expected, findings) +} + +func TestUnpinnedImageWarning(t *testing.T) { + t.Parallel() + unpinnedImage := "registry.com:9001/whatever/image:1.0.0" + badImage := "badimage:badimage@@sha256:3fbc632167424a6d997e74f5" + cosignSignature := "ghcr.io/stefanprodan/podinfo:sha256-57a654ace69ec02ba8973093b6a786faa15640575fbf0dbb603db55aca2ccec8.sig" + cosignAttestation := "ghcr.io/stefanprodan/podinfo:sha256-57a654ace69ec02ba8973093b6a786faa15640575fbf0dbb603db55aca2ccec8.att" + component := types.ZarfComponent{Images: []string{ + unpinnedImage, + "busybox:latest@sha256:3fbc632167424a6d997e74f52b878d7cc478225cffac6bc977eedfe51c7f4e79", + badImage, + cosignSignature, + cosignAttestation, + }} + findings := checkForUnpinnedImages(component, 0) + expected := []PackageFinding{ + { + Item: unpinnedImage, + Description: "Image not pinned with digest", + Severity: SevWarn, + YqPath: ".components.[0].images.[0]", + }, + { + Item: badImage, + Description: "Failed to parse image reference", + Severity: SevWarn, + YqPath: ".components.[0].images.[2]", + }, + } + require.Equal(t, expected, findings) +} + +func TestUnpinnnedFileWarning(t *testing.T) { + t.Parallel() + fileURL := "http://example.com/file.zip" + localFile := "local.txt" + zarfFiles := []types.ZarfFile{ + { + Source: fileURL, + }, + { + Source: localFile, + }, + { + Source: fileURL, + Shasum: "fake-shasum", + }, + } + component := types.ZarfComponent{Files: zarfFiles} + findings := checkForUnpinnedFiles(component, 0) + expected := []PackageFinding{ + { + Item: fileURL, + Description: "No shasum for remote file", + Severity: SevWarn, + YqPath: ".components.[0].files.[0]", + }, + } + require.Equal(t, expected, findings) + require.Len(t, findings, 1) +} + +func TestIsImagePinned(t *testing.T) { + t.Parallel() + tests := []struct { + input string + expected bool + err error + }{ + { + input: "registry.com:8080/zarf-dev/whatever", + expected: false, + err: nil, + }, + { + input: "ghcr.io/zarf-dev/pepr/controller:v0.15.0", + expected: false, + err: nil, + }, + { + input: "busybox:latest@sha256:3fbc632167424a6d997e74f52b878d7cc478225cffac6bc977eedfe51c7f4e79", + expected: true, + err: nil, + }, + { + input: "busybox:bad/image", + expected: false, + err: errors.New("invalid reference format"), + }, + { + input: "busybox:###ZARF_PKG_TMPL_BUSYBOX_IMAGE###", + expected: true, + err: nil, + }, + } + for _, tc := range tests { + t.Run(tc.input, func(t *testing.T) { + actual, err := isPinnedImage(tc.input) + if err != nil { + require.EqualError(t, err, tc.err.Error()) + } + require.Equal(t, tc.expected, actual) + }) + } +} diff --git a/src/pkg/lint/schema.go b/src/pkg/lint/schema.go new file mode 100644 index 0000000000..ae3e991863 --- /dev/null +++ b/src/pkg/lint/schema.go @@ -0,0 +1,79 @@ +// SPDX-License-Identifier: Apache-2.0 +// SPDX-FileCopyrightText: 2021-Present The Zarf Authors + +// Package lint contains functions for verifying zarf yaml files are valid +package lint + +import ( + "fmt" + "io/fs" + "regexp" + + "github.com/xeipuuv/gojsonschema" + "github.com/zarf-dev/zarf/src/pkg/layout" + "github.com/zarf-dev/zarf/src/pkg/utils" +) + +// ZarfSchema is exported so main.go can embed the schema file +var ZarfSchema fs.ReadFileFS + +// ValidatePackageSchema checks the Zarf package in the current directory against the Zarf schema +func ValidatePackageSchema() ([]PackageFinding, error) { + var untypedZarfPackage interface{} + if err := utils.ReadYaml(layout.ZarfYAML, &untypedZarfPackage); err != nil { + return nil, err + } + + jsonSchema, err := ZarfSchema.ReadFile("zarf.schema.json") + if err != nil { + return nil, err + } + + return getSchemaFindings(jsonSchema, untypedZarfPackage) +} + +func makeFieldPathYqCompat(field string) string { + if field == "(root)" { + return field + } + // \b is a metacharacter that will stop at the next non-word character (including .) + // https://regex101.com/r/pIRPk0/1 + re := regexp.MustCompile(`(\b\d+\b)`) + + wrappedField := re.ReplaceAllString(field, "[$1]") + + return fmt.Sprintf(".%s", wrappedField) +} + +func getSchemaFindings(jsonSchema []byte, obj interface{}) ([]PackageFinding, error) { + var findings []PackageFinding + schemaErrors, err := runSchema(jsonSchema, obj) + if err != nil { + return nil, err + } + + for _, schemaErr := range schemaErrors { + findings = append(findings, PackageFinding{ + YqPath: makeFieldPathYqCompat(schemaErr.Field()), + Description: schemaErr.Description(), + Severity: SevErr, + }) + } + + return findings, nil +} + +func runSchema(jsonSchema []byte, pkg interface{}) ([]gojsonschema.ResultError, error) { + schemaLoader := gojsonschema.NewBytesLoader(jsonSchema) + documentLoader := gojsonschema.NewGoLoader(pkg) + + result, err := gojsonschema.Validate(schemaLoader, documentLoader) + if err != nil { + return nil, err + } + + if !result.Valid() { + return result.Errors(), nil + } + return nil, nil +} diff --git a/src/pkg/packager/lint/lint_test.go b/src/pkg/lint/schema_test.go similarity index 56% rename from src/pkg/packager/lint/lint_test.go rename to src/pkg/lint/schema_test.go index 213c0938d2..bb6adde541 100644 --- a/src/pkg/packager/lint/lint_test.go +++ b/src/pkg/lint/schema_test.go @@ -5,8 +5,6 @@ package lint import ( - "context" - "errors" "fmt" "os" "testing" @@ -19,7 +17,7 @@ import ( func TestZarfSchema(t *testing.T) { t.Parallel() - zarfSchema, err := os.ReadFile("../../../../zarf.schema.json") + zarfSchema, err := os.ReadFile("../../../zarf.schema.json") require.NoError(t, err) tests := []struct { @@ -119,7 +117,6 @@ func TestZarfSchema(t *testing.T) { }, } for _, tt := range tests { - tt := tt t.Run(tt.name, func(t *testing.T) { t.Parallel() findings, err := runSchema(zarfSchema, tt.pkg) @@ -173,17 +170,17 @@ components: t.Run("test schema findings is created as expected", func(t *testing.T) { t.Parallel() - findings, err := validateSchema(zarfSchema, types.ZarfPackage{ + findings, err := getSchemaFindings(zarfSchema, types.ZarfPackage{ Kind: types.ZarfInitConfig, Metadata: types.ZarfMetadata{ Name: "invalid", }, }) require.NoError(t, err) - expected := []types.PackageFinding{ + expected := []PackageFinding{ { Description: "Invalid type. Expected: array, given: null", - Severity: types.SevErr, + Severity: SevErr, YqPath: ".components", }, } @@ -191,89 +188,8 @@ components: }) } -func TestValidateComponent(t *testing.T) { +func TestYqCompat(t *testing.T) { t.Parallel() - - t.Run("Unpinnned repo warning", func(t *testing.T) { - t.Parallel() - unpinnedRepo := "https://github.com/zarf-dev/zarf-public-test.git" - component := types.ZarfComponent{Repos: []string{ - unpinnedRepo, - "https://dev.azure.com/defenseunicorns/zarf-public-test/_git/zarf-public-test@v0.0.1", - }} - findings := checkForUnpinnedRepos(component, 0) - expected := []types.PackageFinding{ - { - Item: unpinnedRepo, - Description: "Unpinned repository", - Severity: types.SevWarn, - YqPath: ".components.[0].repos.[0]", - }, - } - require.Equal(t, expected, findings) - }) - - t.Run("Unpinnned image warning", func(t *testing.T) { - t.Parallel() - unpinnedImage := "registry.com:9001/whatever/image:1.0.0" - badImage := "badimage:badimage@@sha256:3fbc632167424a6d997e74f5" - cosignSignature := "ghcr.io/stefanprodan/podinfo:sha256-57a654ace69ec02ba8973093b6a786faa15640575fbf0dbb603db55aca2ccec8.sig" - cosignAttestation := "ghcr.io/stefanprodan/podinfo:sha256-57a654ace69ec02ba8973093b6a786faa15640575fbf0dbb603db55aca2ccec8.att" - component := types.ZarfComponent{Images: []string{ - unpinnedImage, - "busybox:latest@sha256:3fbc632167424a6d997e74f52b878d7cc478225cffac6bc977eedfe51c7f4e79", - badImage, - cosignSignature, - cosignAttestation, - }} - findings := checkForUnpinnedImages(component, 0) - expected := []types.PackageFinding{ - { - Item: unpinnedImage, - Description: "Image not pinned with digest", - Severity: types.SevWarn, - YqPath: ".components.[0].images.[0]", - }, - { - Item: badImage, - Description: "Failed to parse image reference", - Severity: types.SevWarn, - YqPath: ".components.[0].images.[2]", - }, - } - require.Equal(t, expected, findings) - }) - - t.Run("Unpinnned file warning", func(t *testing.T) { - t.Parallel() - fileURL := "http://example.com/file.zip" - localFile := "local.txt" - zarfFiles := []types.ZarfFile{ - { - Source: fileURL, - }, - { - Source: localFile, - }, - { - Source: fileURL, - Shasum: "fake-shasum", - }, - } - component := types.ZarfComponent{Files: zarfFiles} - findings := checkForUnpinnedFiles(component, 0) - expectedErr := []types.PackageFinding{ - { - Item: fileURL, - Description: "No shasum for remote file", - Severity: types.SevWarn, - YqPath: ".components.[0].files.[0]", - }, - } - require.Equal(t, expectedErr, findings) - require.Len(t, findings, 1) - }) - t.Run("Wrap standalone numbers in bracket", func(t *testing.T) { t.Parallel() input := "components12.12.import.path" @@ -288,74 +204,4 @@ func TestValidateComponent(t *testing.T) { actual := makeFieldPathYqCompat(input) require.Equal(t, input, actual) }) - - t.Run("Test composable components with bad path", func(t *testing.T) { - t.Parallel() - zarfPackage := types.ZarfPackage{ - Components: []types.ZarfComponent{ - { - Import: types.ZarfComponentImport{Path: "bad-path"}, - }, - }, - Metadata: types.ZarfMetadata{Name: "test-zarf-package"}, - } - - createOpts := types.ZarfCreateOptions{Flavor: "", BaseDir: "."} - _, err := lintComponents(context.Background(), zarfPackage, createOpts) - require.Error(t, err) - }) - - t.Run("isImagePinned", func(t *testing.T) { - t.Parallel() - tests := []struct { - input string - expected bool - err error - }{ - { - input: "registry.com:8080/defenseunicorns/whatever", - expected: false, - err: nil, - }, - { - input: "ghcr.io/defenseunicorns/pepr/controller:v0.15.0", - expected: false, - err: nil, - }, - { - input: "busybox:latest@sha256:3fbc632167424a6d997e74f52b878d7cc478225cffac6bc977eedfe51c7f4e79", - expected: true, - err: nil, - }, - { - input: "busybox:bad/image", - expected: false, - err: errors.New("invalid reference format"), - }, - { - input: "busybox:###ZARF_PKG_TMPL_BUSYBOX_IMAGE###", - expected: true, - err: nil, - }, - { - input: "ghcr.io/stefanprodan/podinfo:sha256-57a654ace69ec02ba8973093b6a786faa15640575fbf0dbb603db55aca2ccec8.sig", - expected: true, - err: nil, - }, - { - input: "ghcr.io/stefanprodan/podinfo:sha256-57a654ace69ec02ba8973093b6a786faa15640575fbf0dbb603db55aca2ccec8.att", - expected: true, - err: nil, - }, - } - for _, tc := range tests { - t.Run(tc.input, func(t *testing.T) { - actual, err := isPinnedImage(tc.input) - if err != nil { - require.EqualError(t, err, tc.err.Error()) - } - require.Equal(t, tc.expected, actual) - }) - } - }) } diff --git a/src/pkg/packager/creator/creator_test.go b/src/pkg/packager/creator/creator_test.go index 1c2e3b7153..9312fe0a2c 100644 --- a/src/pkg/packager/creator/creator_test.go +++ b/src/pkg/packager/creator/creator_test.go @@ -6,16 +6,33 @@ package creator import ( "context" + "io/fs" + "os" "path/filepath" "testing" "github.com/stretchr/testify/require" "github.com/zarf-dev/zarf/src/pkg/layout" + "github.com/zarf-dev/zarf/src/pkg/lint" "github.com/zarf-dev/zarf/src/types" ) +type mockSchemaLoader struct { + b []byte +} + +func (m *mockSchemaLoader) ReadFile(_ string) ([]byte, error) { + return m.b, nil +} + +// Satisfy fs.ReadFileFS interface +func (m *mockSchemaLoader) Open(_ string) (fs.File, error) { + return nil, nil +} + func TestLoadPackageDefinition(t *testing.T) { - t.Parallel() + // TODO once creator is refactored to not expect to be in the same directory as the zarf.yaml file + // this test can be re-parallelized tests := []struct { name string testDir string @@ -31,7 +48,7 @@ func TestLoadPackageDefinition(t *testing.T) { { name: "invalid package definition", testDir: "invalid", - expectedErr: "package must have at least 1 component", + expectedErr: "found errors in schema", creator: NewPackageCreator(types.ZarfCreateOptions{}, ""), }, { @@ -43,17 +60,28 @@ func TestLoadPackageDefinition(t *testing.T) { { name: "invalid package definition", testDir: "invalid", - expectedErr: "package must have at least 1 component", + expectedErr: "found errors in schema", creator: NewSkeletonCreator(types.ZarfCreateOptions{}, types.ZarfPublishOptions{}), }, } + b, err := os.ReadFile("../../../../zarf.schema.json") + require.NoError(t, err) + lint.ZarfSchema = &mockSchemaLoader{b: b} for _, tt := range tests { tt := tt t.Run(tt.name, func(t *testing.T) { - t.Parallel() + cwd, err := os.Getwd() + require.NoError(t, err) + defer func() { + err = os.Chdir(cwd) + require.NoError(t, err) + }() + path := filepath.Join("testdata", tt.testDir) + err = os.Chdir(path) + require.NoError(t, err) - src := layout.New(filepath.Join("testdata", tt.testDir)) + src := layout.New(".") pkg, _, err := tt.creator.LoadPackageDefinition(context.Background(), src) if tt.expectedErr == "" { diff --git a/src/pkg/packager/creator/normal.go b/src/pkg/packager/creator/normal.go index 32e2ea1bbb..6f42c55865 100644 --- a/src/pkg/packager/creator/normal.go +++ b/src/pkg/packager/creator/normal.go @@ -74,7 +74,6 @@ func (pc *PackageCreator) LoadPackageDefinition(ctx context.Context, src *layout if err != nil { return types.ZarfPackage{}, nil, err } - warnings = append(warnings, composeWarnings...) // After components are composed, template the active package. @@ -119,7 +118,7 @@ func (pc *PackageCreator) LoadPackageDefinition(ctx context.Context, src *layout } } - if err := pkg.Validate(); err != nil { + if err := Validate(pkg, pc.createOpts.BaseDir); err != nil { return types.ZarfPackage{}, nil, err } diff --git a/src/pkg/packager/creator/skeleton.go b/src/pkg/packager/creator/skeleton.go index 3c95623542..9ddf24379a 100644 --- a/src/pkg/packager/creator/skeleton.go +++ b/src/pkg/packager/creator/skeleton.go @@ -70,7 +70,7 @@ func (sc *SkeletonCreator) LoadPackageDefinition(ctx context.Context, src *layou message.Warn(warning) } - if err := pkg.Validate(); err != nil { + if err := Validate(pkg, sc.createOpts.BaseDir); err != nil { return types.ZarfPackage{}, nil, err } diff --git a/src/pkg/packager/creator/utils.go b/src/pkg/packager/creator/utils.go index 5c3f962766..4d72edb59f 100644 --- a/src/pkg/packager/creator/utils.go +++ b/src/pkg/packager/creator/utils.go @@ -5,15 +5,37 @@ package creator import ( + "fmt" "os" "runtime" "time" "github.com/zarf-dev/zarf/src/config" + "github.com/zarf-dev/zarf/src/pkg/lint" "github.com/zarf-dev/zarf/src/pkg/packager/deprecated" "github.com/zarf-dev/zarf/src/types" ) +// Validate errors if a package violates the schema or any runtime validations +// This must be run while in the parent directory of the zarf.yaml being validated +func Validate(pkg types.ZarfPackage, baseDir string) error { + if err := pkg.Validate(); err != nil { + return fmt.Errorf("package validation failed: %w", err) + } + + findings, err := lint.ValidatePackageSchema() + if err != nil { + return fmt.Errorf("unable to check schema: %w", err) + } + + if lint.HasSevOrHigher(findings, lint.SevErr) { + lint.PrintFindings(findings, lint.SevErr, baseDir, pkg.Metadata.Name) + return fmt.Errorf("found errors in schema") + } + + return nil +} + // recordPackageMetadata records various package metadata during package create. func recordPackageMetadata(pkg *types.ZarfPackage, createOpts types.ZarfCreateOptions) error { now := time.Now() diff --git a/src/pkg/packager/dev.go b/src/pkg/packager/dev.go index 4363c0b49a..1c1208be14 100644 --- a/src/pkg/packager/dev.go +++ b/src/pkg/packager/dev.go @@ -6,21 +6,16 @@ package packager import ( "context" - "errors" "fmt" "os" - "path/filepath" "runtime" "github.com/defenseunicorns/pkg/helpers/v2" - "github.com/fatih/color" "github.com/zarf-dev/zarf/src/config" "github.com/zarf-dev/zarf/src/pkg/layout" "github.com/zarf-dev/zarf/src/pkg/message" "github.com/zarf-dev/zarf/src/pkg/packager/creator" "github.com/zarf-dev/zarf/src/pkg/packager/filters" - "github.com/zarf-dev/zarf/src/pkg/packager/lint" - "github.com/zarf-dev/zarf/src/pkg/utils" "github.com/zarf-dev/zarf/src/types" ) @@ -58,8 +53,8 @@ func (p *Packager) DevDeploy(ctx context.Context) error { return err } - if err := p.cfg.Pkg.Validate(); err != nil { - return fmt.Errorf("unable to validate package: %w", err) + if err := creator.Validate(p.cfg.Pkg, p.cfg.CreateOpts.BaseDir); err != nil { + return fmt.Errorf("package validation failed: %w", err) } if err := p.populatePackageVariableConfig(); err != nil { @@ -110,69 +105,3 @@ func (p *Packager) DevDeploy(ctx context.Context) error { // cd back return os.Chdir(cwd) } - -// Lint ensures a package is valid & follows suggested conventions -func (p *Packager) Lint(ctx context.Context) error { - if err := os.Chdir(p.cfg.CreateOpts.BaseDir); err != nil { - return fmt.Errorf("unable to access directory %q: %w", p.cfg.CreateOpts.BaseDir, err) - } - - if err := utils.ReadYaml(layout.ZarfYAML, &p.cfg.Pkg); err != nil { - return err - } - - findings, err := lint.Validate(ctx, p.cfg.Pkg, p.cfg.CreateOpts) - if err != nil { - return fmt.Errorf("linting failed: %w", err) - } - - if len(findings) == 0 { - message.Successf("0 findings for %q", p.cfg.Pkg.Metadata.Name) - return nil - } - - mapOfFindingsByPath := lint.GroupFindingsByPath(findings, types.SevWarn, p.cfg.Pkg.Metadata.Name) - - header := []string{"Type", "Path", "Message"} - - for _, findings := range mapOfFindingsByPath { - lintData := [][]string{} - for _, finding := range findings { - lintData = append(lintData, []string{ - colorWrapSev(finding.Severity), - message.ColorWrap(finding.YqPath, color.FgCyan), - itemizedDescription(finding.Description, finding.Item), - }) - } - var packagePathFromUser string - if helpers.IsOCIURL(findings[0].PackagePathOverride) { - packagePathFromUser = findings[0].PackagePathOverride - } else { - packagePathFromUser = filepath.Join(p.cfg.CreateOpts.BaseDir, findings[0].PackagePathOverride) - } - message.Notef("Linting package %q at %s", findings[0].PackageNameOverride, packagePathFromUser) - message.Table(header, lintData) - } - - if lint.HasSeverity(findings, types.SevErr) { - return errors.New("errors during lint") - } - - return nil -} - -func itemizedDescription(description string, item string) string { - if item == "" { - return description - } - return fmt.Sprintf("%s - %s", description, item) -} - -func colorWrapSev(s types.Severity) string { - if s == types.SevErr { - return message.ColorWrap("Error", color.FgRed) - } else if s == types.SevWarn { - return message.ColorWrap("Warning", color.FgYellow) - } - return "unknown" -} diff --git a/src/pkg/packager/lint/findings.go b/src/pkg/packager/lint/findings.go deleted file mode 100644 index 8b48bdea78..0000000000 --- a/src/pkg/packager/lint/findings.go +++ /dev/null @@ -1,41 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 -// SPDX-FileCopyrightText: 2021-Present The Zarf Authors - -// Package lint contains functions for verifying zarf yaml files are valid -package lint - -import ( - "github.com/defenseunicorns/pkg/helpers/v2" - "github.com/zarf-dev/zarf/src/types" -) - -// GroupFindingsByPath groups findings by their package path -func GroupFindingsByPath(findings []types.PackageFinding, severity types.Severity, packageName string) map[string][]types.PackageFinding { - findings = helpers.RemoveMatches(findings, func(finding types.PackageFinding) bool { - return finding.Severity > severity - }) - for i := range findings { - if findings[i].PackageNameOverride == "" { - findings[i].PackageNameOverride = packageName - } - if findings[i].PackagePathOverride == "" { - findings[i].PackagePathOverride = "." - } - } - - mapOfFindingsByPath := make(map[string][]types.PackageFinding) - for _, finding := range findings { - mapOfFindingsByPath[finding.PackagePathOverride] = append(mapOfFindingsByPath[finding.PackagePathOverride], finding) - } - return mapOfFindingsByPath -} - -// HasSeverity returns true if the findings contain a severity equal to or greater than the given severity -func HasSeverity(findings []types.PackageFinding, severity types.Severity) bool { - for _, finding := range findings { - if finding.Severity <= severity { - return true - } - } - return false -} diff --git a/src/pkg/packager/lint/findings_test.go b/src/pkg/packager/lint/findings_test.go deleted file mode 100644 index 522135eb96..0000000000 --- a/src/pkg/packager/lint/findings_test.go +++ /dev/null @@ -1,122 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 -// SPDX-FileCopyrightText: 2021-Present The Zarf Authors - -// Package lint contains functions for verifying zarf yaml files are valid -package lint - -import ( - "testing" - - "github.com/stretchr/testify/require" - "github.com/zarf-dev/zarf/src/types" -) - -func TestGroupFindingsByPath(t *testing.T) { - t.Parallel() - tests := []struct { - name string - findings []types.PackageFinding - severity types.Severity - packageName string - want map[string][]types.PackageFinding - }{ - { - name: "same package multiple findings", - findings: []types.PackageFinding{ - {Severity: types.SevWarn, PackageNameOverride: "import", PackagePathOverride: "path"}, - {Severity: types.SevWarn, PackageNameOverride: "import", PackagePathOverride: "path"}, - }, - severity: types.SevWarn, - packageName: "testPackage", - want: map[string][]types.PackageFinding{ - "path": { - {Severity: types.SevWarn, PackageNameOverride: "import", PackagePathOverride: "path"}, - {Severity: types.SevWarn, PackageNameOverride: "import", PackagePathOverride: "path"}, - }, - }, - }, - { - name: "different packages single finding", - findings: []types.PackageFinding{ - {Severity: types.SevWarn, PackageNameOverride: "import", PackagePathOverride: "path"}, - {Severity: types.SevErr, PackageNameOverride: "", PackagePathOverride: ""}, - }, - severity: types.SevWarn, - packageName: "testPackage", - want: map[string][]types.PackageFinding{ - "path": {{Severity: types.SevWarn, PackageNameOverride: "import", PackagePathOverride: "path"}}, - ".": {{Severity: types.SevErr, PackageNameOverride: "testPackage", PackagePathOverride: "."}}, - }, - }, - { - name: "Multiple findings, mixed severity", - findings: []types.PackageFinding{ - {Severity: types.SevWarn, PackageNameOverride: "", PackagePathOverride: ""}, - {Severity: types.SevErr, PackageNameOverride: "", PackagePathOverride: ""}, - }, - severity: types.SevErr, - packageName: "testPackage", - want: map[string][]types.PackageFinding{ - ".": {{Severity: types.SevErr, PackageNameOverride: "testPackage", PackagePathOverride: "."}}, - }, - }, - } - for _, tt := range tests { - tt := tt - t.Run(tt.name, func(t *testing.T) { - t.Parallel() - require.Equal(t, tt.want, GroupFindingsByPath(tt.findings, tt.severity, tt.packageName)) - }) - } -} - -func TestHasSeverity(t *testing.T) { - t.Parallel() - tests := []struct { - name string - severity types.Severity - expected bool - findings []types.PackageFinding - }{ - { - name: "error severity present", - findings: []types.PackageFinding{ - { - Severity: types.SevErr, - }, - }, - severity: types.SevErr, - expected: true, - }, - { - name: "error severity not present", - findings: []types.PackageFinding{ - { - Severity: types.SevWarn, - }, - }, - severity: types.SevErr, - expected: false, - }, - { - name: "err and warning severity present", - findings: []types.PackageFinding{ - { - Severity: types.SevWarn, - }, - { - Severity: types.SevErr, - }, - }, - severity: types.SevErr, - expected: true, - }, - } - for _, tt := range tests { - tt := tt - t.Run(tt.name, func(t *testing.T) { - t.Parallel() - require.Equal(t, tt.expected, HasSeverity(tt.findings, tt.severity)) - }) - } -} diff --git a/src/pkg/packager/lint/lint.go b/src/pkg/packager/lint/lint.go deleted file mode 100644 index 34ab432fe0..0000000000 --- a/src/pkg/packager/lint/lint.go +++ /dev/null @@ -1,278 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 -// SPDX-FileCopyrightText: 2021-Present The Zarf Authors - -// Package lint contains functions for verifying zarf yaml files are valid -package lint - -import ( - "context" - "fmt" - "io/fs" - "regexp" - "strings" - - "github.com/defenseunicorns/pkg/helpers/v2" - "github.com/xeipuuv/gojsonschema" - "github.com/zarf-dev/zarf/src/config" - "github.com/zarf-dev/zarf/src/config/lang" - "github.com/zarf-dev/zarf/src/pkg/layout" - "github.com/zarf-dev/zarf/src/pkg/packager/composer" - "github.com/zarf-dev/zarf/src/pkg/packager/creator" - "github.com/zarf-dev/zarf/src/pkg/transform" - "github.com/zarf-dev/zarf/src/pkg/utils" - "github.com/zarf-dev/zarf/src/types" -) - -// ZarfSchema is exported so main.go can embed the schema file -var ZarfSchema fs.ReadFileFS - -// Validate the given Zarf package. The Zarf package should not already be composed when sent to this function. -func Validate(ctx context.Context, pkg types.ZarfPackage, createOpts types.ZarfCreateOptions) ([]types.PackageFinding, error) { - var findings []types.PackageFinding - compFindings, err := lintComponents(ctx, pkg, createOpts) - if err != nil { - return nil, err - } - findings = append(findings, compFindings...) - - jsonSchema, err := ZarfSchema.ReadFile("zarf.schema.json") - if err != nil { - return nil, err - } - - var untypedZarfPackage interface{} - if err := utils.ReadYaml(layout.ZarfYAML, &untypedZarfPackage); err != nil { - return nil, err - } - - schemaFindings, err := validateSchema(jsonSchema, untypedZarfPackage) - if err != nil { - return nil, err - } - findings = append(findings, schemaFindings...) - - return findings, nil -} - -func lintComponents(ctx context.Context, pkg types.ZarfPackage, createOpts types.ZarfCreateOptions) ([]types.PackageFinding, error) { - var findings []types.PackageFinding - - for i, component := range pkg.Components { - arch := config.GetArch(pkg.Metadata.Architecture) - if !composer.CompatibleComponent(component, arch, createOpts.Flavor) { - continue - } - - chain, err := composer.NewImportChain(ctx, component, i, pkg.Metadata.Name, arch, createOpts.Flavor) - if err != nil { - return nil, err - } - - node := chain.Head() - for node != nil { - component := node.ZarfComponent - compFindings := fillComponentTemplate(&component, &createOpts) - compFindings = append(compFindings, checkComponent(component, node.Index())...) - for i := range compFindings { - compFindings[i].PackagePathOverride = node.ImportLocation() - compFindings[i].PackageNameOverride = node.OriginalPackageName() - } - findings = append(findings, compFindings...) - node = node.Next() - } - } - return findings, nil -} - -func fillComponentTemplate(c *types.ZarfComponent, createOpts *types.ZarfCreateOptions) []types.PackageFinding { - var findings []types.PackageFinding - err := creator.ReloadComponentTemplate(c) - if err != nil { - findings = append(findings, types.PackageFinding{ - Description: err.Error(), - Severity: types.SevWarn, - }) - } - templateMap := map[string]string{} - - setVarsAndWarn := func(templatePrefix string, deprecated bool) { - yamlTemplates, err := utils.FindYamlTemplates(c, templatePrefix, "###") - if err != nil { - findings = append(findings, types.PackageFinding{ - Description: err.Error(), - Severity: types.SevWarn, - }) - } - - for key := range yamlTemplates { - if deprecated { - findings = append(findings, types.PackageFinding{ - Description: fmt.Sprintf(lang.PkgValidateTemplateDeprecation, key, key, key), - Severity: types.SevWarn, - }) - } - _, present := createOpts.SetVariables[key] - if !present { - findings = append(findings, types.PackageFinding{ - Description: lang.UnsetVarLintWarning, - Severity: types.SevWarn, - }) - } - } - for key, value := range createOpts.SetVariables { - templateMap[fmt.Sprintf("%s%s###", templatePrefix, key)] = value - } - } - - setVarsAndWarn(types.ZarfPackageTemplatePrefix, false) - - // [DEPRECATION] Set the Package Variable syntax as well for backward compatibility - setVarsAndWarn(types.ZarfPackageVariablePrefix, true) - - //nolint: errcheck // This error should bubble up - utils.ReloadYamlTemplate(c, templateMap) - return findings -} - -func isPinnedImage(image string) (bool, error) { - transformedImage, err := transform.ParseImageRef(image) - if err != nil { - if strings.Contains(image, types.ZarfPackageTemplatePrefix) || - strings.Contains(image, types.ZarfPackageVariablePrefix) { - return true, nil - } - return false, err - } - if isCosignSignature(transformedImage.Tag) || isCosignAttestation(transformedImage.Tag) { - return true, nil - } - return (transformedImage.Digest != ""), err -} - -func isCosignSignature(image string) bool { - return strings.HasSuffix(image, ".sig") -} - -func isCosignAttestation(image string) bool { - return strings.HasSuffix(image, ".att") -} - -func isPinnedRepo(repo string) bool { - return (strings.Contains(repo, "@")) -} - -// checkComponent runs lint rules against a component -func checkComponent(c types.ZarfComponent, i int) []types.PackageFinding { - var findings []types.PackageFinding - findings = append(findings, checkForUnpinnedRepos(c, i)...) - findings = append(findings, checkForUnpinnedImages(c, i)...) - findings = append(findings, checkForUnpinnedFiles(c, i)...) - return findings -} - -func checkForUnpinnedRepos(c types.ZarfComponent, i int) []types.PackageFinding { - var findings []types.PackageFinding - for j, repo := range c.Repos { - repoYqPath := fmt.Sprintf(".components.[%d].repos.[%d]", i, j) - if !isPinnedRepo(repo) { - findings = append(findings, types.PackageFinding{ - YqPath: repoYqPath, - Description: "Unpinned repository", - Item: repo, - Severity: types.SevWarn, - }) - } - } - return findings -} - -func checkForUnpinnedImages(c types.ZarfComponent, i int) []types.PackageFinding { - var findings []types.PackageFinding - for j, image := range c.Images { - imageYqPath := fmt.Sprintf(".components.[%d].images.[%d]", i, j) - pinnedImage, err := isPinnedImage(image) - if err != nil { - findings = append(findings, types.PackageFinding{ - YqPath: imageYqPath, - Description: "Failed to parse image reference", - Item: image, - Severity: types.SevWarn, - }) - continue - } - if !pinnedImage { - findings = append(findings, types.PackageFinding{ - YqPath: imageYqPath, - Description: "Image not pinned with digest", - Item: image, - Severity: types.SevWarn, - }) - } - } - return findings -} - -func checkForUnpinnedFiles(c types.ZarfComponent, i int) []types.PackageFinding { - var findings []types.PackageFinding - for j, file := range c.Files { - fileYqPath := fmt.Sprintf(".components.[%d].files.[%d]", i, j) - if file.Shasum == "" && helpers.IsURL(file.Source) { - findings = append(findings, types.PackageFinding{ - YqPath: fileYqPath, - Description: "No shasum for remote file", - Item: file.Source, - Severity: types.SevWarn, - }) - } - } - return findings -} - -func makeFieldPathYqCompat(field string) string { - if field == "(root)" { - return field - } - // \b is a metacharacter that will stop at the next non-word character (including .) - // https://regex101.com/r/pIRPk0/1 - re := regexp.MustCompile(`(\b\d+\b)`) - - wrappedField := re.ReplaceAllString(field, "[$1]") - - return fmt.Sprintf(".%s", wrappedField) -} - -func validateSchema(jsonSchema []byte, untypedZarfPackage interface{}) ([]types.PackageFinding, error) { - var findings []types.PackageFinding - - schemaErrors, err := runSchema(jsonSchema, untypedZarfPackage) - if err != nil { - return nil, err - } - - if len(schemaErrors) != 0 { - for _, schemaErr := range schemaErrors { - findings = append(findings, types.PackageFinding{ - YqPath: makeFieldPathYqCompat(schemaErr.Field()), - Description: schemaErr.Description(), - Severity: types.SevErr, - }) - } - } - - return findings, err -} - -func runSchema(jsonSchema []byte, pkg interface{}) ([]gojsonschema.ResultError, error) { - schemaLoader := gojsonschema.NewBytesLoader(jsonSchema) - documentLoader := gojsonschema.NewGoLoader(pkg) - - result, err := gojsonschema.Validate(schemaLoader, documentLoader) - if err != nil { - return nil, err - } - - if !result.Valid() { - return result.Errors(), nil - } - return nil, nil -} diff --git a/src/pkg/variables/types.go b/src/pkg/variables/types.go index 3fb8d18d80..b106e911fa 100644 --- a/src/pkg/variables/types.go +++ b/src/pkg/variables/types.go @@ -60,21 +60,8 @@ type SetVariable struct { Value string `json:"value" jsonschema:"description=The value the variable is currently set with"` } -// Validate runs all validation checks on a package variable. -func (v Variable) Validate() error { - if !IsUppercaseNumberUnderscore(v.Name) { - return fmt.Errorf(lang.PkgValidateMustBeUppercase, v.Name) - } - return nil -} - // Validate runs all validation checks on a package constant. func (c Constant) Validate() error { - // ensure the constant name is only capitals and underscores - if !IsUppercaseNumberUnderscore(c.Name) { - return fmt.Errorf(lang.PkgValidateErrPkgConstantName, c.Name) - } - if !regexp.MustCompile(c.Pattern).MatchString(c.Value) { return fmt.Errorf(lang.PkgValidateErrPkgConstantPattern, c.Name, c.Pattern) } diff --git a/src/types/package.go b/src/types/package.go index 17419dd6e3..cb097d6e42 100644 --- a/src/types/package.go +++ b/src/types/package.go @@ -43,6 +43,8 @@ func (pkg ZarfPackage) IsSBOMAble() bool { // ZarfMetadata lists information about the current ZarfPackage. type ZarfMetadata struct { + // The Name regex permits lowercase letters, numbers, and hyphens not at the start + // https://regex101.com/r/FLdG9G/2 Name string `json:"name" jsonschema:"description=Name to identify this Zarf package,pattern=^[a-z0-9][a-z0-9\\-]*$"` Description string `json:"description,omitempty" jsonschema:"description=Additional information about this package"` Version string `json:"version,omitempty" jsonschema:"description=Generic string set by a package author to track the package version (Note: ZarfInitConfigs will always be versioned to the CLIVersion they were created with)"` diff --git a/src/types/validate.go b/src/types/validate.go index 63ee4584d9..e045e69520 100644 --- a/src/types/validate.go +++ b/src/types/validate.go @@ -9,7 +9,6 @@ import ( "fmt" "path/filepath" "regexp" - "slices" "github.com/defenseunicorns/pkg/helpers/v2" "github.com/zarf-dev/zarf/src/config/lang" @@ -45,20 +44,6 @@ func (pkg ZarfPackage) Validate() error { err = errors.Join(err, fmt.Errorf(lang.PkgValidateErrInitNoYOLO)) } - if !IsLowercaseNumberHyphenNoStartHyphen(pkg.Metadata.Name) { - err = errors.Join(err, fmt.Errorf(lang.PkgValidateErrPkgName, pkg.Metadata.Name)) - } - - if len(pkg.Components) == 0 { - err = errors.Join(err, fmt.Errorf("package must have at least 1 component")) - } - - for _, variable := range pkg.Variables { - if varErr := variable.Validate(); varErr != nil { - err = errors.Join(err, fmt.Errorf(lang.PkgValidateErrVariable, varErr)) - } - } - for _, constant := range pkg.Constants { if varErr := constant.Validate(); varErr != nil { err = errors.Join(err, fmt.Errorf(lang.PkgValidateErrConstant, varErr)) @@ -96,14 +81,6 @@ func (pkg ZarfPackage) Validate() error { } uniqueComponentNames[component.Name] = true - if !IsLowercaseNumberHyphenNoStartHyphen(component.Name) { - err = errors.Join(err, fmt.Errorf(lang.PkgValidateErrComponentName, component.Name)) - } - - if !slices.Contains(supportedOS, component.Only.LocalOS) { - err = errors.Join(err, fmt.Errorf(lang.PkgValidateErrComponentLocalOS, component.Name, component.Only.LocalOS, supportedOS)) - } - if component.IsRequired() { if component.Default { err = errors.Join(err, fmt.Errorf(lang.PkgValidateErrComponentReqDefault, component.Name)) @@ -254,9 +231,6 @@ func (as ZarfComponentActionSet) Validate() error { // Validate runs all validation checks on an action. func (action ZarfComponentAction) Validate() error { var err error - for _, variable := range action.SetVariables { - err = errors.Join(err, variable.Validate()) - } if action.Wait != nil { // Validate only cmd or wait, not both @@ -282,10 +256,6 @@ func (action ZarfComponentAction) Validate() error { func (chart ZarfChart) Validate() error { var err error - if chart.Name == "" { - err = errors.Join(err, fmt.Errorf(lang.PkgValidateErrChartNameMissing)) - } - if len(chart.Name) > ZarfMaxChartNameLength { err = errors.Join(err, fmt.Errorf(lang.PkgValidateErrChartName, chart.Name, ZarfMaxChartNameLength)) } @@ -314,10 +284,6 @@ func (chart ZarfChart) Validate() error { func (manifest ZarfManifest) Validate() error { var err error - if manifest.Name == "" { - err = errors.Join(err, fmt.Errorf(lang.PkgValidateErrManifestNameMissing)) - } - if len(manifest.Name) > ZarfMaxChartNameLength { err = errors.Join(err, fmt.Errorf(lang.PkgValidateErrManifestNameLength, manifest.Name, ZarfMaxChartNameLength)) } diff --git a/src/types/validate_test.go b/src/types/validate_test.go index f283302675..b0ebc60e8f 100644 --- a/src/types/validate_test.go +++ b/src/types/validate_test.go @@ -38,30 +38,16 @@ func TestZarfPackageValidate(t *testing.T) { }, expectedErrs: nil, }, - { - name: "no components", - pkg: ZarfPackage{ - Kind: ZarfPackageConfig, - Metadata: ZarfMetadata{ - Name: "empty-components", - }, - Components: []ZarfComponent{}, - }, - expectedErrs: []string{"package must have at least 1 component"}, - }, { name: "invalid package", pkg: ZarfPackage{ Kind: ZarfPackageConfig, Metadata: ZarfMetadata{ - Name: "-invalid-package", + Name: "invalid-package", }, Components: []ZarfComponent{ { - Name: "-invalid", - Only: ZarfComponentOnlyTarget{ - LocalOS: "unsupportedOS", - }, + Name: "invalid", Required: helpers.BoolPtr(true), Default: true, Charts: []ZarfChart{ @@ -95,15 +81,7 @@ func TestZarfPackageValidate(t *testing.T) { Name: "duplicate", }, }, - Variables: []variables.InteractiveVariable{ - { - Variable: variables.Variable{Name: "not_uppercase"}, - }, - }, Constants: []variables.Constant{ - { - Name: "not_uppercase", - }, { Name: "BAD", Pattern: "^good_val$", @@ -112,13 +90,8 @@ func TestZarfPackageValidate(t *testing.T) { }, }, expectedErrs: []string{ - fmt.Sprintf(lang.PkgValidateErrPkgName, "-invalid-package"), - fmt.Errorf(lang.PkgValidateErrVariable, fmt.Errorf(lang.PkgValidateMustBeUppercase, "not_uppercase")).Error(), - fmt.Errorf(lang.PkgValidateErrConstant, fmt.Errorf(lang.PkgValidateErrPkgConstantName, "not_uppercase")).Error(), fmt.Errorf(lang.PkgValidateErrConstant, fmt.Errorf(lang.PkgValidateErrPkgConstantPattern, "BAD", "^good_val$")).Error(), - fmt.Sprintf(lang.PkgValidateErrComponentName, "-invalid"), - fmt.Sprintf(lang.PkgValidateErrComponentLocalOS, "-invalid", "unsupportedOS", supportedOS), - fmt.Sprintf(lang.PkgValidateErrComponentReqDefault, "-invalid"), + fmt.Sprintf(lang.PkgValidateErrComponentReqDefault, "invalid"), fmt.Sprintf(lang.PkgValidateErrChartNameNotUnique, "chart1"), fmt.Sprintf(lang.PkgValidateErrManifestNameNotUnique, "manifest1"), fmt.Sprintf(lang.PkgValidateErrComponentReqGrouped, "required-in-group"), @@ -187,11 +160,6 @@ func TestValidateManifest(t *testing.T) { manifest: ZarfManifest{Name: "valid", Files: []string{"a-file"}}, expectedErrs: nil, }, - { - name: "empty name", - manifest: ZarfManifest{Name: "", Files: []string{"a-file"}}, - expectedErrs: []string{lang.PkgValidateErrManifestNameMissing}, - }, { name: "long name", manifest: ZarfManifest{Name: longName, Files: []string{"a-file"}}, @@ -231,11 +199,6 @@ func TestValidateChart(t *testing.T) { chart: ZarfChart{Name: "chart1", Namespace: "whatever", URL: "http://whatever", Version: "v1.0.0"}, expectedErrs: nil, }, - { - name: "empty name", - chart: ZarfChart{Name: "", Namespace: "whatever", URL: "http://whatever", Version: "v1.0.0"}, - expectedErrs: []string{lang.PkgValidateErrChartNameMissing}, - }, { name: "long name", chart: ZarfChart{Name: longName, Namespace: "whatever", URL: "http://whatever", Version: "v1.0.0"}, @@ -244,7 +207,7 @@ func TestValidateChart(t *testing.T) { }, }, { - name: "no url or local path", + name: "no url, local path, version, or namespace", chart: ZarfChart{Name: "invalid"}, expectedErrs: []string{ fmt.Sprintf(lang.PkgValidateErrChartNamespaceMissing, "invalid"), From a93d65a5518daf3d598a3586a3fae8ced126b7eb Mon Sep 17 00:00:00 2001 From: Philip Laine Date: Thu, 25 Jul 2024 17:22:11 +0200 Subject: [PATCH 11/11] refactor: remove overly verbose debug logs (#2751) Signed-off-by: Philip Laine --- src/internal/agent/hooks/argocd-application.go | 2 -- src/internal/agent/http/admission/handler.go | 3 --- src/internal/agent/http/server.go | 5 ----- src/internal/agent/operations/hook.go | 3 --- src/internal/packager/git/checkout.go | 6 ------ src/internal/packager/git/gitea.go | 10 ---------- src/internal/packager/helm/chart.go | 10 ++-------- src/internal/packager/helm/images.go | 2 -- src/internal/packager/helm/post-render.go | 2 -- src/internal/packager/images/push.go | 2 -- src/pkg/cluster/tunnel.go | 2 -- src/pkg/packager/common.go | 16 ++++------------ src/pkg/packager/creator/compose.go | 2 -- src/pkg/packager/creator/normal.go | 2 -- src/pkg/packager/creator/skeleton.go | 2 -- src/pkg/packager/prepare.go | 3 +-- src/pkg/packager/sources/new.go | 3 --- src/pkg/packager/sources/oci.go | 2 -- src/pkg/utils/io.go | 5 ----- src/pkg/utils/network.go | 1 - src/test/e2e/00_use_cli_test.go | 2 ++ 21 files changed, 9 insertions(+), 76 deletions(-) diff --git a/src/internal/agent/hooks/argocd-application.go b/src/internal/agent/hooks/argocd-application.go index 8886ba2ff9..f9d3238aee 100644 --- a/src/internal/agent/hooks/argocd-application.go +++ b/src/internal/agent/hooks/argocd-application.go @@ -72,8 +72,6 @@ func mutateApplication(ctx context.Context, r *v1.AdmissionRequest, cluster *clu return nil, fmt.Errorf(lang.ErrUnmarshal, err) } - message.Debugf("Data %v", string(r.Object.Raw)) - patches := []operations.PatchOperation{} if app.Spec.Source != nil { diff --git a/src/internal/agent/http/admission/handler.go b/src/internal/agent/http/admission/handler.go index 56589a7c73..4b4d69323b 100644 --- a/src/internal/agent/http/admission/handler.go +++ b/src/internal/agent/http/admission/handler.go @@ -117,9 +117,6 @@ func (h *Handler) Serve(hook operations.Hook) http.HandlerFunc { return } - message.Debug("PATCH: ", string(admissionResponse.Response.Patch)) - message.Debug("RESPONSE: ", string(jsonResponse)) - message.Infof(lang.AgentInfoWebhookAllowed, r.URL.Path, review.Request.Operation, result.Allowed) w.WriteHeader(http.StatusOK) //nolint: errcheck // ignore diff --git a/src/internal/agent/http/server.go b/src/internal/agent/http/server.go index b5953ee0e2..6a79aaa449 100644 --- a/src/internal/agent/http/server.go +++ b/src/internal/agent/http/server.go @@ -14,13 +14,10 @@ import ( "github.com/zarf-dev/zarf/src/internal/agent/hooks" "github.com/zarf-dev/zarf/src/internal/agent/http/admission" "github.com/zarf-dev/zarf/src/pkg/cluster" - "github.com/zarf-dev/zarf/src/pkg/message" ) // NewAdmissionServer creates a http.Server for the mutating webhook admission handler. func NewAdmissionServer(ctx context.Context, port string) (*http.Server, error) { - message.Debugf("http.NewAdmissionServer(%s)", port) - c, err := cluster.NewCluster() if err != nil { return nil, err @@ -56,8 +53,6 @@ func NewAdmissionServer(ctx context.Context, port string) (*http.Server, error) // NewProxyServer creates and returns an http proxy server. func NewProxyServer(port string) *http.Server { - message.Debugf("http.NewHTTPProxy(%s)", port) - mux := http.NewServeMux() mux.Handle("/healthz", healthz()) mux.Handle("/", ProxyHandler()) diff --git a/src/internal/agent/operations/hook.go b/src/internal/agent/operations/hook.go index 627ce58094..8c411adee7 100644 --- a/src/internal/agent/operations/hook.go +++ b/src/internal/agent/operations/hook.go @@ -8,7 +8,6 @@ import ( "fmt" "github.com/zarf-dev/zarf/src/config/lang" - "github.com/zarf-dev/zarf/src/pkg/message" admission "k8s.io/api/admission/v1" ) @@ -32,8 +31,6 @@ type Hook struct { // Execute evaluates the request and try to execute the function for operation specified in the request. func (h *Hook) Execute(r *admission.AdmissionRequest) (*Result, error) { - message.Debugf("operations.Execute(*admission.AdmissionRequest) - %#v , %s/%s: %#v", r.Kind, r.Namespace, r.Name, r.Operation) - switch r.Operation { case admission.Create: return wrapperExecution(h.Create, r) diff --git a/src/internal/packager/git/checkout.go b/src/internal/packager/git/checkout.go index 4441e48873..2ee91d96b5 100644 --- a/src/internal/packager/git/checkout.go +++ b/src/internal/packager/git/checkout.go @@ -15,8 +15,6 @@ import ( // CheckoutTag performs a `git checkout` of the provided tag to a detached HEAD. func (g *Git) CheckoutTag(tag string) error { - message.Debugf("git checkout tag %s", tag) - options := &git.CheckoutOptions{ Branch: ParseRef(tag), } @@ -35,8 +33,6 @@ func (g *Git) checkoutRefAsBranch(ref string, branch plumbing.ReferenceName) err // than checking out to a detached head, checks out to the provided branch ref // It will delete the branch provided if it exists. func (g *Git) checkoutTagAsBranch(tag string, branch plumbing.ReferenceName) error { - message.Debugf("git checkout tag %s on %s", tag, branch) - repo, err := git.PlainOpen(g.GitPath) if err != nil { return fmt.Errorf("not a valid git repo or unable to open: %w", err) @@ -54,8 +50,6 @@ func (g *Git) checkoutTagAsBranch(tag string, branch plumbing.ReferenceName) err // with the provided hash // It will delete the branch provided if it exists. func (g *Git) checkoutHashAsBranch(hash plumbing.Hash, branch plumbing.ReferenceName) error { - message.Debugf("git checkout hash %s on %s", hash, branch) - repo, err := git.PlainOpen(g.GitPath) if err != nil { return fmt.Errorf("not a valid git repo or unable to open: %w", err) diff --git a/src/internal/packager/git/gitea.go b/src/internal/packager/git/gitea.go index 4bfbcf60ab..a6715d29d5 100644 --- a/src/internal/packager/git/gitea.go +++ b/src/internal/packager/git/gitea.go @@ -32,8 +32,6 @@ type CreateTokenResponse struct { // CreateReadOnlyUser uses the Gitea API to create a non-admin Zarf user. func (g *Git) CreateReadOnlyUser(ctx context.Context) error { - message.Debugf("git.CreateReadOnlyUser()") - c, err := cluster.NewCluster() if err != nil { return err @@ -119,8 +117,6 @@ func (g *Git) UpdateZarfGiteaUsers(ctx context.Context, oldState *types.ZarfStat // UpdateGitUser updates Zarf git server users func (g *Git) UpdateGitUser(ctx context.Context, oldAdminPass string, username string, userpass string) error { - message.Debugf("git.UpdateGitUser()") - c, err := cluster.NewCluster() if err != nil { return err @@ -157,8 +153,6 @@ func (g *Git) UpdateGitUser(ctx context.Context, oldAdminPass string, username s // CreatePackageRegistryToken uses the Gitea API to create a package registry token. func (g *Git) CreatePackageRegistryToken(ctx context.Context) (CreateTokenResponse, error) { - message.Debugf("git.CreatePackageRegistryToken()") - c, err := cluster.NewCluster() if err != nil { return CreateTokenResponse{}, err @@ -287,8 +281,6 @@ func UpdateGiteaPVC(ctx context.Context, shouldRollBack bool) (string, error) { // DoHTTPThings adds http request boilerplate and perform the request, checking for a successful response. func (g *Git) DoHTTPThings(request *netHttp.Request, username, secret string) ([]byte, int, error) { - message.Debugf("git.DoHttpThings()") - // Prep the request with boilerplate client := &netHttp.Client{Timeout: time.Second * 20} request.SetBasicAuth(username, secret) @@ -312,8 +304,6 @@ func (g *Git) DoHTTPThings(request *netHttp.Request, username, secret string) ([ } func (g *Git) addReadOnlyUserToRepo(tunnelURL, repo string) error { - message.Debugf("git.addReadOnlyUserToRepo()") - // Add the readonly user to the repo addCollabBody := map[string]string{ "permission": "read", diff --git a/src/internal/packager/helm/chart.go b/src/internal/packager/helm/chart.go index 0bd483df7f..bca8773294 100644 --- a/src/internal/packager/helm/chart.go +++ b/src/internal/packager/helm/chart.go @@ -61,7 +61,6 @@ func (h *Helm) InstallOrUpgradeChart(ctx context.Context) (types.ConnectStrings, histClient := action.NewHistory(h.actionConfig) tryHelm := func() error { var err error - var output *release.Release releases, histErr := histClient.Run(h.chart.ReleaseName) @@ -71,14 +70,14 @@ func (h *Helm) InstallOrUpgradeChart(ctx context.Context) (types.ConnectStrings, // No prior release, try to install it. spinner.Updatef("Attempting chart installation") - output, err = h.installChart(postRender) + _, err = h.installChart(postRender) } else if histErr == nil && len(releases) > 0 { // Otherwise, there is a prior release so upgrade it. spinner.Updatef("Attempting chart upgrade") lastRelease := releases[len(releases)-1] - output, err = h.upgradeChart(lastRelease, postRender) + _, err = h.upgradeChart(lastRelease, postRender) } else { // 😭 things aren't working return fmt.Errorf("unable to verify the chart installation status: %w", histErr) @@ -88,7 +87,6 @@ func (h *Helm) InstallOrUpgradeChart(ctx context.Context) (types.ConnectStrings, return err } - message.Debug(output.Info.Description) spinner.Success() return nil } @@ -128,7 +126,6 @@ func (h *Helm) InstallOrUpgradeChart(ctx context.Context) (types.ConnectStrings, // TemplateChart generates a helm template from a given chart. func (h *Helm) TemplateChart(ctx context.Context) (manifest string, chartValues chartutil.Values, err error) { - message.Debugf("helm.TemplateChart()") spinner := message.NewProgressSpinner("Templating helm chart %s", h.chart.Name) defer spinner.Stop() @@ -324,7 +321,6 @@ func (h *Helm) upgradeChart(lastRelease *release.Release, postRender *renderer) } func (h *Helm) rollbackChart(name string, version int) error { - message.Debugf("helm.rollbackChart(%s)", name) client := action.NewRollback(h.actionConfig) client.CleanupOnFail = true client.Force = true @@ -335,7 +331,6 @@ func (h *Helm) rollbackChart(name string, version int) error { } func (h *Helm) uninstallChart(name string) (*release.UninstallReleaseResponse, error) { - message.Debugf("helm.uninstallChart(%s)", name) client := action.NewUninstall(h.actionConfig) client.KeepHistory = false client.Wait = true @@ -344,7 +339,6 @@ func (h *Helm) uninstallChart(name string) (*release.UninstallReleaseResponse, e } func (h *Helm) loadChartData() (*chart.Chart, chartutil.Values, error) { - message.Debugf("helm.loadChartData()") var ( loadedChart *chart.Chart chartValues chartutil.Values diff --git a/src/internal/packager/helm/images.go b/src/internal/packager/helm/images.go index 390ce5c8be..b5399f2590 100644 --- a/src/internal/packager/helm/images.go +++ b/src/internal/packager/helm/images.go @@ -6,7 +6,6 @@ package helm import ( "github.com/defenseunicorns/pkg/helpers/v2" "github.com/goccy/go-yaml" - "github.com/zarf-dev/zarf/src/pkg/message" "helm.sh/helm/v3/pkg/chart/loader" "helm.sh/helm/v3/pkg/chartutil" ) @@ -45,7 +44,6 @@ func FindAnnotatedImagesForChart(chartPath string, values chartutil.Values) (ima // Only include the image if the current values/condition specify it should be included if i.Condition != "" { value, err := values.PathValue(i.Condition) - message.Debugf("%#v - %#v - %#v\n", value, i.Condition, err) // We intentionally ignore the error here because the key could be missing from the values.yaml if err == nil && value == true { images = append(images, i.Image) diff --git a/src/internal/packager/helm/post-render.go b/src/internal/packager/helm/post-render.go index 60d8fde0e3..b115b33ddf 100644 --- a/src/internal/packager/helm/post-render.go +++ b/src/internal/packager/helm/post-render.go @@ -38,8 +38,6 @@ type renderer struct { } func (h *Helm) newRenderer(ctx context.Context) (*renderer, error) { - message.Debugf("helm.NewRenderer()") - rend := &renderer{ Helm: h, connectStrings: types.ConnectStrings{}, diff --git a/src/internal/packager/images/push.go b/src/internal/packager/images/push.go index 08625ab385..0d0752f9fe 100644 --- a/src/internal/packager/images/push.go +++ b/src/internal/packager/images/push.go @@ -99,8 +99,6 @@ func Push(ctx context.Context, cfg PushConfig) error { return err } - message.Debugf("push %s -> %s)", refInfo.Reference, offlineNameCRC) - if err = pushImage(img, offlineNameCRC); err != nil { return err } diff --git a/src/pkg/cluster/tunnel.go b/src/pkg/cluster/tunnel.go index f0a1a660e0..719d81e008 100644 --- a/src/pkg/cluster/tunnel.go +++ b/src/pkg/cluster/tunnel.go @@ -185,8 +185,6 @@ func (c *Cluster) checkForZarfConnectLabel(ctx context.Context, name string) (Tu var err error var zt TunnelInfo - message.Debugf("Looking for a Zarf Connect Label in the cluster") - selector, err := metav1.LabelSelectorAsSelector(&metav1.LabelSelector{ MatchLabels: map[string]string{ ZarfConnectLabelName: name, diff --git a/src/pkg/packager/common.go b/src/pkg/packager/common.go index a5b77ff9d1..a753ec29d4 100644 --- a/src/pkg/packager/common.go +++ b/src/pkg/packager/common.go @@ -107,25 +107,17 @@ func New(cfg *types.PackagerConfig, mods ...Modifier) (*Packager, error) { // If the temp directory is not set, set it to the default if pkgr.layout == nil { - if err = pkgr.setTempDirectory(config.CommonOptions.TempDirectory); err != nil { + dir, err := utils.MakeTempDir(config.CommonOptions.TempDirectory) + if err != nil { return nil, fmt.Errorf("unable to create package temp paths: %w", err) } + message.Debug("Using temporary directory:", dir) + pkgr.layout = layout.New(dir) } return pkgr, nil } -// setTempDirectory sets the temp directory for the packager. -func (p *Packager) setTempDirectory(path string) error { - dir, err := utils.MakeTempDir(path) - if err != nil { - return fmt.Errorf("unable to create package temp paths: %w", err) - } - - p.layout = layout.New(dir) - return nil -} - // ClearTempPaths removes the temp directory and any files within it. func (p *Packager) ClearTempPaths() { // Remove the temp directory, but don't throw an error if it fails diff --git a/src/pkg/packager/creator/compose.go b/src/pkg/packager/creator/compose.go index 8844c0305f..bbd1325b31 100644 --- a/src/pkg/packager/creator/compose.go +++ b/src/pkg/packager/creator/compose.go @@ -7,7 +7,6 @@ package creator import ( "context" - "github.com/zarf-dev/zarf/src/pkg/message" "github.com/zarf-dev/zarf/src/pkg/packager/composer" "github.com/zarf-dev/zarf/src/types" ) @@ -37,7 +36,6 @@ func ComposeComponents(ctx context.Context, pkg types.ZarfPackage, flavor string if err != nil { return types.ZarfPackage{}, nil, err } - message.Debugf("%s", chain) // migrate any deprecated component configurations now warning := chain.Migrate(pkg.Build) diff --git a/src/pkg/packager/creator/normal.go b/src/pkg/packager/creator/normal.go index 6f42c55865..99b0f572b4 100644 --- a/src/pkg/packager/creator/normal.go +++ b/src/pkg/packager/creator/normal.go @@ -372,8 +372,6 @@ func (pc *PackageCreator) addComponent(ctx context.Context, component types.Zarf } for filesIdx, file := range component.Files { - message.Debugf("Loading %#v", file) - rel := filepath.Join(layout.FilesDir, strconv.Itoa(filesIdx), filepath.Base(file.Target)) dst := filepath.Join(componentPaths.Base, rel) destinationDir := filepath.Dir(dst) diff --git a/src/pkg/packager/creator/skeleton.go b/src/pkg/packager/creator/skeleton.go index 9ddf24379a..c7b2d3d706 100644 --- a/src/pkg/packager/creator/skeleton.go +++ b/src/pkg/packager/creator/skeleton.go @@ -209,8 +209,6 @@ func (sc *SkeletonCreator) addComponent(component types.ZarfComponent, dst *layo } for filesIdx, file := range component.Files { - message.Debugf("Loading %#v", file) - if helpers.IsURL(file.Source) { continue } diff --git a/src/pkg/packager/prepare.go b/src/pkg/packager/prepare.go index 0ca1f35f91..a52cc9c0f4 100644 --- a/src/pkg/packager/prepare.go +++ b/src/pkg/packager/prepare.go @@ -255,8 +255,7 @@ func (p *Packager) findImages(ctx context.Context) (imgMap map[string][]string, } // Break the manifest into separate resources - contentString := string(contents) - message.Debugf("%s", contentString) + // TODO: Do not dogsled error yamls, _ := utils.SplitYAML(contents) resources = append(resources, yamls...) diff --git a/src/pkg/packager/sources/new.go b/src/pkg/packager/sources/new.go index 9018632085..4d43cc229c 100644 --- a/src/pkg/packager/sources/new.go +++ b/src/pkg/packager/sources/new.go @@ -14,7 +14,6 @@ import ( "github.com/defenseunicorns/pkg/oci" "github.com/zarf-dev/zarf/src/config" "github.com/zarf-dev/zarf/src/pkg/layout" - "github.com/zarf-dev/zarf/src/pkg/message" "github.com/zarf-dev/zarf/src/pkg/packager/filters" "github.com/zarf-dev/zarf/src/pkg/zoci" "github.com/zarf-dev/zarf/src/types" @@ -85,7 +84,5 @@ func New(pkgOpts *types.ZarfPackageOptions) (PackageSource, error) { return nil, fmt.Errorf("could not identify source type for %q", pkgSrc) } - message.Debugf("Using %T for %q", source, pkgSrc) - return source, nil } diff --git a/src/pkg/packager/sources/oci.go b/src/pkg/packager/sources/oci.go index 99a98137fc..33e4ba3fad 100644 --- a/src/pkg/packager/sources/oci.go +++ b/src/pkg/packager/sources/oci.go @@ -35,8 +35,6 @@ type OCISource struct { // LoadPackage loads a package from an OCI registry. func (s *OCISource) LoadPackage(ctx context.Context, dst *layout.PackagePaths, filter filters.ComponentFilterStrategy, unarchiveAll bool) (pkg types.ZarfPackage, warnings []string, err error) { - message.Debugf("Loading package from %q", s.PackageSource) - pkg, err = s.FetchZarfYAML(ctx) if err != nil { return pkg, nil, err diff --git a/src/pkg/utils/io.go b/src/pkg/utils/io.go index 06885d623a..7edee56422 100755 --- a/src/pkg/utils/io.go +++ b/src/pkg/utils/io.go @@ -11,7 +11,6 @@ import ( "github.com/defenseunicorns/pkg/helpers/v2" "github.com/zarf-dev/zarf/src/config" - "github.com/zarf-dev/zarf/src/pkg/message" ) const ( @@ -25,14 +24,10 @@ func MakeTempDir(basePath string) (string, error) { return "", err } } - tmp, err := os.MkdirTemp(basePath, tmpPathPrefix) if err != nil { return "", err } - - message.Debug("Using temporary directory:", tmp) - return tmp, nil } diff --git a/src/pkg/utils/network.go b/src/pkg/utils/network.go index 4bd6945f36..be0b80a2ed 100644 --- a/src/pkg/utils/network.go +++ b/src/pkg/utils/network.go @@ -40,7 +40,6 @@ func parseChecksum(src string) (string, string, error) { // DownloadToFile downloads a given URL to the target filepath (including the cosign key if necessary). func DownloadToFile(ctx context.Context, src string, dst string, cosignKeyPath string) (err error) { - message.Debugf("Downloading %s to %s", src, dst) // check if the parsed URL has a checksum // if so, remove it and use the checksum to validate the file src, checksum, err := parseChecksum(src) diff --git a/src/test/e2e/00_use_cli_test.go b/src/test/e2e/00_use_cli_test.go index ff8a07106b..b663d58454 100644 --- a/src/test/e2e/00_use_cli_test.go +++ b/src/test/e2e/00_use_cli_test.go @@ -143,6 +143,7 @@ func TestUseCLI(t *testing.T) { require.Greater(t, len(files), 1) }) + // TODO: Refactor test as it depends on debug log output for validation. t.Run("zarf package inspect with tmpdir", func(t *testing.T) { t.Parallel() path := fmt.Sprintf("build/zarf-package-component-actions-%s.tar.zst", e2e.Arch) @@ -152,6 +153,7 @@ func TestUseCLI(t *testing.T) { require.NoError(t, err, stdOut, stdErr) }) + // TODO: Refactor test as it depends on debug log output for validation. t.Run("zarf package deploy with tmpdir", func(t *testing.T) { t.Parallel() tmpdir := t.TempDir()