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

⚠️ Fakeclient: Reject Delete with mismatched ResourceVersion #1582

Merged
merged 1 commit into from
Jul 8, 2021
Merged

⚠️ Fakeclient: Reject Delete with mismatched ResourceVersion #1582

merged 1 commit into from
Jul 8, 2021

Conversation

2uasimojo
Copy link
Contributor

@2uasimojo 2uasimojo commented Jul 7, 2021

Delete takes optional varargs comprising DeleteOptions. Previously fakeclient was validating that these could be run through ApplyOptions, but otherwise ignoring them.

With this commit, fakeclient will observe a DeleteOption specifying a Precondition.ResourceVersion, rejecting the deletion if the value does not match what's on the "server", bringing fakeclient's behavior more in line with a real client.

Note that, while technically a breaking change, any test that was relying on the previous behavior was already broken.

xref #832 / 25ef372 which did something similar for Create and Update. Major difference being that those methods do ResourceVersion matching by default, whereas Delete only does it if opted in via the Precondition.

/assign @vincepri
/assign @mengqiy
/cc @alvaroaleman
/cc @djzager

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

Welcome @2uasimojo!

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 @2uasimojo. 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 needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jul 7, 2021
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

@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 Jul 7, 2021
@2uasimojo
Copy link
Contributor Author

2uasimojo force-pushed the 2uasimojo:fake-delete-ResourceVersion branch from 49338fb to e8c6d31 now

Updated the message to match what happens IRL. (This probably doesn't matter, test-wise, but I thought it would be nice to have parity with the real behavior as much as possible.)

`Delete` takes optional varargs comprising `DeleteOption`s. Previously
fakeclient was validating that these could be run through
`ApplyOptions`, but otherwise ignoring them.

With this commit, fakeclient will observe a `DeleteOption` specifying a
`Precondition.ResourceVersion`, rejecting the deletion if the value does
not match what's on the "server", bringing fakeclient's behavior more in
line with a real client.

Note that, while technically a breaking change, any test that was
relying on the previous behavior was already broken.

xref #832 / 25ef372 which did something similar for `Create` and
`Update`. Major difference being that those methods do `ResourceVersion`
matching by default, whereas `Delete` only does it if opted in via the
`Precondition`.
@2uasimojo
Copy link
Contributor Author

/test pull-controller-runtime-test-master

1 similar comment
@2uasimojo
Copy link
Contributor Author

/test pull-controller-runtime-test-master

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.

thanks!

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

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: 2uasimojo, alvaroaleman

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 Jul 8, 2021
@k8s-ci-robot k8s-ci-robot merged commit 81309dc into kubernetes-sigs:master Jul 8, 2021
@k8s-ci-robot k8s-ci-robot added this to the v0.9.x milestone Jul 8, 2021
@alvaroaleman alvaroaleman modified the milestones: v0.9.x, v0.10.x Jul 8, 2021
@2uasimojo 2uasimojo deleted the fake-delete-ResourceVersion branch July 8, 2021 16:51
thbkrkr added a commit to elastic/cloud-on-k8s that referenced this pull request Sep 27, 2021
The resource version is now required: kubernetes-sigs/controller-runtime#1582
("Fakeclient: Reject Delete with mismatched ResourceVersion").
thbkrkr pushed a commit to elastic/cloud-on-k8s that referenced this pull request Nov 18, 2021
And fix broken unit tests:
- elasticsearch/driver.TestUpgradePodsDeletion_WithNodeTypeMutations
- elasticsearch/driver.TestUpgradePodsDeletion_Delete
- enterprisesearch.TestReconcileEnterpriseSearch_doReconcile_AssociationDelaysVersionUpgrade
- license/trial.TestReconcileTrials_Reconcile/valid_trial_secret_inits_trial

With:
- Set resource version in newTestPod
- Do not reuse the same variable to get trial/license secrets
- Always SetAssociationConf before doReconcile

Because of:
- Client: Ensure no stale data remains in target object kubernetes-sigs/controller-runtime#1640
- Fakeclient: Reject Delete with mismatched ResourceVersion kubernetes-sigs/controller-runtime#1582
fantapsody pushed a commit to fantapsody/cloud-on-k8s that referenced this pull request Feb 7, 2023
And fix broken unit tests:
- elasticsearch/driver.TestUpgradePodsDeletion_WithNodeTypeMutations
- elasticsearch/driver.TestUpgradePodsDeletion_Delete
- enterprisesearch.TestReconcileEnterpriseSearch_doReconcile_AssociationDelaysVersionUpgrade
- license/trial.TestReconcileTrials_Reconcile/valid_trial_secret_inits_trial

With:
- Set resource version in newTestPod
- Do not reuse the same variable to get trial/license secrets
- Always SetAssociationConf before doReconcile

Because of:
- Client: Ensure no stale data remains in target object kubernetes-sigs/controller-runtime#1640
- Fakeclient: Reject Delete with mismatched ResourceVersion kubernetes-sigs/controller-runtime#1582
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/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants