Skip to content

✨ Modify ClusterExtension to use Helm under the hood to apply contents into the cluster - #846

Merged
tmshort merged 19 commits into
mainfrom
helm-poc
May 30, 2024
Merged

✨ Modify ClusterExtension to use Helm under the hood to apply contents into the cluster#846
tmshort merged 19 commits into
mainfrom
helm-poc

Conversation

@bentito

Copy link
Copy Markdown
Contributor

Description

ClusterExtension reconciler needs to perform the following actions:

[See this doc for more detail if possible.]

  1. Based on the cluster Extension spec, get the list of bundles from the catalog and perform resolution.

    • The resolution here need not use dep.py, it can be simple filtering and sorting as done in extension controller currently.
      1. Ref:Extension controller code
      2. Resolution:Extension controller resolution
      3. The resolution step involves fetching the installed version. Since there are no APIs (like BundleDeployment or App) present in clusters that reference the installed bundle, we need to investigate on listing the installed helm charts or use helm secrets. This also means that when the helm chart is created, we need to store metadata that uniquely identifies an extension.
  2. Unpack the contents of the resolved bundle. For this iteration we can cover only registryV1 bundles from an image source.

  3. Conversion of registryV1 to plain bundle.

  4. Creating a Helm chart from the resources present in plain bundle.

  5. Installing helm chart onto the cluster.

    • Helm chart deployer
    • We need to be able to inject metadata into the chart that will be required for resolution as mentioned in 1.(iii).
      • Currently, we run a post render hook, that adds labels on the objects created by the chart: Post render hook details. Will need to figure out on how to store this info in the helm secret or on the helm chart directory.

Reviewer Checklist

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

@bentito
bentito requested a review from a team as a code ownerMay 10, 2024 21:24
@openshift-merge-robotopenshift-merge-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 10, 2024
@netlify

netlifyBot commented May 10, 2024

Copy link
Copy Markdown

Deploy Preview for olmv1 ready!

NameLink
🔨 Latest commiteafc251
🔍 Latest deploy loghttps://app.netlify.com/sites/olmv1/deploys/6658a2435c1e0c00082a1028
😎 Deploy Previewhttps://deploy-preview-846--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 removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 11, 2024
@codecov

codecovBot commented May 11, 2024

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 63.88309% with 173 lines in your changes are missing coverage. Please review.

Project coverage is 75.38%. Comparing base (a458282) to head (60f4c80).
Report is 9 commits behind head on main.

FilesPatch %Lines
...nternal/controllers/clusterextension_controller.go62.02%94 Missing and 26 partials ⚠️
internal/handler/registry.go62.26%10 Missing and 10 partials ⚠️
internal/controllers/clusterextension_status.go45.71%19 Missing ⚠️
cmd/manager/main.go75.86%9 Missing and 5 partials ⚠️
Additional details and impacted files
@@ Coverage Diff @@## main #846 +/- ##
==========================================
- Coverage 83.18% 75.38% -7.80% 
==========================================
Files 15 18 +3 Lines 874 1170 +296 ==========================================
+ Hits 727 882 +155 - Misses 102 208 +106 - Partials 45 80 +35 
FlagCoverage Δ
e2e56.06% <59.91%> (-6.18%)⬇️
unit50.60% <21.03%> (-24.33%)⬇️

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.

@bentito

Copy link
Copy Markdown
ContributorAuthor

@tmshort thanks for deconflicting main.go 👍

Comment threadcmd/manager/main.go Outdated
Comment threadcmd/manager/main.go Outdated
Comment threadcmd/unpack/main.go Outdated
Comment threadCONTRIBUTING.md
Comment thread.goreleaser.yml
Comment threadapi/v1alpha1/clusterextension_types.go Outdated
@bentito
bentitoforce-pushed the helm-poc branch 2 times, most recently from 6b26fd0 to 30df23bCompareMay 14, 2024 21:01

@m1kolam1kola left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I haven't reviewed the controller itself properly and some other bits. Some comments so far.


I think this PR too big to be adequately reviewed. Is there a way we can split this into multiple smaller PRs? I might be missing something, but it looks like unpacker is fairly independent and can be a separate PR. Then changes to goreleaser to make it buildable can be a separate PR. A bunch of helper functions can be moved into a separate PR, I think.

Comment threadDockerfile
Comment threadconfig/manager/kustomization.yaml
Comment threadconfig/rbac/role.yaml
Comment threadinternal/catalogmetadata/types.go Outdated
Comment threadinternal/controllers/clusterextension_registryv1_validation_test.go Outdated
Comment threadinternal/controllers/clusterextension_controller_test.go Outdated
Comment threadinternal/packageerrors/packageerrors.go Outdated
Comment threadtest/e2e/cluster_extension_install_test.go Outdated
Comment threadapi/v1alpha1/clusterextension_types.go Outdated
Comment threadinternal/controllers/clusterextension_controller.go
Comment threadcmd/manager/main.go Outdated
Comment threadcmd/unpack/main.go
Comment threadcmd/manager/main.go
Comment threadcmd/manager/main.go Outdated
Comment threadinternal/controllers/clusterextension_controller.go
Comment threadinternal/controllers/clusterextension_controller.go
Comment threadinternal/controllers/clusterextension_controller.go
varshaprasad96and others added 6 commits May 23, 2024 12:35
Signed-off-by: Varsha Prasad Narsing <varshaprasad96@gmail.com>
It's agreed that this makes debugging and reasoning about log messages and runtime errors much harder.
Signed-off-by: Brett Tofel <btofel@redhat.com>
Fixes the e2e tests in helm-poc branch and restores feature-gate switching.
Signed-off-by: dtfranz <dfranz@redhat.com>
Fixes the defer location to make sure that all resources are cleaned up properly.
Signed-off-by: dtfranz <dfranz@redhat.com>
When tests fail, gatherArtifacts is run to collect cluster state. This PR removes gathering of BundleDeployments since we don't use them anymore and it's generating additional misleading error messages.
Signed-off-by: dtfranz <dfranz@redhat.com>
Signed-off-by: Varsha Prasad Narsing <varshaprasad96@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 May 23, 2024
@codecov-commenter

codecov-commenter commented May 23, 2024

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 68.35443% with 150 lines in your changes are missing coverage. Please review.

Project coverage is 77.21%. Comparing base (7727f8f) to head (eafc251).
Report is 2 commits behind head on main.

FilesPatch %Lines
...nternal/controllers/clusterextension_controller.go67.43%75 Missing and 24 partials ⚠️
internal/handler/registry.go62.26%10 Missing and 10 partials ⚠️
internal/controllers/common_controller.go58.53%17 Missing ⚠️
cmd/manager/main.go75.43%9 Missing and 5 partials ⚠️
Additional details and impacted files
@@ Coverage Diff @@## main #846 +/- ##
==========================================
- Coverage 83.18% 77.21% -5.97% 
==========================================
Files 15 17 +2 Lines 874 1176 +302 ==========================================
+ Hits 727 908 +181 - Misses 102 189 +87 - Partials 45 79 +34 
FlagCoverage Δ
e2e59.86% <64.55%> (-2.38%)⬇️
unit58.52% <33.42%> (-16.42%)⬇️

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.

