Skip to content

Commit 10b66f1

Browse files
authored
Merge branch 'master' into feat/update-behavior
2 parents 1c809f1 + 889af4b commit 10b66f1

File tree

2 files changed

+33
-13
lines changed

2 files changed

+33
-13
lines changed

pkg/argocd/update.go

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -291,18 +291,7 @@ func UpdateApplication(updateConf *UpdateConfiguration, state *SyncIterationStat
291291
continue
292292
}
293293

294-
// If the user has specified digest as update strategy, but the running
295-
// image is configured to use a tag and no digest, we need to set an
296-
// initial dummy digest, so that tag.Equals() will return false.
297-
// TODO: Fix this. This is just a workaround.
298-
if vc.Strategy == image.StrategyDigest {
299-
if !updateableImage.ImageTag.IsDigest() {
300-
log.Tracef("Setting dummy digest for image %s", updateableImage.GetFullNameWithTag())
301-
updateableImage.ImageTag.TagDigest = "dummy"
302-
}
303-
}
304-
305-
if needsUpdate(updateableImage, applicationImage, latest) {
294+
if needsUpdate(updateableImage, applicationImage, latest, vc.Strategy) {
306295
appImageWithTag := applicationImage.WithTag(latest)
307296
appImageFullNameWithTag := appImageWithTag.GetFullNameWithTag()
308297

@@ -406,7 +395,17 @@ func UpdateApplication(updateConf *UpdateConfiguration, state *SyncIterationStat
406395
return result
407396
}
408397

409-
func needsUpdate(updateableImage *image.ContainerImage, applicationImage *image.ContainerImage, latest *tag.ImageTag) bool {
398+
func needsUpdate(updateableImage *image.ContainerImage, applicationImage *image.ContainerImage, latest *tag.ImageTag, strategy image.UpdateStrategy) bool {
399+
if strategy == image.StrategyDigest {
400+
if updateableImage.ImageTag == nil {
401+
return true
402+
}
403+
// When using digest strategy, consider the digest even if the current image
404+
// was referenced by tag. If either digest is missing or differs, we want an update.
405+
if !updateableImage.ImageTag.IsDigest() || updateableImage.ImageTag.TagDigest != latest.TagDigest {
406+
return true
407+
}
408+
}
410409
// If the latest tag does not match image's current tag or the kustomize image is different, it means we have an update candidate.
411410
return !updateableImage.ImageTag.Equals(latest) || applicationImage.KustomizeImage != nil && applicationImage.DiffersFrom(updateableImage, false)
412411
}

registry-scanner/pkg/log/log.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ package log
99
// It might seem redundant, but we really want the different output streams.
1010

1111
import (
12+
"context"
1213
"fmt"
1314
"io"
1415
"os"
@@ -178,6 +179,26 @@ func disableLogColors() bool {
178179
return strings.ToLower(os.Getenv("ENABLE_LOG_COLORS")) == "false"
179180
}
180181

182+
// A private key type is used to prevent collisions with context keys from other packages.
183+
type loggerKey struct{}
184+
185+
// ContextWithLogger returns a new context.Context that carries the provided logrus Entry.
186+
// Use this to pass a contextual logger down through a call stack.
187+
func ContextWithLogger(ctx context.Context, logger *logrus.Entry) context.Context {
188+
return context.WithValue(ctx, loggerKey{}, logger)
189+
}
190+
191+
// LoggerFromContext retrieves the logrus Entry from the context.
192+
// If no logger is found in the context, it returns the global logger, ensuring
193+
// that a valid logger is always returned.
194+
func LoggerFromContext(ctx context.Context) *logrus.Entry {
195+
if logger, ok := ctx.Value(loggerKey{}).(*logrus.Entry); ok {
196+
return logger
197+
}
198+
// Fallback to the global logger if none is found in the context.
199+
return logrus.NewEntry(Log())
200+
}
201+
181202
// Initializes the logging subsystem with default values
182203
func init() {
183204
logger = logrus.New()

0 commit comments

Comments
 (0)