From e822d95f6897d07f819dd9afaee3ae60b7070064 Mon Sep 17 00:00:00 2001 From: Angel Montero Date: Wed, 29 Jan 2025 21:17:30 +0000 Subject: [PATCH 01/10] fix: change imagePullPolicy to IfNotPresent instead of Never when deploying locally --- pkg/skaffold/kubernetes/manifest/image_pull_policy.go | 9 +++++++-- .../kubernetes/manifest/image_pull_policy_test.go | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/pkg/skaffold/kubernetes/manifest/image_pull_policy.go b/pkg/skaffold/kubernetes/manifest/image_pull_policy.go index e03999578b5..d2beddeb437 100644 --- a/pkg/skaffold/kubernetes/manifest/image_pull_policy.go +++ b/pkg/skaffold/kubernetes/manifest/image_pull_policy.go @@ -18,6 +18,10 @@ package manifest import apimachinery "k8s.io/apimachinery/pkg/runtime/schema" +const imagePullPolicyField = "imagePullPolicy" +const imagePullPolicyAlways = "Always" +const imagePullPolicyNever = "Never" + // resourceSelectorImagePullPolicy selects PodSpecs for transforming the imagePullPolicy field // based on allowlist and denylist rules for their GroupKind and navigation path. type resourceSelectorImagePullPolicy struct{} @@ -73,7 +77,6 @@ type imagePullPolicyReplacer struct{} // Visit sets the value of the "imagePullPolicy" field in a Kubernetes manifest to "Never". func (i *imagePullPolicyReplacer) Visit(gk apimachinery.GroupKind, navpath string, o map[string]interface{}, k string, v interface{}, rs ResourceSelector) bool { - const imagePullPolicyField = "imagePullPolicy" if _, allowed := rs.allowByNavpath(gk, navpath, k); !allowed { return true } @@ -83,6 +86,8 @@ func (i *imagePullPolicyReplacer) Visit(gk apimachinery.GroupKind, navpath strin if _, ok := v.(string); !ok { return true } - o[imagePullPolicyField] = "Never" + if o[imagePullPolicyField] == imagePullPolicyAlways { + o[imagePullPolicyField] = imagePullPolicyNever + } return false } diff --git a/pkg/skaffold/kubernetes/manifest/image_pull_policy_test.go b/pkg/skaffold/kubernetes/manifest/image_pull_policy_test.go index d1ff2a6bba4..8295035019d 100644 --- a/pkg/skaffold/kubernetes/manifest/image_pull_policy_test.go +++ b/pkg/skaffold/kubernetes/manifest/image_pull_policy_test.go @@ -50,7 +50,7 @@ spec: containers: - image: gcr.io/k8s-skaffold/example@sha256:81daf011d63b68cfa514ddab7741a1adddd59d3264118dfb0fd9266328bb8883 name: if-not-present - imagePullPolicy: Never + imagePullPolicy: IfNotPresent - image: gcr.io/k8s-skaffold/example@sha256:81daf011d63b68cfa514ddab7741a1adddd59d3264118dfb0fd9266328bb8883 name: always imagePullPolicy: Never From 3251abdd066f7faa18e94f97a749c4fedaa796d1 Mon Sep 17 00:00:00 2001 From: Angel Montero Date: Wed, 29 Jan 2025 21:57:21 +0000 Subject: [PATCH 02/10] fix: start working on e2e test --- integration/examples/image-pull-policy/k8s-pod.yaml | 9 +++++++++ integration/examples/image-pull-policy/skaffold.yaml | 7 +++++++ 2 files changed, 16 insertions(+) create mode 100644 integration/examples/image-pull-policy/k8s-pod.yaml create mode 100644 integration/examples/image-pull-policy/skaffold.yaml diff --git a/integration/examples/image-pull-policy/k8s-pod.yaml b/integration/examples/image-pull-policy/k8s-pod.yaml new file mode 100644 index 00000000000..eccbd6c2ec7 --- /dev/null +++ b/integration/examples/image-pull-policy/k8s-pod.yaml @@ -0,0 +1,9 @@ +apiVersion: v1 +kind: Pod +metadata: + name: getting-started +spec: + containers: + - name: nginx + image: gcr.io/google-containers/nginx@sha256:f49a843c290594dcf4d193535d1f4ba8af7d56cea2cf79d1e9554f077f1e7aaa + imagePullPolicy: Always diff --git a/integration/examples/image-pull-policy/skaffold.yaml b/integration/examples/image-pull-policy/skaffold.yaml new file mode 100644 index 00000000000..5bec2a5a0e8 --- /dev/null +++ b/integration/examples/image-pull-policy/skaffold.yaml @@ -0,0 +1,7 @@ +apiVersion: skaffold/v4beta13 +kind: Config +manifests: + rawYaml: + - k8s-* +deploy: + kubectl: {} From 79daa053672191e14f4b31cccbb4a32a6b92778e Mon Sep 17 00:00:00 2001 From: Angel Montero Date: Wed, 29 Jan 2025 23:35:22 +0000 Subject: [PATCH 03/10] chore: add integration test --- .../examples/image-pull-policy/Dockerfile | 2 + .../image-pull-policy/always/k8s-pod.yaml | 9 +++ .../{ => always}/skaffold.yaml | 2 +- .../{ => if-not-present}/k8s-pod.yaml | 2 +- .../if-not-present/skaffold.yaml | 7 ++ .../image-pull-policy/never/k8s-pod.yaml | 9 +++ .../image-pull-policy/never/skaffold.yaml | 7 ++ integration/run_test.go | 64 +++++++++++++++++++ 8 files changed, 100 insertions(+), 2 deletions(-) create mode 100644 integration/examples/image-pull-policy/Dockerfile create mode 100644 integration/examples/image-pull-policy/always/k8s-pod.yaml rename integration/examples/image-pull-policy/{ => always}/skaffold.yaml (69%) rename integration/examples/image-pull-policy/{ => if-not-present}/k8s-pod.yaml (86%) create mode 100644 integration/examples/image-pull-policy/if-not-present/skaffold.yaml create mode 100644 integration/examples/image-pull-policy/never/k8s-pod.yaml create mode 100644 integration/examples/image-pull-policy/never/skaffold.yaml diff --git a/integration/examples/image-pull-policy/Dockerfile b/integration/examples/image-pull-policy/Dockerfile new file mode 100644 index 00000000000..c0b2124c3b3 --- /dev/null +++ b/integration/examples/image-pull-policy/Dockerfile @@ -0,0 +1,2 @@ +FROM gcr.io/google-containers/nginx@sha256:f49a843c290594dcf4d193535d1f4ba8af7d56cea2cf79d1e9554f077f1e7aaa +RUN echo "hello world" > example.txt \ No newline at end of file diff --git a/integration/examples/image-pull-policy/always/k8s-pod.yaml b/integration/examples/image-pull-policy/always/k8s-pod.yaml new file mode 100644 index 00000000000..864ec3684e2 --- /dev/null +++ b/integration/examples/image-pull-policy/always/k8s-pod.yaml @@ -0,0 +1,9 @@ +apiVersion: v1 +kind: Pod +metadata: + name: getting-started +spec: + containers: + - name: nginx + image: test-image:built-locally + imagePullPolicy: Always diff --git a/integration/examples/image-pull-policy/skaffold.yaml b/integration/examples/image-pull-policy/always/skaffold.yaml similarity index 69% rename from integration/examples/image-pull-policy/skaffold.yaml rename to integration/examples/image-pull-policy/always/skaffold.yaml index 5bec2a5a0e8..614efb5dcac 100644 --- a/integration/examples/image-pull-policy/skaffold.yaml +++ b/integration/examples/image-pull-policy/always/skaffold.yaml @@ -1,4 +1,4 @@ -apiVersion: skaffold/v4beta13 +apiVersion: skaffold/v4beta12 kind: Config manifests: rawYaml: diff --git a/integration/examples/image-pull-policy/k8s-pod.yaml b/integration/examples/image-pull-policy/if-not-present/k8s-pod.yaml similarity index 86% rename from integration/examples/image-pull-policy/k8s-pod.yaml rename to integration/examples/image-pull-policy/if-not-present/k8s-pod.yaml index eccbd6c2ec7..272b9f15448 100644 --- a/integration/examples/image-pull-policy/k8s-pod.yaml +++ b/integration/examples/image-pull-policy/if-not-present/k8s-pod.yaml @@ -6,4 +6,4 @@ spec: containers: - name: nginx image: gcr.io/google-containers/nginx@sha256:f49a843c290594dcf4d193535d1f4ba8af7d56cea2cf79d1e9554f077f1e7aaa - imagePullPolicy: Always + imagePullPolicy: IfNotPresent diff --git a/integration/examples/image-pull-policy/if-not-present/skaffold.yaml b/integration/examples/image-pull-policy/if-not-present/skaffold.yaml new file mode 100644 index 00000000000..614efb5dcac --- /dev/null +++ b/integration/examples/image-pull-policy/if-not-present/skaffold.yaml @@ -0,0 +1,7 @@ +apiVersion: skaffold/v4beta12 +kind: Config +manifests: + rawYaml: + - k8s-* +deploy: + kubectl: {} diff --git a/integration/examples/image-pull-policy/never/k8s-pod.yaml b/integration/examples/image-pull-policy/never/k8s-pod.yaml new file mode 100644 index 00000000000..629713f3113 --- /dev/null +++ b/integration/examples/image-pull-policy/never/k8s-pod.yaml @@ -0,0 +1,9 @@ +apiVersion: v1 +kind: Pod +metadata: + name: getting-started +spec: + containers: + - name: nginx + image: test-image:built-locally + imagePullPolicy: Never diff --git a/integration/examples/image-pull-policy/never/skaffold.yaml b/integration/examples/image-pull-policy/never/skaffold.yaml new file mode 100644 index 00000000000..614efb5dcac --- /dev/null +++ b/integration/examples/image-pull-policy/never/skaffold.yaml @@ -0,0 +1,7 @@ +apiVersion: skaffold/v4beta12 +kind: Config +manifests: + rawYaml: + - k8s-* +deploy: + kubectl: {} diff --git a/integration/run_test.go b/integration/run_test.go index e877ee7b03d..ac196b0b726 100644 --- a/integration/run_test.go +++ b/integration/run_test.go @@ -19,6 +19,7 @@ package integration import ( "fmt" "os" + "os/exec" "path/filepath" "strings" "testing" @@ -200,6 +201,11 @@ var tests = []struct { args: []string{"-p", "mix-deploy"}, deployments: []string{"frontend", "backend", "go-guestbook-mongodb"}, }, + { + description: "image pull policy run in minikube namespace", + dir: "examples/image-pull-policy", + pods: []string{"getting-started"}, + }, } func TestRun(t *testing.T) { @@ -226,6 +232,60 @@ func TestRun(t *testing.T) { } } +func TestRunWithImagePullPolicy(t *testing.T) { + + miniKubeRunArgs := []string{"image", "build", "examples/image-pull-policy", "-f", "Dockerfile", "-t", "test-image:build-locally"} + imagePullPolicyTests := []struct { + description string + skipBuildingLocalImage bool + dir string + pods []string + targetLog string + }{ + { + description: "'Never' image pull policy works if image is present locally", + dir: "examples/image-pull-policy/never", + pods: []string{"getting-started"}, + }, + { + description: "'Always' doesn't actually pull and reads a local image that doesn't exist remotely", + dir: "examples/image-pull-policy/always", + pods: []string{"getting-started"}, + }, + { + description: "'IfNotPresent' pulls the remote image", + skipBuildingLocalImage: true, + dir: "examples/image-pull-policy/if-not-present", + pods: []string{"getting-started"}, + }, + } + + for _, test := range imagePullPolicyTests { + t.Run(test.description, func(t *testing.T) { + MarkIntegrationTest(t, CanRunWithoutGcp) + + // kubectl uses the minikube context, so build the docker images within minikube + // to make them accessible. + if !test.skipBuildingLocalImage { + if err := exec.Command("minikube", miniKubeRunArgs...).Run(); err != nil { + t.Errorf("unexpected error while running minikube with args: %v, err: %v", miniKubeRunArgs, err) + } + } + + ns, client := SetupNamespace(t) + args := []string{"--cache-artifacts=false"} + if test.dir == "" { + t.Fatalf("A skaffold directory is required") + } + skaffold.Run(args...).InDir(test.dir).InNs(ns.Name).RunOrFail(t) + + client.WaitForPodsReady(test.pods...) + + skaffold.Delete().InDir(test.dir).InNs(ns.Name).RunOrFail(t) + }) + } +} + func TestRunTail(t *testing.T) { for _, test := range tests { t.Run(test.description, func(t *testing.T) { @@ -638,3 +698,7 @@ func TestRunKubectlDefaultNamespace(t *testing.T) { }) } } + +func TestRunImagePullPolicy(t *testing.T) { + +} From 6999eb32f10f99bdba376d1e127635751165eedb Mon Sep 17 00:00:00 2001 From: Angel Montero Date: Wed, 29 Jan 2025 23:48:38 +0000 Subject: [PATCH 04/10] chore: move test files to testdata folder --- integration/run_test.go | 8 ++++---- .../{examples => testdata}/image-pull-policy/Dockerfile | 0 .../image-pull-policy/always/k8s-pod.yaml | 0 .../image-pull-policy/always/skaffold.yaml | 0 .../image-pull-policy/if-not-present/k8s-pod.yaml | 0 .../image-pull-policy/if-not-present/skaffold.yaml | 0 .../image-pull-policy/never/k8s-pod.yaml | 0 .../image-pull-policy/never/skaffold.yaml | 0 8 files changed, 4 insertions(+), 4 deletions(-) rename integration/{examples => testdata}/image-pull-policy/Dockerfile (100%) rename integration/{examples => testdata}/image-pull-policy/always/k8s-pod.yaml (100%) rename integration/{examples => testdata}/image-pull-policy/always/skaffold.yaml (100%) rename integration/{examples => testdata}/image-pull-policy/if-not-present/k8s-pod.yaml (100%) rename integration/{examples => testdata}/image-pull-policy/if-not-present/skaffold.yaml (100%) rename integration/{examples => testdata}/image-pull-policy/never/k8s-pod.yaml (100%) rename integration/{examples => testdata}/image-pull-policy/never/skaffold.yaml (100%) diff --git a/integration/run_test.go b/integration/run_test.go index ac196b0b726..831755c7316 100644 --- a/integration/run_test.go +++ b/integration/run_test.go @@ -234,7 +234,7 @@ func TestRun(t *testing.T) { func TestRunWithImagePullPolicy(t *testing.T) { - miniKubeRunArgs := []string{"image", "build", "examples/image-pull-policy", "-f", "Dockerfile", "-t", "test-image:build-locally"} + miniKubeRunArgs := []string{"image", "build", "testdata/image-pull-policy", "-f", "Dockerfile", "-t", "test-image:build-locally"} imagePullPolicyTests := []struct { description string skipBuildingLocalImage bool @@ -244,18 +244,18 @@ func TestRunWithImagePullPolicy(t *testing.T) { }{ { description: "'Never' image pull policy works if image is present locally", - dir: "examples/image-pull-policy/never", + dir: "testdata/image-pull-policy/never", pods: []string{"getting-started"}, }, { description: "'Always' doesn't actually pull and reads a local image that doesn't exist remotely", - dir: "examples/image-pull-policy/always", + dir: "testdata/image-pull-policy/always", pods: []string{"getting-started"}, }, { description: "'IfNotPresent' pulls the remote image", skipBuildingLocalImage: true, - dir: "examples/image-pull-policy/if-not-present", + dir: "testdata/image-pull-policy/if-not-present", pods: []string{"getting-started"}, }, } diff --git a/integration/examples/image-pull-policy/Dockerfile b/integration/testdata/image-pull-policy/Dockerfile similarity index 100% rename from integration/examples/image-pull-policy/Dockerfile rename to integration/testdata/image-pull-policy/Dockerfile diff --git a/integration/examples/image-pull-policy/always/k8s-pod.yaml b/integration/testdata/image-pull-policy/always/k8s-pod.yaml similarity index 100% rename from integration/examples/image-pull-policy/always/k8s-pod.yaml rename to integration/testdata/image-pull-policy/always/k8s-pod.yaml diff --git a/integration/examples/image-pull-policy/always/skaffold.yaml b/integration/testdata/image-pull-policy/always/skaffold.yaml similarity index 100% rename from integration/examples/image-pull-policy/always/skaffold.yaml rename to integration/testdata/image-pull-policy/always/skaffold.yaml diff --git a/integration/examples/image-pull-policy/if-not-present/k8s-pod.yaml b/integration/testdata/image-pull-policy/if-not-present/k8s-pod.yaml similarity index 100% rename from integration/examples/image-pull-policy/if-not-present/k8s-pod.yaml rename to integration/testdata/image-pull-policy/if-not-present/k8s-pod.yaml diff --git a/integration/examples/image-pull-policy/if-not-present/skaffold.yaml b/integration/testdata/image-pull-policy/if-not-present/skaffold.yaml similarity index 100% rename from integration/examples/image-pull-policy/if-not-present/skaffold.yaml rename to integration/testdata/image-pull-policy/if-not-present/skaffold.yaml diff --git a/integration/examples/image-pull-policy/never/k8s-pod.yaml b/integration/testdata/image-pull-policy/never/k8s-pod.yaml similarity index 100% rename from integration/examples/image-pull-policy/never/k8s-pod.yaml rename to integration/testdata/image-pull-policy/never/k8s-pod.yaml diff --git a/integration/examples/image-pull-policy/never/skaffold.yaml b/integration/testdata/image-pull-policy/never/skaffold.yaml similarity index 100% rename from integration/examples/image-pull-policy/never/skaffold.yaml rename to integration/testdata/image-pull-policy/never/skaffold.yaml From cb9f4ed4c52ba58dfe6b2a2acb7364377a7fb4f7 Mon Sep 17 00:00:00 2001 From: Angel Montero Date: Thu, 30 Jan 2025 14:00:07 +0000 Subject: [PATCH 05/10] remove extra test --- integration/run_test.go | 5 ----- 1 file changed, 5 deletions(-) diff --git a/integration/run_test.go b/integration/run_test.go index 831755c7316..9cc91495b01 100644 --- a/integration/run_test.go +++ b/integration/run_test.go @@ -201,11 +201,6 @@ var tests = []struct { args: []string{"-p", "mix-deploy"}, deployments: []string{"frontend", "backend", "go-guestbook-mongodb"}, }, - { - description: "image pull policy run in minikube namespace", - dir: "examples/image-pull-policy", - pods: []string{"getting-started"}, - }, } func TestRun(t *testing.T) { From ec0eb2d655172e326e4c4cc2a46cf287d2668f7f Mon Sep 17 00:00:00 2001 From: Angel Montero Date: Thu, 30 Jan 2025 14:02:15 +0000 Subject: [PATCH 06/10] fix: remove unnecessary newlines to fix lint --- integration/run_test.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/integration/run_test.go b/integration/run_test.go index 9cc91495b01..5ebd063743c 100644 --- a/integration/run_test.go +++ b/integration/run_test.go @@ -228,7 +228,6 @@ func TestRun(t *testing.T) { } func TestRunWithImagePullPolicy(t *testing.T) { - miniKubeRunArgs := []string{"image", "build", "testdata/image-pull-policy", "-f", "Dockerfile", "-t", "test-image:build-locally"} imagePullPolicyTests := []struct { description string @@ -254,7 +253,6 @@ func TestRunWithImagePullPolicy(t *testing.T) { pods: []string{"getting-started"}, }, } - for _, test := range imagePullPolicyTests { t.Run(test.description, func(t *testing.T) { MarkIntegrationTest(t, CanRunWithoutGcp) From b08608dc8717463eb681c3a23833bb11c9926aa5 Mon Sep 17 00:00:00 2001 From: Angel Montero Date: Thu, 30 Jan 2025 15:23:57 +0000 Subject: [PATCH 07/10] fix: typo. When building the docker image, the tag should be 'built-locally' --- integration/run_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integration/run_test.go b/integration/run_test.go index 5ebd063743c..017716a4fae 100644 --- a/integration/run_test.go +++ b/integration/run_test.go @@ -228,7 +228,7 @@ func TestRun(t *testing.T) { } func TestRunWithImagePullPolicy(t *testing.T) { - miniKubeRunArgs := []string{"image", "build", "testdata/image-pull-policy", "-f", "Dockerfile", "-t", "test-image:build-locally"} + miniKubeRunArgs := []string{"image", "build", "testdata/image-pull-policy", "-f", "Dockerfile", "-t", "test-image:built-locally"} imagePullPolicyTests := []struct { description string skipBuildingLocalImage bool From 7a6372f21a53ab6068b906749f1bc273e858712c Mon Sep 17 00:00:00 2001 From: Angel Montero Date: Thu, 30 Jan 2025 20:40:28 +0000 Subject: [PATCH 08/10] Set the imagePullPolicy from 'Always' to 'IfNotPresent' --- integration/run_test.go | 2 +- pkg/skaffold/kubernetes/manifest/image_pull_policy.go | 4 ++-- pkg/skaffold/kubernetes/manifest/image_pull_policy_test.go | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/integration/run_test.go b/integration/run_test.go index 017716a4fae..e511d5fa551 100644 --- a/integration/run_test.go +++ b/integration/run_test.go @@ -242,7 +242,7 @@ func TestRunWithImagePullPolicy(t *testing.T) { pods: []string{"getting-started"}, }, { - description: "'Always' doesn't actually pull and reads a local image that doesn't exist remotely", + description: "'Always' internally is changed to ifNotPresent and reads a local image that doesn't exist remotely", dir: "testdata/image-pull-policy/always", pods: []string{"getting-started"}, }, diff --git a/pkg/skaffold/kubernetes/manifest/image_pull_policy.go b/pkg/skaffold/kubernetes/manifest/image_pull_policy.go index d2beddeb437..80e5839a9cb 100644 --- a/pkg/skaffold/kubernetes/manifest/image_pull_policy.go +++ b/pkg/skaffold/kubernetes/manifest/image_pull_policy.go @@ -20,7 +20,7 @@ import apimachinery "k8s.io/apimachinery/pkg/runtime/schema" const imagePullPolicyField = "imagePullPolicy" const imagePullPolicyAlways = "Always" -const imagePullPolicyNever = "Never" +const imagePullPolicyIfNotPresent = "IfNotPresent" // resourceSelectorImagePullPolicy selects PodSpecs for transforming the imagePullPolicy field // based on allowlist and denylist rules for their GroupKind and navigation path. @@ -87,7 +87,7 @@ func (i *imagePullPolicyReplacer) Visit(gk apimachinery.GroupKind, navpath strin return true } if o[imagePullPolicyField] == imagePullPolicyAlways { - o[imagePullPolicyField] = imagePullPolicyNever + o[imagePullPolicyField] = imagePullPolicyIfNotPresent } return false } diff --git a/pkg/skaffold/kubernetes/manifest/image_pull_policy_test.go b/pkg/skaffold/kubernetes/manifest/image_pull_policy_test.go index 8295035019d..730a0b4b448 100644 --- a/pkg/skaffold/kubernetes/manifest/image_pull_policy_test.go +++ b/pkg/skaffold/kubernetes/manifest/image_pull_policy_test.go @@ -53,7 +53,7 @@ spec: imagePullPolicy: IfNotPresent - image: gcr.io/k8s-skaffold/example@sha256:81daf011d63b68cfa514ddab7741a1adddd59d3264118dfb0fd9266328bb8883 name: always - imagePullPolicy: Never + imagePullPolicy: IfNotPresent - image: gcr.io/k8s-skaffold/example@sha256:81daf011d63b68cfa514ddab7741a1adddd59d3264118dfb0fd9266328bb8883 name: never imagePullPolicy: Never From fdf13d591efd1b5b51ac27fc7efb9dfeba4e4173 Mon Sep 17 00:00:00 2001 From: Angel Montero Date: Fri, 31 Jan 2025 15:16:38 +0000 Subject: [PATCH 09/10] use existing constants --- pkg/skaffold/kubernetes/manifest/image_pull_policy.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/pkg/skaffold/kubernetes/manifest/image_pull_policy.go b/pkg/skaffold/kubernetes/manifest/image_pull_policy.go index 80e5839a9cb..c69e45e3b68 100644 --- a/pkg/skaffold/kubernetes/manifest/image_pull_policy.go +++ b/pkg/skaffold/kubernetes/manifest/image_pull_policy.go @@ -16,11 +16,12 @@ limitations under the License. package manifest -import apimachinery "k8s.io/apimachinery/pkg/runtime/schema" +import ( + "k8s.io/api/core/v1" + apimachinery "k8s.io/apimachinery/pkg/runtime/schema" +) const imagePullPolicyField = "imagePullPolicy" -const imagePullPolicyAlways = "Always" -const imagePullPolicyIfNotPresent = "IfNotPresent" // resourceSelectorImagePullPolicy selects PodSpecs for transforming the imagePullPolicy field // based on allowlist and denylist rules for their GroupKind and navigation path. @@ -86,8 +87,8 @@ func (i *imagePullPolicyReplacer) Visit(gk apimachinery.GroupKind, navpath strin if _, ok := v.(string); !ok { return true } - if o[imagePullPolicyField] == imagePullPolicyAlways { - o[imagePullPolicyField] = imagePullPolicyIfNotPresent + if o[imagePullPolicyField] == v1.PullAlways { + o[imagePullPolicyField] = v1.PullIfNotPresent } return false } From 7efe7b3e8b8f3f05b67313aa8c24a639f0b3111f Mon Sep 17 00:00:00 2001 From: Angel Montero Date: Fri, 31 Jan 2025 18:00:03 +0000 Subject: [PATCH 10/10] fix comparison --- pkg/skaffold/kubernetes/manifest/image_pull_policy.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/skaffold/kubernetes/manifest/image_pull_policy.go b/pkg/skaffold/kubernetes/manifest/image_pull_policy.go index c69e45e3b68..2acbfa9c098 100644 --- a/pkg/skaffold/kubernetes/manifest/image_pull_policy.go +++ b/pkg/skaffold/kubernetes/manifest/image_pull_policy.go @@ -17,7 +17,7 @@ limitations under the License. package manifest import ( - "k8s.io/api/core/v1" + v1 "k8s.io/api/core/v1" apimachinery "k8s.io/apimachinery/pkg/runtime/schema" ) @@ -87,7 +87,7 @@ func (i *imagePullPolicyReplacer) Visit(gk apimachinery.GroupKind, navpath strin if _, ok := v.(string); !ok { return true } - if o[imagePullPolicyField] == v1.PullAlways { + if o[imagePullPolicyField] == string(v1.PullAlways) { o[imagePullPolicyField] = v1.PullIfNotPresent } return false