From 88df97288b1e3abd53f70b4d81abf072afc860da Mon Sep 17 00:00:00 2001 From: kevinrizza Date: Thu, 12 Jun 2025 15:31:13 -0400 Subject: [PATCH] Set ImagePullPolicy ifNotPresent for server container When the change to use the copy content sidecar container was added for the extract content option it properly set the ifNotPresent pull policy for the bundle image, but the actual server container is getting the wrong value and is not based on the opm image passed to the catalog operator. This commit updates the main registry server container to variably set the container to pull only if not present. Signed-off-by: kevinrizza --- .../registry/reconciler/reconciler.go | 1 + .../registry/reconciler/reconciler_test.go | 65 ++++++++++++++----- 2 files changed, 51 insertions(+), 15 deletions(-) diff --git a/pkg/controller/registry/reconciler/reconciler.go b/pkg/controller/registry/reconciler/reconciler.go index 3455bcb2c3..c0ac7d9283 100644 --- a/pkg/controller/registry/reconciler/reconciler.go +++ b/pkg/controller/registry/reconciler/reconciler.go @@ -305,6 +305,7 @@ func Pod(source *operatorsv1alpha1.CatalogSource, name, opmImg, utilImage, img s pod.Spec.Containers[0].Image = opmImg pod.Spec.Containers[0].Command = []string{"/bin/opm"} + pod.Spec.Containers[0].ImagePullPolicy = image.InferImagePullPolicy(opmImg) var containerArgs = []string{ "serve", filepath.Join(catalogPath, "catalog"), diff --git a/pkg/controller/registry/reconciler/reconciler_test.go b/pkg/controller/registry/reconciler/reconciler_test.go index 783801cf93..9b8eed6443 100644 --- a/pkg/controller/registry/reconciler/reconciler_test.go +++ b/pkg/controller/registry/reconciler/reconciler_test.go @@ -914,32 +914,58 @@ func TestPodNodeSelector(t *testing.T) { func TestPullPolicy(t *testing.T) { var table = []struct { - image string - policy corev1.PullPolicy + image string + policy corev1.PullPolicy + opmImage string + extractContent bool }{ { - image: "quay.io/operator-framework/olm@sha256:b9d011c0fbfb65b387904f8fafc47ee1a9479d28d395473341288ee126ed993b", - policy: corev1.PullIfNotPresent, + image: "quay.io/operator-framework/olm@sha256:b9d011c0fbfb65b387904f8fafc47ee1a9479d28d395473341288ee126ed993b", + policy: corev1.PullIfNotPresent, + opmImage: "opmImage", + extractContent: false, }, { - image: "gcc@sha256:06a6f170d7fff592e44b089c0d2e68d870573eb9a23d9c66d4b6ea11f8fad18b", - policy: corev1.PullIfNotPresent, + image: "gcc@sha256:06a6f170d7fff592e44b089c0d2e68d870573eb9a23d9c66d4b6ea11f8fad18b", + policy: corev1.PullIfNotPresent, + opmImage: "opmImage", + extractContent: false, }, { - image: "myimage:1.0", - policy: corev1.PullAlways, + image: "myimage:1.0", + policy: corev1.PullAlways, + opmImage: "opmImage", + extractContent: false, }, { - image: "busybox", - policy: corev1.PullAlways, + image: "busybox", + policy: corev1.PullAlways, + opmImage: "opmImage", + extractContent: false, }, { - image: "gcc@sha256:06a6f170d7fff592e44b089c0d2e68", - policy: corev1.PullIfNotPresent, + image: "gcc@sha256:06a6f170d7fff592e44b089c0d2e68", + policy: corev1.PullIfNotPresent, + opmImage: "opmImage", + extractContent: false, }, { - image: "hello@md5:b1946ac92492d2347c6235b4d2611184", - policy: corev1.PullIfNotPresent, + image: "hello@md5:b1946ac92492d2347c6235b4d2611184", + policy: corev1.PullIfNotPresent, + opmImage: "opmImage", + extractContent: false, + }, + { + image: "quay.io/operator-framework/olm@sha256:b9d011c0fbfb65b387904f8fafc47ee1a9479d28d395473341288ee126ed993b", + policy: corev1.PullIfNotPresent, + opmImage: "quay.io/operator-framework/olm@sha256:b9d011c0fbfb65b387904f8fafc47ee1a9479d28d395473341288ee126ed993b", + extractContent: true, + }, + { + image: "quay.io/operator-framework/olm@sha256:b9d011c0fbfb65b387904f8fafc47ee1a9479d28d395473341288ee126ed993b", + policy: corev1.PullAlways, + opmImage: "quay.io/operator-framework/olm:latest", + extractContent: true, }, } @@ -951,7 +977,16 @@ func TestPullPolicy(t *testing.T) { } for _, tt := range table { - p, err := Pod(source, "catalog", "opmImage", "utilImage", tt.image, serviceAccount("", "service-account"), nil, nil, int32(0), int32(0), int64(workloadUserID), v1alpha1.Legacy) + if tt.extractContent { + grpcPodConfig := &v1alpha1.GrpcPodConfig{ + ExtractContent: &v1alpha1.ExtractContentConfig{ + CacheDir: "/tmp/cache", + CatalogDir: "/catalog", + }, + } + source.Spec.GrpcPodConfig = grpcPodConfig + } + p, err := Pod(source, "catalog", tt.opmImage, "utilImage", tt.image, serviceAccount("", "service-account"), nil, nil, int32(0), int32(0), int64(workloadUserID), v1alpha1.Legacy) require.NoError(t, err) policy := p.Spec.Containers[0].ImagePullPolicy if policy != tt.policy {