Skip to content

Commit bb4ee45

Browse files
committed
Fix Use IfNotPresent policy when operator-sdk run bundle --if-not-present operator-framework#6795
1 parent 4c30e49 commit bb4ee45

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

internal/olm/operator/registry/fbcindex/fbc_registry_pod.go

+8
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ type FBCRegistryPod struct { //nolint:maligned
6060
// BundleItems contains all bundles to be added to a registry pod.
6161
BundleItems []index.BundleItem
6262

63+
// ImagePullPolicy is the image pull policy for the registry pod, default is PullAlways
64+
ImagePullPolicy corev1.PullPolicy
65+
6366
// Index image contains a database of pointers to operator manifest content that is queriable via an API.
6467
// new version of an operator bundle when published can be added to an index image
6568
IndexImage string
@@ -156,6 +159,11 @@ func (f *FBCRegistryPod) Create(ctx context.Context, cfg *operator.Configuration
156159
}
157160
}
158161

162+
if f.ImagePullPolicy == "" {
163+
f.ImagePullPolicy = corev1.PullAlways
164+
}
165+
f.pod.Spec.Containers[0].ImagePullPolicy = f.ImagePullPolicy
166+
159167
if err := f.cfg.Client.Create(ctx, f.pod); err != nil {
160168
return nil, fmt.Errorf("error creating pod: %w", err)
161169
}

internal/olm/operator/registry/index/registry_pod.go

+8
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ type SQLiteRegistryPod struct { //nolint:maligned
5858
// BundleItems contains all bundles to be added to a registry pod.
5959
BundleItems []BundleItem
6060

61+
// ImagePullPolicy is the image pull policy for the registry pod, default is PullAlways
62+
ImagePullPolicy corev1.PullPolicy
63+
6164
// Index image contains a database of pointers to operator manifest content that is queriable via an API.
6265
// new version of an operator bundle when published can be added to an index image
6366
IndexImage string
@@ -151,6 +154,11 @@ func (rp *SQLiteRegistryPod) Create(ctx context.Context, cfg *operator.Configura
151154
}
152155
}
153156

157+
if rp.ImagePullPolicy == "" {
158+
rp.ImagePullPolicy = corev1.PullAlways
159+
}
160+
rp.pod.Spec.Containers[0].ImagePullPolicy = rp.ImagePullPolicy
161+
154162
if err := rp.cfg.Client.Create(ctx, rp.pod); err != nil {
155163
return nil, fmt.Errorf("error creating pod: %w", err)
156164
}

internal/olm/operator/registry/index_image.go

+10
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ type IndexImageCatalogCreator struct {
9797
HasFBCLabel bool
9898
FBCContent string
9999
PackageName string
100+
ImagePullPolicy string
100101
IndexImage string
101102
InitImage string
102103
BundleImage string
@@ -138,6 +139,13 @@ func (c *IndexImageCatalogCreator) BindFlags(fs *pflag.FlagSet) {
138139
"while pulling bundles")
139140
fs.BoolVar(&c.UseHTTP, "use-http", false, "use plain HTTP for container image registries "+
140141
"while pulling bundles")
142+
fs.StringVar(&c.ImagePullPolicy, "image-pull-policy", string(corev1.PullAlways), "image pull policy for the registry pod")
143+
_ = fs.MarkHidden("image-pull-policy")
144+
pullIfNotPresent := false
145+
fs.BoolVar(&pullIfNotPresent, "pull-if-not-present", false, "pull the image only if it is not present locally")
146+
if pullIfNotPresent {
147+
c.ImagePullPolicy = string(corev1.PullIfNotPresent)
148+
}
141149

142150
// default to Legacy
143151
c.SecurityContext = SecurityContext{ContextType: Legacy}
@@ -531,6 +539,7 @@ func (c IndexImageCatalogCreator) createAnnotatedRegistry(ctx context.Context, c
531539
InitImage: c.InitImage,
532540
FBCContent: c.FBCContent,
533541
SecurityContext: c.SecurityContext.String(),
542+
ImagePullPolicy: corev1.PullPolicy(c.ImagePullPolicy),
534543
}
535544

536545
pod, err = fbcRegistryPod.Create(ctx, c.cfg, cs)
@@ -548,6 +557,7 @@ func (c IndexImageCatalogCreator) createAnnotatedRegistry(ctx context.Context, c
548557
SkipTLSVerify: c.SkipTLSVerify,
549558
UseHTTP: c.UseHTTP,
550559
SecurityContext: c.SecurityContext.String(),
560+
ImagePullPolicy: corev1.PullPolicy(c.ImagePullPolicy),
551561
}
552562

553563
if registryPod.DBPath, err = c.getDBPath(ctx); err != nil {

0 commit comments

Comments
 (0)