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

Update hander/enqueue_annotation.go #2

Conversation

varshaprasad96
Copy link
Member

This commit updates the implementation in enqueue_annotation, to
watch dependent resources based on the presence of an annotation.

Motivation: (Taken from PR #892 of Controller Runtime)

While owner references are the idiomatic way to manage dependent resources, they don't solve all use cases. Owner references have restrictions that limit which objects can own other objects.

An annotation-based watch handler does not have these restrictions. However, they don't provide the same feature set either.

The watch handler can be used to trigger reconciliation of a parent resource based on changes to dependent resources that include an annotation. The purpose of this handler is to support cross-scope ownership relationships that are not supported by native owner references.

For example, owner references are used for garbage collection. If a resource's owner is deleted, the resource will also be deleted. Because of this, annotation references need to be paired with a finalizer so that the operator can manually garbage collect.

Co-Authored-by: Camila Macedo [email protected]

go.mod Outdated Show resolved Hide resolved
// SetWatchOwnerAnnotation is a helper method to add watch annotation-based with the owner NamespacedName and
// schema.GroupKind to the object provided. This allows you to declare the watch annotations of an owner to an object.
// If a annotation to the same object already exists, it'll be overwritten with the newly provided version.
func SetOwnerAnnotation(owner, object metav1.Object, ownerGK schema.GroupKind) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

See that it is a helper. so, we need to update the places in SDK that are using the annotation.

Copy link
Contributor

@camilamacedo86 camilamacedo86 left a comment

Choose a reason for hiding this comment

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

This PR kubernetes-sigs/controller-runtime#892 received a lot of contributions from the devs in the controller-runtime. So, I think it is in good shape. What is missing to do here;

  • Cleanup the go mod
  • Update the places across the project to use the helper
  • We need to check the CI. (lint to ensure that all is fine, test to check if these tests are ok, ansible and helm as well to check that nothing broke after that and all is properly updated)

Copy link
Member

@joelanford joelanford left a comment

Choose a reason for hiding this comment

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

Unit tests pass for me once I remove the unnecessary dependency on running envtest. However, given all the nits and discrepancies I found, I'm a little concerned with the validity of the tests.

Let's make sure to double/triple check everything before we merge.

go.mod Outdated Show resolved Hide resolved
handler/enqueue_annotation.go Outdated Show resolved Hide resolved
handler/enqueue_annotation.go Outdated Show resolved Hide resolved
handler/enqueue_annotation.go Outdated Show resolved Hide resolved
handler/enqueue_annotation.go Outdated Show resolved Hide resolved
handler/enqueue_annotation_test.go Outdated Show resolved Hide resolved
handler/enqueue_annotation_suite_test.go Outdated Show resolved Hide resolved
handler/enqueue_annotation_suite_test.go Outdated Show resolved Hide resolved
handler/enqueue_annotation_suite_test.go Outdated Show resolved Hide resolved
handler/enqueue_annotation_test.go Outdated Show resolved Hide resolved
@jmrodri jmrodri changed the base branch from master to main July 21, 2020 22:02
@openshift-ci-robot openshift-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 22, 2020
varshaprasad96 and others added 3 commits July 22, 2020 11:55
This commit updates the implementation in enqueue_annotation, to
watch dependent resources based on the presence of an annotation
on them.

Co-Authored-by: Camila Macedo <[email protected]>
@openshift-ci-robot openshift-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 22, 2020
@varshaprasad96 varshaprasad96 force-pushed the annotations/watch-resources branch 3 times, most recently from 5835cd5 to c15d42b Compare July 22, 2020 19:04
@varshaprasad96
Copy link
Member Author

varshaprasad96 commented Jul 22, 2020

Addressed review comments, and made changes to the PR.

@coveralls
Copy link

coveralls commented Jul 22, 2020

Pull Request Test Coverage Report for Build 180371929

  • 29 of 29 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 100.0%

Totals Coverage Status
Change from base Build 178609315: 0.0%
Covered Lines: 134
Relevant Lines: 134

💛 - Coveralls

Copy link
Member

@estroz estroz left a comment

Choose a reason for hiding this comment

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

Mostly nits and grammar, looks great otherwise.

handler/enqueue_annotation.go Outdated Show resolved Hide resolved
handler/enqueue_annotation.go Outdated Show resolved Hide resolved
handler/enqueue_annotation.go Outdated Show resolved Hide resolved
handler/enqueue_annotation.go Outdated Show resolved Hide resolved
handler/enqueue_annotation.go Outdated Show resolved Hide resolved
handler/enqueue_annotation.go Outdated Show resolved Hide resolved
handler/enqueue_annotation.go Show resolved Hide resolved
handler/enqueue_annotation.go Outdated Show resolved Hide resolved
handler/enqueue_annotation.go Outdated Show resolved Hide resolved
handler/enqueue_annotation.go Outdated Show resolved Hide resolved
handler/enqueue_annotation.go Outdated Show resolved Hide resolved
handler/enqueue_annotation.go Outdated Show resolved Hide resolved
handler/handler_test.go Outdated Show resolved Hide resolved
handler/handler_test.go Outdated Show resolved Hide resolved
handler/handler_test.go Outdated Show resolved Hide resolved
handler/handler_test.go Outdated Show resolved Hide resolved
handler/handler_test.go Outdated Show resolved Hide resolved
handler/handler_test.go Outdated Show resolved Hide resolved
@varshaprasad96 varshaprasad96 force-pushed the annotations/watch-resources branch 2 times, most recently from ce9b384 to 5be29f3 Compare July 23, 2020 16:36
Copy link
Member

@joelanford joelanford 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-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Jul 23, 2020
Copy link
Member

@estroz estroz 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-robot
Copy link

New changes are detected. LGTM label has been removed.

@openshift-ci-robot openshift-ci-robot removed the lgtm Indicates that a PR is ready to be merged. label Jul 23, 2020
@varshaprasad96 varshaprasad96 merged commit 525cb9a into operator-framework:main Jul 23, 2020
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.

6 participants