Skip to content

Commit

Permalink
Merge pull request #2372 from k8s-infra-cherrypick-robot/cherry-pick-…
Browse files Browse the repository at this point in the history
…2365-to-release-0.15

[release-0.15] 🐛 fakeClient.Status().Update(...) cannot recognize resource version conflicts
  • Loading branch information
k8s-ci-robot authored Jun 11, 2023
2 parents 530dde0 + 37c58ae commit 111c938
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 111c938

Please sign in to comment.