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

feat: adds EnabledWhen to the feature builder #1057

Merged

Conversation

cam-garrison
Copy link
Contributor

@cam-garrison cam-garrison commented Jun 12, 2024

Description

This PR introduces a featureBuilder function that enables conditional toggling of features named EnabledWhen. Features can now be activated or deactivated based on specific conditions such as the target platform, management mode, or the presence of particular resources in the cluster.

Building on the previous PR linked below which we didn't finish up, this update ensures that feature.Cleanup() is called if a feature's EnabledWhen() status changes from true to false across multiple reconciles. Additionally, this PR includes enhanced testing to validate these changes.

JIRA issue:

https://issues.redhat.com/browse/RHOAIENG-8540

re-doing and finishing up work from PR #793

How Has This Been Tested?

Wrote additional cleanup integration tests - using an example function checking if a certain namespace exists to enable the feature.

Ensured the feature applied when the namespace exists and that the feature was cleaned up on "reconcile" when the namespace no longer exists.

Screenshot or short clip:

Merge criteria:

  • Have a meaningful commit messages.
  • Testing instructions have been added in the PR body (for PRs involving changes that are not immediately obvious).
  • The developer has manually tested the changes and verified that the changes work

@zdtsw
Copy link
Member

zdtsw commented Jun 13, 2024

so this EnabledWhen can be used to replace PreCondition in some way?

@cam-garrison
Copy link
Contributor Author

so this EnabledWhen can be used to replace PreCondition in some way?

PreCondition will fail when trying to apply Features and EnabledWhen will only apply feature when condition is met. So we could in some cases end up replacing with EnabledWhen (ie authorino exists, install xyz) but the two functionalities are not interchangeable.

@cam-garrison
Copy link
Contributor Author

added hold label to get additional review from @bartoszmajsak before allowing auto-merge

pkg/feature/builder.go Outdated Show resolved Hide resolved
@@ -58,7 +59,7 @@ var _ = Describe("feature cleanup", func() {
Expect(featuresHandler.Apply()).Should(Succeed())

// then
Eventually(createdSecretHasOwnerReferenceToOwningFeature(namespace, secretName)).
Eventually(createdSecretHasOwnerReferenceToOwningFeature(namespace)).
Copy link
Contributor

Choose a reason for hiding this comment

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

Any reason to remove secret name as a param? With this change we hardcode the secret name in the func itself, not sure we want 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.

This was removed as linter complained as we were passing in the same secret name each time IIRC

Expect(featuresHandler.Apply()).Should(Succeed())

// then
Eventually(createdSecretHasOwnerReferenceToOwningFeature(namespace)).
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if we shouldn't test something different here. We should ensure nothing that is supposed to be created by the defined feature (including tracker) should exist in the cluster.

On top of that, Consistently might be better instead of Eventually (which can pass in the first run). The clean-up from the previous run might not be done yet on the cluster when this test is executed. I see you are handling it with the current implementation by checking if ns is in a deletion state, though I believe switching it to Consistently should make it safer if we happen to rework the test fixture, but keep the expectations the same.

})

func createdSecretHasOwnerReferenceToOwningFeature(namespace, secretName string) func() error {
func createdSecretHasOwnerReferenceToOwningFeature(namespace string) func() error {
Copy link
Contributor

Choose a reason for hiding this comment

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

In createdSecretHasOwnerReferenceToOwningFeature shouldn't we ensure we look up the FT matching the feature, not assuming there's a FT matching any Feature in the cluster that was related to "test-secret"? In other words I would think this function also expects a Feature to be passed by only reading the signature. Otherwise we assume a bit too much internally.

tests/integration/features/cleanup_int_test.go Outdated Show resolved Hide resolved
pkg/feature/builder.go Outdated Show resolved Hide resolved
@cam-garrison
Copy link
Contributor Author

linter fails when nolint has preceding space and fails when it does not have preceding space : / fixing this tmrw

bartoszmajsak added a commit that referenced this pull request Jun 27, 2024
Copy link
Contributor

@bartoszmajsak bartoszmajsak 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 label Jul 2, 2024
Copy link

openshift-ci bot commented Jul 2, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: bartoszmajsak, zdtsw

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

The pull request process is described here

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-merge-bot openshift-merge-bot bot merged commit bff2e6a into opendatahub-io:incubation Jul 2, 2024
8 checks passed
VaishnaviHire pushed a commit to VaishnaviHire/opendatahub-operator that referenced this pull request Jul 24, 2024
* rebase on top of latest inc

* fix linter

* rename test func

* Update pkg/feature/builder.go

Co-authored-by: Bartosz Majsak <[email protected]>

* Update pkg/feature/builder.go

Co-authored-by: Bartosz Majsak <[email protected]>

* fix err var name

* Update tests/integration/features/cleanup_int_test.go

Co-authored-by: Bartosz Majsak <[email protected]>

* fix linter, add ctx

* re-remove pesky whitespace

* move logic to apply and improve tests

* ensure feature tracker is also removed

* Update tests/integration/features/cleanup_int_test.go

Co-authored-by: Bartosz Majsak <[email protected]>

---------

Co-authored-by: Bartosz Majsak <[email protected]>
(cherry picked from commit bff2e6a)
VaishnaviHire pushed a commit to VaishnaviHire/opendatahub-operator that referenced this pull request Jul 24, 2024
* rebase on top of latest inc

* fix linter

* rename test func

* Update pkg/feature/builder.go

Co-authored-by: Bartosz Majsak <[email protected]>

* Update pkg/feature/builder.go

Co-authored-by: Bartosz Majsak <[email protected]>

* fix err var name

* Update tests/integration/features/cleanup_int_test.go

Co-authored-by: Bartosz Majsak <[email protected]>

* fix linter, add ctx

* re-remove pesky whitespace

* move logic to apply and improve tests

* ensure feature tracker is also removed

* Update tests/integration/features/cleanup_int_test.go

Co-authored-by: Bartosz Majsak <[email protected]>

---------

Co-authored-by: Bartosz Majsak <[email protected]>
(cherry picked from commit bff2e6a)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

5 participants