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: provide option to control reconciliation when creating resources #974

Merged

Conversation

cam-garrison
Copy link
Contributor

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

Description

Previously, every manifest/template (which is not a patch) was applied only once and left without reconciliation when Manifests are created/applied by our Features.

This PR aims to give users more control over when if resources are reconciled, allowing for them to mark resources as those that should be updated on operator reconcile by marking them with the annotation:

"opendatahub.io/managed": "true" for those that should be reconciled. If the annotation is not present or is set to "false" we do not reconcile, maintaining previous behavior.

The PR also provides another more convenient way to mark that all Manifests part of a Feature should be annotated and reconciled with the new Managed() part of the builder. Simply add Managed(). to the call chain of a builder to enforce that all resources created by the Feature will be updated on reconcile. Like so:

createServiceErr := feature.CreateFeature("create-local-gw-svc").
				For(handler).
				UsingConfig(envTest.Config).
				ManifestSource(fixtures.TestEmbeddedFiles).
				Manifests(path.Join(fixtures.BaseDir, "local-gateway-svc.tmpl.yaml")).
				Managed().
				Load()

How Has This Been Tested?

See the tests added both testing the behavior of CreateResource() as well as Managed().

Also tested manually with an operator build that contained some dummy configmap manifests, one with the annotation as true and one without the annotation, and checked that after editing each and triggering a reconcile, the managed configmap was reconciled to its previous state and the non-managed configmap still contained my changes.

Merge criteria:

  • The commits are squashed in a cohesive manner and have meaningful 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

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.

Thanks for this work! That was the big missing piece to make Features more suitable for operator use cases.

A few things in this review:

  • important calling Update vs Patch (server-side apply) (open for discussion, that's why I tagged @aslakknutsen). The kustomize deploy.go logic does the latter.
  • some minor simplifications in the manifest logic
  • remark about the focus of the tests (🏅 for writing them, my suggestion is about what is the subject of the test, but the foundation is solid!)

pkg/feature/raw_resources.go Outdated Show resolved Hide resolved
pkg/feature/raw_resources.go Outdated Show resolved Hide resolved
pkg/feature/raw_resources.go Outdated Show resolved Hide resolved
if exists && managed == "true" {
// update or create object since we manage it
if err == nil {
if err := cli.Update(context.TODO(), object); err != nil {
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 don't want to make server-side apply here, WDYT @aslakknutsen ?

// Perform server-side apply
data, err := json.Marshal(obj)
if err != nil {
return err
}
return cli.Patch(ctx, found, client.RawPatch(types.ApplyPatchType, data), client.ForceOwnership, client.FieldOwner(owner.GetName()))

pkg/feature/raw_resources.go Outdated Show resolved Hide resolved
@@ -123,4 +124,29 @@ metadata:
Expect(realNs.Name).To(Equal("real-file-test-ns"))
})

It("should set the managed annotation when feature is managed", func() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure we need such a test scenario. It focuses on the "how" part (implementation detail) whereas we should be testing the behavior (if it's actually managed).

I was thinking - how about converting the entire resources_int_test.go test cases to be feature-driven with Managed being invoked or not? This is what we need to test here - and also scenario when we do not call .Managed() explicitly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

96c7980 reworked!

pkg/feature/manifest.go Outdated Show resolved Hide resolved
pkg/feature/manifest.go Outdated Show resolved Hide resolved
pkg/feature/manifest.go Outdated Show resolved Hide resolved
tests/integration/features/resources_int_test.go Outdated Show resolved Hide resolved
pkg/feature/raw_resources.go Outdated Show resolved Hide resolved
Copy link

openshift-ci bot commented Apr 26, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: aslakknutsen, 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

@cam-garrison
Copy link
Contributor Author

/retest-required

@openshift-merge-bot openshift-merge-bot bot merged commit a679cd3 into opendatahub-io:incubation Apr 26, 2024
8 checks passed
cam-garrison added a commit that referenced this pull request Apr 26, 2024
#974)

* add reconiliation option to feature+createResource

* fix typo in test

* extract markAsManaged

Co-authored-by: Bartosz Majsak <bartosz.majsak@gmail.com>

* remove dead const

* re-add fixture, rework MarkAsManaged defn

* refactor/rename ApplyResources

* rework testing, unexport applyResources

* error out faster in applyResources

---------

Co-authored-by: Bartosz Majsak <bartosz.majsak@gmail.com>
zdtsw pushed a commit to zdtsw-forking/rhods-operator that referenced this pull request May 9, 2024
opendatahub-io#974)

* add reconiliation option to feature+createResource

* fix typo in test

* extract markAsManaged

Co-authored-by: Bartosz Majsak <bartosz.majsak@gmail.com>

* remove dead const

* re-add fixture, rework MarkAsManaged defn

* refactor/rename ApplyResources

* rework testing, unexport applyResources

* error out faster in applyResources

---------

Co-authored-by: Bartosz Majsak <bartosz.majsak@gmail.com>
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.

None yet

4 participants