From c4fcd8f2a4c0acb70df9ad6ba3d363bd4abfa90e Mon Sep 17 00:00:00 2001 From: huiwq1990 Date: Wed, 15 Nov 2023 15:36:53 +0800 Subject: [PATCH] resource synch process for delete event Signed-off-by: huiwq1990 --- .../clustersynchro/resource_synchro.go | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/pkg/synchromanager/clustersynchro/resource_synchro.go b/pkg/synchromanager/clustersynchro/resource_synchro.go index 0e0ade89f..f961a89e3 100644 --- a/pkg/synchromanager/clustersynchro/resource_synchro.go +++ b/pkg/synchromanager/clustersynchro/resource_synchro.go @@ -317,18 +317,18 @@ func (synchro *ResourceSynchro) OnDelete(obj interface{}) { return } - key, err := cache.DeletionHandlingMetaNamespaceKeyFunc(obj) - if err != nil { - return + if d, ok := obj.(cache.DeletedFinalStateUnknown); ok { + if obj, ok = d.Obj.(*unstructured.Unstructured); !ok { + namespace, name, err := cache.SplitMetaNamespaceKey(d.Key) + if err != nil { + return + } + obj = &metav1.PartialObjectMetadata{ObjectMeta: metav1.ObjectMeta{Namespace: namespace, Name: name}} + } } - namespace, name, err := cache.SplitMetaNamespaceKey(key) - if err != nil { - return + if o, ok := obj.(*unstructured.Unstructured); ok { + synchro.pruneObject(o) } - - // Since it is not necessary to save the complete deleted object to the queue, - // we convert the object to `PartialObjectMetadata` - obj = &metav1.PartialObjectMetadata{ObjectMeta: metav1.ObjectMeta{Namespace: namespace, Name: name}} _ = synchro.queue.Delete(obj) }