Skip to content

Commit 37c58ae

Browse files
iiiceook8s-infra-cherrypick-robot
authored and
k8s-infra-cherrypick-robot
committed
🐛 fakeClient.Status().Update(...) cannot recognize resource version conflicts
The fake client of subresource is unable to correctly handle the case of resource version conflict when updating. The phenomenon is that it did not return a 409 status error. Signed-off-by: iiiceoo <[email protected]>
1 parent 530dde0 commit 37c58ae

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

pkg/client/fake/client.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -992,11 +992,11 @@ func copyNonStatusFrom(old, new runtime.Object) error {
992992
}
993993
}
994994

995-
newClientObject.SetResourceVersion(rv)
996-
997995
if err := fromMapStringAny(newMapStringAny, new); err != nil {
998996
return fmt.Errorf("failed to convert back from map[string]any: %w", err)
999997
}
998+
newClientObject.SetResourceVersion(rv)
999+
10001000
return nil
10011001
}
10021002

pkg/client/fake/client_test.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -1431,14 +1431,15 @@ var _ = Describe("Fake client", func() {
14311431
It("should return a conflict error when an incorrect RV is used on status update", func() {
14321432
obj := &corev1.Node{
14331433
ObjectMeta: metav1.ObjectMeta{
1434-
Name: "node",
1434+
Name: "node",
1435+
ResourceVersion: trackerAddResourceVersion,
14351436
},
14361437
}
14371438
cl := NewClientBuilder().WithStatusSubresource(obj).WithObjects(obj).Build()
14381439

14391440
obj.Status.Phase = corev1.NodeRunning
14401441
obj.ResourceVersion = "invalid"
1441-
err := cl.Update(context.Background(), obj)
1442+
err := cl.Status().Update(context.Background(), obj)
14421443
Expect(apierrors.IsConflict(err)).To(BeTrue())
14431444
})
14441445

0 commit comments

Comments
 (0)