Skip to content

Conversation

@everettraven
Copy link
Contributor

@everettraven everettraven commented Jul 18, 2024

Description

Makes the reconcile method on the ClusterExtensionReconciler easier to unit test by encapsulating distinct operations as interfaces that can be mocked:

  • (Done before this PR) Resolution is now done via a Resolver interface.
    • (Done as part of this PR) Bundle validation is now done by the Resolver. The reasoning behind this is that it reduces the complexity of the reconcile method by making the assumption that the configured Resolver will always return a valid bundle. Validation unit tests that existed in the internal/controller package have been moved and updated in the internal/resolve package
  • Unpacking was unchanged
  • Installation of content is now abstracted into a more generic Applier interface. This makes it easier to, in the future, swap out the underlying installation method by implementing a new Applier interface and swapping it out for the existing one. The existing Helm-based installation logic was moved to an implementation of this interface.
  • Watching of managed resources was moved to a new Watcher interface that was implemented as part of the provided service account work. This was going to be a change that took place in the near future. From a functionality perspective, nothing should have changed.
  • Unit tests added for the ClusterExtensionReconciler.reconcile() method

Reviewer Checklist

  • API Go Documentation
  • Tests: Unit Tests (and E2E Tests, if appropriate)
  • Comprehensive Commit Messages
  • Links to related GitHub Issue(s)

@openshift-ci openshift-ci bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jul 18, 2024
@netlify
Copy link

netlify bot commented Jul 18, 2024

Deploy Preview for olmv1 ready!

Name Link
🔨 Latest commit dcd37f0
🔍 Latest deploy log https://app.netlify.com/sites/olmv1/deploys/66acee810502b8000801f846
😎 Deploy Preview https://deploy-preview-1068--olmv1.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@openshift-merge-robot openshift-merge-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 18, 2024
@joelanford
Copy link
Member

Nice! I like this idea. I'll take a closer look at this tomorrow, but one thing I would suggest off the bat is talking to @thetechnick about the Applier interface. I was chatting with him last week about experimenting with plugging package-operator's apply logic into operator-controller. I figure having a second implementation candidate would help validate our ideas behind the shape of that interface.

@thetechnick
Copy link
Contributor

I do have a very rough first PoC here:
thetechnick#1
It directly uses Package Operator APIs to offload bundle reconciliation, so operator-controller just has to create a ClusterPackage, read status from it and lean back, while getting features similar to the OLMv0 Subscription config for free.

@everettraven
Copy link
Contributor Author

@joelanford Sounds good. Are you thinking to utilize the ClusterPackage similarly to what @thetechnick has done (via the PoC) or more along the lines of importing the apply logic and using it as a library?

I'd be a bit hesitant to move back to an approach where we are creating an underlying resource like the ClusterPackage since we intentionally decided to deviate from that approach relatively recently (~3ish months ago).

@everettraven everettraven force-pushed the shiftweek/reconciler branch from 9afedde to 9fe7cf0 Compare July 25, 2024 20:02
@openshift-merge-robot openshift-merge-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 25, 2024
Preflights []Preflight
}

func (h *Helm) Apply(ctx context.Context, contentFS fs.FS, ext *ocv1alpha1.ClusterExtension, labels map[string]string) ([]client.Object, string, error) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ideally we make this function more easily unit testable and add explicit unit tests for this function and the individual components but I would put that out of scope of the intention of this PR.

