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

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

Merged
merged 19 commits into from
May 30, 2024

Conversation

bentito
Copy link
Contributor

@bentito bentito commented May 10, 2024

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 owner May 10, 2024 21:24
@openshift-merge-robot openshift-merge-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 10, 2024
Copy link

netlify bot commented May 10, 2024

Deploy Preview for olmv1 ready!

Name Link
🔨 Latest commit eafc251
🔍 Latest deploy log https://app.netlify.com/sites/olmv1/deploys/6658a2435c1e0c00082a1028
😎 Deploy Preview https://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-robot openshift-merge-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 11, 2024
Copy link

codecov bot commented May 11, 2024

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.

Files Patch % Lines
...nternal/controllers/clusterextension_controller.go 62.02% 94 Missing and 26 partials ⚠️
internal/handler/registry.go 62.26% 10 Missing and 10 partials ⚠️
internal/controllers/clusterextension_status.go 45.71% 19 Missing ⚠️
cmd/manager/main.go 75.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     
Flag Coverage Δ
e2e 56.06% <59.91%> (-6.18%) ⬇️
unit 50.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
Contributor Author

bentito commented May 12, 2024

@tmshort thanks for deconflicting main.go 👍

@operator-framework operator-framework deleted a comment from openshift-ci bot May 13, 2024
@operator-framework operator-framework deleted a comment from openshift-ci bot May 13, 2024
@operator-framework operator-framework deleted a comment from openshift-ci bot May 13, 2024
cmd/manager/main.go Outdated Show resolved Hide resolved
cmd/manager/main.go Outdated Show resolved Hide resolved
cmd/unpack/main.go Outdated Show resolved Hide resolved
@bentito bentito force-pushed the helm-poc branch 2 times, most recently from 6b26fd0 to 30df23b Compare May 14, 2024 21:01
Copy link
Member

@m1kola m1kola left a comment

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.

Dockerfile Outdated Show resolved Hide resolved
config/manager/kustomization.yaml Show resolved Hide resolved
config/rbac/role.yaml Show resolved Hide resolved
internal/catalogmetadata/types.go Outdated Show resolved Hide resolved
internal/controllers/clusterextension_controller_test.go Outdated Show resolved Hide resolved
internal/packageerrors/packageerrors.go Outdated Show resolved Hide resolved
test/e2e/cluster_extension_install_test.go Outdated Show resolved Hide resolved
api/v1alpha1/clusterextension_types.go Outdated Show resolved Hide resolved
cmd/manager/main.go Outdated Show resolved Hide resolved
cmd/manager/main.go Outdated Show resolved Hide resolved
varshaprasad96 and 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-robot openshift-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
Copy link

codecov-commenter commented May 23, 2024

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.

Files Patch % Lines
...nternal/controllers/clusterextension_controller.go 67.43% 75 Missing and 24 partials ⚠️
internal/handler/registry.go 62.26% 10 Missing and 10 partials ⚠️
internal/controllers/common_controller.go 58.53% 17 Missing ⚠️
cmd/manager/main.go 75.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     
Flag Coverage Δ
e2e 59.86% <64.55%> (-2.38%) ⬇️
unit 58.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
Contributor

tmshort commented May 29, 2024

@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>
.goreleaser.yml Outdated Show resolved Hide resolved
return currentRelease, stateUnchanged, nil
}

var GetInstalledbundle = func(ctx context.Context, acg helmclient.ActionClientGetter, allBundles []*catalogmetadata.Bundle, ext *ocv1alpha1.ClusterExtension) (*catalogmetadata.Bundle, error) {
Copy link
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
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:

type InstalledBundleGetter interface {
  GetInstalledBundle(...) (...)
}

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

type Reconciler struct {
  ...
  InstalledBundleGetter InstalledBundleGetter
  ...
}

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
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
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:

type Reconciler struct {
  GetInstalledBundleFunc func(...)(...)
}

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
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
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
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
Contributor Author

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?

Signed-off-by: Brett Tofel <btofel@redhat.com>
Signed-off-by: Brett Tofel <btofel@redhat.com>
Sign up for free to 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