🐛 Fakeclient: Allow concurrent patching if RV is unset or null #2979
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
. TheversionedTracker
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 tonull
. Thisnull
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.