@everettraven everettraven marked this pull request as ready for review July 26, 2024 19:29
@everettraven everettraven requested a review from a team as a code owner July 26, 2024 19:29
@openshift-ci openshift-ci bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jul 26, 2024
@everettraven everettraven changed the title ✨ WIP: reconciler refactor ✨ refactor ClusterExtensionReconciler.reconcile() Jul 26, 2024
installedBundleVersion, err := mmsemver.NewVersion(installedBundle.Version)
if err != nil {
return nil, err
return nil, fmt.Errorf("parsing installed bundle version %q: %w | installedBundle %v", installedBundle.Version, err, installedBundle)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
return nil, fmt.Errorf("parsing installed bundle version %q: %w | installedBundle %v", installedBundle.Version, err, installedBundle)
return nil, fmt.Errorf("parsing installed bundle %q version %q: %w | installedBundle %v", installedBundle.Name, installedBundle.Version, err)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah shoot, some of that is still debugging changes I didn't rollback - thanks for catching that!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

should be updated in 8c12758

@everettraven
Copy link
Contributor Author

I will squash commits after reviews are fully addressed

@codecov
Copy link

codecov bot commented Jul 26, 2024

Codecov Report

Attention: Patch coverage is 56.91057% with 53 lines in your changes missing coverage. Please review.

Project coverage is 75.28%. Comparing base (989a3df) to head (dcd37f0).

Files Patch % Lines
internal/applier/helm.go 41.97% 35 Missing and 12 partials ⚠️
cmd/manager/main.go 70.00% 2 Missing and 1 partial ⚠️
internal/catalogmetadata/filter/successors.go 0.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1068      +/-   ##
==========================================
- Coverage   75.65%   75.28%   -0.38%     
==========================================
  Files          31       33       +2     
  Lines        1902     1861      -41     
==========================================
- Hits         1439     1401      -38     
- Misses        320      321       +1     
+ Partials      143      139       -4     
Flag Coverage Δ
e2e 56.85% <48.78%> (-1.20%) ⬇️
unit 52.17% <23.57%> (+2.43%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

@openshift-merge-robot openshift-merge-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 1, 2024
@tmshort
Copy link
Contributor

tmshort commented Aug 1, 2024

Looks reasonable to me, but needs a rebase.

…testing

by moving bundle validation logic to the resolver, moving installation
of content behind a new Applier interface, and using the new
contentmanager.Watcher interface for watching managed objects

Signed-off-by: everettraven <[email protected]>
Signed-off-by: everettraven <[email protected]>
Signed-off-by: everettraven <[email protected]>
Signed-off-by: everettraven <[email protected]>
Signed-off-by: everettraven <[email protected]>
Signed-off-by: everettraven <[email protected]>
@everettraven everettraven force-pushed the shiftweek/reconciler branch from 8c12758 to dcd37f0 Compare August 2, 2024 14:34
@openshift-merge-robot openshift-merge-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 2, 2024
@everettraven everettraven enabled auto-merge August 2, 2024 15:09
@everettraven everettraven added this pull request to the merge queue Aug 2, 2024
Copy link
Contributor

@tmshort tmshort left a comment

Choose a reason for hiding this comment

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

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Aug 2, 2024
Merged via the queue into operator-framework:main with commit cab9eab Aug 2, 2024
perdasilva pushed a commit to LalatenduMohanty/operator-controller that referenced this pull request Aug 13, 2024
…#1068)

* update reconciler with logical interface abstractions to simply unit testing

by moving bundle validation logic to the resolver, moving installation
of content behind a new Applier interface, and using the new
contentmanager.Watcher interface for watching managed objects

Signed-off-by: everettraven <[email protected]>

* update testing

Signed-off-by: everettraven <[email protected]>

* update testing

Signed-off-by: everettraven <[email protected]>

* remove bundle validation unit tests from controller package

Signed-off-by: everettraven <[email protected]>

* make linter happy

Signed-off-by: everettraven <[email protected]>

* remove postrenderer, replace with map[string]string for labels

Signed-off-by: everettraven <[email protected]>

* update debugging error string

Signed-off-by: everettraven <[email protected]>

* rebase fixes

Signed-off-by: everettraven <[email protected]>

---------

Signed-off-by: everettraven <[email protected]>
perdasilva pushed a commit to kevinrizza/operator-controller that referenced this pull request Aug 13, 2024
…#1068)

* update reconciler with logical interface abstractions to simply unit testing

by moving bundle validation logic to the resolver, moving installation
of content behind a new Applier interface, and using the new
contentmanager.Watcher interface for watching managed objects

Signed-off-by: everettraven <[email protected]>

* update testing

Signed-off-by: everettraven <[email protected]>

* update testing

Signed-off-by: everettraven <[email protected]>

* remove bundle validation unit tests from controller package

Signed-off-by: everettraven <[email protected]>

* make linter happy

Signed-off-by: everettraven <[email protected]>

* remove postrenderer, replace with map[string]string for labels

Signed-off-by: everettraven <[email protected]>

* update debugging error string

Signed-off-by: everettraven <[email protected]>

* rebase fixes

Signed-off-by: everettraven <[email protected]>

---------

Signed-off-by: everettraven <[email protected]>
@skattoju skattoju mentioned this pull request Sep 25, 2024
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm Indicates that a PR is ready to be merged.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants