Skip to content

Commit

Permalink
Merge pull request #1760 from openshift-cherrypick-robot/cherry-pick-…
Browse files Browse the repository at this point in the history
…1755-to-release-4.5

[release-4.5] Bug 1878359: update catalog image pull policy
  • Loading branch information
openshift-merge-robot committed Sep 18, 2020
2 parents 4bcba8c + 943a41b commit 77fa97b
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 4 deletions.
12 changes: 8 additions & 4 deletions pkg/controller/registry/reconciler/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
package reconciler

import (
"strings"

"github.com/operator-framework/api/pkg/operators/v1alpha1"
controllerclient "github.com/operator-framework/operator-lifecycle-manager/pkg/lib/controller-runtime/client"
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/operatorclient"
Expand Down Expand Up @@ -90,12 +92,14 @@ func NewRegistryReconcilerFactory(lister operatorlister.OperatorLister, opClient
}

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

pod := &v1.Pod{
Expand Down
48 changes: 48 additions & 0 deletions pkg/controller/registry/reconciler/reconciler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package reconciler

import (
"github.com/operator-framework/api/pkg/operators/v1alpha1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"testing"
Expand All @@ -26,3 +27,50 @@ func TestPodNodeSelector(t *testing.T) {
gotCatSrcPodSelector[key])
}
}

func TestPullPolicy(t *testing.T) {
var table = []struct {
image string
policy corev1.PullPolicy
}{
{
image: "quay.io/operator-framework/olm@sha256:b9d011c0fbfb65b387904f8fafc47ee1a9479d28d395473341288ee126ed993b",
policy: corev1.PullIfNotPresent,
},
{
image: "gcc@sha256:06a6f170d7fff592e44b089c0d2e68d870573eb9a23d9c66d4b6ea11f8fad18b",
policy: corev1.PullIfNotPresent,
},
{
image: "myimage:1.0",
policy: corev1.PullAlways,
},
{
image: "busybox",
policy: corev1.PullAlways,
},
{
image: "gcc@sha256:06a6f170d7fff592e44b089c0d2e68",
policy: corev1.PullIfNotPresent,
},
{
image: "hello@md5:b1946ac92492d2347c6235b4d2611184",
policy: corev1.PullIfNotPresent,
},
}

source := &v1alpha1.CatalogSource{
ObjectMeta: metav1.ObjectMeta{
Name: "test",
Namespace: "test-ns",
},
}

for _, tt := range table {
p := Pod(source, "catalog", tt.image, nil, int32(0), int32(0))
policy := p.Spec.Containers[0].ImagePullPolicy
if policy != tt.policy {
t.Fatalf("expected pull policy %s for image %s", tt.policy, tt.image)
}
}
}

0 comments on commit 77fa97b

Please sign in to comment.