Skip to content

Commit

Permalink
🐛 fakeClient.Status().Update(...) cannot recognize resource version c…
Browse files Browse the repository at this point in the history
…onflicts

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]>
  • Loading branch information
iiiceoo authored and k8s-infra-cherrypick-robot committed Jun 11, 2023
1 parent 530dde0 commit 37c58ae
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
4 changes: 2 additions & 2 deletions pkg/client/fake/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -992,11 +992,11 @@ func copyNonStatusFrom(old, new runtime.Object) error {
}
}

newClientObject.SetResourceVersion(rv)

if err := fromMapStringAny(newMapStringAny, new); err != nil {
return fmt.Errorf("failed to convert back from map[string]any: %w", err)
}
newClientObject.SetResourceVersion(rv)

return nil
}

Expand Down
5 changes: 3 additions & 2 deletions pkg/client/fake/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1431,14 +1431,15 @@ var _ = Describe("Fake client", func() {
It("should return a conflict error when an incorrect RV is used on status update", func() {
obj := &corev1.Node{
ObjectMeta: metav1.ObjectMeta{
Name: "node",
Name: "node",
ResourceVersion: trackerAddResourceVersion,
},
}
cl := NewClientBuilder().WithStatusSubresource(obj).WithObjects(obj).Build()

obj.Status.Phase = corev1.NodeRunning
obj.ResourceVersion = "invalid"
err := cl.Update(context.Background(), obj)
err := cl.Status().Update(context.Background(), obj)
Expect(apierrors.IsConflict(err)).To(BeTrue())
})

Expand Down

0 comments on commit 37c58ae

Please sign in to comment.