From 8cf3add6054088a66128031e5d34dbf380d64d22 Mon Sep 17 00:00:00 2001 From: Ricardo La Rosa Date: Fri, 2 Oct 2020 11:47:11 +0100 Subject: [PATCH 1/3] Fix return of error when images are built remotely --- pkg/skaffold/build/cache/retrieve.go | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/pkg/skaffold/build/cache/retrieve.go b/pkg/skaffold/build/cache/retrieve.go index 380a7cf8a3e..d5fd4263b8d 100644 --- a/pkg/skaffold/build/cache/retrieve.go +++ b/pkg/skaffold/build/cache/retrieve.go @@ -147,8 +147,12 @@ func maintainArtifactOrder(built []build.Artifact, artifacts []*latest.Artifact) } func (c *cache) addArtifacts(ctx context.Context, bRes []build.Artifact, hashByName map[string]string) error { + + var err error + for _, a := range bRes { entry := ImageDetails{} + imageID := "" if !c.imagesAreLocal { ref, err := docker.ParseReference(a.Tag) @@ -157,15 +161,14 @@ func (c *cache) addArtifacts(ctx context.Context, bRes []build.Artifact, hashByN } entry.Digest = ref.Digest - } - - imageID, err := c.client.ImageID(ctx, a.Tag) - if err != nil { - return err - } - - if imageID != "" { - entry.ID = imageID + } else { + imageID, err = c.client.ImageID(ctx, a.Tag) + if err != nil { + return err + } + if imageID != "" { + entry.ID = imageID + } } c.cacheMutex.Lock() From c2fff564f43a5ad89ddf2c643706fd195b0329e6 Mon Sep 17 00:00:00 2001 From: Ricardo La Rosa Date: Fri, 2 Oct 2020 13:44:43 +0100 Subject: [PATCH 2/3] Remove unnecessary leading newline --- pkg/skaffold/build/cache/retrieve.go | 1 - 1 file changed, 1 deletion(-) diff --git a/pkg/skaffold/build/cache/retrieve.go b/pkg/skaffold/build/cache/retrieve.go index d5fd4263b8d..7bb6f49cd0c 100644 --- a/pkg/skaffold/build/cache/retrieve.go +++ b/pkg/skaffold/build/cache/retrieve.go @@ -147,7 +147,6 @@ func maintainArtifactOrder(built []build.Artifact, artifacts []*latest.Artifact) } func (c *cache) addArtifacts(ctx context.Context, bRes []build.Artifact, hashByName map[string]string) error { - var err error for _, a := range bRes { From 834d6a8975346113007b76b9723461e7412c6777 Mon Sep 17 00:00:00 2001 From: Ricardo La Rosa Date: Fri, 2 Oct 2020 16:40:41 +0100 Subject: [PATCH 3/3] Simplify func addArtifacts --- pkg/skaffold/build/cache/retrieve.go | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/pkg/skaffold/build/cache/retrieve.go b/pkg/skaffold/build/cache/retrieve.go index 7bb6f49cd0c..5d8d870c825 100644 --- a/pkg/skaffold/build/cache/retrieve.go +++ b/pkg/skaffold/build/cache/retrieve.go @@ -147,33 +147,27 @@ func maintainArtifactOrder(built []build.Artifact, artifacts []*latest.Artifact) } func (c *cache) addArtifacts(ctx context.Context, bRes []build.Artifact, hashByName map[string]string) error { - var err error - for _, a := range bRes { entry := ImageDetails{} - imageID := "" - - if !c.imagesAreLocal { - ref, err := docker.ParseReference(a.Tag) - if err != nil { - return fmt.Errorf("parsing reference %q: %w", a.Tag, err) - } - - entry.Digest = ref.Digest - } else { - imageID, err = c.client.ImageID(ctx, a.Tag) + if c.imagesAreLocal { + imageID, err := c.client.ImageID(ctx, a.Tag) if err != nil { return err } + if imageID != "" { entry.ID = imageID } + } else { + ref, err := docker.ParseReference(a.Tag) + if err != nil { + return fmt.Errorf("parsing reference %q: %w", a.Tag, err) + } + entry.Digest = ref.Digest } - c.cacheMutex.Lock() c.artifactCache[hashByName[a.ImageName]] = entry c.cacheMutex.Unlock() } - return nil }