From 8d1316f77eb80c99f0999705fd180c0f5b638bb0 Mon Sep 17 00:00:00 2001 From: dkarpele Date: Wed, 5 Nov 2025 18:49:29 +0100 Subject: [PATCH] fix: configure the global logger for argo-cd utilities Signed-off-by: dkarpele --- cmd/run.go | 11 ++++++++++- ext/git/client.go | 5 +++-- ext/git/creds.go | 13 +++++++------ 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/cmd/run.go b/cmd/run.go index dc54625a..22644bba 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -23,7 +23,9 @@ import ( "github.com/argoproj-labs/argocd-image-updater/registry-scanner/pkg/registry" "github.com/argoproj/argo-cd/v3/util/askpass" + argocdlog "github.com/argoproj/argo-cd/v3/util/log" + "github.com/sirupsen/logrus" "github.com/spf13/cobra" "golang.org/x/sync/semaphore" @@ -47,6 +49,14 @@ func newRunCommand() *cobra.Command { Use: "run", Short: "Runs the argocd-image-updater with a set of options", RunE: func(cmd *cobra.Command, args []string) error { + // Configure the global logger for vendored argo-cd utilities + logLvl, err := logrus.ParseLevel(cfg.LogLevel) + if err != nil { + return fmt.Errorf("could not parse log level: %w", err) + } + logrus.SetLevel(logLvl) + logrus.SetFormatter(argocdlog.CreateFormatter(cfg.LogFormat)) + if err := log.SetLogLevel(cfg.LogLevel); err != nil { return err } @@ -126,7 +136,6 @@ func newRunCommand() *cobra.Command { log.Warnf("Check interval is very low - it is not recommended to run below 1m0s") } - var err error if !disableKubernetes { ctx := context.Background() cfg.KubeClient, err = getKubeConfig(ctx, cfg.ArgocdNamespace, kubeConfig) diff --git a/ext/git/client.go b/ext/git/client.go index b0f98b01..20958eb0 100644 --- a/ext/git/client.go +++ b/ext/git/client.go @@ -24,7 +24,6 @@ import ( githttp "github.com/go-git/go-git/v5/plumbing/transport/http" "github.com/go-git/go-git/v5/storage/memory" "github.com/google/uuid" - log "github.com/sirupsen/logrus" "golang.org/x/crypto/ssh" "golang.org/x/crypto/ssh/knownhosts" apierrors "k8s.io/apimachinery/pkg/api/errors" @@ -35,6 +34,8 @@ import ( "github.com/argoproj/argo-cd/v3/util/env" executil "github.com/argoproj/argo-cd/v3/util/exec" "github.com/argoproj/argo-cd/v3/util/proxy" + + "github.com/argoproj-labs/argocd-image-updater/registry-scanner/pkg/log" ) var ErrInvalidRepoURL = fmt.Errorf("repo URL is invalid") @@ -489,7 +490,7 @@ func (m *nativeGitClient) getRefs() ([]*plumbing.Reference, error) { myLockUUID, err := uuid.NewRandom() myLockId := "" if err != nil { - log.Debug("Error generating git references cache lock id: ", err) + log.Debugf("Error generating git references cache lock id: %v", err) } else { myLockId = myLockUUID.String() } diff --git a/ext/git/creds.go b/ext/git/creds.go index c849404f..602e66d9 100644 --- a/ext/git/creds.go +++ b/ext/git/creds.go @@ -22,11 +22,12 @@ import ( argoio "github.com/argoproj/gitops-engine/pkg/utils/io" "github.com/argoproj/gitops-engine/pkg/utils/text" "github.com/bradleyfalzon/ghinstallation/v2" - log "github.com/sirupsen/logrus" "github.com/argoproj/argo-cd/v3/common" certutil "github.com/argoproj/argo-cd/v3/util/cert" argoioutils "github.com/argoproj/argo-cd/v3/util/io" + + "github.com/argoproj-labs/argocd-image-updater/registry-scanner/pkg/log" ) var ( @@ -286,10 +287,10 @@ func (c SSHCreds) Environ() (io.Closer, []string, error) { } defer func() { if err = file.Close(); err != nil { - log.WithFields(log.Fields{ - common.SecurityField: common.SecurityMedium, - common.SecurityCWEField: common.SecurityCWEMissingReleaseOfFileDescriptor, - }).Errorf("error closing file %q: %v", file.Name(), err) + log.WithContext(). + AddField(common.SecurityField, common.SecurityMedium). + AddField(common.SecurityCWEField, common.SecurityCWEMissingReleaseOfFileDescriptor). + Errorf("error closing file %q: %v", file.Name(), err) } }() @@ -304,7 +305,7 @@ func (c SSHCreds) Environ() (io.Closer, []string, error) { env = append(env, fmt.Sprintf("GIT_SSL_CAINFO=%s", c.caPath)) } if c.insecure { - log.Warn("temporarily disabling strict host key checking (i.e. '-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null'), please don't use in production") + log.Warnf("temporarily disabling strict host key checking (i.e. '-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null'), please don't use in production") // StrictHostKeyChecking will add the host to the knownhosts file, we don't want that - a security issue really, // UserKnownHostsFile=/dev/null is therefore used so we write the new insecure host to /dev/null args = append(args, "-o", "StrictHostKeyChecking=no", "-o", "UserKnownHostsFile=/dev/null")