Skip to content

Commit b54b084

Browse files
authored
Fix Use IfNotPresent policy when operator-sdk run bundle --if-not-present #6795 (#6851)
Signed-off-by: Tiger Kaovilai <[email protected]>
1 parent 1d451c0 commit b54b084

File tree

5 files changed

+22
-0
lines changed

5 files changed

+22
-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

+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 {

website/content/en/docs/cli/operator-sdk_run_bundle-upgrade.md

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ operator-sdk run bundle-upgrade <bundle-image> [flags]
2121
```
2222
--ca-secret-name string Name of a generic secret containing a PEM root certificate file required to pull bundle images. This secret *must* be in the namespace that this command is configured to run in, and the file *must* be encoded under the key "cert.pem"
2323
-h, --help help for bundle-upgrade
24+
--image-pull-policy string image pull policy for the registry pod (default "Always")
2425
--kubeconfig string Path to the kubeconfig file to use for CLI requests.
2526
-n, --namespace string If present, namespace scope for this CLI request
2627
--pull-secret-name string Name of image pull secret ("type: kubernetes.io/dockerconfigjson") required to pull bundle images. This secret *must* be both in the namespace and an imagePullSecret of the service account that this command is configured to run in

website/content/en/docs/cli/operator-sdk_run_bundle.md

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ operator-sdk run bundle <bundle-image> [flags]
3131
--ca-secret-name string Name of a generic secret containing a PEM root certificate file required to pull bundle images. This secret *must* be in the namespace that this command is configured to run in, and the file *must* be encoded under the key "cert.pem"
3232
--decompression-image string image used in an init container in the registry pod to decompress the compressed catalog contents. cat and gzip binaries are expected to exist in the PATH (default "registry.access.redhat.com/ubi9/ubi:9.4")
3333
-h, --help help for bundle
34+
--image-pull-policy string image pull policy for the registry pod (default "Always")
3435
--index-image string index image in which to inject bundle (default "quay.io/operator-framework/opm:latest")
3536
--install-mode InstallModeValue install mode
3637
--kubeconfig string Path to the kubeconfig file to use for CLI requests.

0 commit comments

Comments
 (0)