Skip to content

Commit

Permalink
fix: first and last image won't be detected as known image, do not ad…
Browse files Browse the repository at this point in the history
…d single quote to the jsonpath (#9448) (#9449)
  • Loading branch information
6uliver authored Jun 19, 2024
1 parent 54102ff commit 3967f5c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion pkg/skaffold/kubernetes/loader/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ func (i *ImageLoader) loadImages(ctx context.Context, out io.Writer, artifacts [
}

func findKnownImages(ctx context.Context, cli *kubectl.CLI) ([]string, error) {
nodeGetOut, err := cli.RunOut(ctx, "get", "nodes", `-ojsonpath='{@.items[*].status.images[*].names[*]}'`)
nodeGetOut, err := cli.RunOut(ctx, "get", "nodes", `-ojsonpath={@.items[*].status.images[*].names[*]}`)
if err != nil {
return nil, fmt.Errorf("unable to inspect the nodes: %w", err)
}
Expand Down
20 changes: 10 additions & 10 deletions pkg/skaffold/kubernetes/loader/load_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,29 +46,29 @@ func TestLoadImagesInKindNodes(t *testing.T) {
cluster: "kind",
deployed: []graph.Artifact{{Tag: "tag1"}},
commands: testutil.
CmdRunOut("kubectl --context kubecontext --namespace namespace get nodes -ojsonpath='{@.items[*].status.images[*].names[*]}'", "").
CmdRunOut("kubectl --context kubecontext --namespace namespace get nodes -ojsonpath={@.items[*].status.images[*].names[*]}", "").
AndRunOut("kind load docker-image --name kind tag1", "output: image loaded"),
},
{
description: "load missing image",
cluster: "other-kind",
deployed: []graph.Artifact{{Tag: "tag1"}, {Tag: "tag2"}},
commands: testutil.
CmdRunOut("kubectl --context kubecontext --namespace namespace get nodes -ojsonpath='{@.items[*].status.images[*].names[*]}'", "docker.io/library/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",
deployed: []graph.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"),
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",
deployed: []graph.Artifact{{Tag: "tag"}},
commands: testutil.
CmdRunOutErr("kubectl --context kubecontext --namespace namespace get nodes -ojsonpath='{@.items[*].status.images[*].names[*]}'", "", errors.New("BUG")),
CmdRunOutErr("kubectl --context kubecontext --namespace namespace get nodes -ojsonpath={@.items[*].status.images[*].names[*]}", "", errors.New("BUG")),
shouldErr: true,
expectedError: "unable to inspect",
},
Expand All @@ -77,7 +77,7 @@ func TestLoadImagesInKindNodes(t *testing.T) {
cluster: "kind",
deployed: []graph.Artifact{{Tag: "tag"}},
commands: testutil.
CmdRunOut("kubectl --context kubecontext --namespace namespace get nodes -ojsonpath='{@.items[*].status.images[*].names[*]}'", "").
CmdRunOut("kubectl --context kubecontext --namespace namespace get nodes -ojsonpath={@.items[*].status.images[*].names[*]}", "").
AndRunOutErr("kind load docker-image --name kind tag", "output: error!", errors.New("BUG")),
shouldErr: true,
expectedError: "output: error!",
Expand All @@ -100,29 +100,29 @@ func TestLoadImagesInK3dNodes(t *testing.T) {
cluster: "k3d",
deployed: []graph.Artifact{{Tag: "tag1"}},
commands: testutil.
CmdRunOut("kubectl --context kubecontext --namespace namespace get nodes -ojsonpath='{@.items[*].status.images[*].names[*]}'", "").
CmdRunOut("kubectl --context kubecontext --namespace namespace get nodes -ojsonpath={@.items[*].status.images[*].names[*]}", "").
AndRunOut("k3d image import --cluster k3d tag1", "output: image loaded"),
},
{
description: "load missing image",
cluster: "other-k3d",
deployed: []graph.Artifact{{Tag: "tag1"}, {Tag: "tag2"}},
commands: testutil.
CmdRunOut("kubectl --context kubecontext --namespace namespace get nodes -ojsonpath='{@.items[*].status.images[*].names[*]}'", "docker.io/library/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",
deployed: []graph.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"),
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",
deployed: []graph.Artifact{{Tag: "tag"}},
commands: testutil.
CmdRunOutErr("kubectl --context kubecontext --namespace namespace get nodes -ojsonpath='{@.items[*].status.images[*].names[*]}'", "", errors.New("BUG")),
CmdRunOutErr("kubectl --context kubecontext --namespace namespace get nodes -ojsonpath={@.items[*].status.images[*].names[*]}", "", errors.New("BUG")),
shouldErr: true,
expectedError: "unable to inspect",
},
Expand All @@ -131,7 +131,7 @@ func TestLoadImagesInK3dNodes(t *testing.T) {
cluster: "k3d",
deployed: []graph.Artifact{{Tag: "tag"}},
commands: testutil.
CmdRunOut("kubectl --context kubecontext --namespace namespace get nodes -ojsonpath='{@.items[*].status.images[*].names[*]}'", "").
CmdRunOut("kubectl --context kubecontext --namespace namespace get nodes -ojsonpath={@.items[*].status.images[*].names[*]}", "").
AndRunOutErr("k3d image import --cluster k3d tag", "output: error!", errors.New("BUG")),
shouldErr: true,
expectedError: "output: error!",
Expand Down

0 comments on commit 3967f5c

Please sign in to comment.