Move image existence checks into downloading functions.

pull/11223/head
Andriy Dzikh 2021-04-27 16:36:32 -07:00
parent 26634c18a8
commit d6f60bbd4a
2 changed files with 13 additions and 9 deletions

View File

@ -75,6 +75,11 @@ func ImageExistsInDaemon(img string) bool {
// ImageToCache writes img to the local cache directory
func ImageToCache(img string) error {
if ImageExistsInCache(img) {
klog.Infof("%s exists in cache, skipping pull", img)
return nil
}
f := filepath.Join(constants.KICCacheDir, path.Base(img)+".tar")
f = localpath.SanitizeCacheDir(f)
@ -140,6 +145,10 @@ func ImageToCache(img string) error {
// ImageToDaemon writes img to the local docker daemon
func ImageToDaemon(img string) error {
if ImageExistsInDaemon(img) {
klog.Infof("%s exists in daemon, skipping pull", img)
return nil
}
// buffered channel
c := make(chan v1.Update, 200)

View File

@ -127,16 +127,11 @@ func beginDownloadKicBaseImage(g *errgroup.Group, cc *config.ClusterConfig, down
}()
for _, img := range append([]string{baseImg}, kic.FallbackImages...) {
var err error
if download.ImageExistsInCache(img) {
klog.Infof("%s exists in cache, skipping pull", img)
klog.Infof("Downloading %s to local cache", img)
err = download.ImageToCache(img)
if err == nil {
klog.Infof("successfully saved %s as a tarball", img)
finalImg = img
} else {
klog.Infof("Downloading %s to local cache", img)
err = download.ImageToCache(img)
if err == nil {
klog.Infof("successfully saved %s as a tarball", img)
finalImg = img
}
}
if downloadOnly {
return err