99 "k8s.io/apimachinery/pkg/runtime"
1010 "k8s.io/apimachinery/pkg/watch"
1111 "k8s.io/client-go/tools/cache"
12- "k8s.io/klog/v2"
13-
1412 "open-cluster-management.io/sdk-go/pkg/cloudevents/clients/utils"
1513 "open-cluster-management.io/sdk-go/pkg/cloudevents/generic"
1614 "open-cluster-management.io/sdk-go/pkg/cloudevents/generic/types"
@@ -52,8 +50,6 @@ func (s *AgentInformerWatcherStore[T]) Delete(resource runtime.Object) error {
5250}
5351
5452func (s * AgentInformerWatcherStore [T ]) HandleReceivedResource (ctx context.Context , action types.ResourceAction , resource T ) error {
55- logger := klog .FromContext (ctx )
56-
5753 switch action {
5854 case types .Added :
5955 newObj , err := utils .ToRuntimeObject (resource )
@@ -63,24 +59,22 @@ func (s *AgentInformerWatcherStore[T]) HandleReceivedResource(ctx context.Contex
6359
6460 return s .Add (newObj )
6561 case types .Modified :
66- newObj , err := meta .Accessor (resource )
62+ accessor , err := meta .Accessor (resource )
6763 if err != nil {
6864 return err
6965 }
7066
71- lastObj , exists , err := s .Get (newObj .GetNamespace (), newObj .GetName ())
67+ lastObj , exists , err := s .Get (accessor .GetNamespace (), accessor .GetName ())
7268 if err != nil {
7369 return err
7470 }
7571 if ! exists {
76- return fmt .Errorf ("the resource %s/%s does not exist" , newObj .GetNamespace (), newObj .GetName ())
72+ return fmt .Errorf ("the resource %s/%s does not exist" , accessor .GetNamespace (), accessor .GetName ())
7773 }
7874
79- // prevent the resource from being updated if it is deleting
75+ // if resource is deleting, keep the deletiong timestamp
8076 if ! lastObj .GetDeletionTimestamp ().IsZero () {
81- logger .Info ("the resource is deleting, ignore the update" ,
82- "resourceNamespace" , newObj .GetNamespace (), "resourceName" , newObj .GetName ())
83- return nil
77+ accessor .SetDeletionTimestamp (lastObj .GetDeletionTimestamp ())
8478 }
8579
8680 updated , err := utils .ToRuntimeObject (resource )
@@ -99,10 +93,6 @@ func (s *AgentInformerWatcherStore[T]) HandleReceivedResource(ctx context.Contex
9993 return nil
10094 }
10195
102- if len (newObj .GetFinalizers ()) != 0 {
103- return nil
104- }
105-
10696 last , exists , err := s .Get (newObj .GetNamespace (), newObj .GetName ())
10797 if err != nil {
10898 return err
@@ -116,6 +106,19 @@ func (s *AgentInformerWatcherStore[T]) HandleReceivedResource(ctx context.Contex
116106 return err
117107 }
118108
109+ // trigger an update event if the object is deleting.
110+ // Only need to update generation/finalizer/deletionTimeStamp of the object.
111+ if len (newObj .GetFinalizers ()) != 0 {
112+ accessor , err := meta .Accessor (deletingObj )
113+ if err != nil {
114+ return err
115+ }
116+ accessor .SetDeletionTimestamp (newObj .GetDeletionTimestamp ())
117+ accessor .SetFinalizers (newObj .GetFinalizers ())
118+ accessor .SetGeneration (newObj .GetGeneration ())
119+ return s .Update (deletingObj )
120+ }
121+
119122 return s .Delete (deletingObj )
120123 default :
121124 return fmt .Errorf ("unsupported resource action %s" , action )
0 commit comments