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: Allow concurrent patching if RV is unset or null #2979

Closed

Conversation

alvaroaleman
Copy link
Member

Currently, the fake client always errors if patches are done concurrently rather than only if the patch contains a ResourceVersion.

This is because we have a number of checks including the one related to resourceVersion implemented in a versionedTracker. The versionedTracker receives the patched object and assumes that the patchedObject only contains a RV if the patch had one. That turns out not to be true, it almost always has one.

The reason the object we receive in the versionedTracker almost always has a RV is that we use a client-go reactor to apply the patch to an object. The way this works is that the reactor takes the patch and a tracker, fetches the object from the tracker and applies the patch to it. This means that the resulting object always has a resourceVersion unless the patch explicitly set it to null. This null case apparently is special cased in the Kubernetes apiserver to be acceptable, so we do the same here.

Fix the original issue by checking in the fakeclient if the patch modifies the RV and if not, retry conflicts.

The goal of this patch is to address #2960 without introducing any other change in behavior. It does explicitly not address #2977 as that might break some peoples test.

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: 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 cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Oct 12, 2024
@k8s-ci-robot k8s-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Oct 12, 2024
Currently, the fake client always errors if patches are done
concurrently rather than only if the patch contains a ResourceVersion.

This is because we have a number of checks including the one related to
resourceVersion implemented in a `versionedTracker`. The
`versionedTracker` receives the patched object and assumes that the
patchedObject only contains a RV if the patch had one. That turns out
not to be true, it almost always has one.

The reason the object we receive in the `versionedTracker` almost always
has a RV is that we use a client-go reactor to apply the patch to an
object. The way this works is that the reactor takes the patch and a
tracker, fetches the object from the tracker and applies the patch to
it. This means that the resulting object always has a resourceVersion
unless the patch explicitly set it to `null`. This `null` case
apparently is special cased in the Kubernetes apiserver to be
acceptable, so we do the same here.

Fix the original issue by checking in the fakeclient if the patch
modifies the RV and if not, retry conflicts.
@alvaroaleman
Copy link
Member Author

Closing this, I think #2980 is the better approach. This change fixes the issue but introduces another: We allow dirty writes of the ResoruceVersion. I think just backporting #2980 is better.

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. 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.

2 participants