From 1ee41400240373cbb43230c84a7a0112835a49c8 Mon Sep 17 00:00:00 2001 From: Max Walther Date: Fri, 4 Jun 2021 19:07:57 +0200 Subject: [PATCH] Try to warm all images and warn about errors (#1653) When providing multiple images to warm, the warmer stops at the first error. There are use cases however where an image is provided to the warmer which does not yet exist on purpose (e.g. CI/CD latest image only created at first release). Thus we want to try all given images and only error if none of them work. --- pkg/cache/warm.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/pkg/cache/warm.go b/pkg/cache/warm.go index c7c36cda8..fd9e3c607 100644 --- a/pkg/cache/warm.go +++ b/pkg/cache/warm.go @@ -39,6 +39,7 @@ func WarmCache(opts *config.WarmerOptions) error { logrus.Debugf("%s\n", cacheDir) logrus.Debugf("%s\n", images) + errs := 0 for _, img := range images { tarBuf := new(bytes.Buffer) manifestBuf := new(bytes.Buffer) @@ -53,7 +54,8 @@ func WarmCache(opts *config.WarmerOptions) error { digest, err := cw.Warm(img, opts) if err != nil { if !IsAlreadyCached(err) { - return err + logrus.Warnf("Error while trying to warm image: %v %v", img, err) + errs++ } continue @@ -62,11 +64,18 @@ func WarmCache(opts *config.WarmerOptions) error { cachePath := path.Join(cacheDir, digest.String()) if err := writeBufsToFile(cachePath, tarBuf, manifestBuf); err != nil { - return err + logrus.Warnf("Error while writing %v to cache: %v", img, err) + errs++ + continue } logrus.Debugf("Wrote %s to cache", img) } + + if len(images) == errs { + return errors.New("Failed to warm any of the given images") + } + return nil }