Skip to content

Commit db08942

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

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

Diff for: 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
}

Diff for: 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
}

Diff for: internal/olm/operator/registry/index_image.go

+4
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,7 @@ 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")
141143

142144
// default to Legacy
143145
c.SecurityContext = SecurityContext{ContextType: Legacy}
@@ -531,6 +533,7 @@ func (c IndexImageCatalogCreator) createAnnotatedRegistry(ctx context.Context, c
531533
InitImage: c.InitImage,
532534
FBCContent: c.FBCContent,
533535
SecurityContext: c.SecurityContext.String(),
536+
ImagePullPolicy: corev1.PullPolicy(c.ImagePullPolicy),
534537
}
535538

536539
pod, err = fbcRegistryPod.Create(ctx, c.cfg, cs)
@@ -548,6 +551,7 @@ func (c IndexImageCatalogCreator) createAnnotatedRegistry(ctx context.Context, c
548551
SkipTLSVerify: c.SkipTLSVerify,
549552
UseHTTP: c.UseHTTP,
550553
SecurityContext: c.SecurityContext.String(),
554+
ImagePullPolicy: corev1.PullPolicy(c.ImagePullPolicy),
551555
}
552556

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

0 commit comments

Comments
 (0)