Skip to content

Commit

Permalink
generate bundle: Add Image Digest Resolver Option
Browse files Browse the repository at this point in the history
Add option to select the image digest resolver when rendering bundles with
image digests pinned. The set of supported tools is defined in the
`operator-manifest-tools` library (currently `crane`, `skopeo`, and `script`).

Fixes operator-framework#6868

Signed-off-by: Adam Kaplan <[email protected]>
  • Loading branch information
adambkaplan committed Nov 19, 2024
1 parent 0735b20 commit 773fce8
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 3 deletions.
10 changes: 10 additions & 0 deletions changelog/fragments/feat-image-digest-resolver.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
entries:
- description: >
Add `--image-digest-resolver` option to the operator-sdk
`generate bundle` command. When using image digests in operator bundles,
this lets developers choose `crane`, `skopeo` or a custom script to
resolve image SHAs.
kind: "addition"
# Is this a breaking change?
breaking: false
36 changes: 33 additions & 3 deletions internal/cmd/operator-sdk/generate/bundle/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ func (c *bundleCmd) setDefaults() (err error) {
if c.packageName, c.layout, err = genutil.GetPackageNameAndLayout(c.packageName); err != nil {
return err
}

return nil
}

Expand Down Expand Up @@ -148,6 +149,23 @@ func (c bundleCmd) validateManifests() (err error) {
}
}

if c.useImageDigests {
if len(c.imageDigestResolver) == 0 {
return errors.New("--image-digest-resolver cannot be empty when using image digests")
}
isValid := false
for _, r := range imageresolver.GetResolverOptions() {
if c.imageDigestResolver == string(r) {
isValid = true
break
}
}
if !isValid {
return fmt.Errorf("--image-digest-resolver must be one of: %s", imageresolver.GetResolverOptions())
}

}

return nil
}

Expand Down Expand Up @@ -311,9 +329,8 @@ func (c bundleCmd) pinImages(manifestPath string) error {
if err != nil {
return err
}
resolverArgs := make(map[string]string)
resolverArgs["usedefault"] = "true"
resolver, err := imageresolver.GetResolver(imageresolver.ResolverCrane, resolverArgs)

resolver, err := imageresolver.GetResolver(imageresolver.ResolverOption(c.imageDigestResolver), c.resolverArgs())
if err != nil {
return err
}
Expand All @@ -329,3 +346,16 @@ func (c bundleCmd) pinImages(manifestPath string) error {

return nil
}

func (c bundleCmd) resolverArgs() map[string]string {
resolverArgs := make(map[string]string)

switch c.imageDigestResolver {
case string(imageresolver.ResolverCrane):
resolverArgs["usedefault"] = "true"
case string(imageresolver.ResolverSkopeo):
case string(imageresolver.ResolverScript):
default:
}
return resolverArgs
}
3 changes: 3 additions & 0 deletions internal/cmd/operator-sdk/generate/bundle/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ type bundleCmd struct {

// Use Image Digests flag to toggle using traditional Image tags vs SHA Digests
useImageDigests bool
// Tool to use when resolving image digests. Defaults to crane.
imageDigestResolver string
}

// NewCmd returns the 'bundle' command configured for the new project layout.
Expand Down Expand Up @@ -144,6 +146,7 @@ func (c *bundleCmd) addFlagsTo(fs *pflag.FlagSet) {
fs.StringVar(&c.packageName, "package", "", "Bundle's package name")

fs.BoolVar(&c.useImageDigests, "use-image-digests", false, "Use SHA Digest for images")
fs.StringVar(&c.imageDigestResolver, "image-digest-resolver", "crane", "Resolver for image digests. Options are crane, skopeo, or script")
}

func (c bundleCmd) println(a ...interface{}) {
Expand Down

0 comments on commit 773fce8

Please sign in to comment.