Skip to content

Commit 86838d6

Browse files
authored
Set ImagePullPolicy ifNotPresent for server container (#3599)
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 <[email protected]>
1 parent 3775a4d commit 86838d6

File tree

2 files changed

+51
-15
lines changed

2 files changed

+51
-15
lines changed

pkg/controller/registry/reconciler/reconciler.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@ func Pod(source *operatorsv1alpha1.CatalogSource, name, opmImg, utilImage, img s
305305

306306
pod.Spec.Containers[0].Image = opmImg
307307
pod.Spec.Containers[0].Command = []string{"/bin/opm"}
308+
pod.Spec.Containers[0].ImagePullPolicy = image.InferImagePullPolicy(opmImg)
308309
var containerArgs = []string{
309310
"serve",
310311
filepath.Join(catalogPath, "catalog"),

pkg/controller/registry/reconciler/reconciler_test.go

Lines changed: 50 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -914,32 +914,58 @@ func TestPodNodeSelector(t *testing.T) {
914914

915915
func TestPullPolicy(t *testing.T) {
916916
var table = []struct {
917-
image string
918-
policy corev1.PullPolicy
917+
image string
918+
policy corev1.PullPolicy
919+
opmImage string
920+
extractContent bool
919921
}{
920922
{
921-
image: "quay.io/operator-framework/olm@sha256:b9d011c0fbfb65b387904f8fafc47ee1a9479d28d395473341288ee126ed993b",
922-
policy: corev1.PullIfNotPresent,
923+
image: "quay.io/operator-framework/olm@sha256:b9d011c0fbfb65b387904f8fafc47ee1a9479d28d395473341288ee126ed993b",
924+
policy: corev1.PullIfNotPresent,
925+
opmImage: "opmImage",
926+
extractContent: false,
923927
},
924928
{
925-
image: "gcc@sha256:06a6f170d7fff592e44b089c0d2e68d870573eb9a23d9c66d4b6ea11f8fad18b",
926-
policy: corev1.PullIfNotPresent,
929+
image: "gcc@sha256:06a6f170d7fff592e44b089c0d2e68d870573eb9a23d9c66d4b6ea11f8fad18b",
930+
policy: corev1.PullIfNotPresent,
931+
opmImage: "opmImage",
932+
extractContent: false,
927933
},
928934
{
929-
image: "myimage:1.0",
930-
policy: corev1.PullAlways,
935+
image: "myimage:1.0",
936+
policy: corev1.PullAlways,
937+
opmImage: "opmImage",
938+
extractContent: false,
931939
},
932940
{
933-
image: "busybox",
934-
policy: corev1.PullAlways,
941+
image: "busybox",
942+
policy: corev1.PullAlways,
943+
opmImage: "opmImage",
944+
extractContent: false,
935945
},
936946
{
937-
image: "gcc@sha256:06a6f170d7fff592e44b089c0d2e68",
938-
policy: corev1.PullIfNotPresent,
947+
image: "gcc@sha256:06a6f170d7fff592e44b089c0d2e68",
948+
policy: corev1.PullIfNotPresent,
949+
opmImage: "opmImage",
950+
extractContent: false,
939951
},
940952
{
941-
image: "hello@md5:b1946ac92492d2347c6235b4d2611184",
942-
policy: corev1.PullIfNotPresent,
953+
image: "hello@md5:b1946ac92492d2347c6235b4d2611184",
954+
policy: corev1.PullIfNotPresent,
955+
opmImage: "opmImage",
956+
extractContent: false,
957+
},
958+
{
959+
image: "quay.io/operator-framework/olm@sha256:b9d011c0fbfb65b387904f8fafc47ee1a9479d28d395473341288ee126ed993b",
960+
policy: corev1.PullIfNotPresent,
961+
opmImage: "quay.io/operator-framework/olm@sha256:b9d011c0fbfb65b387904f8fafc47ee1a9479d28d395473341288ee126ed993b",
962+
extractContent: true,
963+
},
964+
{
965+
image: "quay.io/operator-framework/olm@sha256:b9d011c0fbfb65b387904f8fafc47ee1a9479d28d395473341288ee126ed993b",
966+
policy: corev1.PullAlways,
967+
opmImage: "quay.io/operator-framework/olm:latest",
968+
extractContent: true,
943969
},
944970
}
945971

@@ -951,7 +977,16 @@ func TestPullPolicy(t *testing.T) {
951977
}
952978

953979
for _, tt := range table {
954-
p, err := Pod(source, "catalog", "opmImage", "utilImage", tt.image, serviceAccount("", "service-account"), nil, nil, int32(0), int32(0), int64(workloadUserID), v1alpha1.Legacy)
980+
if tt.extractContent {
981+
grpcPodConfig := &v1alpha1.GrpcPodConfig{
982+
ExtractContent: &v1alpha1.ExtractContentConfig{
983+
CacheDir: "/tmp/cache",
984+
CatalogDir: "/catalog",
985+
},
986+
}
987+
source.Spec.GrpcPodConfig = grpcPodConfig
988+
}
989+
p, err := Pod(source, "catalog", tt.opmImage, "utilImage", tt.image, serviceAccount("", "service-account"), nil, nil, int32(0), int32(0), int64(workloadUserID), v1alpha1.Legacy)
955990
require.NoError(t, err)
956991
policy := p.Spec.Containers[0].ImagePullPolicy
957992
if policy != tt.policy {

0 commit comments

Comments
 (0)