Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions pkg/client/fake/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1171,9 +1171,15 @@ func (c *fakeClient) patch(obj client.Object, patch client.Patch, opts ...client
return err
}

// SSA deletionTimestamp updates are silently ignored
if patch.Type() == types.ApplyPatchType && !isApplyCreate {
obj.SetDeletionTimestamp(oldAccessor.GetDeletionTimestamp())
if patch.Type() == types.ApplyPatchType {
if isApplyCreate {
// Overwrite it unconditionally, this matches the apiserver behavior
// which allows to set it on create, but will then ignore it.
obj.SetResourceVersion("1")
} else {
// SSA deletionTimestamp updates are silently ignored
obj.SetDeletionTimestamp(oldAccessor.GetDeletionTimestamp())
}
}

data, err := patch.Data(obj)
Expand Down
23 changes: 23 additions & 0 deletions pkg/client/fake/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2877,6 +2877,29 @@ var _ = Describe("Fake client", func() {
Expect(len(cms.Items)).To(BeEquivalentTo(1))
})

It("sets resourceVersion on SSA create", func(ctx SpecContext) {
obj := corev1applyconfigurations.
ConfigMap("foo", "default").
WithData(map[string]string{"some": "data"})

cl := NewClientBuilder().Build()
Expect(cl.Apply(ctx, obj, client.FieldOwner("foo"))).NotTo(HaveOccurred())
// Ideally we should only test for it to not be empty, realistically we will
// break ppl if we ever start setting a different value.
Expect(obj.ResourceVersion).To(BeEquivalentTo(ptr.To("1")))
})

It("ignores a passed resourceVersion on SSA create", func(ctx SpecContext) {
obj := corev1applyconfigurations.
ConfigMap("foo", "default").
WithData(map[string]string{"some": "data"}).
WithResourceVersion("1234")

cl := NewClientBuilder().Build()
Expect(cl.Apply(ctx, obj, client.FieldOwner("foo"))).NotTo(HaveOccurred())
Expect(obj.ResourceVersion).To(BeEquivalentTo(ptr.To("1")))
})

It("allows to set deletionTimestamp on an object during SSA create", func(ctx SpecContext) {
now := metav1.Time{Time: time.Now().Round(time.Second)}
obj := corev1applyconfigurations.
Expand Down