diff --git a/src/cmd/initialize.go b/src/cmd/initialize.go index 70e73c1223..0543f97749 100644 --- a/src/cmd/initialize.go +++ b/src/cmd/initialize.go @@ -36,6 +36,7 @@ var initCmd = &cobra.Command{ Long: lang.CmdInitLong, Example: lang.CmdInitExample, RunE: func(cmd *cobra.Command, _ []string) error { + ctx := cmd.Context() if err := validateInitFlags(); err != nil { return fmt.Errorf("invalid command flags were provided: %w", err) } @@ -50,7 +51,7 @@ var initCmd = &cobra.Command{ return err } - src, err := sources.New(&pkgConfig.PkgOpts) + src, err := sources.New(ctx, &pkgConfig.PkgOpts) if err != nil { return err } @@ -65,7 +66,7 @@ var initCmd = &cobra.Command{ } defer pkgClient.ClearTempPaths() - err = pkgClient.Deploy(cmd.Context()) + err = pkgClient.Deploy(ctx) if err != nil { return err } @@ -142,7 +143,7 @@ func downloadInitPackage(ctx context.Context, cacheDirectory string) (string, er // If the user wants to download the init-package, download it if confirmDownload { - remote, err := zoci.NewRemote(url, oci.PlatformForArch(config.GetArch())) + remote, err := zoci.NewRemote(ctx, url, oci.PlatformForArch(config.GetArch())) if err != nil { return "", err } diff --git a/src/cmd/tools/zarf.go b/src/cmd/tools/zarf.go index 1bf56fd574..d33af49cdf 100644 --- a/src/cmd/tools/zarf.go +++ b/src/cmd/tools/zarf.go @@ -222,13 +222,14 @@ var downloadInitCmd = &cobra.Command{ Use: "download-init", Short: lang.CmdToolsDownloadInitShort, RunE: func(cmd *cobra.Command, _ []string) error { + ctx := cmd.Context() url := zoci.GetInitPackageURL(config.CLIVersion) - remote, err := zoci.NewRemote(url, oci.PlatformForArch(config.GetArch())) + remote, err := zoci.NewRemote(ctx, url, oci.PlatformForArch(config.GetArch())) if err != nil { return fmt.Errorf("unable to download the init package: %w", err) } source := &sources.OCISource{Remote: remote} - _, err = source.Collect(cmd.Context(), outputDirectory) + _, err = source.Collect(ctx, outputDirectory) if err != nil { return fmt.Errorf("unable to download the init package: %w", err) } diff --git a/src/internal/git/repository.go b/src/internal/git/repository.go index 9d2b2d4918..be0215044b 100644 --- a/src/internal/git/repository.go +++ b/src/internal/git/repository.go @@ -18,6 +18,7 @@ import ( "github.com/go-git/go-git/v5/plumbing/transport" "github.com/go-git/go-git/v5/plumbing/transport/http" + "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" @@ -146,6 +147,7 @@ func (r *Repository) Path() string { // Push pushes the repository to the remote git server. func (r *Repository) Push(ctx context.Context, address, username, password string) error { + l := logger.From(ctx) repo, err := git.PlainOpen(r.path) if err != nil { return fmt.Errorf("not a valid git repo or unable to open: %w", err) @@ -195,10 +197,13 @@ func (r *Repository) Push(ctx context.Context, address, username, password strin err = repo.FetchContext(ctx, fetchOptions) if errors.Is(err, transport.ErrRepositoryNotFound) { message.Debugf("Repo not yet available offline, skipping fetch...") + l.Debug("repo not yet available offline, skipping fetch") } else if errors.Is(err, git.ErrForceNeeded) { message.Debugf("Repo fetch requires force, skipping fetch...") + l.Debug("repo fetch requires force, skipping fetch") } else if errors.Is(err, git.NoErrAlreadyUpToDate) { message.Debugf("Repo already up-to-date, skipping fetch...") + l.Debug("repo already up-to-date, skipping fetch") } else if err != nil { return fmt.Errorf("unable to fetch the git repo prior to push: %w", err) } @@ -217,6 +222,7 @@ func (r *Repository) Push(ctx context.Context, address, username, password strin }) if errors.Is(err, git.NoErrAlreadyUpToDate) { message.Debug("Repo already up-to-date") + l.Debug("repo already up-to-date") } else if errors.Is(err, plumbing.ErrObjectNotFound) { return fmt.Errorf("unable to push repo due to likely shallow clone: %s", err.Error()) } else if err != nil { diff --git a/src/internal/packager/helm/chart.go b/src/internal/packager/helm/chart.go index 35e1e5625c..0bb12a03bb 100644 --- a/src/internal/packager/helm/chart.go +++ b/src/internal/packager/helm/chart.go @@ -9,9 +9,10 @@ import ( "context" "errors" "fmt" - "github.com/zarf-dev/zarf/src/pkg/logger" "time" + "github.com/zarf-dev/zarf/src/pkg/logger" + "github.com/Masterminds/semver/v3" "github.com/avast/retry-go/v4" plutoversionsfile "github.com/fairwindsops/pluto/v5" @@ -35,15 +36,18 @@ import ( // InstallOrUpgradeChart performs a helm install of the given chart. func (h *Helm) InstallOrUpgradeChart(ctx context.Context) (types.ConnectStrings, string, error) { - fromMessage := h.chart.URL - if fromMessage == "" { - fromMessage = "Zarf-generated helm chart" + l := logger.From(ctx) + start := time.Now() + source := h.chart.URL + if source == "" { + source = "Zarf-generated" } - spinner := message.NewProgressSpinner("Processing helm chart %s:%s from %s", + spinner := message.NewProgressSpinner("Processing helm chart %s:%s source: %s", h.chart.Name, h.chart.Version, - fromMessage) + source) defer spinner.Stop() + l.Info("processing helm chart", "name", h.chart.Name, "version", h.chart.Version, "source", source) // If no release name is specified, use the chart name. if h.chart.ReleaseName == "" { @@ -51,7 +55,7 @@ func (h *Helm) InstallOrUpgradeChart(ctx context.Context) (types.ConnectStrings, } // Setup K8s connection. - err := h.createActionConfig(h.chart.Namespace, spinner) + err := h.createActionConfig(ctx, h.chart.Namespace, spinner) if err != nil { return nil, "", fmt.Errorf("unable to initialize the K8s client: %w", err) } @@ -73,15 +77,18 @@ func (h *Helm) InstallOrUpgradeChart(ctx context.Context) (types.ConnectStrings, releases, histErr := histClient.Run(h.chart.ReleaseName) spinner.Updatef("Checking for existing helm deployment") + l.Debug("checking for existing helm deployment") if errors.Is(histErr, driver.ErrReleaseNotFound) { // No prior release, try to install it. spinner.Updatef("Attempting chart installation") + l.Info("performing Helm install", "chart", h.chart.Name) release, err = h.installChart(helmCtx, postRender) } else if histErr == nil && len(releases) > 0 { // Otherwise, there is a prior release so upgrade it. spinner.Updatef("Attempting chart upgrade") + l.Info("performing Helm upgrade", "chart", h.chart.Name) lastRelease := releases[len(releases)-1] @@ -118,6 +125,7 @@ func (h *Helm) InstallOrUpgradeChart(ctx context.Context) (types.ConnectStrings, // Attempt to rollback on a failed upgrade. spinner.Updatef("Performing chart rollback") + l.Info("performing Helm rollback", "chart", h.chart.Name) err = h.rollbackChart(h.chart.ReleaseName, previouslyDeployedVersion) if err != nil { return nil, "", fmt.Errorf("%w: unable to rollback: %w", installErr, err) @@ -137,11 +145,13 @@ func (h *Helm) InstallOrUpgradeChart(ctx context.Context) (types.ConnectStrings, if !h.chart.NoWait { // Ensure we don't go past the timeout by using a context initialized with the helm timeout spinner.Updatef("Running health checks") + l.Info("running health checks", "chart", h.chart.Name) if err := healthchecks.WaitForReadyRuntime(helmCtx, h.cluster.Watcher, runtimeObjs); err != nil { return nil, "", err } } spinner.Success() + l.Debug("done processing helm chart", "name", h.chart.Name, "duration", time.Since(start)) // return any collected connect strings for zarf connect. return postRender.connectStrings, h.chart.ReleaseName, nil @@ -152,7 +162,7 @@ func (h *Helm) TemplateChart(ctx context.Context) (manifest string, chartValues spinner := message.NewProgressSpinner("Templating helm chart %s", h.chart.Name) defer spinner.Stop() - err = h.createActionConfig(h.chart.Namespace, spinner) + err = h.createActionConfig(ctx, h.chart.Namespace, spinner) // Setup K8s connection. if err != nil { @@ -216,7 +226,7 @@ func (h *Helm) TemplateChart(ctx context.Context) (manifest string, chartValues // RemoveChart removes a chart from the cluster. func (h *Helm) RemoveChart(ctx context.Context, namespace string, name string, spinner *message.Spinner) error { // Establish a new actionConfig for the namespace. - _ = h.createActionConfig(namespace, spinner) + _ = h.createActionConfig(ctx, namespace, spinner) // Perform the uninstall. response, err := h.uninstallChart(name) message.Debug(response) @@ -230,7 +240,7 @@ func (h *Helm) UpdateReleaseValues(ctx context.Context, updatedValues map[string spinner := message.NewProgressSpinner("Updating values for helm release %s", h.chart.ReleaseName) defer spinner.Stop() - err := h.createActionConfig(h.chart.Namespace, spinner) + err := h.createActionConfig(ctx, h.chart.Namespace, spinner) if err != nil { return fmt.Errorf("unable to initialize the K8s client: %w", err) } diff --git a/src/internal/packager/helm/destroy.go b/src/internal/packager/helm/destroy.go index 21693aaa92..86e0b63ce6 100644 --- a/src/internal/packager/helm/destroy.go +++ b/src/internal/packager/helm/destroy.go @@ -26,7 +26,7 @@ func Destroy(ctx context.Context, purgeAllZarfInstallations bool) { h := Helm{} // Initially load the actionConfig without a namespace - err := h.createActionConfig("", spinner) + err := h.createActionConfig(ctx, "", spinner) if err != nil { // Don't fatal since this is a removal action spinner.Errorf(err, "Unable to initialize the K8s client") diff --git a/src/internal/packager/helm/post-render.go b/src/internal/packager/helm/post-render.go index c316375acb..b80109ffd0 100644 --- a/src/internal/packager/helm/post-render.go +++ b/src/internal/packager/helm/post-render.go @@ -16,6 +16,7 @@ import ( "github.com/defenseunicorns/pkg/helpers/v2" "github.com/zarf-dev/zarf/src/config" "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/utils" "github.com/zarf-dev/zarf/src/types" @@ -117,6 +118,7 @@ func (r *renderer) Run(renderedManifests *bytes.Buffer) (*bytes.Buffer, error) { } func (r *renderer) adoptAndUpdateNamespaces(ctx context.Context) error { + l := logger.From(ctx) c := r.cluster namespaceList, err := r.cluster.Clientset.CoreV1().Namespaces().List(ctx, metav1.ListOptions{}) if err != nil { @@ -142,6 +144,7 @@ func (r *renderer) adoptAndUpdateNamespaces(ctx context.Context) error { // https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/#initial-namespaces if slices.Contains([]string{"default", "kube-node-lease", "kube-public", "kube-system"}, name) { message.Warnf("Refusing to adopt the initial namespace: %s", name) + l.Warn("refusing to adopt initial namespace", "name", name) } else { // This is an existing namespace to adopt _, err := c.Clientset.CoreV1().Namespaces().Update(ctx, namespace, metav1.UpdateOptions{}) @@ -181,6 +184,7 @@ func (r *renderer) adoptAndUpdateNamespaces(ctx context.Context) error { }() if err != nil { message.WarnErrf(err, "Problem creating registry secret for the %s namespace", name) + l.Warn("problem creating registry secret", "namespace", name, "error", err.Error()) } // Create or update the zarf git server secret @@ -201,6 +205,7 @@ func (r *renderer) adoptAndUpdateNamespaces(ctx context.Context) error { }() if err != nil { message.WarnErrf(err, "Problem creating git server secret for the %s namespace", name) + l.Warn("problem creating git server secret", "namespace", name, "error", err.Error()) } } } @@ -208,6 +213,7 @@ func (r *renderer) adoptAndUpdateNamespaces(ctx context.Context) error { } func (r *renderer) editHelmResources(ctx context.Context, resources []releaseutil.Manifest, finalManifestsOutput *bytes.Buffer) error { + l := logger.From(ctx) dc, err := dynamic.NewForConfig(r.cluster.RestConfig) if err != nil { return err @@ -231,8 +237,10 @@ func (r *renderer) editHelmResources(ctx context.Context, resources []releaseuti // parse the namespace resource so it can be applied out-of-band by zarf instead of helm to avoid helm ns shenanigans if err := runtime.DefaultUnstructuredConverter.FromUnstructured(rawData.UnstructuredContent(), namespace); err != nil { message.WarnErrf(err, "could not parse namespace %s", rawData.GetName()) + l.Warn("failed to parse namespace", "name", rawData.GetName(), "error", err) } else { message.Debugf("Matched helm namespace %s for zarf annotation", namespace.Name) + l.Debug("matched helm namespace for zarf annotation", "name", namespace.Name) namespace.Labels = cluster.AdoptZarfManagedLabels(namespace.Labels) // Add it to the stack r.namespaces[namespace.Name] = namespace @@ -253,6 +261,7 @@ func (r *renderer) editHelmResources(ctx context.Context, resources []releaseuti if key, keyExists := labels[cluster.ZarfConnectLabelName]; keyExists { // If there is a zarf-connect label message.Debugf("Match helm service %s for zarf connection %s", rawData.GetName(), key) + l.Debug("match helm service for zarf connection", "service", rawData.GetName(), "connection-key", key) // Add the connectString for processing later in the deployment r.connectStrings[key] = types.ConnectString{ diff --git a/src/internal/packager/helm/utils.go b/src/internal/packager/helm/utils.go index 8d3d5f3202..38b9e1f889 100644 --- a/src/internal/packager/helm/utils.go +++ b/src/internal/packager/helm/utils.go @@ -5,9 +5,12 @@ package helm import ( + "context" "fmt" + "log/slog" "github.com/defenseunicorns/pkg/helpers/v2" + "github.com/zarf-dev/zarf/src/pkg/logger" "github.com/zarf-dev/zarf/src/pkg/message" "helm.sh/helm/v3/pkg/action" "helm.sh/helm/v3/pkg/chart" @@ -60,7 +63,7 @@ func (h *Helm) parseChartValues() (chartutil.Values, error) { return helpers.MergeMapRecursive(chartValues, h.valuesOverrides), nil } -func (h *Helm) createActionConfig(namespace string, spinner *message.Spinner) error { +func (h *Helm) createActionConfig(ctx context.Context, namespace string, spinner *message.Spinner) error { // Initialize helm SDK actionConfig := new(action.Configuration) // Set the settings for the helm SDK @@ -70,7 +73,12 @@ func (h *Helm) createActionConfig(namespace string, spinner *message.Spinner) er h.settings.SetNamespace(namespace) // Setup K8s connection - err := actionConfig.Init(h.settings.RESTClientGetter(), namespace, "", spinner.Updatef) + helmLogger := spinner.Updatef + if logger.Enabled(ctx) { + l := logger.From(ctx) + helmLogger = slog.NewLogLogger(l.Handler(), slog.LevelDebug).Printf + } + err := actionConfig.Init(h.settings.RESTClientGetter(), namespace, "", helmLogger) // Set the actionConfig is the received Helm pointer h.actionConfig = actionConfig diff --git a/src/internal/packager/helm/zarf.go b/src/internal/packager/helm/zarf.go index b6945a6e8c..4783f6557e 100644 --- a/src/internal/packager/helm/zarf.go +++ b/src/internal/packager/helm/zarf.go @@ -81,7 +81,7 @@ func (h *Helm) UpdateZarfAgentValues(ctx context.Context) error { return err } - err = h.createActionConfig(cluster.ZarfNamespaceName, spinner) + err = h.createActionConfig(ctx, cluster.ZarfNamespaceName, spinner) if err != nil { return err } @@ -111,7 +111,7 @@ func (h *Helm) UpdateZarfAgentValues(ctx context.Context) error { Value: agentImage.Tag, }, }) - applicationTemplates, err := template.GetZarfTemplates("zarf-agent", h.state) + applicationTemplates, err := template.GetZarfTemplates(ctx, "zarf-agent", h.state) if err != nil { return fmt.Errorf("error setting up the templates: %w", err) } diff --git a/src/internal/packager/images/push.go b/src/internal/packager/images/push.go index e04c628023..1930754e45 100644 --- a/src/internal/packager/images/push.go +++ b/src/internal/packager/images/push.go @@ -10,10 +10,10 @@ import ( "github.com/avast/retry-go/v4" "github.com/google/go-containerregistry/pkg/crane" - "github.com/google/go-containerregistry/pkg/logs" v1 "github.com/google/go-containerregistry/pkg/v1" "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" @@ -21,8 +21,7 @@ import ( // Push pushes images to a registry. func Push(ctx context.Context, cfg PushConfig) error { - logs.Warn.SetOutput(&message.DebugWriter{}) - logs.Progress.SetOutput(&message.DebugWriter{}) + l := logger.From(ctx) toPush := map[transform.Image]v1.Image{} // Build an image list from the references @@ -67,6 +66,7 @@ func Push(ctx context.Context, cfg PushConfig) error { }() for refInfo, img := range toPush { message.Infof("Pushing %s", refInfo.Reference) + l.Info("pushing image", "name", refInfo.Reference) // If this is not a no checksum image push it for use with the Zarf agent if !cfg.NoChecksum { offlineNameCRC, err := transform.ImageTransformHost(registryURL, refInfo.Reference) diff --git a/src/internal/packager/template/template.go b/src/internal/packager/template/template.go index a77d09de93..f069698425 100644 --- a/src/internal/packager/template/template.go +++ b/src/internal/packager/template/template.go @@ -43,7 +43,7 @@ func GetZarfVariableConfig(ctx context.Context) *variables.VariableConfig { } // GetZarfTemplates returns the template keys and values to be used for templating. -func GetZarfTemplates(componentName string, state *types.ZarfState) (templateMap map[string]*variables.TextTemplate, err error) { +func GetZarfTemplates(ctx context.Context, componentName string, state *types.ZarfState) (templateMap map[string]*variables.TextTemplate, err error) { templateMap = make(map[string]*variables.TextTemplate) if state != nil { @@ -102,7 +102,7 @@ func GetZarfTemplates(componentName string, state *types.ZarfState) (templateMap } } - debugPrintTemplateMap(templateMap) + debugPrintTemplateMap(ctx, templateMap) return templateMap, nil } @@ -127,7 +127,9 @@ func generateHtpasswd(regInfo *types.RegistryInfo) (string, error) { return "", nil } -func debugPrintTemplateMap(templateMap map[string]*variables.TextTemplate) { +func debugPrintTemplateMap(ctx context.Context, templateMap map[string]*variables.TextTemplate) { + // TODO (@austinabro321) sanitize the template by making a copy and changing the actual keys + // then use json.MarshalIndent to create the json debugText := "templateMap = { " for key, template := range templateMap { @@ -141,4 +143,5 @@ func debugPrintTemplateMap(templateMap map[string]*variables.TextTemplate) { debugText += " }" message.Debug(debugText) + logger.From(ctx).Debug(debugText) } diff --git a/src/internal/packager2/layout/import.go b/src/internal/packager2/layout/import.go index a1c917eee0..6c29aa31b5 100644 --- a/src/internal/packager2/layout/import.go +++ b/src/internal/packager2/layout/import.go @@ -54,7 +54,7 @@ func resolveImports(ctx context.Context, pkg v1alpha1.ZarfPackage, packagePath, return v1alpha1.ZarfPackage{}, err } } else if component.Import.URL != "" { - remote, err := zoci.NewRemote(component.Import.URL, zoci.PlatformForSkeleton()) + remote, err := zoci.NewRemote(ctx, component.Import.URL, zoci.PlatformForSkeleton()) if err != nil { return v1alpha1.ZarfPackage{}, err } @@ -166,7 +166,7 @@ func fetchOCISkeleton(ctx context.Context, component v1alpha1.ZarfComponent, pac } // Get the descriptor for the component. - remote, err := zoci.NewRemote(component.Import.URL, zoci.PlatformForSkeleton()) + remote, err := zoci.NewRemote(ctx, component.Import.URL, zoci.PlatformForSkeleton()) if err != nil { return "", err } diff --git a/src/internal/packager2/pull.go b/src/internal/packager2/pull.go index 538facc5b9..5f9dc2b5b7 100644 --- a/src/internal/packager2/pull.go +++ b/src/internal/packager2/pull.go @@ -99,7 +99,7 @@ func pullOCI(ctx context.Context, src, tarPath, shasum string, filter filters.Co src = fmt.Sprintf("%s@sha256:%s", src, shasum) } arch := config.GetArch() - remote, err := zoci.NewRemote(src, oci.PlatformForArch(arch)) + remote, err := zoci.NewRemote(ctx, src, oci.PlatformForArch(arch)) if err != nil { return false, err } diff --git a/src/pkg/cluster/data.go b/src/pkg/cluster/data.go index 68148003a7..a85f52c7ab 100644 --- a/src/pkg/cluster/data.go +++ b/src/pkg/cluster/data.go @@ -25,6 +25,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/utils" "github.com/zarf-dev/zarf/src/pkg/utils/exec" @@ -33,6 +34,7 @@ import ( // HandleDataInjection waits for the target pod(s) to come up and inject the data into them // todo: this currently requires kubectl but we should have enough k8s work to make this native now. func (c *Cluster) HandleDataInjection(ctx context.Context, data v1alpha1.ZarfDataInjection, componentPath *layout.ComponentPaths, dataIdx int) error { + l := logger.From(ctx) injectionCompletionMarker := filepath.Join(componentPath.DataInjections, config.GetDataInjectionMarker()) if err := os.WriteFile(injectionCompletionMarker, []byte("🦄"), helpers.ReadWriteUser); err != nil { return fmt.Errorf("unable to create the data injection completion marker: %w", err) @@ -61,6 +63,7 @@ func (c *Cluster) HandleDataInjection(ctx context.Context, data v1alpha1.ZarfDat } message.Debugf("Attempting to inject data into %s", data.Target) + l.Debug("performing data injection", "target", data.Target) source := filepath.Join(componentPath.DataInjections, filepath.Base(data.Target.Path)) if helpers.InvalidPath(source) { @@ -91,6 +94,7 @@ func (c *Cluster) HandleDataInjection(ctx context.Context, data v1alpha1.ZarfDat kubectlBinPath := "kubectl" if err != nil { message.Warnf("Unable to get the zarf executable path, falling back to host kubectl: %s", err) + l.Warn("unable to get the zarf executable path, falling back to host kubectl", "error", err) } else { kubectlBinPath = fmt.Sprintf("%s tools kubectl", zarfCommand) } @@ -171,6 +175,7 @@ type podFilter func(pod corev1.Pod) bool // If the timeout is reached, an empty list will be returned. // TODO: Test, refactor and/or remove. func waitForPodsAndContainers(ctx context.Context, clientset kubernetes.Interface, target podLookup, include podFilter) ([]corev1.Pod, error) { + l := logger.From(ctx) readyPods, err := retry.DoWithData(func() ([]corev1.Pod, error) { listOpts := metav1.ListOptions{ LabelSelector: target.Selector, @@ -180,6 +185,7 @@ func waitForPodsAndContainers(ctx context.Context, clientset kubernetes.Interfac return nil, err } message.Debugf("Found %d pods for target %#v", len(podList.Items), target) + l.Debug("found pods matching the target", "count", len(podList.Items), "target", target) // Sort the pods from newest to oldest sort.Slice(podList.Items, func(i, j int) bool { return podList.Items[i].CreationTimestamp.After(podList.Items[j].CreationTimestamp.Time) @@ -188,6 +194,7 @@ func waitForPodsAndContainers(ctx context.Context, clientset kubernetes.Interfac readyPods := []corev1.Pod{} for _, pod := range podList.Items { message.Debugf("Testing pod %q", pod.Name) + l.Debug("testing pod", "name", pod.Name) // If an include function is provided, only keep pods that return true if include != nil && !include(pod) { @@ -197,6 +204,7 @@ func waitForPodsAndContainers(ctx context.Context, clientset kubernetes.Interfac // Handle container targeting if target.Container != "" { message.Debugf("Testing pod %q for container %q", pod.Name, target.Container) + l.Debug("testing container", "name", target.Container, "source-pod", pod.Name) // Check the status of initContainers for a running match for _, initContainer := range pod.Status.InitContainerStatuses { @@ -219,6 +227,7 @@ func waitForPodsAndContainers(ctx context.Context, clientset kubernetes.Interfac } else { status := pod.Status.Phase message.Debugf("Testing pod %q phase, want (%q) got (%q)", pod.Name, corev1.PodRunning, status) + l.Debug(fmt.Sprintf("checking pod for %s status", corev1.PodRunning), "pod", pod.Name, "status", status) // Regular status checking without a container if status == corev1.PodRunning { readyPods = append(readyPods, pod) diff --git a/src/pkg/cluster/state.go b/src/pkg/cluster/state.go index a6274356a0..0ad4dac449 100644 --- a/src/pkg/cluster/state.go +++ b/src/pkg/cluster/state.go @@ -235,7 +235,6 @@ func (c *Cluster) debugPrintZarfState(ctx context.Context, state *types.ZarfStat if state == nil { return } - // this is a shallow copy, nested pointers WILL NOT be copied oldState := *state sanitized := c.sanitizeZarfState(&oldState) @@ -244,7 +243,6 @@ func (c *Cluster) debugPrintZarfState(ctx context.Context, state *types.ZarfStat return } message.Debugf("ZarfState - %s", string(b)) - logger.From(ctx).Debug("cluster.debugPrintZarfState", "state", sanitized) } diff --git a/src/pkg/packager/common.go b/src/pkg/packager/common.go index 442335cec0..f74a9d68c2 100644 --- a/src/pkg/packager/common.go +++ b/src/pkg/packager/common.go @@ -8,11 +8,12 @@ import ( "context" "errors" "fmt" - "github.com/zarf-dev/zarf/src/pkg/logger" "os" "slices" "strings" + "github.com/zarf-dev/zarf/src/pkg/logger" + "github.com/Masterminds/semver/v3" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -106,7 +107,7 @@ func New(cfg *types.PackagerConfig, mods ...Modifier) (*Packager, error) { // Fill the source if it wasn't provided - note source can be nil if the package is being created if pkgr.source == nil && pkgr.cfg.CreateOpts.BaseDir == "" { - pkgr.source, err = sources.New(&pkgr.cfg.PkgOpts) + pkgr.source, err = sources.New(pkgr.ctx, &pkgr.cfg.PkgOpts) if err != nil { return nil, err } diff --git a/src/pkg/packager/composer/oci.go b/src/pkg/packager/composer/oci.go index 4d2589f717..4a49ce569f 100644 --- a/src/pkg/packager/composer/oci.go +++ b/src/pkg/packager/composer/oci.go @@ -28,7 +28,7 @@ func (ic *ImportChain) getRemote(ctx context.Context, url string) (*zoci.Remote, return ic.remote, nil } var err error - ic.remote, err = zoci.NewRemote(url, zoci.PlatformForSkeleton()) + ic.remote, err = zoci.NewRemote(ctx, url, zoci.PlatformForSkeleton()) if err != nil { return nil, err } diff --git a/src/pkg/packager/creator/differential.go b/src/pkg/packager/creator/differential.go index a373bcc4f2..d3aea389d9 100644 --- a/src/pkg/packager/creator/differential.go +++ b/src/pkg/packager/creator/differential.go @@ -25,7 +25,7 @@ func loadDifferentialData(ctx context.Context, diffPkgPath string) (diffData *ty diffLayout := layout.New(tmpdir) defer os.RemoveAll(diffLayout.Base) - src, err := sources.New(&types.ZarfPackageOptions{ + src, err := sources.New(ctx, &types.ZarfPackageOptions{ PackageSource: diffPkgPath, }) if err != nil { diff --git a/src/pkg/packager/creator/normal.go b/src/pkg/packager/creator/normal.go index d13d05e595..c97cab63c1 100644 --- a/src/pkg/packager/creator/normal.go +++ b/src/pkg/packager/creator/normal.go @@ -292,8 +292,7 @@ func (pc *PackageCreator) Output(ctx context.Context, dst *layout.PackagePaths, if err != nil { return err } - // TODO(mkcp): Port zoci.NewRemote to new logger - remote, err := zoci.NewRemote(ref, oci.PlatformForArch(config.GetArch())) + remote, err := zoci.NewRemote(ctx, ref, oci.PlatformForArch(config.GetArch())) if err != nil { return err } diff --git a/src/pkg/packager/deploy.go b/src/pkg/packager/deploy.go index 26079df5d4..6ecf6cc229 100644 --- a/src/pkg/packager/deploy.go +++ b/src/pkg/packager/deploy.go @@ -34,6 +34,7 @@ import ( "github.com/zarf-dev/zarf/src/internal/packager/template" "github.com/zarf-dev/zarf/src/pkg/cluster" "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/actions" "github.com/zarf-dev/zarf/src/pkg/packager/filters" @@ -56,6 +57,8 @@ func (p *Packager) resetRegistryHPA(ctx context.Context) { // Deploy attempts to deploy the given PackageConfig. func (p *Packager) Deploy(ctx context.Context) error { + l := logger.From(ctx) + start := time.Now() isInteractive := !config.CommonOptions.Confirm deployFilter := filters.Combine( @@ -89,12 +92,18 @@ func (p *Packager) Deploy(ctx context.Context) error { return err } warnings = append(warnings, validateWarnings...) + for _, warning := range validateWarnings { + l.Warn(warning) + } sbomViewFiles, sbomWarnings, err := p.layout.SBOMs.StageSBOMViewFiles() if err != nil { return err } warnings = append(warnings, sbomWarnings...) + for _, warning := range sbomWarnings { + l.Warn(warning) + } // Confirm the overall package deployment if !p.confirmAction(config.ZarfDeployStage, warnings, sbomViewFiles) { @@ -124,10 +133,12 @@ func (p *Packager) Deploy(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 deployment complete") + l.Debug("Zarf deployment complete", "duration", time.Since(start)) err = p.printTablesForDeployment(ctx, deployedComponents) if err != nil { @@ -139,6 +150,7 @@ func (p *Packager) Deploy(ctx context.Context) error { // deployComponents loops through a list of ZarfComponents and deploys them. func (p *Packager) deployComponents(ctx context.Context) ([]types.DeployedComponent, error) { + l := logger.From(ctx) deployedComponents := []types.DeployedComponent{} // Process all the components we are deploying @@ -165,6 +177,7 @@ func (p *Packager) deployComponents(ctx context.Context) ([]types.DeployedCompon installedCharts, err := p.cluster.GetInstalledChartsForComponent(ctx, p.cfg.Pkg.Metadata.Name, component) if err != nil { message.Debugf("Unable to fetch installed Helm charts for component '%s': %s", component.Name, err.Error()) + l.Debug("unable to fetch installed Helm charts", "component", component.Name, "error", err.Error()) } deployedComponent.InstalledCharts = installedCharts } @@ -186,6 +199,7 @@ func (p *Packager) deployComponents(ctx context.Context) ([]types.DeployedCompon onFailure := func() { if err := actions.Run(ctx, onDeploy.Defaults, onDeploy.OnFailure, p.variableConfig); err != nil { message.Debugf("unable to run component failure action: %s", err.Error()) + l.Debug("unable to run component failure action", "error", err.Error()) } } @@ -195,6 +209,7 @@ func (p *Packager) deployComponents(ctx context.Context) ([]types.DeployedCompon if p.isConnectedToCluster() { if _, err := p.cluster.RecordPackageDeployment(ctx, p.cfg.Pkg, deployedComponents); err != nil { message.Debugf("Unable to record package deployment for component %q: this will affect features like `zarf package remove`: %s", component.Name, err.Error()) + l.Debug("unable to record package deployment", "component", component.Name, "error", err.Error()) } } return nil, fmt.Errorf("unable to deploy component %q: %w", component.Name, deployErr) @@ -205,6 +220,7 @@ func (p *Packager) deployComponents(ctx context.Context) ([]types.DeployedCompon if p.isConnectedToCluster() { if _, err := p.cluster.RecordPackageDeployment(ctx, p.cfg.Pkg, deployedComponents); err != nil { message.Debugf("Unable to record package deployment for component %q: this will affect features like `zarf package remove`: %s", component.Name, err.Error()) + l.Debug("unable to record package deployment", "component", component.Name, "error", err.Error()) } } @@ -218,6 +234,7 @@ func (p *Packager) deployComponents(ctx context.Context) ([]types.DeployedCompon } func (p *Packager) deployInitComponent(ctx context.Context, component v1alpha1.ZarfComponent) ([]types.InstalledChart, error) { + l := logger.From(ctx) hasExternalRegistry := p.cfg.InitOpts.RegistryInfo.Address != "" isSeedRegistry := component.Name == "zarf-seed-registry" isRegistry := component.Name == "zarf-registry" @@ -239,6 +256,7 @@ func (p *Packager) deployInitComponent(ctx context.Context, component v1alpha1.Z if hasExternalRegistry && (isSeedRegistry || isInjector || isRegistry) { message.Notef("Not deploying the component (%s) since external registry information was provided during `zarf init`", component.Name) + l.Info("skipping init package component since external registry information was provided", "component", component.Name) return nil, nil } @@ -274,11 +292,13 @@ func (p *Packager) deployInitComponent(ctx context.Context, component v1alpha1.Z // Deploy a Zarf Component. func (p *Packager) deployComponent(ctx context.Context, component v1alpha1.ZarfComponent, noImgChecksum bool, noImgPush bool) ([]types.InstalledChart, error) { + l := logger.From(ctx) + start := time.Now() // Toggles for general deploy operations componentPath := p.layout.Components.Dirs[component.Name] - // All components now require a name message.HeaderInfof("📦 %s COMPONENT", strings.ToUpper(component.Name)) + l.Info("deploying component", "name", component.Name) hasImages := len(component.Images) > 0 && !noImgPush hasCharts := len(component.Charts) > 0 @@ -301,13 +321,14 @@ func (p *Packager) deployComponent(ctx context.Context, component v1alpha1.ZarfC if hasImages && !p.hpaModified && p.state.RegistryInfo.IsInternal() { if err := p.cluster.DisableRegHPAScaleDown(ctx); err != nil { message.Debugf("unable to disable the registry HPA scale down: %s", err.Error()) + l.Debug("unable to disable the registry HPA scale down", "error", err.Error()) } else { p.hpaModified = true } } } - err := p.populateComponentAndStateTemplates(component.Name) + err := p.populateComponentAndStateTemplates(ctx, component.Name) if err != nil { return nil, err } @@ -317,7 +338,7 @@ func (p *Packager) deployComponent(ctx context.Context, component v1alpha1.ZarfC } if hasFiles { - if err := p.processComponentFiles(component, componentPath.Files); err != nil { + if err := p.processComponentFiles(ctx, component, componentPath.Files); err != nil { return nil, fmt.Errorf("unable to process the component files: %w", err) } } @@ -357,6 +378,7 @@ func (p *Packager) deployComponent(ctx context.Context, component v1alpha1.ZarfC healthCheckContext, cancel := context.WithTimeout(ctx, p.cfg.DeployOpts.Timeout) defer cancel() spinner := message.NewProgressSpinner("Running health checks") + l.Info("running health checks") defer spinner.Stop() if err = healthchecks.Run(healthCheckContext, p.cluster.Watcher, component.HealthChecks); err != nil { return nil, fmt.Errorf("health checks failed: %w", err) @@ -368,16 +390,21 @@ func (p *Packager) deployComponent(ctx context.Context, component v1alpha1.ZarfC if err != nil { return nil, err } + l.Debug("done deploying component", "name", component.Name, "duration", time.Since(start)) return charts, nil } // Move files onto the host of the machine performing the deployment. -func (p *Packager) processComponentFiles(component v1alpha1.ZarfComponent, pkgLocation string) error { +func (p *Packager) processComponentFiles(ctx context.Context, component v1alpha1.ZarfComponent, pkgLocation string) error { + l := logger.From(ctx) spinner := message.NewProgressSpinner("Copying %d files", len(component.Files)) + start := time.Now() + l.Info("copying files", "count", len(component.Files)) defer spinner.Stop() for fileIdx, file := range component.Files { spinner.Updatef("Loading %s", file.Target) + l.Info("loading file", "name", file.Target) fileLocation := filepath.Join(pkgLocation, strconv.Itoa(fileIdx), filepath.Base(file.Target)) if helpers.InvalidPath(fileLocation) { @@ -387,6 +414,7 @@ func (p *Packager) processComponentFiles(component v1alpha1.ZarfComponent, pkgLo // If a shasum is specified check it again on deployment as well if file.Shasum != "" { spinner.Updatef("Validating SHASUM for %s", file.Target) + l.Debug("Validating SHASUM", "file", file.Target) if err := helpers.SHAsMatch(fileLocation, file.Shasum); err != nil { return err } @@ -417,6 +445,7 @@ func (p *Packager) processComponentFiles(component v1alpha1.ZarfComponent, pkgLo // If the file is a text file, template it if isText { spinner.Updatef("Templating %s", file.Target) + l.Debug("template file", "name", file.Target) if err := p.variableConfig.ReplaceTextTemplate(subFile); err != nil { return fmt.Errorf("unable to template file %s: %w", subFile, err) } @@ -425,6 +454,7 @@ func (p *Packager) processComponentFiles(component v1alpha1.ZarfComponent, pkgLo // Copy the file to the destination spinner.Updatef("Saving %s", file.Target) + l.Debug("saving file", "name", file.Target) err = helpers.CreatePathAndCopy(fileLocation, file.Target) if err != nil { return fmt.Errorf("unable to copy file %s to %s: %w", fileLocation, file.Target, err) @@ -449,15 +479,18 @@ func (p *Packager) processComponentFiles(component v1alpha1.ZarfComponent, pkgLo } spinner.Success() + l.Debug("done copying files", "duration", time.Since(start)) return nil } // setupState fetches the current ZarfState from the k8s cluster and sets the packager to use it func (p *Packager) setupState(ctx context.Context) error { + l := logger.From(ctx) // If we are touching K8s, make sure we can talk to it once per deployment spinner := message.NewProgressSpinner("Loading the Zarf State from the Kubernetes cluster") defer spinner.Stop() + l.Debug("loading the Zarf State from the Kubernetes cluster") state, err := p.cluster.LoadZarfState(ctx) // We ignore the error if in YOLO mode because Zarf should not be initiated. @@ -473,8 +506,8 @@ func (p *Packager) setupState(ctx context.Context) error { // YOLO mode, so minimal state needed state.Distro = "YOLO" - // Try to create the zarf namespace spinner.Updatef("Creating the Zarf namespace") + l.Info("creating the Zarf namespace") zarfNamespace := cluster.NewZarfManagedNamespace(cluster.ZarfNamespaceName) err := func() error { _, err := p.cluster.Clientset.CoreV1().Namespaces().Create(ctx, zarfNamespace, metav1.CreateOptions{}) @@ -499,6 +532,9 @@ func (p *Packager) setupState(ctx context.Context) error { message.Warn("This package is in YOLO mode, but the cluster was already initialized with 'zarf init'. " + "This may cause issues if the package does not exclude any charts or manifests from the Zarf Agent using " + "the pod or namespace label `zarf.dev/agent: ignore'.") + l.Warn("This package is in YOLO mode, but the cluster was already initialized with 'zarf init'. " + + "This may cause issues if the package does not exclude any charts or manifests from the Zarf Agent using " + + "the pod or namespace label `zarf.dev/agent: ignore'.") } p.state = state @@ -507,8 +543,8 @@ func (p *Packager) setupState(ctx context.Context) error { return nil } -func (p *Packager) populateComponentAndStateTemplates(componentName string) error { - applicationTemplates, err := template.GetZarfTemplates(componentName, p.state) +func (p *Packager) populateComponentAndStateTemplates(ctx context.Context, componentName string) error { + applicationTemplates, err := template.GetZarfTemplates(ctx, componentName, p.state) if err != nil { return err } @@ -548,7 +584,9 @@ func (p *Packager) pushImagesToRegistry(ctx context.Context, componentImages []s // Push all of the components git repos to the configured git server. func (p *Packager) pushReposToRepository(ctx context.Context, reposPath string, repos []string) error { + l := logger.From(ctx) for _, repoURL := range repos { + l.Info("pushing repository", "name", repoURL, "server", p.state.GitServer.Address) repository, err := git.Open(reposPath, repoURL) if err != nil { return err @@ -728,13 +766,15 @@ func (p *Packager) installChartAndManifests(ctx context.Context, componentPaths connectStrings, installedChartName, err := helmCfg.InstallOrUpgradeChart(ctx) if err != nil { return nil, err - } + } installedCharts = append(installedCharts, types.InstalledChart{Namespace: manifest.Namespace, ChartName: installedChartName, ConnectStrings: connectStrings}) } return installedCharts, nil } +// TODO once deploy is refactored to load the Zarf package and cluster objects in the cmd package +// table printing should be moved to cmd func (p *Packager) printTablesForDeployment(ctx context.Context, componentsToDeploy []types.DeployedComponent) error { // If not init config, print the application connection table if !p.cfg.Pkg.IsInitConfig() { diff --git a/src/pkg/packager/prepare.go b/src/pkg/packager/prepare.go index 1e43335898..89b5ebe625 100644 --- a/src/pkg/packager/prepare.go +++ b/src/pkg/packager/prepare.go @@ -140,7 +140,7 @@ func (p *Packager) findImages(ctx context.Context) (map[string][]string, error) if err != nil { return nil, err } - err = p.populateComponentAndStateTemplates(component.Name) + err = p.populateComponentAndStateTemplates(ctx, component.Name) if err != nil { return nil, err } diff --git a/src/pkg/packager/publish.go b/src/pkg/packager/publish.go index 95d4c66a36..34c54bd546 100644 --- a/src/pkg/packager/publish.go +++ b/src/pkg/packager/publish.go @@ -40,7 +40,7 @@ func (p *Packager) Publish(ctx context.Context) (err error) { arch := config.GetArch() - dstRemote, err := zoci.NewRemote(p.cfg.PublishOpts.PackageDestination, oci.PlatformForArch(arch)) + dstRemote, err := zoci.NewRemote(ctx, p.cfg.PublishOpts.PackageDestination, oci.PlatformForArch(arch)) if err != nil { return err } @@ -95,7 +95,7 @@ func (p *Packager) Publish(ctx context.Context) (err error) { } else { platform = oci.PlatformForArch(p.cfg.Pkg.Build.Architecture) } - remote, err := zoci.NewRemote(ref, platform) + remote, err := zoci.NewRemote(ctx, ref, platform) if err != nil { return err } diff --git a/src/pkg/packager/sources/new.go b/src/pkg/packager/sources/new.go index 65d0af6762..063901fac8 100644 --- a/src/pkg/packager/sources/new.go +++ b/src/pkg/packager/sources/new.go @@ -59,7 +59,7 @@ func Identify(pkgSrc string) string { } // New returns a new PackageSource based on the provided package options. -func New(pkgOpts *types.ZarfPackageOptions) (PackageSource, error) { +func New(ctx context.Context, pkgOpts *types.ZarfPackageOptions) (PackageSource, error) { var source PackageSource pkgSrc := pkgOpts.PackageSource @@ -70,7 +70,7 @@ func New(pkgOpts *types.ZarfPackageOptions) (PackageSource, error) { pkgSrc = fmt.Sprintf("%s@sha256:%s", pkgSrc, pkgOpts.Shasum) } arch := config.GetArch() - remote, err := zoci.NewRemote(pkgSrc, oci.PlatformForArch(arch)) + remote, err := zoci.NewRemote(ctx, pkgSrc, oci.PlatformForArch(arch)) if err != nil { return nil, err } diff --git a/src/pkg/packager/sources/new_test.go b/src/pkg/packager/sources/new_test.go index 17d1481192..eb14403778 100644 --- a/src/pkg/packager/sources/new_test.go +++ b/src/pkg/packager/sources/new_test.go @@ -93,7 +93,7 @@ func TestNewPackageSource(t *testing.T) { t.Parallel() require.Equal(t, tt.expectedIdentify, Identify(tt.src)) - ps, err := New(&types.ZarfPackageOptions{PackageSource: tt.src}) + ps, err := New(context.Background(), &types.ZarfPackageOptions{PackageSource: tt.src}) require.NoError(t, err) require.IsType(t, tt.expectedType, ps) }) @@ -166,8 +166,9 @@ func TestPackageSource(t *testing.T) { PackageSource: tt.src, Shasum: tt.shasum, } + ctx := context.Background() - ps, err := New(opts) + ps, err := New(ctx, opts) require.NoError(t, err) packageDir := t.TempDir() pkgLayout := layout.New(packageDir) @@ -180,7 +181,7 @@ func TestPackageSource(t *testing.T) { require.Empty(t, warnings) require.Equal(t, expectedPkg, pkg) - ps, err = New(opts) + ps, err = New(ctx, opts) require.NoError(t, err) metadataDir := t.TempDir() metadataLayout := layout.New(metadataDir) @@ -189,7 +190,7 @@ func TestPackageSource(t *testing.T) { require.Empty(t, warnings) require.Equal(t, expectedPkg, metadata) - ps, err = New(opts) + ps, err = New(ctx, opts) require.NoError(t, err) collectDir := t.TempDir() fp, err := ps.Collect(context.Background(), collectDir) diff --git a/src/pkg/packager/sources/tarball.go b/src/pkg/packager/sources/tarball.go index 5b556f78e1..b7a00dc159 100644 --- a/src/pkg/packager/sources/tarball.go +++ b/src/pkg/packager/sources/tarball.go @@ -12,11 +12,13 @@ import ( "io" "os" "path/filepath" + "time" "github.com/defenseunicorns/pkg/helpers/v2" "github.com/mholt/archiver/v3" "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/pkg/zoci" @@ -35,8 +37,11 @@ type TarballSource struct { // LoadPackage loads a package from a tarball. func (s *TarballSource) LoadPackage(ctx context.Context, dst *layout.PackagePaths, filter filters.ComponentFilterStrategy, unarchiveAll bool) (pkg v1alpha1.ZarfPackage, warnings []string, err error) { + l := logger.From(ctx) spinner := message.NewProgressSpinner("Loading package from %q", s.PackageSource) defer spinner.Stop() + start := time.Now() + l.Info("loading package", "source", s.PackageSource) if s.Shasum != "" { if err := helpers.SHAsMatch(s.PackageSource, s.Shasum); err != nil { @@ -100,12 +105,14 @@ func (s *TarballSource) LoadPackage(ctx context.Context, dst *layout.PackagePath if !dst.IsLegacyLayout() { spinner := message.NewProgressSpinner("Validating full package checksums") defer spinner.Stop() + l.Info("validating package checksums", "source", s.PackageSource) if err := ValidatePackageIntegrity(dst, pkg.Metadata.AggregateChecksum, false); err != nil { return pkg, nil, err } spinner.Success() + l.Debug("done validating package checksums", "source", s.PackageSource) if !s.SkipSignatureValidation { if err := ValidatePackageSignature(ctx, dst, s.PublicKeyPath); err != nil { @@ -136,6 +143,7 @@ func (s *TarballSource) LoadPackage(ctx context.Context, dst *layout.PackagePath } spinner.Success() + l.Debug("done loading package", "source", s.PackageSource, "duration", time.Since(start)) return pkg, warnings, nil } diff --git a/src/pkg/zoci/common.go b/src/pkg/zoci/common.go index 29e9f34564..ab8f92f3bf 100644 --- a/src/pkg/zoci/common.go +++ b/src/pkg/zoci/common.go @@ -5,11 +5,13 @@ package zoci import ( + "context" "log/slog" "github.com/defenseunicorns/pkg/oci" ocispec "github.com/opencontainers/image-spec/specs-go/v1" "github.com/zarf-dev/zarf/src/config" + "github.com/zarf-dev/zarf/src/pkg/logger" "github.com/zarf-dev/zarf/src/pkg/message" ) @@ -29,12 +31,15 @@ type Remote struct { // NewRemote returns an oras remote repository client and context for the given url // with zarf opination embedded -func NewRemote(url string, platform ocispec.Platform, mods ...oci.Modifier) (*Remote, error) { - logger := slog.New(message.ZarfHandler{}) +func NewRemote(ctx context.Context, url string, platform ocispec.Platform, mods ...oci.Modifier) (*Remote, error) { + l := slog.New(message.ZarfHandler{}) + if logger.Enabled(ctx) { + l = logger.From(ctx) + } modifiers := append([]oci.Modifier{ oci.WithPlainHTTP(config.CommonOptions.PlainHTTP), oci.WithInsecureSkipVerify(config.CommonOptions.InsecureSkipTLSVerify), - oci.WithLogger(logger), + oci.WithLogger(l), oci.WithUserAgent("zarf/" + config.CLIVersion), }, mods...) remote, err := oci.NewOrasRemote(url, platform, modifiers...) diff --git a/src/test/e2e/14_oci_compose_test.go b/src/test/e2e/14_oci_compose_test.go index 6a983c7fc3..3f8c0a452b 100644 --- a/src/test/e2e/14_oci_compose_test.go +++ b/src/test/e2e/14_oci_compose_test.go @@ -189,18 +189,18 @@ func (suite *PublishCopySkeletonSuite) Test_3_Copy() { dstRegistry := testutil.SetupInMemoryRegistry(testutil.TestContext(t), t, 31890) dstRef := strings.Replace(ref, suite.Reference.Registry, dstRegistry, 1) + ctx := testutil.TestContext(t) - src, err := zoci.NewRemote(ref, oci.PlatformForArch(e2e.Arch), oci.WithPlainHTTP(true)) + src, err := zoci.NewRemote(ctx, ref, oci.PlatformForArch(e2e.Arch), oci.WithPlainHTTP(true)) suite.NoError(err) - dst, err := zoci.NewRemote(dstRef, oci.PlatformForArch(e2e.Arch), oci.WithPlainHTTP(true)) + dst, err := zoci.NewRemote(ctx, dstRef, oci.PlatformForArch(e2e.Arch), oci.WithPlainHTTP(true)) suite.NoError(err) reg, err := remote.NewRegistry(strings.Split(dstRef, "/")[0]) suite.NoError(err) reg.PlainHTTP = true attempt := 0 - ctx := testutil.TestContext(t) for attempt <= 5 { err = reg.Ping(ctx) if err == nil {