Skip to content

⚠ Handle finalizers in the fake client #1399

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

Merged
merged 2 commits into from
Mar 2, 2021

Conversation

tjamet
Copy link
Contributor

@tjamet tjamet commented Feb 26, 2021

The fake client differs significantly from the real implementation.
With the real client implementation, upon the deletion of a resource,
when finalizers are set the DeletionTimestamp is filled with a non-null
value.
This triggers a number of reconciling loops for all controllers that then
can take the opportunity to inspect the resource being deleted, perform
the required cleaning actions and then update the resource by removing
their finalizers as the cleaning job have been done.

In the current implementation, the Delete function implements a straight
delete and hence triggers a false positive or negative test when trying
to run tests at the client level, without interacting with the objects.

For example:

client.CreateObject()
controller.Reconcile()
Expect(Something).To(BeDone())
client.DeleteObject()
controller.Reconcile()
Expect(SomethingElse).To(BeDone())

In the real life, SomethingElse would actually be done as the controller
would still have access to the resource. In the current fake implementation,
this is not the case as the controller does not have access to the
resource any longer.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Feb 26, 2021
@k8s-ci-robot
Copy link
Contributor

Welcome @tjamet!

It looks like this is your first PR to kubernetes-sigs/controller-runtime 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-sigs/controller-runtime has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot
Copy link
Contributor

Hi @tjamet. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Feb 26, 2021
@k8s-ci-robot k8s-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Feb 26, 2021
@tjamet tjamet changed the title Handle finalizers in the fake client ✨ Handle finalizers in the fake client Feb 26, 2021
@tjamet tjamet changed the title ✨ Handle finalizers in the fake client ✨ Handle finalizers in the fake client Feb 26, 2021
The fake client differs significantly from the real implementation.
With the real client implementation, upon the deletion of a resource,
when finalizers are set the DeletionTimestamp is filled with a non-null
value.
This triggers a number of reconciling loops for all controllers that then
can take the opportunity to inspect the resource being deleted, perform
the required cleaning actions and then update the resource by removing
their finalizers as the cleaning job have been done.

In the current implementation, the Delete function implements a straight
delete and hence triggers a false positive or negative test when trying
to run tests at the client level, without interacting with the objects.

For example:

```
client.CreateObject()
controller.Reconcile()
Expect(Something).To(BeDone())
client.DeleteObject()
controller.Reconcile()
Expect(SomethingElse).To(BeDone())
```

In the real life, SomethingElse would actually be done as the controller
would still have access to the resource. In the current fake implementation,
this is not the case as the controller does not have access to the
resource any longer.
@tjamet tjamet force-pushed the fake/client/finalizers branch from 755c845 to 4f23760 Compare February 26, 2021 08:11
@tjamet
Copy link
Contributor Author

tjamet commented Feb 26, 2021

I think the PR is ready on its own. I didn't implement yet the feature in DeleteAllOf which would probably also be required

Copy link
Member

@alvaroaleman alvaroaleman left a comment

Choose a reason for hiding this comment

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

/ok-to-test

This is a breaking change and needs to be marked as such

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Feb 27, 2021
@tjamet
Copy link
Contributor Author

tjamet commented Feb 27, 2021

/retest

@tjamet
Copy link
Contributor Author

tjamet commented Feb 27, 2021

This is a breaking change and needs to be marked as such

Sure! shall I use ⚠ then?

@alvaroaleman
Copy link
Member

Sure! shall I use  then?

Yes, please.

I think the PR is ready on its own. I didn't implement yet the feature in DeleteAllOf which would probably also be required

Can you implement that as well, please? Not having it there will surprise users.

@tjamet tjamet changed the title ✨ Handle finalizers in the fake client ⚠ Handle finalizers in the fake client Mar 1, 2021
@tjamet
Copy link
Contributor Author

tjamet commented Mar 1, 2021

Can you implement that as well, please? Not having it there will surprise users

Sure! I will push it soon

@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Mar 2, 2021
@tjamet tjamet force-pushed the fake/client/finalizers branch from b53c144 to 286a287 Compare March 2, 2021 15:12
Copy link
Member

@alvaroaleman alvaroaleman left a comment

Choose a reason for hiding this comment

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

/label tide/merge-method-squash
/lgtm
/approve

thank you!

@k8s-ci-robot
Copy link
Contributor

@alvaroaleman: The label(s) /label tide/merge-method-squash cannot be applied. These labels are supported: api-review

In response to this:

/label tide/merge-method-squash
/lgtm
/approve

thank you!

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Mar 2, 2021
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: alvaroaleman, tjamet

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

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Mar 2, 2021
@alvaroaleman
Copy link
Member

/hold

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Mar 2, 2021
@alvaroaleman alvaroaleman added the tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges. label Mar 2, 2021
@alvaroaleman
Copy link
Member

/hold cancel
Labeler gets fixed in kubernetes/test-infra#21119

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Mar 2, 2021
@k8s-ci-robot k8s-ci-robot merged commit 854c5e8 into kubernetes-sigs:master Mar 2, 2021
2uasimojo added a commit to 2uasimojo/hive that referenced this pull request Jul 13, 2021
Update tests for controller-runtime changes from 0.8.2 to 0.9.2(+).

Most of these changes react to
kubernetes-sigs/controller-runtime#1399, which
made the fake client's Delete behave more like the real thing:
- If the object has finalizers, set `DeletionTimestamp` but don't
actually delete.
- If there are no finalizers, actually delete.
- Updates that remove the last finalizer from an object with a
`DeletionTimestamp` actually delete the object.

Then there's
kubernetes-sigs/controller-runtime#1390 which
deduplicates objects in the reconcile queue for Update actions.
RainbowMango pushed a commit to RainbowMango/controller-runtime that referenced this pull request Sep 1, 2021
* Handle finalizers in the fake client

The fake client differs significantly from the real implementation.
With the real client implementation, upon the deletion of a resource,
when finalizers are set the DeletionTimestamp is filled with a non-null
value.
This triggers a number of reconciling loops for all controllers that then
can take the opportunity to inspect the resource being deleted, perform
the required cleaning actions and then update the resource by removing
their finalizers as the cleaning job have been done.

In the current implementation, the Delete function implements a straight
delete and hence triggers a false positive or negative test when trying
to run tests at the client level, without interacting with the objects.

For example:

```
client.CreateObject()
controller.Reconcile()
Expect(Something).To(BeDone())
client.DeleteObject()
controller.Reconcile()
Expect(SomethingElse).To(BeDone())
```

In the real life, SomethingElse would actually be done as the controller
would still have access to the resource. In the current fake implementation,
this is not the case as the controller does not have access to the
resource any longer.

* Handle finalizers when deleting collections
eggfoobar added a commit to eggfoobar/cloud-credential-operator that referenced this pull request Dec 22, 2021
Fake client now respects finalizers, if any are present
delete functionality will simulate real cluster resource delete
More info: kubernetes-sigs/controller-runtime#1399

Signed-off-by: ehila <[email protected]>
eggfoobar added a commit to eggfoobar/cloud-credential-operator that referenced this pull request Dec 23, 2021
Fake client now respects finalizers, if any are present
delete functionality will simulate real cluster resource delete
More info: kubernetes-sigs/controller-runtime#1399

Signed-off-by: ehila <[email protected]>
eggfoobar added a commit to eggfoobar/cloud-credential-operator that referenced this pull request Jan 5, 2022
Signed-off-by: ehila <[email protected]>

fix: unit test for cleanup stale state

Fake client now respects finalizers, if any are present
delete functionality will simulate real cluster resource delete
More info: kubernetes-sigs/controller-runtime#1399

Signed-off-by: ehila <[email protected]>

fix: updated unit tests mock object with max call

Signed-off-by: ehila <[email protected]>
akalenyu added a commit to akalenyu/controller-lifecycle-operator-sdk that referenced this pull request Mar 19, 2023
akalenyu added a commit to akalenyu/controller-lifecycle-operator-sdk that referenced this pull request Mar 19, 2023
akalenyu added a commit to akalenyu/controller-lifecycle-operator-sdk that referenced this pull request Mar 19, 2023
akalenyu added a commit to akalenyu/controller-lifecycle-operator-sdk that referenced this pull request Mar 19, 2023
akalenyu added a commit to akalenyu/controller-lifecycle-operator-sdk that referenced this pull request Mar 19, 2023
akalenyu added a commit to akalenyu/controller-lifecycle-operator-sdk that referenced this pull request Mar 19, 2023
akalenyu added a commit to akalenyu/controller-lifecycle-operator-sdk that referenced this pull request Mar 19, 2023
akalenyu added a commit to akalenyu/controller-lifecycle-operator-sdk that referenced this pull request Mar 20, 2023
akalenyu added a commit to akalenyu/controller-lifecycle-operator-sdk that referenced this pull request Mar 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants