Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

template/*: allow passing custom bundle renderer #1423

Conversation

joelanford
Copy link
Member

Description of the change:
Make the template rendering libraries accept a bundle renderer function.

Motivation for the change:
This allows importers of operator-registry to provide custom rendering logic for bundle references that appear in template configuration files.

This would enable third-parties to build experimental bundle transport formats and continue using the standard operator-registry template tooling with them.

Reviewer Checklist

  • Implementation matches the proposed design, or proposal is updated to match implementation
  • Sufficient unit test coverage
  • Sufficient end-to-end test coverage
  • Docs updated or added to /docs
  • Commit messages sensible and descriptive

Copy link
Contributor

openshift-ci bot commented Aug 22, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: joelanford

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 22, 2024
@joelanford
Copy link
Member Author

Seems like the semver template explicitly expects the references in the template file to show up in the rendered FBC. Looking to see if that can be relaxed somehow because that breaks the use case I'm trying to make work (render a bundle from a local OCI archive file)

Copy link

codecov bot commented Aug 23, 2024

Codecov Report

Attention: Patch coverage is 58.33333% with 10 lines in your changes missing coverage. Please review.

Project coverage is 48.30%. Comparing base (e787595) to head (f262850).
Report is 30 commits behind head on master.

Files with missing lines Patch % Lines
alpha/template/semver/semver.go 68.42% 6 Missing ⚠️
alpha/action/render.go 25.00% 3 Missing ⚠️
alpha/template/basic/basic.go 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1423      +/-   ##
==========================================
+ Coverage   48.14%   48.30%   +0.15%     
==========================================
  Files         136      136              
  Lines       12780    12798      +18     
==========================================
+ Hits         6153     6182      +29     
+ Misses       5593     5581      -12     
- Partials     1034     1035       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

buildBundleList(&sv.Fast.Bundles, &bundleDict)
buildBundleList(&sv.Stable.Bundles, &bundleDict)

bundleDict := buildBundleList(*sv)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: would it be worth renaming sv to make the code a bit more readable?

(*dict)[b.Image] = struct{}{}
func buildBundleList(t semverTemplate) map[string]string {
dict := make(map[string]string)
for _, bl := range []semverTemplateChannelBundles{t.Candidate, t.Fast, t.Stable} {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: wdyt about making the making the semverTemplateChannelBundles list a parameter? Before we could see which channel templates were being used to create the bundle list at the top level. Might also make the method more flexible? (though given that it isn't exported - maybe not...XD).

Copy link
Contributor

@perdasilva perdasilva left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I'm understanding it right, aside from updating some error messages to be more readable (thank you!), we're moving the Template type(s) to be more flexible, allowing users to implement their own rendering behavior. In general it lgtm. I've left a few comments and suggestions, but nothing that I think is blocking or that we couldn't address later. I don't know enough about the downstream (not as in to the downstream) side-effects of this change to approve. I'd think @grokspawn would be the best person here to reason about the big picture effects of this change (though I doubt there will be anything too serious).

"io"

"github.com/blang/semver/v4"

"github.com/operator-framework/operator-registry/alpha/action/migrations"
"github.com/operator-framework/operator-registry/pkg/image"
"github.com/operator-framework/operator-registry/alpha/declcfg"
)

// data passed into this module externally
type Template struct {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: should we just make Template (as defined in basic with just the RenderBundle method) a shared type that basic and semver sub-type and implement? The basic and semver packages could even export a factory functions to get new instances of templates?

@perdasilva
Copy link
Contributor

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Sep 12, 2024
@openshift-merge-bot openshift-merge-bot bot merged commit 1adde98 into operator-framework:master Sep 12, 2024
11 of 12 checks passed
@perdasilva
Copy link
Contributor

@joelanford Oh shit! ocp-bot merged it coz I put /lgtm 🫤
should we disable it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants