Skip to content

Commit

Permalink
normalize an image before checking known images in kind/k3d cluster (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
anshlykov authored Nov 12, 2020
1 parent e685dd2 commit 416804a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
8 changes: 7 additions & 1 deletion pkg/skaffold/runner/load_images.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import (
"strings"
"time"

"github.com/docker/distribution/reference"

"github.com/GoogleContainerTools/skaffold/pkg/skaffold/build"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/color"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/kubectl"
Expand Down Expand Up @@ -66,7 +68,11 @@ func (r *SkaffoldRunner) loadImages(ctx context.Context, out io.Writer, artifact
return fmt.Errorf("unable to retrieve node's images: %w", err)
}
}
if util.StrSliceContains(knownImages, artifact.Tag) {
normalizedImageRef, err := reference.ParseNormalizedNamed(artifact.Tag)
if err != nil {
return err
}
if util.StrSliceContains(knownImages, normalizedImageRef.String()) {
color.Green.Fprintln(out, "Found")
continue
}
Expand Down
20 changes: 18 additions & 2 deletions pkg/skaffold/runner/load_images_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,17 @@ func TestLoadImagesInKindNodes(t *testing.T) {
built: []build.Artifact{{Tag: "tag1"}, {Tag: "tag2"}},
deployed: []build.Artifact{{Tag: "tag1"}, {Tag: "tag2"}},
commands: testutil.
CmdRunOut("kubectl --context kubecontext --namespace namespace get nodes -ojsonpath='{@.items[*].status.images[*].names[*]}'", "tag1").
CmdRunOut("kubectl --context kubecontext --namespace namespace get nodes -ojsonpath='{@.items[*].status.images[*].names[*]}'", "docker.io/library/tag1").
AndRunOut("kind load docker-image --name other-kind tag2", "output: image loaded"),
},
{
description: "no new images",
cluster: "kind",
built: []build.Artifact{{Tag: "tag0"}, {Tag: "docker.io/library/tag1"}, {Tag: "docker.io/tag2"}, {Tag: "gcr.io/test/tag3"}, {Tag: "someregistry.com/tag4"}},
deployed: []build.Artifact{{Tag: "tag0"}, {Tag: "docker.io/library/tag1"}, {Tag: "docker.io/tag2"}, {Tag: "gcr.io/test/tag3"}, {Tag: "someregistry.com/tag4"}},
commands: testutil.
CmdRunOut("kubectl --context kubecontext --namespace namespace get nodes -ojsonpath='{@.items[*].status.images[*].names[*]}'", "docker.io/library/tag0 docker.io/library/tag1 docker.io/library/tag2 gcr.io/test/tag3 someregistry.com/tag4"),
},
{
description: "inspect error",
built: []build.Artifact{{Tag: "tag"}},
Expand Down Expand Up @@ -122,9 +130,17 @@ func TestLoadImagesInK3dNodes(t *testing.T) {
built: []build.Artifact{{Tag: "tag1"}, {Tag: "tag2"}},
deployed: []build.Artifact{{Tag: "tag1"}, {Tag: "tag2"}},
commands: testutil.
CmdRunOut("kubectl --context kubecontext --namespace namespace get nodes -ojsonpath='{@.items[*].status.images[*].names[*]}'", "tag1").
CmdRunOut("kubectl --context kubecontext --namespace namespace get nodes -ojsonpath='{@.items[*].status.images[*].names[*]}'", "docker.io/library/tag1").
AndRunOut("k3d image import --cluster other-k3d tag2", "output: image loaded"),
},
{
description: "no new images",
cluster: "k3d",
built: []build.Artifact{{Tag: "tag0"}, {Tag: "docker.io/library/tag1"}, {Tag: "docker.io/tag2"}, {Tag: "gcr.io/test/tag3"}, {Tag: "someregistry.com/tag4"}},
deployed: []build.Artifact{{Tag: "tag0"}, {Tag: "docker.io/library/tag1"}, {Tag: "docker.io/tag2"}, {Tag: "gcr.io/test/tag3"}, {Tag: "someregistry.com/tag4"}},
commands: testutil.
CmdRunOut("kubectl --context kubecontext --namespace namespace get nodes -ojsonpath='{@.items[*].status.images[*].names[*]}'", "docker.io/library/tag0 docker.io/library/tag1 docker.io/library/tag2 gcr.io/test/tag3 someregistry.com/tag4"),
},
{
description: "inspect error",
built: []build.Artifact{{Tag: "tag"}},
Expand Down

0 comments on commit 416804a

Please sign in to comment.