Skip to content

Commit 6069873

Browse files
authored
fix: configure the global logger for argo-cd utilities (#1322)
Signed-off-by: dkarpele <karpelevich@gmail.com>
1 parent 5ed9f6d commit 6069873

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed

cmd/run.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ import (
2323
"github.com/argoproj-labs/argocd-image-updater/registry-scanner/pkg/registry"
2424

2525
"github.com/argoproj/argo-cd/v3/util/askpass"
26+
argocdlog "github.com/argoproj/argo-cd/v3/util/log"
2627

28+
"github.com/sirupsen/logrus"
2729
"github.com/spf13/cobra"
2830

2931
"golang.org/x/sync/semaphore"
@@ -47,6 +49,14 @@ func newRunCommand() *cobra.Command {
4749
Use: "run",
4850
Short: "Runs the argocd-image-updater with a set of options",
4951
RunE: func(cmd *cobra.Command, args []string) error {
52+
// Configure the global logger for vendored argo-cd utilities
53+
logLvl, err := logrus.ParseLevel(cfg.LogLevel)
54+
if err != nil {
55+
return fmt.Errorf("could not parse log level: %w", err)
56+
}
57+
logrus.SetLevel(logLvl)
58+
logrus.SetFormatter(argocdlog.CreateFormatter(cfg.LogFormat))
59+
5060
if err := log.SetLogLevel(cfg.LogLevel); err != nil {
5161
return err
5262
}
@@ -126,7 +136,6 @@ func newRunCommand() *cobra.Command {
126136
log.Warnf("Check interval is very low - it is not recommended to run below 1m0s")
127137
}
128138

129-
var err error
130139
if !disableKubernetes {
131140
ctx := context.Background()
132141
cfg.KubeClient, err = getKubeConfig(ctx, cfg.ArgocdNamespace, kubeConfig)

ext/git/client.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import (
2424
githttp "github.com/go-git/go-git/v5/plumbing/transport/http"
2525
"github.com/go-git/go-git/v5/storage/memory"
2626
"github.com/google/uuid"
27-
log "github.com/sirupsen/logrus"
2827
"golang.org/x/crypto/ssh"
2928
"golang.org/x/crypto/ssh/knownhosts"
3029
apierrors "k8s.io/apimachinery/pkg/api/errors"
@@ -35,6 +34,8 @@ import (
3534
"github.com/argoproj/argo-cd/v3/util/env"
3635
executil "github.com/argoproj/argo-cd/v3/util/exec"
3736
"github.com/argoproj/argo-cd/v3/util/proxy"
37+
38+
"github.com/argoproj-labs/argocd-image-updater/registry-scanner/pkg/log"
3839
)
3940

4041
var ErrInvalidRepoURL = fmt.Errorf("repo URL is invalid")
@@ -489,7 +490,7 @@ func (m *nativeGitClient) getRefs() ([]*plumbing.Reference, error) {
489490
myLockUUID, err := uuid.NewRandom()
490491
myLockId := ""
491492
if err != nil {
492-
log.Debug("Error generating git references cache lock id: ", err)
493+
log.Debugf("Error generating git references cache lock id: %v", err)
493494
} else {
494495
myLockId = myLockUUID.String()
495496
}

ext/git/creds.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,12 @@ import (
2222
argoio "github.com/argoproj/gitops-engine/pkg/utils/io"
2323
"github.com/argoproj/gitops-engine/pkg/utils/text"
2424
"github.com/bradleyfalzon/ghinstallation/v2"
25-
log "github.com/sirupsen/logrus"
2625

2726
"github.com/argoproj/argo-cd/v3/common"
2827
certutil "github.com/argoproj/argo-cd/v3/util/cert"
2928
argoioutils "github.com/argoproj/argo-cd/v3/util/io"
29+
30+
"github.com/argoproj-labs/argocd-image-updater/registry-scanner/pkg/log"
3031
)
3132

3233
var (
@@ -286,10 +287,10 @@ func (c SSHCreds) Environ() (io.Closer, []string, error) {
286287
}
287288
defer func() {
288289
if err = file.Close(); err != nil {
289-
log.WithFields(log.Fields{
290-
common.SecurityField: common.SecurityMedium,
291-
common.SecurityCWEField: common.SecurityCWEMissingReleaseOfFileDescriptor,
292-
}).Errorf("error closing file %q: %v", file.Name(), err)
290+
log.WithContext().
291+
AddField(common.SecurityField, common.SecurityMedium).
292+
AddField(common.SecurityCWEField, common.SecurityCWEMissingReleaseOfFileDescriptor).
293+
Errorf("error closing file %q: %v", file.Name(), err)
293294
}
294295
}()
295296

@@ -304,7 +305,7 @@ func (c SSHCreds) Environ() (io.Closer, []string, error) {
304305
env = append(env, fmt.Sprintf("GIT_SSL_CAINFO=%s", c.caPath))
305306
}
306307
if c.insecure {
307-
log.Warn("temporarily disabling strict host key checking (i.e. '-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null'), please don't use in production")
308+
log.Warnf("temporarily disabling strict host key checking (i.e. '-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null'), please don't use in production")
308309
// StrictHostKeyChecking will add the host to the knownhosts file, we don't want that - a security issue really,
309310
// UserKnownHostsFile=/dev/null is therefore used so we write the new insecure host to /dev/null
310311
args = append(args, "-o", "StrictHostKeyChecking=no", "-o", "UserKnownHostsFile=/dev/null")

0 commit comments

Comments
 (0)