* Proposed way to unskip some tests
TestClusterExtensionChannelVersionExists mostly restored here
Signed-off-by: Brett Tofel <btofel@redhat.com>
* Refactors global variable names
Signed-off-by: Brett Tofel <btofel@redhat.com>
* Removes BundleDeployment related checking
In just one test, for now.
Signed-off-by: Brett Tofel <btofel@redhat.com>
* fix unit test - TestClusterExtensionChannelVersionExists
* Unskip all - failing tests (up|down)grade should err
Unskips all in clusterextension_controller_test.go
Signed-off-by: Brett Tofel <btofel@redhat.com>
* Unskip all clusterextension_registryv1_validation_test.go
Still failing tests (up|down)grade should err b/c we don't have an installedBundle to check against
Signed-off-by: Brett Tofel <btofel@redhat.com>
* debugging
Signed-off-by: Varsha Prasad Narsing <varshaprasad96@gmail.com>
* Fixes and additions pending & unpack path
Signed-off-by: Brett Tofel <btofel@redhat.com>
* Fix linter, remove debug logs and extraneous file
Signed-off-by: dtfranz <dfranz@redhat.com>
* Fix e2e failure due to race condition
Signed-off-by: dtfranz <dfranz@redhat.com>
---------
Signed-off-by: Brett Tofel <btofel@redhat.com>
Signed-off-by: Varsha Prasad Narsing <varshaprasad96@gmail.com>
Signed-off-by: dtfranz <dfranz@redhat.com>
Co-authored-by: Varsha Prasad Narsing <varshaprasad96@gmail.com>
Co-authored-by: dtfranz <dfranz@redhat.com>
@tmshort

Copy link
Copy Markdown
Contributor

@everettraven@m1kola@acornett21 PTAL
We've rebased the PR and updated the unit tests, and will be going forward with this. Other significant changes to be done have been noted in various issues.

Signed-off-by: Brett Tofel <btofel@redhat.com>
Comment thread.goreleaser.yml Outdated
Comment threadinternal/controllers/clusterextension_controller_test.go Outdated
return currentRelease, stateUnchanged, nil
}

var GetInstalledbundle = func(ctx context.Context, acg helmclient.ActionClientGetter, allBundles []*catalogmetadata.Bundle, ext *ocv1alpha1.ClusterExtension) (*catalogmetadata.Bundle, error) {

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.

Why did this go from a method to a global variable (package scoped)? Doing this opens us up to bugs if this variable is somehow overwritten. I would highly recommend avoiding this.

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.

Instead of using a global variable, I would recommend creating a new interface like:

typeInstalledBundleGetterinterface {
GetInstalledBundle(...) (...)
}

and make use of it via a field in the reconciler like:

typeReconcilerstruct {
...InstalledBundleGetterInstalledBundleGetter...
}
func (r*Reconciler) reconcile(...) (...) {
...installedBundle, err:=r.InstalledBundleGetter.GetInstalledBundle(...)
...
}

This has the ability to be mocked for testing while also preventing potential issues with using global variables

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The reason for not creating an interface was GetInstalledBundle need not be exposed to the user in any way, it’s just for mocking purposes that we need to do this. If we are exposing it, then we may also have to expose the resolver logic and make it a separate interface.

Both of them were too much of a change, and since the var is inside an internal pkg, the chances of external users changing it are super minimal.

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.

Coming back around to this, something like:

typeReconcilerstruct {
GetInstalledBundleFuncfunc(...)(...)
}

might be even better due to it being an explicit type that I don't believe would be allowed to be set as nil, alleviating the need to do a potential validation check for a nil reference

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Though not the best design for now, since it's internal and has no chances of external users breaking it - I'd suggest to do it in a follow up. Especially because it'll require a lot more bits of controller to be changed. An even better way would be for us to instead modify the way we have designed unit tests to mock better.

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.

And I think ^ would result in less work to change while getting the benefits of no longer using a global variable

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.

If you really prefer this being done in a follow up I won't stop this from going in, but this is something that I would think we want fixed very quickly. I don't think this is a good practice, even if it is in an internal package.

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.

well I'm part-way through with the swap out to interface, just doing the mocks needed in the tests now. If you are okay with it in a soon to be added PR, can we can get an approve on this PR and merge?

Comment threadinternal/controllers/clusterextension_registryv1_validation_test.go Outdated
bentito added 2 commits May 30, 2024 09:56
Signed-off-by: Brett Tofel <btofel@redhat.com>
Signed-off-by: Brett Tofel <btofel@redhat.com>
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants

@bentito@dtfranz@tmshort@varshaprasad96@codecov-commenter@m1kola@joelanford@everettraven@acornett21@openshift-merge-robot