Skip to content

Commit bd70379

Browse files
authored
fixed logging output when adding images (#732)
1 parent 243671f commit bd70379

2 files changed

Lines changed: 11 additions & 10 deletions

File tree

cmd/hauler/cli/store/add.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ func storeLocalImage(ctx context.Context, s *store.Layout, i v1.Image, _ *flags.
389389
start := time.Now()
390390
ignoreErrors := flags.ShouldIgnoreErrors(ro)
391391

392-
l.Debugf("adding image [%s] from local Docker daemon to the store", i.Name)
392+
l.Debugf("resolving image [%s] from local Docker daemon (rewrite=%q)", i.Name, rewrite)
393393

394394
r, err := name.ParseReference(i.Name)
395395
if err != nil {
@@ -480,7 +480,10 @@ func storeImage(ctx context.Context, s *store.Layout, i v1.Image, platform strin
480480
return err
481481
}
482482

483-
log.BaseFromContext(ctx).Debugf("adding image [%s] to the store", i.Name)
483+
insecureSkipTLSVerify := derefInsecure(i.InsecureSkipTLSVerify)
484+
caFile := i.CaFile
485+
486+
log.BaseFromContext(ctx).Debugf("resolving image [%s] (verified=%t, platform=%q, excludeExtras=%t, insecureSkipTLSVerify=%t, caFile=%q, rewrite=%q, digest=%q)", i.Name, verified, platform, excludeExtras, insecureSkipTLSVerify, caFile, rewrite, pinnedDigest)
484487

485488
r, err := name.ParseReference(i.Name)
486489
if err != nil {
@@ -493,9 +496,6 @@ func storeImage(ctx context.Context, s *store.Layout, i v1.Image, platform strin
493496
}
494497
}
495498

496-
insecureSkipTLSVerify := derefInsecure(i.InsecureSkipTLSVerify)
497-
caFile := i.CaFile
498-
499499
// fetch image along with any associated signatures and attestations.
500500
// A fresh store.ImageStats is built inside the closure on every attempt,
501501
// not once outside it, so a failed attempt's partial layer/byte counts

cmd/hauler/cli/store/sync_test.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2033,7 +2033,7 @@ func TestSyncImages_ErrorPropagation(t *testing.T) {
20332033
// goroutine has fully returned (including cancelling gctx on failure), so
20342034
// jobs run strictly in slice order and the good jobs are guaranteed to
20352035
// observe the already-cancelled context before doing anything.
2036-
func TestRunImageJobs_CancelledJobsDoNotLogAddingImage(t *testing.T) {
2036+
func TestRunImageJobs_CancelledJobsDoNotLogResolvingImage(t *testing.T) {
20372037
host, remoteOpts := newTestRegistry(t)
20382038

20392039
const nGood = 3
@@ -2047,8 +2047,9 @@ func TestRunImageJobs_CancelledJobsDoNotLogAddingImage(t *testing.T) {
20472047

20482048
s := newTestStore(t)
20492049
var buf bytes.Buffer
2050-
// "adding image [...]" now logs at Debug (cmd/hauler/cli/store/add.go),
2051-
// so this test needs Debug-level output visible. Per-logger .Level() is
2050+
// "resolving image [...]" (storeImage's per-job startup line in
2051+
// cmd/hauler/cli/store/add.go) logs at Debug, so this test needs
2052+
// Debug-level output visible. Per-logger .Level() is
20522053
// not sufficient on its own: zerolog's Logger.should() gates on
20532054
// max(logger.level, zerolog.GlobalLevel()) -- and GlobalLevel is
20542055
// process-global state that other tests in this package mutate (e.g.
@@ -2073,9 +2074,9 @@ func TestRunImageJobs_CancelledJobsDoNotLogAddingImage(t *testing.T) {
20732074
t.Fatal("runImageJobs: expected error, got nil")
20742075
}
20752076

2076-
got := strings.Count(buf.String(), "adding image [")
2077+
got := strings.Count(buf.String(), "resolving image [")
20772078
if got != 1 {
2078-
t.Errorf("\"adding image [\" logged %d times, want exactly 1 (only the failed job should have attempted logging; the %d good jobs queued after it must never start)\nfull log:\n%s", got, nGood, buf.String())
2079+
t.Errorf("\"resolving image [\" logged %d times, want exactly 1 (only the failed job should have attempted logging; the %d good jobs queued after it must never start)\nfull log:\n%s", got, nGood, buf.String())
20792080
}
20802081
}
20812082

0 commit comments

Comments
 (0)