From 785feeb306c45d0b9289f7c180cd650917f2a2e2 Mon Sep 17 00:00:00 2001 From: Ansible-man <93239366+Ansible-man@users.noreply.github.com> Date: Fri, 1 Nov 2024 12:30:09 -0500 Subject: [PATCH 1/7] feat: make zarf-agent pods comply with offical restricted pod security standard (#3036) Signed-off-by: Cade Thomas Signed-off-by: schristoff <28318173+schristoff@users.noreply.github.com> Signed-off-by: dependabot[bot] Co-authored-by: Cade Thomas Co-authored-by: schristoff <28318173+schristoff@users.noreply.github.com> Co-authored-by: Austin Abro <37223396+AustinAbro321@users.noreply.github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- packages/zarf-agent/manifests/deployment.yaml | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/packages/zarf-agent/manifests/deployment.yaml b/packages/zarf-agent/manifests/deployment.yaml index a8e481845f..61731ada18 100644 --- a/packages/zarf-agent/manifests/deployment.yaml +++ b/packages/zarf-agent/manifests/deployment.yaml @@ -21,6 +21,13 @@ spec: - name: private-registry priorityClassName: system-node-critical serviceAccountName: zarf + # Security context to comply with restricted PSS + securityContext: + runAsUser: 1000 + fsGroup: 2000 + runAsGroup: 2000 + seccompProfile: + type: "RuntimeDefault" containers: - name: server image: "###ZARF_REGISTRY###/###ZARF_CONST_AGENT_IMAGE###:###ZARF_CONST_AGENT_IMAGE_TAG###" @@ -32,6 +39,12 @@ spec: scheme: HTTPS ports: - containerPort: 8443 + securityContext: + readOnlyRootFilesystem: true + allowPrivilegeEscalation: false + runAsNonRoot: true + capabilities: + drop: ["ALL"] resources: requests: memory: "32Mi" From 9a0874ad4bec8fadd8834dc61efd4db2051abf0c Mon Sep 17 00:00:00 2001 From: Philip Laine Date: Sat, 2 Nov 2024 02:08:15 +0100 Subject: [PATCH 2/7] Refactor config e2e test to not depend on CLI output (#3173) Signed-off-by: Philip Laine --- src/test/e2e/29_config_file_test.go | 65 ++++++++--------------------- 1 file changed, 18 insertions(+), 47 deletions(-) diff --git a/src/test/e2e/29_config_file_test.go b/src/test/e2e/29_config_file_test.go index bcef00ad87..f291f76ef0 100644 --- a/src/test/e2e/29_config_file_test.go +++ b/src/test/e2e/29_config_file_test.go @@ -5,59 +5,35 @@ package test import ( + "context" "fmt" - "os" "path/filepath" "testing" "github.com/stretchr/testify/require" -) - -const envKey = "ZARF_CONFIG" - -func TestConfigFile(t *testing.T) { - t.Log("E2E: Config file") - - var ( - path = fmt.Sprintf("zarf-package-config-file-%s.tar.zst", e2e.Arch) - dir = "examples/config-file" - config = "zarf-config.toml" - ) - - e2e.CleanFiles(t, path) - - // Test the config file environment variable - t.Setenv(envKey, filepath.Join(dir, config)) - defer func() { - require.NoError(t, os.Unsetenv(envKey)) - }() - configFileTests(t, dir, path) - configFileDefaultTests(t) - - stdOut, stdErr, err := e2e.Zarf(t, "package", "remove", path, "--confirm") - require.NoError(t, err, stdOut, stdErr) + layout2 "github.com/zarf-dev/zarf/src/internal/packager2/layout" +) - // Cleanup - e2e.CleanFiles(t, path) -} +func TestConfigFileCreate(t *testing.T) { + tmpDir := t.TempDir() + dir := "examples/config-file" -func configFileTests(t *testing.T, dir, path string) { - t.Helper() + t.Setenv("ZARF_CONFIG", filepath.Join(dir, "zarf-config.toml")) - _, stdErr, err := e2e.Zarf(t, "package", "create", dir, "--confirm") + _, _, err := e2e.Zarf(t, "package", "create", dir, "--confirm", "-o", tmpDir) 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(t, "package", "deploy", path, "--confirm") + tarPath := filepath.Join(tmpDir, fmt.Sprintf("zarf-package-config-file-%s.tar.zst", e2e.Arch)) + pkgLayout, err := layout2.LoadFromTar(context.Background(), tarPath, layout2.PackageLayoutOptions{}) + require.NoError(t, err) + require.Equal(t, "This is a zebra and they have stripes", pkgLayout.Pkg.Components[1].Description) + require.Equal(t, "This is a leopard and they have spots", pkgLayout.Pkg.Components[2].Description) + _, err = pkgLayout.GetSBOM(t.TempDir()) require.NoError(t, err) - require.Contains(t, string(stdErr), "📦 LION COMPONENT") - require.NotContains(t, string(stdErr), "📦 LEOPARD COMPONENT") - require.NotContains(t, string(stdErr), "📦 ZEBRA COMPONENT") - // This package does not contain anything SBOMable - require.NotContains(t, string(stdErr), "This package does NOT contain an SBOM.") + _, _, err = e2e.Zarf(t, "package", "deploy", tarPath, "--confirm") + require.NoError(t, err) // Verify the configmap was properly templated kubectlOut, _, err := e2e.Kubectl(t, "-n", "zarf", "get", "configmap", "simple-configmap", "-o", "jsonpath={.data.templateme\\.properties}") @@ -99,9 +75,7 @@ H4RxbE+FpmsMAUCpdrzvFkc= require.Equal(t, tlsKey, kubectlOut) } -func configFileDefaultTests(t *testing.T) { - t.Helper() - +func TestConfigFileDefault(t *testing.T) { globalFlags := []string{ "architecture: 509a38f0", "log_level: 6a845a41", @@ -144,10 +118,7 @@ func configFileDefaultTests(t *testing.T) { } // Test remaining default initializers - t.Setenv(envKey, filepath.Join("src", "test", "zarf-config-test.toml")) - defer func() { - require.NoError(t, os.Unsetenv(envKey)) - }() + t.Setenv("ZARF_CONFIG", filepath.Join("src", "test", "zarf-config-test.toml")) // Test global flags stdOut, _, err := e2e.Zarf(t, "--help") From a2c3ad3e7c66f90283654a31fe6e93e85a0dd3e6 Mon Sep 17 00:00:00 2001 From: Joonas Bergius Date: Mon, 4 Nov 2024 09:56:20 -0700 Subject: [PATCH 3/7] chore: make the nightly tests run only in `zarf-dev/zarf` (#3174) Signed-off-by: Joonas Bergius --- .github/workflows/nightly-ecr.yml | 1 + .github/workflows/nightly-eks.yml | 1 + 2 files changed, 2 insertions(+) diff --git a/.github/workflows/nightly-ecr.yml b/.github/workflows/nightly-ecr.yml index e4fdb3b431..ccd8fa956c 100644 --- a/.github/workflows/nightly-ecr.yml +++ b/.github/workflows/nightly-ecr.yml @@ -16,6 +16,7 @@ permissions: jobs: ecr-nightly-test: + if: ${{ github.repository == 'zarf-dev/zarf' }} runs-on: ubuntu-latest steps: - name: Checkout diff --git a/.github/workflows/nightly-eks.yml b/.github/workflows/nightly-eks.yml index 262e4b00c2..ce4dab24ba 100644 --- a/.github/workflows/nightly-eks.yml +++ b/.github/workflows/nightly-eks.yml @@ -24,6 +24,7 @@ concurrency: jobs: eks-nightly-test: + if: ${{ github.repository == 'zarf-dev/zarf' }} runs-on: ubuntu-latest steps: - name: Checkout From 3b873c8cef737dfdfb3c5ba20de50f68ab05ab47 Mon Sep 17 00:00:00 2001 From: Allen Conlon Date: Mon, 4 Nov 2024 12:23:44 -0500 Subject: [PATCH 4/7] fear: allow versioning of init packages outside of binary version (#3169) Signed-off-by: Allen Conlon --- src/pkg/packager/creator/utils.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pkg/packager/creator/utils.go b/src/pkg/packager/creator/utils.go index 3d5c5ef016..891e80db5a 100644 --- a/src/pkg/packager/creator/utils.go +++ b/src/pkg/packager/creator/utils.go @@ -54,7 +54,7 @@ func recordPackageMetadata(pkg *v1alpha1.ZarfPackage, createOpts types.ZarfCreat hostname, _ := os.Hostname() pkg.Build.Terminal = hostname - if pkg.IsInitConfig() { + if pkg.IsInitConfig() && pkg.Metadata.Version == "" { pkg.Metadata.Version = config.CLIVersion } From 115f4f25f6c4416719adecd80d44bb520d4281a6 Mon Sep 17 00:00:00 2001 From: Austin Abro <37223396+AustinAbro321@users.noreply.github.com> Date: Mon, 4 Nov 2024 13:54:17 -0500 Subject: [PATCH 5/7] chore: slog dev deploy (#3176) Signed-off-by: Austin Abro --- src/pkg/packager/deploy.go | 2 ++ src/pkg/packager/dev.go | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/src/pkg/packager/deploy.go b/src/pkg/packager/deploy.go index 6ecf6cc229..133dba9e8d 100644 --- a/src/pkg/packager/deploy.go +++ b/src/pkg/packager/deploy.go @@ -48,9 +48,11 @@ var ( ) func (p *Packager) resetRegistryHPA(ctx context.Context) { + l := logger.From(ctx) if p.isConnectedToCluster() && p.hpaModified { if err := p.cluster.EnableRegHPAScaleDown(ctx); err != nil { message.Debugf("unable to reenable the registry HPA scale down: %s", err.Error()) + l.Debug("unable to reenable the registry HPA scale down", "error", err.Error()) } } } diff --git a/src/pkg/packager/dev.go b/src/pkg/packager/dev.go index 1985edb655..589eedb5be 100644 --- a/src/pkg/packager/dev.go +++ b/src/pkg/packager/dev.go @@ -9,10 +9,12 @@ import ( "fmt" "os" "runtime" + "time" "github.com/defenseunicorns/pkg/helpers/v2" "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/creator" "github.com/zarf-dev/zarf/src/pkg/packager/filters" @@ -21,6 +23,8 @@ import ( // DevDeploy creates + deploys a package in one shot func (p *Packager) DevDeploy(ctx context.Context) error { + l := logger.From(ctx) + start := time.Now() config.CommonOptions.Confirm = true p.cfg.CreateOpts.SkipSBOM = !p.cfg.CreateOpts.NoYOLO @@ -74,6 +78,7 @@ func (p *Packager) DevDeploy(ctx context.Context) error { } message.HeaderInfof("📦 PACKAGE DEPLOY %s", p.cfg.Pkg.Metadata.Name) + l.Info("starting package deploy", "name", p.cfg.Pkg.Metadata.Name) if !p.cfg.CreateOpts.NoYOLO { p.cfg.Pkg.Metadata.YOLO = true @@ -108,10 +113,12 @@ func (p *Packager) DevDeploy(ctx context.Context) error { } if len(deployedComponents) == 0 { message.Warn("No components were selected for deployment. Inspect the package to view the available components and select components interactively or by name with \"--components\"") + l.Warn("No components were selected for deployment. Inspect the package to view the available components and select components interactively or by name with \"--components\"") } // Notify all the things about the successful deployment message.Successf("Zarf dev deployment complete") + l.Debug("dev deployment complete", "package", p.cfg.Pkg.Metadata.Name, "duration", time.Since(start)) message.HorizontalRule() message.Title("Next steps:", "") From ff4376011f99635a33150a2a1341671564b5bffc Mon Sep 17 00:00:00 2001 From: Austin Abro <37223396+AustinAbro321@users.noreply.github.com> Date: Mon, 4 Nov 2024 14:22:39 -0500 Subject: [PATCH 6/7] chore: slogger for zarf dev generate (#3178) Signed-off-by: Austin Abro --- src/pkg/packager/generate.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/pkg/packager/generate.go b/src/pkg/packager/generate.go index 5d92d56b8d..0f84a8295c 100644 --- a/src/pkg/packager/generate.go +++ b/src/pkg/packager/generate.go @@ -10,6 +10,7 @@ import ( "os" "path/filepath" "strings" + "time" "github.com/defenseunicorns/pkg/helpers/v2" goyaml "github.com/goccy/go-yaml" @@ -17,11 +18,14 @@ import ( "github.com/zarf-dev/zarf/src/config" "github.com/zarf-dev/zarf/src/pkg/layout" "github.com/zarf-dev/zarf/src/pkg/lint" + "github.com/zarf-dev/zarf/src/pkg/logger" "github.com/zarf-dev/zarf/src/pkg/message" ) // Generate generates a Zarf package definition. func (p *Packager) Generate(ctx context.Context) error { + l := logger.From(ctx) + start := time.Now() generatedZarfYAMLPath := filepath.Join(p.cfg.GenerateOpts.Output, layout.ZarfYAML) spinner := message.NewProgressSpinner("Generating package for %q at %s", p.cfg.GenerateOpts.Name, generatedZarfYAMLPath) @@ -29,6 +33,9 @@ func (p *Packager) Generate(ctx context.Context) error { prefixed := filepath.Join(p.cfg.GenerateOpts.Output, fmt.Sprintf("%s-%s", p.cfg.GenerateOpts.Name, layout.ZarfYAML)) message.Warnf("%s already exists, writing to %s", generatedZarfYAMLPath, prefixed) + l.Warn("using a prefixed name since zarf.yaml already exists in the output directory", + "output-directory", p.cfg.GenerateOpts.Output, + "name", prefixed) generatedZarfYAMLPath = prefixed @@ -36,6 +43,7 @@ func (p *Packager) Generate(ctx context.Context) error { return fmt.Errorf("unable to generate package, %s already exists", generatedZarfYAMLPath) } } + l.Info("generating package", "name", p.cfg.GenerateOpts.Name, "path", generatedZarfYAMLPath) generatedComponent := v1alpha1.ZarfComponent{ Name: p.cfg.GenerateOpts.Name, @@ -67,6 +75,7 @@ func (p *Packager) Generate(ctx context.Context) error { if err != nil { // purposefully not returning error here, as we can still generate the package without images message.Warnf("Unable to find images: %s", err.Error()) + l.Error("failed to find images", "error", err.Error()) } for i := range p.cfg.Pkg.Components { @@ -96,6 +105,7 @@ func (p *Packager) Generate(ctx context.Context) error { content = strings.Replace(content, "components:\n", "\ncomponents:\n", 1) spinner.Successf("Generated package for %q at %s", p.cfg.GenerateOpts.Name, generatedZarfYAMLPath) + l.Debug("generated package", "name", p.cfg.GenerateOpts.Name, "path", generatedZarfYAMLPath, "duration", time.Since(start)) return os.WriteFile(generatedZarfYAMLPath, []byte(content), helpers.ReadAllWriteUser) } From 84e69c44ccfa2d216032ca0a115977d7843a9b55 Mon Sep 17 00:00:00 2001 From: Austin Abro <37223396+AustinAbro321@users.noreply.github.com> Date: Tue, 5 Nov 2024 09:00:52 -0500 Subject: [PATCH 7/7] chore: slogger for `zarf init` (#3168) Signed-off-by: Austin Abro --- src/cmd/initialize.go | 18 ++++++++++-------- src/cmd/root.go | 2 -- src/pkg/cluster/injector.go | 9 +++++++++ src/pkg/cluster/state.go | 13 +++++++++++-- src/pkg/logger/logger.go | 37 +++++++++++++++++++++++++++++++++++++ src/pkg/packager/deploy.go | 2 +- src/pkg/zoci/pull.go | 6 ++++-- 7 files changed, 72 insertions(+), 15 deletions(-) diff --git a/src/cmd/initialize.go b/src/cmd/initialize.go index 0543f97749..d2fe5d5d35 100644 --- a/src/cmd/initialize.go +++ b/src/cmd/initialize.go @@ -18,6 +18,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/logger" "github.com/zarf-dev/zarf/src/pkg/message" "github.com/zarf-dev/zarf/src/pkg/packager" "github.com/zarf-dev/zarf/src/pkg/packager/sources" @@ -70,6 +71,9 @@ var initCmd = &cobra.Command{ if err != nil { return err } + // Since the new logger ignores pterm output the credential table is no longer printed on init. + // This note is the intended replacement, rather than printing creds by default. + logger.From(ctx).Info("init complete. To get credentials for Zarf deployed services run `zarf tools get-creds`") return nil }, } @@ -110,28 +114,26 @@ func findInitPackage(ctx context.Context, initPackageName string) (string, error return filepath.Join(absCachePath, initPackageName), nil } + if config.CommonOptions.Confirm { + return "", lang.ErrInitNotFound + } + // Finally, if the init-package doesn't exist in the cache directory, suggest downloading it downloadCacheTarget, err := downloadInitPackage(ctx, absCachePath) if err != nil { - if errors.Is(err, lang.ErrInitNotFound) { - return "", err - } return "", fmt.Errorf("failed to download the init package: %w", err) } return downloadCacheTarget, nil } func downloadInitPackage(ctx context.Context, cacheDirectory string) (string, error) { - if config.CommonOptions.Confirm { - return "", lang.ErrInitNotFound - } - + l := logger.From(ctx) url := zoci.GetInitPackageURL(config.CLIVersion) // Give the user the choice to download the init-package and note that this does require an internet connection message.Question(fmt.Sprintf(lang.CmdInitPullAsk, url)) - message.Note(lang.CmdInitPullNote) + l.Info("the init package was not found locally, but can be pulled in connected environments", "url", fmt.Sprintf("oci://%s", url)) var confirmDownload bool prompt := &survey.Confirm{ diff --git a/src/cmd/root.go b/src/cmd/root.go index 63513c7104..86f01eb1cc 100644 --- a/src/cmd/root.go +++ b/src/cmd/root.go @@ -222,8 +222,6 @@ func setupMessage(cfg messageCfg) error { message.InitializePTerm(io.Discard) // Disable all progress bars and spinners message.NoProgress = true - // Ensures no user input is needed while we maintain backwards compatibility with message - config.CommonOptions.Confirm = true return nil } diff --git a/src/pkg/cluster/injector.go b/src/pkg/cluster/injector.go index 8586934710..ff9aac1fb9 100644 --- a/src/pkg/cluster/injector.go +++ b/src/pkg/cluster/injector.go @@ -27,6 +27,7 @@ import ( "github.com/zarf-dev/zarf/src/config" "github.com/zarf-dev/zarf/src/internal/healthchecks" + "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" @@ -34,6 +35,8 @@ import ( // StartInjection initializes a Zarf injection into the cluster. func (c *Cluster) StartInjection(ctx context.Context, tmpDir, imagesDir string, injectorSeedSrcs []string) error { + l := logger.From(ctx) + start := time.Now() // Stop any previous running injection before starting. err := c.StopInjection(ctx) if err != nil { @@ -42,6 +45,7 @@ func (c *Cluster) StartInjection(ctx context.Context, tmpDir, imagesDir string, spinner := message.NewProgressSpinner("Attempting to bootstrap the seed image into the cluster") defer spinner.Stop() + l.Info("creating Zarf injector resources") resReq := corev1.ResourceRequirements{ Requests: corev1.ResourceList{ @@ -123,11 +127,15 @@ func (c *Cluster) StartInjection(ctx context.Context, tmpDir, imagesDir string, } spinner.Success() + l.Debug("done with injection", "duration", time.Since(start)) return nil } // StopInjection handles cleanup once the seed registry is up. func (c *Cluster) StopInjection(ctx context.Context) error { + start := time.Now() + l := logger.From(ctx) + l.Debug("deleting injector resources") err := c.Clientset.CoreV1().Pods(ZarfNamespaceName).Delete(ctx, "injector", metav1.DeleteOptions{}) if err != nil && !kerrors.IsNotFound(err) { return err @@ -183,6 +191,7 @@ func (c *Cluster) StopInjection(ctx context.Context) error { if err != nil { return err } + l.Debug("done deleting injector resources", "duration", time.Since(start)) return nil } diff --git a/src/pkg/cluster/state.go b/src/pkg/cluster/state.go index 0ad4dac449..82ba76b28e 100644 --- a/src/pkg/cluster/state.go +++ b/src/pkg/cluster/state.go @@ -37,12 +37,14 @@ const ( // InitZarfState initializes the Zarf state with the given temporary directory and init configs. func (c *Cluster) InitZarfState(ctx context.Context, initOptions types.ZarfInitOptions) error { + l := logger.From(ctx) spinner := message.NewProgressSpinner("Gathering cluster state information") defer spinner.Stop() // Attempt to load an existing state prior to init. // NOTE: We are ignoring the error here because we don't really expect a state to exist yet. spinner.Updatef("Checking cluster for existing Zarf deployment") + l.Debug("checking cluster for existing Zarf deployment") state, err := c.LoadZarfState(ctx) if err != nil && !kerrors.IsNotFound(err) { return fmt.Errorf("failed to check for existing state: %w", err) @@ -52,7 +54,7 @@ func (c *Cluster) InitZarfState(ctx context.Context, initOptions types.ZarfInitO if state == nil { state = &types.ZarfState{} spinner.Updatef("New cluster, no prior Zarf deployments found") - + l.Debug("new cluster, no prior Zarf deployments found") if initOptions.ApplianceMode { // If the K3s component is being deployed, skip distro detection. state.Distro = DistroIsK3s @@ -75,6 +77,7 @@ func (c *Cluster) InitZarfState(ctx context.Context, initOptions types.ZarfInitO if state.Distro != DistroIsUnknown { spinner.Updatef("Detected K8s distro %s", state.Distro) + l.Debug("Detected K8s distro", "name", state.Distro) } // Setup zarf agent PKI @@ -90,7 +93,8 @@ func (c *Cluster) InitZarfState(ctx context.Context, initOptions types.ZarfInitO } // Mark existing namespaces as ignored for the zarf agent to prevent mutating resources we don't own. for _, namespace := range namespaceList.Items { - spinner.Updatef("Marking existing namespace %s as ignored by Zarf Agent", namespace.Name) + l.Debug("marking namespace as ignored by Zarf Agent", "name", namespace.Name) + if namespace.Labels == nil { // Ensure label map exists to avoid nil panic namespace.Labels = make(map[string]string) @@ -106,6 +110,7 @@ func (c *Cluster) InitZarfState(ctx context.Context, initOptions types.ZarfInitO // Try to create the zarf namespace. spinner.Updatef("Creating the Zarf namespace") + l.Debug("creating the Zarf namespace") zarfNamespace := NewZarfManagedNamespace(ZarfNamespaceName) err = func() error { _, err := c.Clientset.CoreV1().Namespaces().Create(ctx, zarfNamespace, metav1.CreateOptions{}) @@ -154,17 +159,21 @@ func (c *Cluster) InitZarfState(ctx context.Context, initOptions types.ZarfInitO initOptions.ArtifactServer.FillInEmptyValues() state.ArtifactServer = initOptions.ArtifactServer } else { + // TODO (@austinabro321) validate immediately in `zarf init` if these are set and not equal and error out if so if helpers.IsNotZeroAndNotEqual(initOptions.GitServer, state.GitServer) { message.Warn("Detected a change in Git Server init options on a re-init. Ignoring... To update run:") message.ZarfCommand("tools update-creds git") + l.Warn("ignoring change in git sever init options on re-init, to update run `zarf tools update-creds git`") } if helpers.IsNotZeroAndNotEqual(initOptions.RegistryInfo, state.RegistryInfo) { message.Warn("Detected a change in Image Registry init options on a re-init. Ignoring... To update run:") message.ZarfCommand("tools update-creds registry") + l.Warn("ignoring change to registry init options on re-init, to update run `zarf tools update-creds registry`") } if helpers.IsNotZeroAndNotEqual(initOptions.ArtifactServer, state.ArtifactServer) { message.Warn("Detected a change in Artifact Server init options on a re-init. Ignoring... To update run:") message.ZarfCommand("tools update-creds artifact") + l.Warn("ignoring change to registry init options on re-init, to update run `zarf tools update-creds registry`") } } diff --git a/src/pkg/logger/logger.go b/src/pkg/logger/logger.go index 82e98d44e6..c812f7b3ca 100644 --- a/src/pkg/logger/logger.go +++ b/src/pkg/logger/logger.go @@ -37,6 +37,22 @@ var ( Error = Level(slog.LevelError) // 8 ) +// String returns the string representation of the Level. +func (l Level) String() string { + switch l { + case Debug: + return "debug" + case Info: + return "info" + case Warn: + return "warn" + case Error: + return "error" + default: + return "unknown" + } +} + // validLevels is a set that provides an ergonomic way to check if a level is a member of the set. var validLevels = map[Level]bool{ Debug: true, @@ -99,6 +115,18 @@ var ( DestinationNone Destination = io.Discard ) +// can't define method on Destination type +func destinationString(d Destination) string { + switch { + case d == DestinationDefault: + return "os.Stderr" + case d == DestinationNone: + return "io.Discard" + default: + return "unknown" + } +} + // Config is configuration for a logger. type Config struct { // Level sets the log level. An empty value corresponds to Info aka 0. @@ -107,6 +135,15 @@ type Config struct { Destination } +// LogValue of config +func (c Config) LogValue() slog.Value { + return slog.GroupValue( + slog.String("level", c.Level.String()), + slog.Any("format", c.Format), + slog.Any("Destination", destinationString(c.Destination)), + ) +} + // ConfigDefault returns a Config with defaults like Text formatting at Info level writing to Stderr. func ConfigDefault() Config { return Config{ diff --git a/src/pkg/packager/deploy.go b/src/pkg/packager/deploy.go index 133dba9e8d..f21ddba5c2 100644 --- a/src/pkg/packager/deploy.go +++ b/src/pkg/packager/deploy.go @@ -285,7 +285,7 @@ func (p *Packager) deployInitComponent(ctx context.Context, component v1alpha1.Z // Do cleanup for when we inject the seed registry during initialization if isSeedRegistry { if err := p.cluster.StopInjection(ctx); err != nil { - return nil, fmt.Errorf("unable to seed the Zarf Registry: %w", err) + return nil, fmt.Errorf("failed to delete injector resources: %w", err) } } diff --git a/src/pkg/zoci/pull.go b/src/pkg/zoci/pull.go index 1984f87ffd..54e58cb4ed 100644 --- a/src/pkg/zoci/pull.go +++ b/src/pkg/zoci/pull.go @@ -35,7 +35,6 @@ var ( // - zarf.yaml.sig func (r *Remote) PullPackage(ctx context.Context, destinationDir string, concurrency int, layersToPull ...ocispec.Descriptor) (_ []ocispec.Descriptor, err error) { isPartialPull := len(layersToPull) > 0 - r.Log().Debug(fmt.Sprintf("Pulling %s", r.Repo().Reference)) manifest, err := r.FetchRoot(ctx) if err != nil { @@ -52,11 +51,14 @@ func (r *Remote) PullPackage(ctx context.Context, destinationDir string, concurr } layersToPull = append(layersToPull, manifest.Config) + layerSize := oci.SumDescsSize(layersToPull) + // TODO (@austinabro321) change this and other r.Log() calls to the proper slog format + r.Log().Info(fmt.Sprintf("Pulling %s, size: %s", r.Repo().Reference, utils.ByteFormat(float64(layerSize), 2))) + // Create a thread to update a progress bar as we save the package to disk doneSaving := make(chan error) successText := fmt.Sprintf("Pulling %q", helpers.OCIURLPrefix+r.Repo().Reference.String()) - layerSize := oci.SumDescsSize(layersToPull) go utils.RenderProgressBarForLocalDirWrite(destinationDir, layerSize, doneSaving, "Pulling", successText) dst, err := file.New(destinationDir)