-
Notifications
You must be signed in to change notification settings - Fork 545
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
OCPBUGS-4955: Set ImagePullPolicy of bundle unpacker to "IfNotPresent…
…" for image digests (#2908) * Capture ImagePullPolicy selection from image as func, export for wider use, implement in bundle unpacker, add tests Signed-off-by: Daniel Franz <dfranz@redhat.com> * Fixed using wrong image as reference for pull policy inference Signed-off-by: Daniel Franz <dfranz@redhat.com> * Fixed unit test using wrong vars for path/image/etc. Signed-off-by: Daniel Franz <dfranz@redhat.com> * Remove comment block Signed-off-by: Daniel Franz <dfranz@redhat.com> * Generate hash just once for digestPath Signed-off-by: Daniel Franz <dfranz@redhat.com> Signed-off-by: Daniel Franz <dfranz@redhat.com>
- Loading branch information
Showing
5 changed files
with
87 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package image | ||
|
||
import ( | ||
"strings" | ||
|
||
corev1 "k8s.io/api/core/v1" | ||
) | ||
|
||
func InferImagePullPolicy(image string) corev1.PullPolicy { | ||
// Ensure the 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 pods will result in the latest version of the content being delivered on-cluster. | ||
if strings.Contains(image, "@") { | ||
return corev1.PullIfNotPresent | ||
} | ||
return corev1.PullAlways | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package image_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/image" | ||
"github.com/stretchr/testify/require" | ||
corev1 "k8s.io/api/core/v1" | ||
) | ||
|
||
func TestInferImagePullPolicy(t *testing.T) { | ||
tests := []struct { | ||
description string | ||
img string | ||
expectedPolicy corev1.PullPolicy | ||
}{ | ||
{ | ||
description: "WithImageTag", | ||
img: "my-image:my-tag", | ||
expectedPolicy: corev1.PullAlways, | ||
}, | ||
{ | ||
description: "WithImageDigest", | ||
img: "my-image@sha256:54d626e08c1c802b305dad30b7e54a82f102390cc92c7d4db112048935236e9c", | ||
expectedPolicy: corev1.PullIfNotPresent, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.description, func(t *testing.T) { | ||
policy := image.InferImagePullPolicy(tt.img) | ||
require.Equal(t, tt.expectedPolicy, policy) | ||
}) | ||
} | ||
} |