k8s/client/fake: let update operations respect resource versioning#44264
Merged
giorio94 merged 7 commits intocilium:mainfrom Feb 14, 2026
Merged
k8s/client/fake: let update operations respect resource versioning#44264giorio94 merged 7 commits intocilium:mainfrom
giorio94 merged 7 commits intocilium:mainfrom
Conversation
Member
Author
|
/ci-integration |
Member
Author
|
Back to draft, as a few tests need to be fixed. |
Update the TestResource_WithFakeClient test to correctly specify the expected resource version during updates, in preparation for extending the fake client to actually enforce optimistic concurrency control. Signed-off-by: Marco Iorio <marco.iorio@isovalent.com>
Update the TestUpdatePodLabels test to correctly specify the expected resource version during updates, in preparation for extending the fake client to actually enforce optimistic concurrency control. Signed-off-by: Marco Iorio <marco.iorio@isovalent.com>
83c73c6 to
0d98ebe
Compare
Member
Author
|
/ci-integration |
Member
Author
|
/ci-runtime |
Update the Test_LocalNodeCIDRsSyncer test to correctly specify the expected resource version during updates, in preparation for extending the fake client to actually enforce optimistic concurrency control. Signed-off-by: Marco Iorio <marco.iorio@isovalent.com>
Update the bgp tests to correctly specify the expected resource version during updates, in preparation for extending the fake client to actually enforce optimistic concurrency control. Signed-off-by: Marco Iorio <marco.iorio@isovalent.com>
Update the UpdateObjects helper to use the [ObjectTracker.Patch], instead of [ObjectTracker.Update], in preparation for the subsequent commit that will make the latter implement optimistic concurrency control, and validate resource version mismatches, which is not required in this context. Signed-off-by: Marco Iorio <marco.iorio@isovalent.com>
Currently, the object tracker is affected by a bug that causes the resource version to not be set on creation or update if the object does not have the [metav1.TypeMeta] set. Indeed, in that case, the function updating the TypeMeta creates a deep copy of the object, causing operations performed via [meta.Accessor] to act on the old copy, and not have effect. Let's get this fixed by changing the [fillTypeMetaIfNeeded] function to not create a deep copy, given that it already operates on a copy of the original object. Signed-off-by: Marco Iorio <marco.iorio@isovalent.com>
Currently, the statedb object tracker backing the fake kubernetes client used for testing purposes does not respect resource versioning, and allows update operations to succeed regardless of the provided resource version. While convenient for the `k8s/update` command itself, this approach is problematic in case of controllers acting on the same resources, as it can lead to objects being unexpectedly reverted to incorrect versions, due to the missing optimistic concurrency control. Let's get this fixed by extending the update implementation to additionally compare the resource version of the stored and provided objects, and reject the update in case they do not match, as the real Kubernetes API Server would do. By default, the k8s/update command still ignores the provided resource version, letting the update succeed regardless: this matches the desired behavior in the vast majority of the tests, and avoids the need for complex operations to set the expected resource version. Still, if necessary, the stricter behavior can be enabled via the dedicated flag. Signed-off-by: Marco Iorio <marco.iorio@isovalent.com>
0d98ebe to
f09bfad
Compare
Member
Author
|
/test |
Member
Author
Fixed, reviewable again. |
joamaki
approved these changes
Feb 12, 2026
christarazi
approved these changes
Feb 13, 2026
YutaroHayakawa
approved these changes
Feb 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 statedb object tracker backing the fake kubernetes client used for testing purposes does not respect resource versioning, and allows update operations to succeed regardless of the provided resource version. While convenient for the
k8s/updatecommand itself, this approach is problematic in case of controllers acting on the same resources, as it can lead to objects being unexpectedly reverted to incorrect versions, due to the missing optimistic concurrency control.Let's get this fixed by extending the update implementation to additionally compare the resource version of the stored and provided objects, and reject the update in case they do not match, as the real Kubernetes API Server would do. By default, the k8s/update command still ignores the provided resource version, letting the update succeed regardless: this matches the desired behavior in the vast majority of the tests, and avoids the need for complex operations to set the expected resource version. Still, if necessary, the stricter behavior can be enabled via the dedicated flag.