Skip to content

Commit 895eb98

Browse files
committed
fix: update catalog pull policy to Always in case the image is not digest-based.
1 parent bcbc5d6 commit 895eb98

File tree

2 files changed

+56
-4
lines changed

2 files changed

+56
-4
lines changed

pkg/controller/registry/reconciler/reconciler.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
package reconciler
33

44
import (
5+
"strings"
6+
57
"github.com/operator-framework/api/pkg/operators/v1alpha1"
68
controllerclient "github.com/operator-framework/operator-lifecycle-manager/pkg/lib/controller-runtime/client"
79
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/operatorclient"
@@ -90,12 +92,14 @@ func NewRegistryReconcilerFactory(lister operatorlister.OperatorLister, opClient
9092
}
9193

9294
func Pod(source *v1alpha1.CatalogSource, name string, image string, labels map[string]string, readinessDelay int32, livenessDelay int32) *v1.Pod {
93-
// ensure catalog image is pulled always if catalog polling is configured
95+
// Ensure the catalog image is always pulled if the image is not based on a digest, measured by whether an "@" is included.
96+
// See https://github.com/docker/distribution/blob/master/reference/reference.go for more info.
97+
// This means recreating non-digest based catalog pods will result in the latest version of the catalog content being delivered on-cluster.
9498
var pullPolicy v1.PullPolicy
95-
if source.Spec.UpdateStrategy != nil {
96-
pullPolicy = v1.PullAlways
97-
} else {
99+
if strings.Contains(image, "@") {
98100
pullPolicy = v1.PullIfNotPresent
101+
} else {
102+
pullPolicy = v1.PullAlways
99103
}
100104

101105
pod := &v1.Pod{

pkg/controller/registry/reconciler/reconciler_test.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package reconciler
22

33
import (
44
"github.com/operator-framework/api/pkg/operators/v1alpha1"
5+
corev1 "k8s.io/api/core/v1"
56
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
67

78
"testing"
@@ -26,3 +27,50 @@ func TestPodNodeSelector(t *testing.T) {
2627
gotCatSrcPodSelector[key])
2728
}
2829
}
30+
31+
func TestPullPolicy(t *testing.T) {
32+
var table = []struct {
33+
image string
34+
policy corev1.PullPolicy
35+
}{
36+
{
37+
image: "quay.io/operator-framework/olm@sha256:b9d011c0fbfb65b387904f8fafc47ee1a9479d28d395473341288ee126ed993b",
38+
policy: corev1.PullIfNotPresent,
39+
},
40+
{
41+
image: "gcc@sha256:06a6f170d7fff592e44b089c0d2e68d870573eb9a23d9c66d4b6ea11f8fad18b",
42+
policy: corev1.PullIfNotPresent,
43+
},
44+
{
45+
image: "myimage:1.0",
46+
policy: corev1.PullAlways,
47+
},
48+
{
49+
image: "busybox",
50+
policy: corev1.PullAlways,
51+
},
52+
{
53+
image: "gcc@sha256:06a6f170d7fff592e44b089c0d2e68",
54+
policy: corev1.PullIfNotPresent,
55+
},
56+
{
57+
image: "hello@md5:b1946ac92492d2347c6235b4d2611184",
58+
policy: corev1.PullIfNotPresent,
59+
},
60+
}
61+
62+
source := &v1alpha1.CatalogSource{
63+
ObjectMeta: metav1.ObjectMeta{
64+
Name: "test",
65+
Namespace: "test-ns",
66+
},
67+
}
68+
69+
for _, tt := range table {
70+
p := Pod(source, "catalog", tt.image, nil, int32(0), int32(0))
71+
policy := p.Spec.Containers[0].ImagePullPolicy
72+
if policy != tt.policy {
73+
t.Fatalf("expected pull policy %s for image %s", tt.policy, tt.image)
74+
}
75+
}
76+
}

0 commit comments

Comments
 (0)