Skip to content

✨ refactor ClusterExtensionReconciler.reconcile() - #1068

Merged
everettraven merged 8 commits into
operator-framework:mainfrom
everettraven:shiftweek/reconciler
Aug 2, 2024
Merged

✨ refactor ClusterExtensionReconciler.reconcile()#1068
everettraven merged 8 commits into
operator-framework:mainfrom
everettraven:shiftweek/reconciler

Conversation

@everettraven

@everettraveneverettraven commented Jul 18, 2024

Copy link
Copy Markdown
Contributor

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-ciopenshift-ciBot 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

netlifyBot commented Jul 18, 2024

Copy link
Copy Markdown

Deploy Preview for olmv1 ready!

NameLink
🔨 Latest commitdcd37f0
🔍 Latest deploy loghttps://app.netlify.com/sites/olmv1/deploys/66acee810502b8000801f846
😎 Deploy Previewhttps://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-robotopenshift-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
Copy Markdown
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
Copy Markdown
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.

Comment threadinternal/controllers/clusterextension_controller.go Outdated
@everettraven

Copy link
Copy Markdown
ContributorAuthor

@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).

@openshift-merge-robotopenshift-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
Copy Markdown
ContributorAuthor

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 ownerJuly 26, 2024 19:29
@openshift-ciopenshift-ciBot 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
@everettraveneverettraven 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
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
ContributorAuthor

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
Copy Markdown
ContributorAuthor

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
Copy Markdown
ContributorAuthor

I will squash commits after reviews are fully addressed

@codecov

codecovBot commented Jul 26, 2024

Copy link
Copy Markdown

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).

FilesPatch %Lines
internal/applier/helm.go41.97%35 Missing and 12 partials ⚠️
cmd/manager/main.go70.00%2 Missing and 1 partial ⚠️
internal/catalogmetadata/filter/successors.go0.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 
FlagCoverage Δ
e2e56.85% <48.78%> (-1.20%)⬇️
unit52.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-robotopenshift-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
Copy Markdown
Contributor

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 <everettraven@gmail.com>
Signed-off-by: everettraven <everettraven@gmail.com>
Signed-off-by: everettraven <everettraven@gmail.com>
Signed-off-by: everettraven <everettraven@gmail.com>
Signed-off-by: everettraven <everettraven@gmail.com>
Signed-off-by: everettraven <everettraven@gmail.com>
Signed-off-by: everettraven <everettraven@gmail.com>
Signed-off-by: everettraven <everettraven@gmail.com>
@openshift-merge-robotopenshift-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 added this pull request to the merge queue Aug 2, 2024

@tmshorttmshort left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

/lgtm

@openshift-ciopenshift-ciBot 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 cab9eabAug 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 <everettraven@gmail.com>
* update testing
Signed-off-by: everettraven <everettraven@gmail.com>
* update testing
Signed-off-by: everettraven <everettraven@gmail.com>
* remove bundle validation unit tests from controller package
Signed-off-by: everettraven <everettraven@gmail.com>
* make linter happy
Signed-off-by: everettraven <everettraven@gmail.com>
* remove postrenderer, replace with map[string]string for labels
Signed-off-by: everettraven <everettraven@gmail.com>
* update debugging error string
Signed-off-by: everettraven <everettraven@gmail.com>
* rebase fixes
Signed-off-by: everettraven <everettraven@gmail.com>
---------
Signed-off-by: everettraven <everettraven@gmail.com>
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 <everettraven@gmail.com>
* update testing
Signed-off-by: everettraven <everettraven@gmail.com>
* update testing
Signed-off-by: everettraven <everettraven@gmail.com>
* remove bundle validation unit tests from controller package
Signed-off-by: everettraven <everettraven@gmail.com>
* make linter happy
Signed-off-by: everettraven <everettraven@gmail.com>
* remove postrenderer, replace with map[string]string for labels
Signed-off-by: everettraven <everettraven@gmail.com>
* update debugging error string
Signed-off-by: everettraven <everettraven@gmail.com>
* rebase fixes
Signed-off-by: everettraven <everettraven@gmail.com>
---------
Signed-off-by: everettraven <everettraven@gmail.com>
@skattojuskattoju mentioned this pull request Sep 25, 2024
4 tasks
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtmIndicates that a PR is ready to be merged.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

@everettraven@joelanford@thetechnick@tmshort@openshift-merge-robot