Skip to content

Commit a589480

Browse files
committed
⚠️ Fakeclient: Set ResourceVersion for SSA Create
We already set this for normal create operations, but missed to do it for creations that happen through SSA.
1 parent 51bd4f4 commit a589480

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

pkg/client/fake/client.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,9 +1171,15 @@ func (c *fakeClient) patch(obj client.Object, patch client.Patch, opts ...client
11711171
return err
11721172
}
11731173

1174-
// SSA deletionTimestamp updates are silently ignored
1175-
if patch.Type() == types.ApplyPatchType && !isApplyCreate {
1176-
obj.SetDeletionTimestamp(oldAccessor.GetDeletionTimestamp())
1174+
if patch.Type() == types.ApplyPatchType {
1175+
if isApplyCreate {
1176+
// Overwrite it unconditionally, this matches the apiserver behavior
1177+
// which allows to set it on create, but will then ignore it.
1178+
obj.SetResourceVersion("1")
1179+
} else {
1180+
// SSA deletionTimestamp updates are silently ignored
1181+
obj.SetDeletionTimestamp(oldAccessor.GetDeletionTimestamp())
1182+
}
11771183
}
11781184

11791185
data, err := patch.Data(obj)

pkg/client/fake/client_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2877,6 +2877,29 @@ var _ = Describe("Fake client", func() {
28772877
Expect(len(cms.Items)).To(BeEquivalentTo(1))
28782878
})
28792879

2880+
It("sets resourceVersion on SSA create", func(ctx SpecContext) {
2881+
obj := corev1applyconfigurations.
2882+
ConfigMap("foo", "default").
2883+
WithData(map[string]string{"some": "data"})
2884+
2885+
cl := NewClientBuilder().Build()
2886+
Expect(cl.Apply(ctx, obj, client.FieldOwner("foo"))).NotTo(HaveOccurred())
2887+
// Ideally we should only test for it to not be empty, realistically we will
2888+
// break ppl if we ever start setting a different value.
2889+
Expect(obj.ResourceVersion).To(BeEquivalentTo(ptr.To("1")))
2890+
})
2891+
2892+
It("ignores a passed resourceVersion on SSA create", func(ctx SpecContext) {
2893+
obj := corev1applyconfigurations.
2894+
ConfigMap("foo", "default").
2895+
WithData(map[string]string{"some": "data"}).
2896+
WithResourceVersion("1234")
2897+
2898+
cl := NewClientBuilder().Build()
2899+
Expect(cl.Apply(ctx, obj, client.FieldOwner("foo"))).NotTo(HaveOccurred())
2900+
Expect(obj.ResourceVersion).To(BeEquivalentTo(ptr.To("1")))
2901+
})
2902+
28802903
It("allows to set deletionTimestamp on an object during SSA create", func(ctx SpecContext) {
28812904
now := metav1.Time{Time: time.Now().Round(time.Second)}
28822905
obj := corev1applyconfigurations.

0 commit comments

Comments
 (0)