Skip to content

Conversation

@grokspawn
Copy link
Contributor

Description of the change:
Replaces #1814

Various type changes and refactoring necessary to make opm alpha render-template capable of detecting the template type from sniffing its schema, as well as name standardization across all template types and a new factory-based creation pattern.

This absolutely sacrifices stability of the API in favor of stability of the datatypes and callflows for future growth.

Motivation for the change:
Since we created a formal schema for the basic catalog template, it made much more sense for Template to be an interface for a creation/call pattern which was increasingly entrenched in users' tooling... so it was easy to put off. But since it was also largely a "move existing stuff around" activity (read: super simple operations with complex propagation and high potential for side effects), it seemed a great opportunity to see what Claude would do with it.

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

@codecov
Copy link

codecov bot commented Nov 25, 2025

Codecov Report

❌ Patch coverage is 54.19847% with 60 lines in your changes missing coverage. Please review.
✅ Project coverage is 57.51%. Comparing base (b7c3f27) to head (a4b0045).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
alpha/template/basic/basic.go 0.00% 27 Missing ⚠️
alpha/template/registry.go 70.96% 18 Missing ⚠️
alpha/template/semver/semver.go 48.00% 13 Missing ⚠️
alpha/template/schema.go 88.23% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##           master    #1844    +/-   ##
========================================
  Coverage   57.50%   57.51%            
========================================
  Files         136      137     +1     
  Lines       12934    13035   +101     
========================================
+ Hits         7438     7497    +59     
- Misses       4341     4382    +41     
- Partials     1155     1156     +1     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors the template rendering system to support automatic template type detection based on schema fields, while still allowing explicit type specification. The changes consolidate the previously separate basic and semver subcommands into a unified render-template command that can auto-detect the template type from the input file's schema field.

Key Changes:

  • Introduced a common Template interface and factory pattern for all template types
  • Implemented schema-based auto-detection using a registry system
  • Unified the command structure from separate subcommands to a single command with optional type specification

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
cmd/opm/alpha/template/cmd.go Replaced separate subcommands with unified render-template command that accepts optional TYPE and FILE arguments
cmd/opm/alpha/template/render.go New file implementing unified rendering logic with auto-detection and explicit type specification support
cmd/opm/alpha/template/basic.go Removed - functionality moved to unified render.go
cmd/opm/alpha/template/semver.go Removed - functionality moved to unified render.go
alpha/template/template.go New file defining Template interface, TemplateFactory interface, and Registry for schema-based template creation
alpha/template/schema.go New file implementing schema detection from YAML/JSON input
alpha/template/basic/basic.go Refactored to implement new Template interface with factory pattern; renamed data struct to BasicTemplateData
alpha/template/semver/semver.go Refactored to implement new Template interface with factory pattern; moved type definitions from types.go and renamed to SemverTemplateData
alpha/template/semver/types.go Removed - content migrated into semver.go
alpha/template/semver/semver_test.go Updated test assertions to use SemverTemplateData and changed to ElementsMatch for order-independent comparison

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated 8 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 12 out of 12 changed files in this pull request and generated 5 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.

@grokspawn grokspawn force-pushed the template-autodetect branch 2 times, most recently from 745a3f7 to cd4bc48 Compare November 26, 2025 03:49
@grokspawn grokspawn requested a review from perdasilva November 26, 2025 04:14
Comment on lines 51 to 63
// and returns a reader that can be used to render the template. The returned reader includes
// both the data consumed during schema detection and the remaining unconsumed data.
Copy link

Choose a reason for hiding this comment

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

could returned reader be hidden inside the returned Template instance? can this reader be used independently?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It could be hidden in the template type, but it's arbitrary. The template is only interested in the reader as an input source, but it isn't inherently a template concern. It's just a general I/O one.

@grokspawn
Copy link
Contributor Author

Thanks for the really detailed review @pedjak! I've included changes which hopefully resolve your concerns and address ambiguity in the PR. Please give it another once over when you have a chance.


type Template struct {
RenderBundle func(context.Context, string) (*declcfg.DeclarativeConfig, error)
func init() {
Copy link

Choose a reason for hiding this comment

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

this init funciton is called only when we import alpha/template/basic package. Hence, only then we are going to register this Factory.

IMHO, we should register it at the other end - within alpha/template/registry.go - in that way all available factories will be registered always.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd initially tried to do that-- feeling similarly-- but I was also trying to optimize the smallest number of new packages and the resulting import cycles basically dictated this approach.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I took another swing at this now that I had some time in the new year! 😄

return schema
}

type BasicTemplateData struct {
Copy link

Choose a reason for hiding this comment

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

does it need to be public?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's used by the template converter to be able to make a basic template from a full FBC representation, so it does need to be public.
I'm sure that I could pivot this away, but the purpose of this PR was to change the functional flow of the CLI commands to be able to simplify them (not needing to always specify the template type) and I could follow up with such things in later efforts.

Bundles []semverTemplateBundleEntry `json:"bundles,omitempty"`
}

type SemverTemplateData struct {
Copy link

Choose a reason for hiding this comment

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

does this need to be public? It is a bit strange that a caller get access to a type, that has member fields of a private type.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When initially implemented, this had to be public/exported in order for marshaling/unmarshaling to function. I haven't revisited.

@grokspawn grokspawn force-pushed the template-autodetect branch from 6243e92 to 0b3a0cb Compare January 9, 2026 16:52
@grokspawn grokspawn force-pushed the template-autodetect branch from 0b3a0cb to ff10956 Compare January 9, 2026 17:21
@dtfranz
Copy link
Contributor

dtfranz commented Jan 14, 2026

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Jan 14, 2026
Signed-off-by: grokspawn <jordan@nimblewidget.com>
Signed-off-by: grokspawn <jordan@nimblewidget.com>
Signed-off-by: grokspawn <jordan@nimblewidget.com>
@grokspawn grokspawn force-pushed the template-autodetect branch from ff10956 to a4b0045 Compare January 14, 2026 23:10
@openshift-ci openshift-ci bot removed the lgtm Indicates that a PR is ready to be merged. label Jan 14, 2026
@dtfranz
Copy link
Contributor

dtfranz commented Jan 14, 2026

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Jan 14, 2026
@grokspawn
Copy link
Contributor Author

/approve

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Jan 15, 2026

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: grokspawn

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

The pull request process is described here

Details 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 Jan 15, 2026
@openshift-merge-bot openshift-merge-bot bot merged commit acfd70b into operator-framework:master Jan 15, 2026
12 of 13 checks passed

func (r *registry) CreateTemplateByType(templateType string, renderBundle BundleRenderer) (Template, error) {
r.mu.RLock()
factory, exists := r.factories[templateType]

Choose a reason for hiding this comment

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

FYI, this change introduces a regression in v1.62.0 because the factories are indexed by the full schema but templateType is only the last portion.

Issue opened:

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. go-apidiff-override lgtm Indicates that a PR is ready to be merged.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants