Skip to content
Closed
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
3 changes: 3 additions & 0 deletions pkg/client/fake/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1198,6 +1198,9 @@ func (c *fakeClient) deleteObjectLocked(gvr schema.GroupVersionResource, accesso
if len(oldAccessor.GetFinalizers()) > 0 {
now := metav1.Now()
oldAccessor.SetDeletionTimestamp(&now)
// Reflect onto the caller's object so Delete matches Create/Update/Get
// and apiserver responses when finalizers delay removal.
accessor.SetDeletionTimestamp(&now)
// Call update directly with mutability parameter set to true to allow
// changes to deletionTimestamp
return c.tracker.update(gvr, old, accessor.GetNamespace(), false, true, metav1.UpdateOptions{})
Expand Down
25 changes: 18 additions & 7 deletions pkg/client/fake/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,21 @@ var _ = Describe("Fake client", func() {
Expect(apierrors.IsNotFound(err)).To(BeTrue())
})

It("should set deletionTimestamp on the object passed to Delete when finalizers are present", func(ctx SpecContext) {
obj := &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: "test-cm",
Namespace: "delete-updates-caller-object",
Finalizers: []string{"finalizers.sigs.k8s.io/test"},
},
}
Expect(cl.Create(ctx, obj)).To(Succeed())
Expect(obj.DeletionTimestamp).To(BeNil())

Expect(cl.Delete(ctx, obj)).To(Succeed())
Expect(obj.DeletionTimestamp).NotTo(BeNil())
})

It("should handle finalizers on Update", func(ctx SpecContext) {
namespacedName := types.NamespacedName{
Name: "test-cm",
Expand Down Expand Up @@ -1211,15 +1226,11 @@ var _ = Describe("Fake client", func() {
By("Deleting the object")
err = cl.Delete(ctx, newObj)
Expect(err).ToNot(HaveOccurred())
Expect(newObj.DeletionTimestamp).NotTo(BeNil())

By("Removing the finalizer")
obj := &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: namespacedName.Name,
Namespace: namespacedName.Namespace,
Finalizers: []string{},
},
}
obj := newObj.DeepCopy()
obj.Finalizers = []string{}
err = cl.Patch(ctx, obj, client.MergeFrom(newObj))
Expect(err).ToNot(HaveOccurred())

Expand Down