Skip to content

Commit

Permalink
refactor: remove overly verbose debug logs (#2751)
Browse files Browse the repository at this point in the history
Signed-off-by: Philip Laine <[email protected]>
  • Loading branch information
phillebaba authored Jul 25, 2024
1 parent 70e8b8d commit a93d65a
Show file tree
Hide file tree
Showing 21 changed files with 9 additions and 76 deletions.
2 changes: 0 additions & 2 deletions src/internal/agent/hooks/argocd-application.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 0 additions & 3 deletions src/internal/agent/http/admission/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 0 additions & 5 deletions src/internal/agent/http/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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())
Expand Down
3 changes: 0 additions & 3 deletions src/internal/agent/operations/hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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)
Expand Down
6 changes: 0 additions & 6 deletions src/internal/packager/git/checkout.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
Expand All @@ -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)
Expand All @@ -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)
Expand Down
10 changes: 0 additions & 10 deletions src/internal/packager/git/gitea.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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",
Expand Down
10 changes: 2 additions & 8 deletions src/internal/packager/helm/chart.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)
Expand All @@ -88,7 +87,6 @@ func (h *Helm) InstallOrUpgradeChart(ctx context.Context) (types.ConnectStrings,
return err
}

message.Debug(output.Info.Description)
spinner.Success()
return nil
}
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
2 changes: 0 additions & 2 deletions src/internal/packager/helm/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 0 additions & 2 deletions src/internal/packager/helm/post-render.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{},
Expand Down
2 changes: 0 additions & 2 deletions src/internal/packager/images/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 0 additions & 2 deletions src/pkg/cluster/tunnel.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
16 changes: 4 additions & 12 deletions src/pkg/packager/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions src/pkg/packager/creator/compose.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 0 additions & 2 deletions src/pkg/packager/creator/normal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 0 additions & 2 deletions src/pkg/packager/creator/skeleton.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
3 changes: 1 addition & 2 deletions src/pkg/packager/prepare.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...)

Expand Down
3 changes: 0 additions & 3 deletions src/pkg/packager/sources/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
2 changes: 0 additions & 2 deletions src/pkg/packager/sources/oci.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 0 additions & 5 deletions src/pkg/utils/io.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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
}

Expand Down
1 change: 0 additions & 1 deletion src/pkg/utils/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions src/test/e2e/00_use_cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()
Expand Down

0 comments on commit a93d65a

Please sign in to comment.