From 3967f5c9686167ad0769de6154d85c0655ca4e4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20N=C3=A9meth?= <6uliver@gmail.com> Date: Wed, 19 Jun 2024 13:45:20 +0200 Subject: [PATCH] fix: first and last image won't be detected as known image, do not add single quote to the jsonpath (#9448) (#9449) --- pkg/skaffold/kubernetes/loader/load.go | 2 +- pkg/skaffold/kubernetes/loader/load_test.go | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/pkg/skaffold/kubernetes/loader/load.go b/pkg/skaffold/kubernetes/loader/load.go index 914fade555a..7325a5d44b6 100644 --- a/pkg/skaffold/kubernetes/loader/load.go +++ b/pkg/skaffold/kubernetes/loader/load.go @@ -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) } diff --git a/pkg/skaffold/kubernetes/loader/load_test.go b/pkg/skaffold/kubernetes/loader/load_test.go index 400defb2337..29b8e8c55bc 100644 --- a/pkg/skaffold/kubernetes/loader/load_test.go +++ b/pkg/skaffold/kubernetes/loader/load_test.go @@ -46,7 +46,7 @@ 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"), }, { @@ -54,7 +54,7 @@ func TestLoadImagesInKindNodes(t *testing.T) { 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"), }, { @@ -62,13 +62,13 @@ func TestLoadImagesInKindNodes(t *testing.T) { 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", }, @@ -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!", @@ -100,7 +100,7 @@ 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"), }, { @@ -108,7 +108,7 @@ func TestLoadImagesInK3dNodes(t *testing.T) { 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"), }, { @@ -116,13 +116,13 @@ func TestLoadImagesInK3dNodes(t *testing.T) { 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", }, @@ -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!",