Skip to content

Commit 06736b1

Browse files
committed
add deletionTimeStamp when deleting objects with clients
Signed-off-by: Troy Connor <[email protected]>
1 parent c80ea33 commit 06736b1

File tree

4 files changed

+10
-0
lines changed

4 files changed

+10
-0
lines changed

pkg/client/fake/client.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -763,6 +763,8 @@ func (c *fakeClient) Delete(ctx context.Context, obj client.Object, opts ...clie
763763
}
764764
delOptions := client.DeleteOptions{}
765765
delOptions.ApplyOptions(opts)
766+
now := metav1.Now()
767+
obj.SetDeletionTimestamp(&now)
766768

767769
for _, dryRunOpt := range delOptions.DryRun {
768770
if dryRunOpt == metav1.DryRunAll {

pkg/client/metadata_client.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ func (mc *metadataClient) Delete(ctx context.Context, obj Object, opts ...Delete
6363

6464
deleteOpts := DeleteOptions{}
6565
deleteOpts.ApplyOptions(opts)
66+
now := metav1.Now()
67+
metadata.SetDeletionTimestamp(&now)
6668

6769
return resInt.Delete(ctx, metadata.Name, *deleteOpts.AsDeleteOptions())
6870
}

pkg/client/typed_client.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package client
1919
import (
2020
"context"
2121

22+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2223
"k8s.io/apimachinery/pkg/runtime"
2324
)
2425

@@ -78,6 +79,8 @@ func (c *typedClient) Delete(ctx context.Context, obj Object, opts ...DeleteOpti
7879

7980
deleteOpts := DeleteOptions{}
8081
deleteOpts.ApplyOptions(opts)
82+
now := metav1.Now()
83+
o.SetDeletionTimestamp(&now)
8184

8285
return o.Delete().
8386
NamespaceIfScoped(o.GetNamespace(), o.isNamespaced()).

pkg/client/unstructured_client.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"fmt"
2222
"strings"
2323

24+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2425
"k8s.io/apimachinery/pkg/runtime"
2526
)
2627

@@ -104,6 +105,8 @@ func (uc *unstructuredClient) Delete(ctx context.Context, obj Object, opts ...De
104105

105106
deleteOpts := DeleteOptions{}
106107
deleteOpts.ApplyOptions(opts)
108+
now := metav1.Now()
109+
o.SetDeletionTimestamp(&now)
107110

108111
return o.Delete().
109112
NamespaceIfScoped(o.GetNamespace(), o.isNamespaced()).

0 commit comments

Comments
 (0)