From 2c1f8bd59cb62a1c3951448e693987eb4cfef974 Mon Sep 17 00:00:00 2001 From: Philip Laine Date: Tue, 23 Jul 2024 12:00:05 +0200 Subject: [PATCH] refactor: remove overly verbose debug logs Signed-off-by: Philip Laine --- src/internal/agent/hooks/argocd-application.go | 2 -- src/internal/agent/http/admission/handler.go | 3 --- src/internal/agent/http/server.go | 5 ----- src/internal/agent/operations/hook.go | 3 --- src/internal/packager/git/checkout.go | 6 ------ src/internal/packager/git/gitea.go | 10 ---------- src/internal/packager/helm/chart.go | 10 ++-------- src/internal/packager/helm/images.go | 2 -- src/internal/packager/helm/post-render.go | 2 -- src/internal/packager/images/push.go | 2 -- src/pkg/cluster/tunnel.go | 2 -- src/pkg/packager/common.go | 16 ++++------------ src/pkg/packager/creator/compose.go | 2 -- src/pkg/packager/creator/normal.go | 2 -- src/pkg/packager/creator/skeleton.go | 2 -- src/pkg/packager/prepare.go | 3 +-- src/pkg/packager/sources/new.go | 3 --- src/pkg/packager/sources/oci.go | 2 -- src/pkg/utils/io.go | 5 ----- src/pkg/utils/network.go | 1 - src/test/e2e/00_use_cli_test.go | 2 ++ 21 files changed, 9 insertions(+), 76 deletions(-) diff --git a/src/internal/agent/hooks/argocd-application.go b/src/internal/agent/hooks/argocd-application.go index 8886ba2ff9..f9d3238aee 100644 --- a/src/internal/agent/hooks/argocd-application.go +++ b/src/internal/agent/hooks/argocd-application.go @@ -72,8 +72,6 @@ func mutateApplication(ctx context.Context, r *v1.AdmissionRequest, cluster *clu return nil, fmt.Errorf(lang.ErrUnmarshal, err) } - message.Debugf("Data %v", string(r.Object.Raw)) - patches := []operations.PatchOperation{} if app.Spec.Source != nil { diff --git a/src/internal/agent/http/admission/handler.go b/src/internal/agent/http/admission/handler.go index 56589a7c73..4b4d69323b 100644 --- a/src/internal/agent/http/admission/handler.go +++ b/src/internal/agent/http/admission/handler.go @@ -117,9 +117,6 @@ func (h *Handler) Serve(hook operations.Hook) http.HandlerFunc { return } - message.Debug("PATCH: ", string(admissionResponse.Response.Patch)) - message.Debug("RESPONSE: ", string(jsonResponse)) - message.Infof(lang.AgentInfoWebhookAllowed, r.URL.Path, review.Request.Operation, result.Allowed) w.WriteHeader(http.StatusOK) //nolint: errcheck // ignore diff --git a/src/internal/agent/http/server.go b/src/internal/agent/http/server.go index b5953ee0e2..6a79aaa449 100644 --- a/src/internal/agent/http/server.go +++ b/src/internal/agent/http/server.go @@ -14,13 +14,10 @@ import ( "github.com/zarf-dev/zarf/src/internal/agent/hooks" "github.com/zarf-dev/zarf/src/internal/agent/http/admission" "github.com/zarf-dev/zarf/src/pkg/cluster" - "github.com/zarf-dev/zarf/src/pkg/message" ) // NewAdmissionServer creates a http.Server for the mutating webhook admission handler. func NewAdmissionServer(ctx context.Context, port string) (*http.Server, error) { - message.Debugf("http.NewAdmissionServer(%s)", port) - c, err := cluster.NewCluster() if err != nil { return nil, err @@ -56,8 +53,6 @@ func NewAdmissionServer(ctx context.Context, port string) (*http.Server, error) // NewProxyServer creates and returns an http proxy server. func NewProxyServer(port string) *http.Server { - message.Debugf("http.NewHTTPProxy(%s)", port) - mux := http.NewServeMux() mux.Handle("/healthz", healthz()) mux.Handle("/", ProxyHandler()) diff --git a/src/internal/agent/operations/hook.go b/src/internal/agent/operations/hook.go index 627ce58094..8c411adee7 100644 --- a/src/internal/agent/operations/hook.go +++ b/src/internal/agent/operations/hook.go @@ -8,7 +8,6 @@ import ( "fmt" "github.com/zarf-dev/zarf/src/config/lang" - "github.com/zarf-dev/zarf/src/pkg/message" admission "k8s.io/api/admission/v1" ) @@ -32,8 +31,6 @@ type Hook struct { // Execute evaluates the request and try to execute the function for operation specified in the request. func (h *Hook) Execute(r *admission.AdmissionRequest) (*Result, error) { - message.Debugf("operations.Execute(*admission.AdmissionRequest) - %#v , %s/%s: %#v", r.Kind, r.Namespace, r.Name, r.Operation) - switch r.Operation { case admission.Create: return wrapperExecution(h.Create, r) diff --git a/src/internal/packager/git/checkout.go b/src/internal/packager/git/checkout.go index 4441e48873..2ee91d96b5 100644 --- a/src/internal/packager/git/checkout.go +++ b/src/internal/packager/git/checkout.go @@ -15,8 +15,6 @@ import ( // CheckoutTag performs a `git checkout` of the provided tag to a detached HEAD. func (g *Git) CheckoutTag(tag string) error { - message.Debugf("git checkout tag %s", tag) - options := &git.CheckoutOptions{ Branch: ParseRef(tag), } @@ -35,8 +33,6 @@ func (g *Git) checkoutRefAsBranch(ref string, branch plumbing.ReferenceName) err // than checking out to a detached head, checks out to the provided branch ref // It will delete the branch provided if it exists. func (g *Git) checkoutTagAsBranch(tag string, branch plumbing.ReferenceName) error { - message.Debugf("git checkout tag %s on %s", tag, branch) - repo, err := git.PlainOpen(g.GitPath) if err != nil { return fmt.Errorf("not a valid git repo or unable to open: %w", err) @@ -54,8 +50,6 @@ func (g *Git) checkoutTagAsBranch(tag string, branch plumbing.ReferenceName) err // with the provided hash // It will delete the branch provided if it exists. func (g *Git) checkoutHashAsBranch(hash plumbing.Hash, branch plumbing.ReferenceName) error { - message.Debugf("git checkout hash %s on %s", hash, branch) - repo, err := git.PlainOpen(g.GitPath) if err != nil { return fmt.Errorf("not a valid git repo or unable to open: %w", err) diff --git a/src/internal/packager/git/gitea.go b/src/internal/packager/git/gitea.go index 4bfbcf60ab..a6715d29d5 100644 --- a/src/internal/packager/git/gitea.go +++ b/src/internal/packager/git/gitea.go @@ -32,8 +32,6 @@ type CreateTokenResponse struct { // CreateReadOnlyUser uses the Gitea API to create a non-admin Zarf user. func (g *Git) CreateReadOnlyUser(ctx context.Context) error { - message.Debugf("git.CreateReadOnlyUser()") - c, err := cluster.NewCluster() if err != nil { return err @@ -119,8 +117,6 @@ func (g *Git) UpdateZarfGiteaUsers(ctx context.Context, oldState *types.ZarfStat // UpdateGitUser updates Zarf git server users func (g *Git) UpdateGitUser(ctx context.Context, oldAdminPass string, username string, userpass string) error { - message.Debugf("git.UpdateGitUser()") - c, err := cluster.NewCluster() if err != nil { return err @@ -157,8 +153,6 @@ func (g *Git) UpdateGitUser(ctx context.Context, oldAdminPass string, username s // CreatePackageRegistryToken uses the Gitea API to create a package registry token. func (g *Git) CreatePackageRegistryToken(ctx context.Context) (CreateTokenResponse, error) { - message.Debugf("git.CreatePackageRegistryToken()") - c, err := cluster.NewCluster() if err != nil { return CreateTokenResponse{}, err @@ -287,8 +281,6 @@ func UpdateGiteaPVC(ctx context.Context, shouldRollBack bool) (string, error) { // DoHTTPThings adds http request boilerplate and perform the request, checking for a successful response. func (g *Git) DoHTTPThings(request *netHttp.Request, username, secret string) ([]byte, int, error) { - message.Debugf("git.DoHttpThings()") - // Prep the request with boilerplate client := &netHttp.Client{Timeout: time.Second * 20} request.SetBasicAuth(username, secret) @@ -312,8 +304,6 @@ func (g *Git) DoHTTPThings(request *netHttp.Request, username, secret string) ([ } func (g *Git) addReadOnlyUserToRepo(tunnelURL, repo string) error { - message.Debugf("git.addReadOnlyUserToRepo()") - // Add the readonly user to the repo addCollabBody := map[string]string{ "permission": "read", diff --git a/src/internal/packager/helm/chart.go b/src/internal/packager/helm/chart.go index 0bd483df7f..bca8773294 100644 --- a/src/internal/packager/helm/chart.go +++ b/src/internal/packager/helm/chart.go @@ -61,7 +61,6 @@ func (h *Helm) InstallOrUpgradeChart(ctx context.Context) (types.ConnectStrings, histClient := action.NewHistory(h.actionConfig) tryHelm := func() error { var err error - var output *release.Release releases, histErr := histClient.Run(h.chart.ReleaseName) @@ -71,14 +70,14 @@ func (h *Helm) InstallOrUpgradeChart(ctx context.Context) (types.ConnectStrings, // No prior release, try to install it. spinner.Updatef("Attempting chart installation") - output, err = h.installChart(postRender) + _, err = h.installChart(postRender) } else if histErr == nil && len(releases) > 0 { // Otherwise, there is a prior release so upgrade it. spinner.Updatef("Attempting chart upgrade") lastRelease := releases[len(releases)-1] - output, err = h.upgradeChart(lastRelease, postRender) + _, err = h.upgradeChart(lastRelease, postRender) } else { // 😭 things aren't working return fmt.Errorf("unable to verify the chart installation status: %w", histErr) @@ -88,7 +87,6 @@ func (h *Helm) InstallOrUpgradeChart(ctx context.Context) (types.ConnectStrings, return err } - message.Debug(output.Info.Description) spinner.Success() return nil } @@ -128,7 +126,6 @@ func (h *Helm) InstallOrUpgradeChart(ctx context.Context) (types.ConnectStrings, // TemplateChart generates a helm template from a given chart. func (h *Helm) TemplateChart(ctx context.Context) (manifest string, chartValues chartutil.Values, err error) { - message.Debugf("helm.TemplateChart()") spinner := message.NewProgressSpinner("Templating helm chart %s", h.chart.Name) defer spinner.Stop() @@ -324,7 +321,6 @@ func (h *Helm) upgradeChart(lastRelease *release.Release, postRender *renderer) } func (h *Helm) rollbackChart(name string, version int) error { - message.Debugf("helm.rollbackChart(%s)", name) client := action.NewRollback(h.actionConfig) client.CleanupOnFail = true client.Force = true @@ -335,7 +331,6 @@ func (h *Helm) rollbackChart(name string, version int) error { } func (h *Helm) uninstallChart(name string) (*release.UninstallReleaseResponse, error) { - message.Debugf("helm.uninstallChart(%s)", name) client := action.NewUninstall(h.actionConfig) client.KeepHistory = false client.Wait = true @@ -344,7 +339,6 @@ func (h *Helm) uninstallChart(name string) (*release.UninstallReleaseResponse, e } func (h *Helm) loadChartData() (*chart.Chart, chartutil.Values, error) { - message.Debugf("helm.loadChartData()") var ( loadedChart *chart.Chart chartValues chartutil.Values diff --git a/src/internal/packager/helm/images.go b/src/internal/packager/helm/images.go index 390ce5c8be..b5399f2590 100644 --- a/src/internal/packager/helm/images.go +++ b/src/internal/packager/helm/images.go @@ -6,7 +6,6 @@ package helm import ( "github.com/defenseunicorns/pkg/helpers/v2" "github.com/goccy/go-yaml" - "github.com/zarf-dev/zarf/src/pkg/message" "helm.sh/helm/v3/pkg/chart/loader" "helm.sh/helm/v3/pkg/chartutil" ) @@ -45,7 +44,6 @@ func FindAnnotatedImagesForChart(chartPath string, values chartutil.Values) (ima // Only include the image if the current values/condition specify it should be included if i.Condition != "" { value, err := values.PathValue(i.Condition) - message.Debugf("%#v - %#v - %#v\n", value, i.Condition, err) // We intentionally ignore the error here because the key could be missing from the values.yaml if err == nil && value == true { images = append(images, i.Image) diff --git a/src/internal/packager/helm/post-render.go b/src/internal/packager/helm/post-render.go index 60d8fde0e3..b115b33ddf 100644 --- a/src/internal/packager/helm/post-render.go +++ b/src/internal/packager/helm/post-render.go @@ -38,8 +38,6 @@ type renderer struct { } func (h *Helm) newRenderer(ctx context.Context) (*renderer, error) { - message.Debugf("helm.NewRenderer()") - rend := &renderer{ Helm: h, connectStrings: types.ConnectStrings{}, diff --git a/src/internal/packager/images/push.go b/src/internal/packager/images/push.go index 08625ab385..0d0752f9fe 100644 --- a/src/internal/packager/images/push.go +++ b/src/internal/packager/images/push.go @@ -99,8 +99,6 @@ func Push(ctx context.Context, cfg PushConfig) error { return err } - message.Debugf("push %s -> %s)", refInfo.Reference, offlineNameCRC) - if err = pushImage(img, offlineNameCRC); err != nil { return err } diff --git a/src/pkg/cluster/tunnel.go b/src/pkg/cluster/tunnel.go index f0a1a660e0..719d81e008 100644 --- a/src/pkg/cluster/tunnel.go +++ b/src/pkg/cluster/tunnel.go @@ -185,8 +185,6 @@ func (c *Cluster) checkForZarfConnectLabel(ctx context.Context, name string) (Tu var err error var zt TunnelInfo - message.Debugf("Looking for a Zarf Connect Label in the cluster") - selector, err := metav1.LabelSelectorAsSelector(&metav1.LabelSelector{ MatchLabels: map[string]string{ ZarfConnectLabelName: name, diff --git a/src/pkg/packager/common.go b/src/pkg/packager/common.go index a5b77ff9d1..a753ec29d4 100644 --- a/src/pkg/packager/common.go +++ b/src/pkg/packager/common.go @@ -107,25 +107,17 @@ func New(cfg *types.PackagerConfig, mods ...Modifier) (*Packager, error) { // If the temp directory is not set, set it to the default if pkgr.layout == nil { - if err = pkgr.setTempDirectory(config.CommonOptions.TempDirectory); err != nil { + dir, err := utils.MakeTempDir(config.CommonOptions.TempDirectory) + if err != nil { return nil, fmt.Errorf("unable to create package temp paths: %w", err) } + message.Debug("Using temporary directory:", dir) + pkgr.layout = layout.New(dir) } return pkgr, nil } -// setTempDirectory sets the temp directory for the packager. -func (p *Packager) setTempDirectory(path string) error { - dir, err := utils.MakeTempDir(path) - if err != nil { - return fmt.Errorf("unable to create package temp paths: %w", err) - } - - p.layout = layout.New(dir) - return nil -} - // ClearTempPaths removes the temp directory and any files within it. func (p *Packager) ClearTempPaths() { // Remove the temp directory, but don't throw an error if it fails diff --git a/src/pkg/packager/creator/compose.go b/src/pkg/packager/creator/compose.go index 8844c0305f..bbd1325b31 100644 --- a/src/pkg/packager/creator/compose.go +++ b/src/pkg/packager/creator/compose.go @@ -7,7 +7,6 @@ package creator import ( "context" - "github.com/zarf-dev/zarf/src/pkg/message" "github.com/zarf-dev/zarf/src/pkg/packager/composer" "github.com/zarf-dev/zarf/src/types" ) @@ -37,7 +36,6 @@ func ComposeComponents(ctx context.Context, pkg types.ZarfPackage, flavor string if err != nil { return types.ZarfPackage{}, nil, err } - message.Debugf("%s", chain) // migrate any deprecated component configurations now warning := chain.Migrate(pkg.Build) diff --git a/src/pkg/packager/creator/normal.go b/src/pkg/packager/creator/normal.go index 6f42c55865..99b0f572b4 100644 --- a/src/pkg/packager/creator/normal.go +++ b/src/pkg/packager/creator/normal.go @@ -372,8 +372,6 @@ func (pc *PackageCreator) addComponent(ctx context.Context, component types.Zarf } for filesIdx, file := range component.Files { - message.Debugf("Loading %#v", file) - rel := filepath.Join(layout.FilesDir, strconv.Itoa(filesIdx), filepath.Base(file.Target)) dst := filepath.Join(componentPaths.Base, rel) destinationDir := filepath.Dir(dst) diff --git a/src/pkg/packager/creator/skeleton.go b/src/pkg/packager/creator/skeleton.go index 9ddf24379a..c7b2d3d706 100644 --- a/src/pkg/packager/creator/skeleton.go +++ b/src/pkg/packager/creator/skeleton.go @@ -209,8 +209,6 @@ func (sc *SkeletonCreator) addComponent(component types.ZarfComponent, dst *layo } for filesIdx, file := range component.Files { - message.Debugf("Loading %#v", file) - if helpers.IsURL(file.Source) { continue } diff --git a/src/pkg/packager/prepare.go b/src/pkg/packager/prepare.go index 0ca1f35f91..a52cc9c0f4 100644 --- a/src/pkg/packager/prepare.go +++ b/src/pkg/packager/prepare.go @@ -255,8 +255,7 @@ func (p *Packager) findImages(ctx context.Context) (imgMap map[string][]string, } // Break the manifest into separate resources - contentString := string(contents) - message.Debugf("%s", contentString) + // TODO: Do not dogsled error yamls, _ := utils.SplitYAML(contents) resources = append(resources, yamls...) diff --git a/src/pkg/packager/sources/new.go b/src/pkg/packager/sources/new.go index 9018632085..4d43cc229c 100644 --- a/src/pkg/packager/sources/new.go +++ b/src/pkg/packager/sources/new.go @@ -14,7 +14,6 @@ import ( "github.com/defenseunicorns/pkg/oci" "github.com/zarf-dev/zarf/src/config" "github.com/zarf-dev/zarf/src/pkg/layout" - "github.com/zarf-dev/zarf/src/pkg/message" "github.com/zarf-dev/zarf/src/pkg/packager/filters" "github.com/zarf-dev/zarf/src/pkg/zoci" "github.com/zarf-dev/zarf/src/types" @@ -85,7 +84,5 @@ func New(pkgOpts *types.ZarfPackageOptions) (PackageSource, error) { return nil, fmt.Errorf("could not identify source type for %q", pkgSrc) } - message.Debugf("Using %T for %q", source, pkgSrc) - return source, nil } diff --git a/src/pkg/packager/sources/oci.go b/src/pkg/packager/sources/oci.go index 99a98137fc..33e4ba3fad 100644 --- a/src/pkg/packager/sources/oci.go +++ b/src/pkg/packager/sources/oci.go @@ -35,8 +35,6 @@ type OCISource struct { // LoadPackage loads a package from an OCI registry. func (s *OCISource) LoadPackage(ctx context.Context, dst *layout.PackagePaths, filter filters.ComponentFilterStrategy, unarchiveAll bool) (pkg types.ZarfPackage, warnings []string, err error) { - message.Debugf("Loading package from %q", s.PackageSource) - pkg, err = s.FetchZarfYAML(ctx) if err != nil { return pkg, nil, err diff --git a/src/pkg/utils/io.go b/src/pkg/utils/io.go index 06885d623a..7edee56422 100755 --- a/src/pkg/utils/io.go +++ b/src/pkg/utils/io.go @@ -11,7 +11,6 @@ import ( "github.com/defenseunicorns/pkg/helpers/v2" "github.com/zarf-dev/zarf/src/config" - "github.com/zarf-dev/zarf/src/pkg/message" ) const ( @@ -25,14 +24,10 @@ func MakeTempDir(basePath string) (string, error) { return "", err } } - tmp, err := os.MkdirTemp(basePath, tmpPathPrefix) if err != nil { return "", err } - - message.Debug("Using temporary directory:", tmp) - return tmp, nil } diff --git a/src/pkg/utils/network.go b/src/pkg/utils/network.go index 4bd6945f36..be0b80a2ed 100644 --- a/src/pkg/utils/network.go +++ b/src/pkg/utils/network.go @@ -40,7 +40,6 @@ func parseChecksum(src string) (string, string, error) { // DownloadToFile downloads a given URL to the target filepath (including the cosign key if necessary). func DownloadToFile(ctx context.Context, src string, dst string, cosignKeyPath string) (err error) { - message.Debugf("Downloading %s to %s", src, dst) // check if the parsed URL has a checksum // if so, remove it and use the checksum to validate the file src, checksum, err := parseChecksum(src) diff --git a/src/test/e2e/00_use_cli_test.go b/src/test/e2e/00_use_cli_test.go index ff8a07106b..b663d58454 100644 --- a/src/test/e2e/00_use_cli_test.go +++ b/src/test/e2e/00_use_cli_test.go @@ -143,6 +143,7 @@ func TestUseCLI(t *testing.T) { require.Greater(t, len(files), 1) }) + // TODO: Refactor test as it depends on debug log output for validation. t.Run("zarf package inspect with tmpdir", func(t *testing.T) { t.Parallel() path := fmt.Sprintf("build/zarf-package-component-actions-%s.tar.zst", e2e.Arch) @@ -152,6 +153,7 @@ func TestUseCLI(t *testing.T) { require.NoError(t, err, stdOut, stdErr) }) + // TODO: Refactor test as it depends on debug log output for validation. t.Run("zarf package deploy with tmpdir", func(t *testing.T) { t.Parallel() tmpdir := t.TempDir()