Skip to content

Commit

Permalink
Fix Use IfNotPresent policy when `operator-sdk run bundle --if-not-pr…
Browse files Browse the repository at this point in the history
…esent` #6795

Signed-off-by: Tiger Kaovilai <tkaovila@redhat.com>
  • Loading branch information
kaovilai committed Oct 30, 2024
1 parent 4c30e49 commit 7d78ddf
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
8 changes: 8 additions & 0 deletions internal/olm/operator/registry/fbcindex/fbc_registry_pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ type FBCRegistryPod struct { //nolint:maligned
// BundleItems contains all bundles to be added to a registry pod.
BundleItems []index.BundleItem

// ImagePullPolicy is the image pull policy for the registry pod, default is PullAlways
ImagePullPolicy corev1.PullPolicy

// Index image contains a database of pointers to operator manifest content that is queriable via an API.
// new version of an operator bundle when published can be added to an index image
IndexImage string
Expand Down Expand Up @@ -156,6 +159,11 @@ func (f *FBCRegistryPod) Create(ctx context.Context, cfg *operator.Configuration
}
}

if f.ImagePullPolicy == "" {
f.ImagePullPolicy = corev1.PullAlways
}
f.pod.Spec.Containers[0].ImagePullPolicy = f.ImagePullPolicy

if err := f.cfg.Client.Create(ctx, f.pod); err != nil {
return nil, fmt.Errorf("error creating pod: %w", err)
}
Expand Down
8 changes: 8 additions & 0 deletions internal/olm/operator/registry/index/registry_pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ type SQLiteRegistryPod struct { //nolint:maligned
// BundleItems contains all bundles to be added to a registry pod.
BundleItems []BundleItem

// ImagePullPolicy is the image pull policy for the registry pod, default is PullAlways
ImagePullPolicy corev1.PullPolicy

// Index image contains a database of pointers to operator manifest content that is queriable via an API.
// new version of an operator bundle when published can be added to an index image
IndexImage string
Expand Down Expand Up @@ -151,6 +154,11 @@ func (rp *SQLiteRegistryPod) Create(ctx context.Context, cfg *operator.Configura
}
}

if rp.ImagePullPolicy == "" {
rp.ImagePullPolicy = corev1.PullAlways
}
rp.pod.Spec.Containers[0].ImagePullPolicy = rp.ImagePullPolicy

if err := rp.cfg.Client.Create(ctx, rp.pod); err != nil {
return nil, fmt.Errorf("error creating pod: %w", err)
}
Expand Down
10 changes: 10 additions & 0 deletions internal/olm/operator/registry/index_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ type IndexImageCatalogCreator struct {
HasFBCLabel bool
FBCContent string
PackageName string
ImagePullPolicy string
IndexImage string
InitImage string
BundleImage string
Expand Down Expand Up @@ -138,6 +139,13 @@ func (c *IndexImageCatalogCreator) BindFlags(fs *pflag.FlagSet) {
"while pulling bundles")
fs.BoolVar(&c.UseHTTP, "use-http", false, "use plain HTTP for container image registries "+
"while pulling bundles")
fs.StringVar(&c.ImagePullPolicy, "image-pull-policy", string(corev1.PullAlways), "image pull policy for the registry pod")
_ = fs.MarkHidden("image-pull-policy")
pullIfNotPresent := false
fs.BoolVar(&pullIfNotPresent, "pull-if-not-present", false, "pull the image only if it is not present locally")
if pullIfNotPresent {
c.ImagePullPolicy = string(corev1.PullIfNotPresent)
}

// default to Legacy
c.SecurityContext = SecurityContext{ContextType: Legacy}
Expand Down Expand Up @@ -531,6 +539,7 @@ func (c IndexImageCatalogCreator) createAnnotatedRegistry(ctx context.Context, c
InitImage: c.InitImage,
FBCContent: c.FBCContent,
SecurityContext: c.SecurityContext.String(),
ImagePullPolicy: corev1.PullPolicy(c.ImagePullPolicy),
}

pod, err = fbcRegistryPod.Create(ctx, c.cfg, cs)
Expand All @@ -548,6 +557,7 @@ func (c IndexImageCatalogCreator) createAnnotatedRegistry(ctx context.Context, c
SkipTLSVerify: c.SkipTLSVerify,
UseHTTP: c.UseHTTP,
SecurityContext: c.SecurityContext.String(),
ImagePullPolicy: corev1.PullPolicy(c.ImagePullPolicy),
}

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

0 comments on commit 7d78ddf

Please sign in to comment.