diff --git a/src/cmd/common/table.go b/src/cmd/common/table.go index ee5f9ee190..0b98266fe7 100644 --- a/src/cmd/common/table.go +++ b/src/cmd/common/table.go @@ -4,6 +4,7 @@ package common import ( + "context" "fmt" "path/filepath" @@ -11,11 +12,12 @@ import ( "github.com/fatih/color" "github.com/zarf-dev/zarf/src/pkg/lint" + "github.com/zarf-dev/zarf/src/pkg/logger" "github.com/zarf-dev/zarf/src/pkg/message" ) // PrintFindings prints the findings in the LintError as a table. -func PrintFindings(lintErr *lint.LintError) { +func PrintFindings(ctx context.Context, lintErr *lint.LintError) { mapOfFindingsByPath := lint.GroupFindingsByPath(lintErr.Findings, lintErr.PackageName) for _, findings := range mapOfFindingsByPath { lintData := [][]string{} @@ -41,6 +43,7 @@ func PrintFindings(lintErr *lint.LintError) { packagePathFromUser = filepath.Join(lintErr.BaseDir, findings[0].PackagePathOverride) } message.Notef("Linting package %q at %s", findings[0].PackageNameOverride, packagePathFromUser) + logger.From(ctx).Info("linting package", "name", findings[0].PackageNameOverride, "path", packagePathFromUser) message.Table([]string{"Type", "Path", "Message"}, lintData) } } diff --git a/src/cmd/dev.go b/src/cmd/dev.go index e8bffd57c0..f723eea911 100644 --- a/src/cmd/dev.go +++ b/src/cmd/dev.go @@ -47,6 +47,7 @@ var devDeployCmd = &cobra.Command{ Short: lang.CmdDevDeployShort, Long: lang.CmdDevDeployLong, RunE: func(cmd *cobra.Command, args []string) error { + ctx := cmd.Context() pkgConfig.CreateOpts.BaseDir = setBaseDirectory(args) v := common.GetViper() @@ -62,10 +63,10 @@ var devDeployCmd = &cobra.Command{ } defer pkgClient.ClearTempPaths() - err = pkgClient.DevDeploy(cmd.Context()) + err = pkgClient.DevDeploy(ctx) var lintErr *lint.LintError if errors.As(err, &lintErr) { - common.PrintFindings(lintErr) + common.PrintFindings(ctx, lintErr) } if err != nil { return fmt.Errorf("failed to dev deploy: %w", err) @@ -242,6 +243,7 @@ var devFindImagesCmd = &cobra.Command{ Short: lang.CmdDevFindImagesShort, Long: lang.CmdDevFindImagesLong, RunE: func(cmd *cobra.Command, args []string) error { + ctx := cmd.Context() pkgConfig.CreateOpts.BaseDir = setBaseDirectory(args) v := common.GetViper() @@ -256,16 +258,16 @@ var devFindImagesCmd = &cobra.Command{ } defer pkgClient.ClearTempPaths() - _, err = pkgClient.FindImages(cmd.Context()) + _, err = pkgClient.FindImages(ctx) var lintErr *lint.LintError if errors.As(err, &lintErr) { // HACK(mkcp): Re-initializing PTerm with a stderr writer isn't great, but it lets us render these lint // tables below for backwards compatibility - if logger.Enabled(cmd.Context()) { + if logger.Enabled(ctx) { message.InitializePTerm(logger.DestinationDefault) } - common.PrintFindings(lintErr) + common.PrintFindings(ctx, lintErr) } if err != nil { return fmt.Errorf("unable to find images: %w", err) @@ -302,21 +304,22 @@ var devLintCmd = &cobra.Command{ Short: lang.CmdDevLintShort, Long: lang.CmdDevLintLong, RunE: func(cmd *cobra.Command, args []string) error { + ctx := cmd.Context() config.CommonOptions.Confirm = true pkgConfig.CreateOpts.BaseDir = setBaseDirectory(args) v := common.GetViper() pkgConfig.CreateOpts.SetVariables = helpers.TransformAndMergeMap( v.GetStringMapString(common.VPkgCreateSet), pkgConfig.CreateOpts.SetVariables, strings.ToUpper) - err := lint.Validate(cmd.Context(), pkgConfig.CreateOpts.BaseDir, pkgConfig.CreateOpts.Flavor, pkgConfig.CreateOpts.SetVariables) + err := lint.Validate(ctx, pkgConfig.CreateOpts.BaseDir, pkgConfig.CreateOpts.Flavor, pkgConfig.CreateOpts.SetVariables) var lintErr *lint.LintError if errors.As(err, &lintErr) { // HACK(mkcp): Re-initializing PTerm with a stderr writer isn't great, but it lets us render these lint // tables below for backwards compatibility - if logger.Enabled(cmd.Context()) { + if logger.Enabled(ctx) { message.InitializePTerm(logger.DestinationDefault) } - common.PrintFindings(lintErr) + common.PrintFindings(ctx, lintErr) // Do not return an error if the findings are all warnings. if lintErr.OnlyWarnings() { return nil @@ -352,11 +355,11 @@ func init() { err := devFindImagesCmd.Flags().MarkDeprecated("set", "this field is replaced by create-set") if err != nil { - message.Debug("Unable to mark dev-find-images flag as set", "error", err) + logger.Default().Debug("unable to mark dev-find-images flag as set", "error", err) } err = devFindImagesCmd.Flags().MarkHidden("set") if err != nil { - message.Debug("Unable to mark dev-find-images flag as hidden", "error", err) + logger.Default().Debug("unable to mark dev-find-images flag as hidden", "error", err) } devFindImagesCmd.Flags().StringVarP(&pkgConfig.CreateOpts.Flavor, "flavor", "f", v.GetString(common.VPkgCreateFlavor), lang.CmdPackageCreateFlagFlavor) devFindImagesCmd.Flags().StringToStringVar(&pkgConfig.CreateOpts.SetVariables, "create-set", v.GetStringMapString(common.VPkgCreateSet), lang.CmdDevFlagSet) @@ -385,7 +388,7 @@ func bindDevDeployFlags(v *viper.Viper) { devDeployFlags.StringVar(&pkgConfig.DeployOpts.RegistryURL, "registry-url", defaultRegistry, lang.CmdDevFlagRegistry) err := devDeployFlags.MarkHidden("registry-url") if err != nil { - message.Debug("Unable to mark dev-deploy flag as hidden", "error", err) + logger.Default().Debug("unable to mark dev-deploy flag as hidden", "error", err) } devDeployFlags.StringToStringVar(&pkgConfig.PkgOpts.SetVariables, "deploy-set", v.GetStringMapString(common.VPkgDeploySet), lang.CmdPackageDeployFlagSet) diff --git a/src/cmd/internal.go b/src/cmd/internal.go index ec68557f7c..fd5221325c 100644 --- a/src/cmd/internal.go +++ b/src/cmd/internal.go @@ -20,6 +20,7 @@ import ( "github.com/zarf-dev/zarf/src/internal/agent" "github.com/zarf-dev/zarf/src/internal/gitea" "github.com/zarf-dev/zarf/src/pkg/cluster" + "github.com/zarf-dev/zarf/src/pkg/logger" "github.com/zarf-dev/zarf/src/pkg/message" ) @@ -154,11 +155,7 @@ tableOfContents: false return "/commands/" + link[:len(link)-3] + "/" } - if err := doc.GenMarkdownTreeCustom(rootCmd, "./site/src/content/docs/commands", prependTitle, linkHandler); err != nil { - return err - } - message.Success(lang.CmdInternalGenerateCliDocsSuccess) - return nil + return doc.GenMarkdownTreeCustom(rootCmd, "./site/src/content/docs/commands", prependTitle, linkHandler) }, } @@ -273,6 +270,7 @@ var updateGiteaPVC = &cobra.Command{ helmShouldCreate, err := c.UpdateGiteaPVC(ctx, pvcName, rollback) if err != nil { message.WarnErr(err, lang.CmdInternalUpdateGiteaPVCErr) + logger.From(ctx).Warn("Unable to update the existing Gitea persistent volume claim", "error", err.Error()) } fmt.Print(helmShouldCreate) return nil @@ -324,7 +322,7 @@ func addHiddenDummyFlag(cmd *cobra.Command, flagDummy string) { cmd.PersistentFlags().StringVar(&dummyStr, flagDummy, "", "") err := cmd.PersistentFlags().MarkHidden(flagDummy) if err != nil { - message.Debug("Unable to add hidden dummy flag", "error", err) + logger.From(cmd.Context()).Debug("Unable to add hidden dummy flag", "error", err) } } } diff --git a/src/cmd/package.go b/src/cmd/package.go index c0d441a0f0..5ab1f4e2b9 100644 --- a/src/cmd/package.go +++ b/src/cmd/package.go @@ -49,7 +49,8 @@ var packageCreateCmd = &cobra.Command{ Short: lang.CmdPackageCreateShort, Long: lang.CmdPackageCreateLong, RunE: func(cmd *cobra.Command, args []string) error { - l := logger.From(cmd.Context()) + ctx := cmd.Context() + l := logger.From(ctx) pkgConfig.CreateOpts.BaseDir = setBaseDirectory(args) var isCleanPathRegex = regexp.MustCompile(`^[a-zA-Z0-9\_\-\/\.\~\\:]+$`) @@ -65,19 +66,19 @@ var packageCreateCmd = &cobra.Command{ v.GetStringMapString(common.VPkgCreateSet), pkgConfig.CreateOpts.SetVariables, strings.ToUpper) pkgClient, err := packager.New(&pkgConfig, - packager.WithContext(cmd.Context()), + packager.WithContext(ctx), ) if err != nil { return err } defer pkgClient.ClearTempPaths() - err = pkgClient.Create(cmd.Context()) + err = pkgClient.Create(ctx) // NOTE(mkcp): LintErrors are rendered with a table var lintErr *lint.LintError if errors.As(err, &lintErr) { - common.PrintFindings(lintErr) + common.PrintFindings(ctx, lintErr) } if err != nil { return fmt.Errorf("failed to create package: %w", err) @@ -99,7 +100,8 @@ var packageDeployCmd = &cobra.Command{ } }, RunE: func(cmd *cobra.Command, args []string) error { - packageSource, err := choosePackage(args) + ctx := cmd.Context() + packageSource, err := choosePackage(ctx, args) if err != nil { return err } @@ -115,8 +117,6 @@ var packageDeployCmd = &cobra.Command{ } defer pkgClient.ClearTempPaths() - ctx := cmd.Context() - if err := pkgClient.Deploy(ctx); err != nil { return fmt.Errorf("failed to deploy package: %w", err) } @@ -138,6 +138,7 @@ var packageMirrorCmd = &cobra.Command{ } }, RunE: func(cmd *cobra.Command, args []string) (err error) { + ctx := cmd.Context() var c *cluster.Cluster if dns.IsServiceURL(pkgConfig.InitOpts.RegistryInfo.Address) || dns.IsServiceURL(pkgConfig.InitOpts.GitServer.Address) { var err error @@ -146,7 +147,7 @@ var packageMirrorCmd = &cobra.Command{ return err } } - src, err := choosePackage(args) + src, err := choosePackage(ctx, args) if err != nil { return err } @@ -180,7 +181,7 @@ var packageMirrorCmd = &cobra.Command{ NoImageChecksum: pkgConfig.MirrorOpts.NoImgChecksum, Retries: pkgConfig.PkgOpts.Retries, } - err = packager2.Mirror(cmd.Context(), mirrorOpt) + err = packager2.Mirror(ctx, mirrorOpt) if err != nil { return err } @@ -201,8 +202,9 @@ var packageInspectCmd = &cobra.Command{ } }, RunE: func(cmd *cobra.Command, args []string) error { + ctx := cmd.Context() // NOTE(mkcp): Gets user input with message - src, err := choosePackage(args) + src, err := choosePackage(ctx, args) if err != nil { return err } @@ -219,7 +221,7 @@ var packageInspectCmd = &cobra.Command{ } if pkgConfig.InspectOpts.ListImages { - output, err := packager2.InspectList(cmd.Context(), inspectOpt) + output, err := packager2.InspectList(ctx, inspectOpt) if err != nil { return fmt.Errorf("failed to inspect package: %w", err) } @@ -231,7 +233,7 @@ var packageInspectCmd = &cobra.Command{ } } - output, err := packager2.Inspect(cmd.Context(), inspectOpt) + output, err := packager2.Inspect(ctx, inspectOpt) if err != nil { return fmt.Errorf("failed to inspect package: %w", err) } @@ -306,7 +308,8 @@ var packageRemoveCmd = &cobra.Command{ } }, RunE: func(cmd *cobra.Command, args []string) error { - packageSource, err := choosePackage(args) + ctx := cmd.Context() + packageSource, err := choosePackage(ctx, args) if err != nil { return err } @@ -322,7 +325,7 @@ var packageRemoveCmd = &cobra.Command{ SkipSignatureValidation: pkgConfig.PkgOpts.SkipSignatureValidation, PublicKeyPath: pkgConfig.PkgOpts.PublicKeyPath, } - err = packager2.Remove(cmd.Context(), removeOpt) + err = packager2.Remove(ctx, removeOpt) if err != nil { return err } @@ -400,10 +403,11 @@ var packagePullCmd = &cobra.Command{ }, } -func choosePackage(args []string) (string, error) { +func choosePackage(ctx context.Context, args []string) (string, error) { if len(args) > 0 { return args[0], nil } + l := logger.From(ctx) var path string prompt := &survey.Input{ Message: lang.CmdPackageChoose, @@ -411,19 +415,19 @@ func choosePackage(args []string) (string, error) { tarPath := config.ZarfPackagePrefix + toComplete + "*.tar" files, err := filepath.Glob(tarPath) if err != nil { - message.Debug("Unable to glob", "tarPath", tarPath, "error", err) + l.Debug("unable to glob", "tarPath", tarPath, "error", err) } zstPath := config.ZarfPackagePrefix + toComplete + "*.tar.zst" zstFiles, err := filepath.Glob(zstPath) if err != nil { - message.Debug("Unable to glob", "zstPath", zstPath, "error", err) + l.Debug("unable to glob", "zstPath", zstPath, "error", err) } splitPath := config.ZarfPackagePrefix + toComplete + "*.part000" splitFiles, err := filepath.Glob(splitPath) if err != nil { - message.Debug("Unable to glob", "splitPath", splitPath, "error", err) + l.Debug("unable to glob", "splitPath", splitPath, "error", err) } files = append(files, zstFiles...) @@ -452,6 +456,7 @@ func getPackageCompletionArgs(cmd *cobra.Command, _ []string, _ string) ([]strin deployedZarfPackages, err := c.GetDeployedZarfPackages(ctx) if err != nil { message.Debug("Unable to get deployed zarf packages for package completion args", "error", err) + logger.From(cmd.Context()).Debug("unable to get deployed zarf packages for package completion args", "error", err) } // Populate list of package names for _, pkg := range deployedZarfPackages { @@ -523,15 +528,15 @@ func bindCreateFlags(v *viper.Viper) { errOD := createFlags.MarkHidden("output-directory") if errOD != nil { - message.Debug("Unable to mark flag output-directory", "error", errOD) + logger.Default().Debug("unable to mark flag output-directory", "error", errOD) } errKey := createFlags.MarkHidden("key") if errKey != nil { - message.Debug("Unable to mark flag key", "error", errKey) + logger.Default().Debug("unable to mark flag key", "error", errKey) } errKP := createFlags.MarkHidden("key-pass") if errKP != nil { - message.Debug("Unable to mark flag key-pass", "error", errKP) + logger.Default().Debug("unable to mark flag key-pass", "error", errKP) } } @@ -554,7 +559,7 @@ func bindDeployFlags(v *viper.Viper) { err := deployFlags.MarkHidden("sget") if err != nil { - message.Debug("Unable to mark flag sget", "error", err) + logger.Default().Debug("unable to mark flag sget", "error", err) } } diff --git a/src/internal/git/repository.go b/src/internal/git/repository.go index be0215044b..95f6bade0a 100644 --- a/src/internal/git/repository.go +++ b/src/internal/git/repository.go @@ -52,6 +52,7 @@ func Open(rootPath, address string) (*Repository, error) { // Clone clones a git repository to the given local path. func Clone(ctx context.Context, rootPath, address string, shallow bool) (*Repository, error) { + l := logger.From(ctx) // Split the remote url and the zarf reference gitURLNoRef, refPlain, err := transform.GitURLSplitRef(address) if err != nil { @@ -97,6 +98,7 @@ func Clone(ctx context.Context, rootPath, address string, shallow bool) (*Reposi repo, err := git.PlainCloneContext(ctx, r.path, false, cloneOpts) if err != nil { message.Notef("Falling back to host 'git', failed to clone the repo %q with Zarf: %s", gitURLNoRef, err.Error()) + l.Info("falling back to host 'git', failed to clone the repo with Zarf", "url", gitURLNoRef, "error", err) err := r.gitCloneFallback(ctx, gitURLNoRef, ref, shallow) if err != nil { return nil, err diff --git a/src/internal/packager/helm/chart.go b/src/internal/packager/helm/chart.go index e000045650..56fb5e59a0 100644 --- a/src/internal/packager/helm/chart.go +++ b/src/internal/packager/helm/chart.go @@ -162,8 +162,10 @@ 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) { + l := logger.From(ctx) spinner := message.NewProgressSpinner("Templating helm chart %s", h.chart.Name) defer spinner.Stop() + l.Debug("templating helm chart", "name", h.chart.Name) err = h.createActionConfig(ctx, h.chart.Namespace, spinner) @@ -240,9 +242,9 @@ func (h *Helm) RemoveChart(ctx context.Context, namespace string, name string, s // 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(ctx context.Context, updatedValues map[string]interface{}) error { + l := logger.From(ctx) spinner := message.NewProgressSpinner("Updating values for helm release %s", h.chart.ReleaseName) defer spinner.Stop() - l := logger.From(ctx) l.Debug("updating values for helm release", "name", h.chart.ReleaseName) err := h.createActionConfig(ctx, h.chart.Namespace, spinner) @@ -330,7 +332,7 @@ func (h *Helm) installChart(ctx context.Context, postRender *renderer) (*release func (h *Helm) upgradeChart(ctx context.Context, lastRelease *release.Release, postRender *renderer) (*release.Release, error) { // Migrate any deprecated APIs (if applicable) - err := h.migrateDeprecatedAPIs(lastRelease) + err := h.migrateDeprecatedAPIs(ctx, lastRelease) if err != nil { return nil, fmt.Errorf("unable to check for API deprecations: %w", err) } @@ -411,7 +413,7 @@ func (h *Helm) loadChartData() (*chart.Chart, chartutil.Values, error) { return loadedChart, chartValues, nil } -func (h *Helm) migrateDeprecatedAPIs(latestRelease *release.Release) error { +func (h *Helm) migrateDeprecatedAPIs(ctx context.Context, latestRelease *release.Release) error { // Get the Kubernetes version from the current cluster kubeVersion, err := h.cluster.Clientset.Discovery().ServerVersion() if err != nil { @@ -458,6 +460,7 @@ func (h *Helm) migrateDeprecatedAPIs(latestRelease *release.Release) error { // If the release was modified in the above loop, save it back to the cluster if modified { message.Warnf("Zarf detected deprecated APIs for the '%s' helm release. Attempting automatic upgrade.", latestRelease.Name) + logger.From(ctx).Warn("detected deprecated APIs for the helm release", "name", latestRelease.Name) // Update current release version to be superseded (same as the helm mapkubeapis plugin) latestRelease.Info.Status = release.StatusSuperseded diff --git a/src/internal/packager/helm/repo.go b/src/internal/packager/helm/repo.go index 7791771282..42991809dc 100644 --- a/src/internal/packager/helm/repo.go +++ b/src/internal/packager/helm/repo.go @@ -8,13 +8,14 @@ import ( "context" "errors" "fmt" - "github.com/zarf-dev/zarf/src/pkg/logger" "log/slog" "os" "path/filepath" "strings" "time" + "github.com/zarf-dev/zarf/src/pkg/logger" + "github.com/defenseunicorns/pkg/helpers/v2" "helm.sh/helm/v3/pkg/action" "helm.sh/helm/v3/pkg/chart" diff --git a/src/internal/packager/helm/zarf.go b/src/internal/packager/helm/zarf.go index 4783f6557e..76ac55c90c 100644 --- a/src/internal/packager/helm/zarf.go +++ b/src/internal/packager/helm/zarf.go @@ -19,6 +19,7 @@ import ( "github.com/zarf-dev/zarf/src/internal/healthchecks" "github.com/zarf-dev/zarf/src/internal/packager/template" "github.com/zarf-dev/zarf/src/pkg/cluster" + "github.com/zarf-dev/zarf/src/pkg/logger" "github.com/zarf-dev/zarf/src/pkg/message" "github.com/zarf-dev/zarf/src/pkg/transform" "github.com/zarf-dev/zarf/src/pkg/utils" @@ -69,6 +70,7 @@ func (h *Helm) UpdateZarfRegistryValues(ctx context.Context) error { // UpdateZarfAgentValues updates the Zarf agent deployment with the new state values func (h *Helm) UpdateZarfAgentValues(ctx context.Context) error { + l := logger.From(ctx) spinner := message.NewProgressSpinner("Gathering information to update Zarf Agent TLS") defer spinner.Stop() @@ -128,6 +130,7 @@ func (h *Helm) UpdateZarfAgentValues(ctx context.Context) error { // https://kubernetes.io/docs/concepts/workloads/controllers/deployment/#updating-a-deployment spinner = message.NewProgressSpinner("Performing a rolling update for the Zarf Agent deployment") defer spinner.Stop() + l.Info("performing a rolling update for the Zarf Agent deployment") // Re-fetch the agent deployment before we update since the resourceVersion has changed after updating the Helm release values. // Avoids this error: https://github.com/kubernetes/kubernetes/issues/28149 diff --git a/src/internal/packager/template/template.go b/src/internal/packager/template/template.go index b673f25a6c..37de2bc444 100644 --- a/src/internal/packager/template/template.go +++ b/src/internal/packager/template/template.go @@ -34,7 +34,7 @@ func GetZarfVariableConfig(ctx context.Context) *variables.VariableConfig { if config.CommonOptions.Confirm { return variable.Default, nil } - return interactive.PromptVariable(variable) + return interactive.PromptVariable(ctx, variable) } if logger.Enabled(ctx) { diff --git a/src/pkg/cluster/injector.go b/src/pkg/cluster/injector.go index b459299460..400b798c1e 100644 --- a/src/pkg/cluster/injector.go +++ b/src/pkg/cluster/injector.go @@ -184,6 +184,7 @@ func (c *Cluster) StopInjection(ctx context.Context) error { } func (c *Cluster) createPayloadConfigMaps(ctx context.Context, spinner *message.Spinner, tmpDir, imagesDir string, injectorSeedSrcs []string) ([]string, string, error) { + l := logger.From(ctx) tarPath := filepath.Join(tmpDir, "payload.tar.gz") seedImagesDir := filepath.Join(tmpDir, "seed-images") if err := helpers.CreateDirectory(seedImagesDir, helpers.ReadWriteExecuteUser); err != nil { @@ -228,6 +229,7 @@ func (c *Cluster) createPayloadConfigMaps(ctx context.Context, spinner *message. } cmNames := []string{} + l.Info("adding archived binary configmaps of registry image to the cluster") for i, data := range chunks { fileName := fmt.Sprintf("zarf-payload-%03d", i) diff --git a/src/pkg/cluster/secrets.go b/src/pkg/cluster/secrets.go index 5cfaf30880..6cd716ece2 100644 --- a/src/pkg/cluster/secrets.go +++ b/src/pkg/cluster/secrets.go @@ -177,6 +177,7 @@ func (c *Cluster) GetServiceInfoFromRegistryAddress(ctx context.Context, stateRe svc, port, err := serviceInfoFromNodePortURL(serviceList.Items, stateRegistryAddress) if err != nil { message.Debugf("registry appears to not be a nodeport service, using original address %q", stateRegistryAddress) + logger.From(ctx).Debug("registry appears to not be a nodeport service, using original address", "address", stateRegistryAddress) return stateRegistryAddress, nil } diff --git a/src/pkg/interactive/components.go b/src/pkg/interactive/components.go index 9b5cee436c..ee5764126c 100644 --- a/src/pkg/interactive/components.go +++ b/src/pkg/interactive/components.go @@ -25,6 +25,7 @@ func SelectOptionalComponent(component v1alpha1.ZarfComponent) (bool, error) { return false, err } if component.Description != "" { + // TODO (@austinabro321) once we move interactiveness to CLI level we should replace this with logger.Info message.Question(component.Description) } diff --git a/src/pkg/interactive/prompt.go b/src/pkg/interactive/prompt.go index b6b6e69c94..d362291352 100644 --- a/src/pkg/interactive/prompt.go +++ b/src/pkg/interactive/prompt.go @@ -5,10 +5,12 @@ package interactive import ( + "context" "fmt" "github.com/AlecAivazis/survey/v2" "github.com/zarf-dev/zarf/src/api/v1alpha1" + "github.com/zarf-dev/zarf/src/pkg/logger" "github.com/zarf-dev/zarf/src/pkg/message" ) @@ -27,9 +29,10 @@ func PromptSigPassword() ([]byte, error) { } // PromptVariable prompts the user for a value for a variable -func PromptVariable(variable v1alpha1.InteractiveVariable) (string, error) { +func PromptVariable(ctx context.Context, variable v1alpha1.InteractiveVariable) (string, error) { if variable.Description != "" { message.Question(variable.Description) + logger.From(ctx).Info(variable.Description) } prompt := &survey.Input{ diff --git a/src/pkg/layout/package.go b/src/pkg/layout/package.go index 2141de586f..0bb4009f4e 100644 --- a/src/pkg/layout/package.go +++ b/src/pkg/layout/package.go @@ -261,7 +261,7 @@ func (pp *PackagePaths) ArchivePackage(ctx context.Context, destinationTarball s } message.Notef("Package is larger than %dMB, splitting into multiple files", maxPackageSizeMB) l.Info("package is larger than max, splitting into multiple files", "maxPackageSize", maxPackageSizeMB) - err := splitFile(destinationTarball, chunkSize) + err := splitFile(ctx, destinationTarball, chunkSize) if err != nil { return fmt.Errorf("unable to split the package archive into multiple files: %w", err) } diff --git a/src/pkg/layout/split.go b/src/pkg/layout/split.go index 3354a66038..2a245b2477 100644 --- a/src/pkg/layout/split.go +++ b/src/pkg/layout/split.go @@ -5,6 +5,7 @@ package layout import ( + "context" "crypto/sha256" "encoding/json" "errors" @@ -13,12 +14,13 @@ import ( "os" "github.com/defenseunicorns/pkg/helpers/v2" + "github.com/zarf-dev/zarf/src/pkg/logger" "github.com/zarf-dev/zarf/src/pkg/message" "github.com/zarf-dev/zarf/src/types" ) // splitFile will split the file into chunks and remove the original file. -func splitFile(srcPath string, chunkSize int) (err error) { +func splitFile(ctx context.Context, srcPath string, chunkSize int) (err error) { srcFile, err := os.Open(srcPath) if err != nil { return err @@ -125,6 +127,6 @@ func splitFile(srcPath string, chunkSize int) (err error) { return fmt.Errorf("unable to write the file %s: %w", path, err) } progressBar.Successf("Package split across %d files", fileCount+1) - + logger.From(ctx).Info("package split across multiple files", "count", fileCount+1) return nil } diff --git a/src/pkg/layout/split_test.go b/src/pkg/layout/split_test.go index 51866374ec..051ef0a6a4 100644 --- a/src/pkg/layout/split_test.go +++ b/src/pkg/layout/split_test.go @@ -4,6 +4,7 @@ package layout import ( + "context" "encoding/json" "fmt" "os" @@ -64,7 +65,7 @@ func TestSplitFile(t *testing.T) { err = f.Close() require.NoError(t, err) - err = splitFile(p, tt.chunkSize) + err = splitFile(context.Background(), p, tt.chunkSize) require.NoError(t, err) _, err = os.Stat(p) diff --git a/src/pkg/packager/common.go b/src/pkg/packager/common.go index f74a9d68c2..333c707a3e 100644 --- a/src/pkg/packager/common.go +++ b/src/pkg/packager/common.go @@ -181,6 +181,7 @@ func (p *Packager) attemptClusterChecks(ctx context.Context) error { if err := p.validatePackageArchitecture(ctx); err != nil { if errors.Is(err, lang.ErrUnableToCheckArch) { message.Warnf("Unable to validate package architecture: %s", err.Error()) + logger.From(ctx).Warn("unable to validate package architecture", "error", err) } else { return err } diff --git a/src/pkg/packager/create.go b/src/pkg/packager/create.go index 125dd002d3..fcc04478e7 100755 --- a/src/pkg/packager/create.go +++ b/src/pkg/packager/create.go @@ -66,7 +66,7 @@ func (p *Packager) Create(ctx context.Context) error { ) // TODO(mkcp): Remove interactive on logger release - if !p.confirmAction(config.ZarfCreateStage, warnings, nil) { + if !p.confirmAction(ctx, config.ZarfCreateStage, warnings, nil) { return fmt.Errorf("package creation canceled") } diff --git a/src/pkg/packager/creator/normal.go b/src/pkg/packager/creator/normal.go index a844e18c9a..31952d2479 100644 --- a/src/pkg/packager/creator/normal.go +++ b/src/pkg/packager/creator/normal.go @@ -82,7 +82,7 @@ func (pc *PackageCreator) LoadPackageDefinition(ctx context.Context, src *layout warnings = append(warnings, composeWarnings...) // After components are composed, template the active package. - pkg, templateWarnings, err := FillActiveTemplate(pkg, pc.createOpts.SetVariables) + pkg, templateWarnings, err := FillActiveTemplate(ctx, pkg, pc.createOpts.SetVariables) if err != nil { return v1alpha1.ZarfPackage{}, nil, fmt.Errorf("unable to fill values in template: %w", err) } diff --git a/src/pkg/packager/creator/skeleton.go b/src/pkg/packager/creator/skeleton.go index 9792230f0b..70db6e94db 100644 --- a/src/pkg/packager/creator/skeleton.go +++ b/src/pkg/packager/creator/skeleton.go @@ -20,6 +20,7 @@ import ( "github.com/zarf-dev/zarf/src/internal/packager/helm" "github.com/zarf-dev/zarf/src/internal/packager/kustomize" "github.com/zarf-dev/zarf/src/pkg/layout" + "github.com/zarf-dev/zarf/src/pkg/logger" "github.com/zarf-dev/zarf/src/pkg/message" "github.com/zarf-dev/zarf/src/pkg/utils" "github.com/zarf-dev/zarf/src/pkg/zoci" @@ -75,9 +76,9 @@ func (sc *SkeletonCreator) LoadPackageDefinition(ctx context.Context, src *layou // Assemble updates all components of the loaded Zarf package with necessary modifications for package assembly. // // It processes each component to ensure correct structure and resource locations. -func (sc *SkeletonCreator) Assemble(_ context.Context, dst *layout.PackagePaths, components []v1alpha1.ZarfComponent, _ string) error { +func (sc *SkeletonCreator) Assemble(ctx context.Context, dst *layout.PackagePaths, components []v1alpha1.ZarfComponent, _ string) error { for _, component := range components { - c, err := sc.addComponent(component, dst) + c, err := sc.addComponent(ctx, component, dst) if err != nil { return err } @@ -120,8 +121,10 @@ func (sc *SkeletonCreator) Output(ctx context.Context, dst *layout.PackagePaths, return dst.SignPackage(sc.publishOpts.SigningKeyPath, sc.publishOpts.SigningKeyPassword, !config.CommonOptions.Confirm) } -func (sc *SkeletonCreator) addComponent(component v1alpha1.ZarfComponent, dst *layout.PackagePaths) (updatedComponent *v1alpha1.ZarfComponent, err error) { +func (sc *SkeletonCreator) addComponent(ctx context.Context, component v1alpha1.ZarfComponent, dst *layout.PackagePaths) (updatedComponent *v1alpha1.ZarfComponent, err error) { + l := logger.From(ctx) message.HeaderInfof("📦 %s COMPONENT", strings.ToUpper(component.Name)) + logger.From(ctx).Info("processing component", "name", component.Name) updatedComponent = &component @@ -235,6 +238,7 @@ func (sc *SkeletonCreator) addComponent(component v1alpha1.ZarfComponent, dst *l for dataIdx, data := range component.DataInjections { spinner.Updatef("Copying data injection %s for %s", data.Target.Path, data.Target.Selector) + l.Debug("copying data injection", "source", data.Source, "target", data.Target.Path) rel := filepath.Join(layout.DataInjectionsDir, strconv.Itoa(dataIdx), filepath.Base(data.Target.Path)) dst := filepath.Join(componentPaths.Base, rel) @@ -269,6 +273,8 @@ func (sc *SkeletonCreator) addComponent(component v1alpha1.ZarfComponent, dst *l // Copy manifests without any processing. spinner.Updatef("Copying manifest %s", path) + l.Debug("copying manifest", "path", path) + if err := helpers.CreatePathAndCopy(path, dst); err != nil { return nil, fmt.Errorf("unable to copy manifest %s: %w", path, err) @@ -280,6 +286,7 @@ func (sc *SkeletonCreator) addComponent(component v1alpha1.ZarfComponent, dst *l for kustomizeIdx, path := range manifest.Kustomizations { // Generate manifests from kustomizations and place in the package. spinner.Updatef("Building kustomization for %s", path) + l.Debug("building kustomization", "path", path) kname := fmt.Sprintf("kustomization-%s-%d.yaml", manifest.Name, kustomizeIdx) rel := filepath.Join(layout.ManifestsDir, kname) diff --git a/src/pkg/packager/creator/template.go b/src/pkg/packager/creator/template.go index 1c5037302f..0d9a1e0246 100644 --- a/src/pkg/packager/creator/template.go +++ b/src/pkg/packager/creator/template.go @@ -5,6 +5,7 @@ package creator import ( + "context" "fmt" "github.com/zarf-dev/zarf/src/api/v1alpha1" @@ -15,7 +16,7 @@ import ( ) // FillActiveTemplate merges user-specified variables into the configuration templates of a zarf.yaml. -func FillActiveTemplate(pkg v1alpha1.ZarfPackage, setVariables map[string]string) (v1alpha1.ZarfPackage, []string, error) { +func FillActiveTemplate(ctx context.Context, pkg v1alpha1.ZarfPackage, setVariables map[string]string) (v1alpha1.ZarfPackage, []string, error) { templateMap := map[string]string{} warnings := []string{} @@ -32,7 +33,7 @@ func FillActiveTemplate(pkg v1alpha1.ZarfPackage, setVariables map[string]string _, present := setVariables[key] if !present && !config.CommonOptions.Confirm { - setVal, err := interactive.PromptVariable(v1alpha1.InteractiveVariable{ + setVal, err := interactive.PromptVariable(ctx, v1alpha1.InteractiveVariable{ Variable: v1alpha1.Variable{Name: key}, }) if err != nil { diff --git a/src/pkg/packager/deploy.go b/src/pkg/packager/deploy.go index 703bdc97ae..c2f7f0b58b 100644 --- a/src/pkg/packager/deploy.go +++ b/src/pkg/packager/deploy.go @@ -108,7 +108,7 @@ func (p *Packager) Deploy(ctx context.Context) error { } // Confirm the overall package deployment - if !p.confirmAction(config.ZarfDeployStage, warnings, sbomViewFiles) { + if !p.confirmAction(ctx, config.ZarfDeployStage, warnings, sbomViewFiles) { return fmt.Errorf("deployment cancelled") } diff --git a/src/pkg/packager/interactive.go b/src/pkg/packager/interactive.go index bc29c8e0f8..7b862ce6f2 100644 --- a/src/pkg/packager/interactive.go +++ b/src/pkg/packager/interactive.go @@ -5,6 +5,7 @@ package packager import ( + "context" "fmt" "os" "path/filepath" @@ -14,11 +15,12 @@ import ( "github.com/pterm/pterm" "github.com/zarf-dev/zarf/src/config" "github.com/zarf-dev/zarf/src/pkg/layout" + "github.com/zarf-dev/zarf/src/pkg/logger" "github.com/zarf-dev/zarf/src/pkg/message" "github.com/zarf-dev/zarf/src/pkg/utils" ) -func (p *Packager) confirmAction(stage string, warnings []string, sbomViewFiles []string) bool { +func (p *Packager) confirmAction(ctx context.Context, stage string, warnings []string, sbomViewFiles []string) bool { pterm.Println() message.HeaderInfof("📦 PACKAGE DEFINITION") err := utils.ColorPrintYAML(p.cfg.Pkg, p.getPackageYAMLHints(stage), true) @@ -50,6 +52,7 @@ func (p *Packager) confirmAction(stage string, warnings []string, sbomViewFiles message.Note(msg) pterm.Println(viewNow) pterm.Println(viewLater) + logger.From(ctx).Info("this package has SBOMs available for review in a temporary directory", "directory", filepath.Join(cwd, layout.SBOMDir)) } else { message.Warn("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.") } diff --git a/src/pkg/packager/mirror.go b/src/pkg/packager/mirror.go index 9e61604144..f715421e6a 100644 --- a/src/pkg/packager/mirror.go +++ b/src/pkg/packager/mirror.go @@ -37,7 +37,7 @@ func (p *Packager) Mirror(ctx context.Context) error { warnings = append(warnings, sbomWarnings...) // Confirm the overall package mirror - if !p.confirmAction(config.ZarfMirrorStage, warnings, sbomViewFiles) { + if !p.confirmAction(ctx, config.ZarfMirrorStage, warnings, sbomViewFiles) { return fmt.Errorf("mirror cancelled") } diff --git a/src/pkg/packager/sources/oci.go b/src/pkg/packager/sources/oci.go index b86d3797d3..6d8b809f74 100644 --- a/src/pkg/packager/sources/oci.go +++ b/src/pkg/packager/sources/oci.go @@ -16,6 +16,7 @@ import ( "github.com/zarf-dev/zarf/src/api/v1alpha1" "github.com/zarf-dev/zarf/src/config" "github.com/zarf-dev/zarf/src/pkg/layout" + "github.com/zarf-dev/zarf/src/pkg/logger" "github.com/zarf-dev/zarf/src/pkg/message" "github.com/zarf-dev/zarf/src/pkg/packager/filters" "github.com/zarf-dev/zarf/src/pkg/utils" @@ -147,6 +148,7 @@ func (s *OCISource) LoadPackageMetadata(ctx context.Context, dst *layout.Package if err := ValidatePackageSignature(ctx, dst, s.PublicKeyPath); err != nil { if errors.Is(err, ErrPkgSigButNoKey) && skipValidation { message.Warn("The package was signed but no public key was provided, skipping signature validation") + logger.From(ctx).Warn("the package was signed but no public key was provided, skipping signature validation") } else { return pkg, nil, err } @@ -187,6 +189,7 @@ func (s *OCISource) Collect(ctx context.Context, dir string) (string, error) { spinner := message.NewProgressSpinner("Validating full package checksums") defer spinner.Stop() + logger.From(ctx).Debug("validating full package checksums") if err := ValidatePackageIntegrity(loaded, pkg.Metadata.AggregateChecksum, false); err != nil { return "", err diff --git a/src/pkg/packager/sources/split.go b/src/pkg/packager/sources/split.go index f4f97a25a6..56873ee002 100644 --- a/src/pkg/packager/sources/split.go +++ b/src/pkg/packager/sources/split.go @@ -17,6 +17,7 @@ import ( "github.com/defenseunicorns/pkg/helpers/v2" "github.com/zarf-dev/zarf/src/api/v1alpha1" "github.com/zarf-dev/zarf/src/pkg/layout" + "github.com/zarf-dev/zarf/src/pkg/logger" "github.com/zarf-dev/zarf/src/pkg/message" "github.com/zarf-dev/zarf/src/pkg/packager/filters" "github.com/zarf-dev/zarf/src/types" @@ -33,7 +34,7 @@ type SplitTarballSource struct { } // Collect turns a split tarball into a full tarball. -func (s *SplitTarballSource) Collect(_ context.Context, dir string) (string, error) { +func (s *SplitTarballSource) Collect(ctx context.Context, dir string) (string, error) { pattern := strings.Replace(s.PackageSource, ".part000", ".part*", 1) fileList, err := filepath.Glob(pattern) if err != nil { @@ -104,8 +105,8 @@ func (s *SplitTarballSource) Collect(_ context.Context, dir string) (string, err _ = os.Remove(file) } - // communicate to the user that the package was reassembled message.Infof("Reassembled package to: %q", reassembled) + logger.From(ctx).Info("Reassembled package", "path", reassembled) return reassembled, nil } diff --git a/src/pkg/packager/sources/tarball.go b/src/pkg/packager/sources/tarball.go index b7a00dc159..73ef522c82 100644 --- a/src/pkg/packager/sources/tarball.go +++ b/src/pkg/packager/sources/tarball.go @@ -199,6 +199,7 @@ func (s *TarballSource) LoadPackageMetadata(ctx context.Context, dst *layout.Pac if err := ValidatePackageSignature(ctx, dst, s.PublicKeyPath); err != nil { if errors.Is(err, ErrPkgSigButNoKey) && skipValidation { message.Warn("The package was signed but no public key was provided, skipping signature validation") + logger.From(ctx).Warn("the package was signed but no public key was provided, skipping signature validation") } else { return pkg, nil, err } diff --git a/src/pkg/packager/sources/validate.go b/src/pkg/packager/sources/validate.go index baf958a699..bf649a1f71 100644 --- a/src/pkg/packager/sources/validate.go +++ b/src/pkg/packager/sources/validate.go @@ -16,6 +16,7 @@ import ( "github.com/defenseunicorns/pkg/helpers/v2" "github.com/zarf-dev/zarf/src/pkg/layout" + "github.com/zarf-dev/zarf/src/pkg/logger" "github.com/zarf-dev/zarf/src/pkg/message" "github.com/zarf-dev/zarf/src/pkg/utils" ) @@ -31,6 +32,7 @@ var ( func ValidatePackageSignature(ctx context.Context, paths *layout.PackagePaths, publicKeyPath string) error { if publicKeyPath != "" { message.Debugf("Using public key %q for signature validation", publicKeyPath) + logger.From(ctx).Debug("using public key for signature validation", "key", publicKeyPath) } // Handle situations where there is no signature within the package diff --git a/src/pkg/utils/cosign.go b/src/pkg/utils/cosign.go index a06beae49f..80020fa6be 100644 --- a/src/pkg/utils/cosign.go +++ b/src/pkg/utils/cosign.go @@ -30,6 +30,7 @@ import ( _ "github.com/sigstore/sigstore/pkg/signature/kms/hashivault" "github.com/zarf-dev/zarf/src/config/lang" + "github.com/zarf-dev/zarf/src/pkg/logger" "github.com/zarf-dev/zarf/src/pkg/message" ) @@ -192,6 +193,7 @@ func CosignVerifyBlob(ctx context.Context, blobRef, sigRef, keyPath string) erro } message.Successf("Package signature validated!") + logger.From(ctx).Debug("package signature validated", "key", keyPath) return nil }