Skip to content

Commit eef9a52

Browse files
committed
resource synch process for delete event
Signed-off-by: huiwq1990 <[email protected]>
1 parent 41975c5 commit eef9a52

File tree

4 files changed

+20
-0
lines changed

4 files changed

+20
-0
lines changed

pkg/storage/internalstorage/resource_storage.go

+4
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,10 @@ func (s *ResourceStorage) Watch(_ context.Context, _ *internal.ListOptions) (wat
278278
return nil, apierrors.NewMethodNotSupported(s.storageGroupResource, "watch")
279279
}
280280

281+
func (s *ResourceStorage) GetStorageName() string {
282+
return StorageName
283+
}
284+
281285
func applyListOptionsToResourceQuery(db *gorm.DB, query *gorm.DB, opts *internal.ListOptions) (int64, *int64, *gorm.DB, error) {
282286
applyFn := func(query *gorm.DB, opts *internal.ListOptions) (*gorm.DB, error) {
283287
query, err := applyOwnerToResourceQuery(db, query, opts)

pkg/storage/memorystorage/memory_resource_storage.go

+4
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,10 @@ func (s *ResourceStorage) Watch(ctx context.Context, options *internal.ListOptio
228228
return watcher, nil
229229
}
230230

231+
func (s *ResourceStorage) GetStorageName() string {
232+
return StorageName
233+
}
234+
231235
type errWatcher struct {
232236
result chan watch.Event
233237
}

pkg/storage/storage.go

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ type StorageFactory interface {
2929

3030
type ResourceStorage interface {
3131
GetStorageConfig() *ResourceStorageConfig
32+
GetStorageName() string
3233

3334
Get(ctx context.Context, cluster, namespace, name string, obj runtime.Object) error
3435
List(ctx context.Context, listObj runtime.Object, opts *internal.ListOptions) error

pkg/synchromanager/clustersynchro/resource_synchro.go

+11
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
clusterv1alpha2 "github.com/clusterpedia-io/api/cluster/v1alpha2"
2222
kubestatemetrics "github.com/clusterpedia-io/clusterpedia/pkg/kube_state_metrics"
2323
"github.com/clusterpedia-io/clusterpedia/pkg/storage"
24+
"github.com/clusterpedia-io/clusterpedia/pkg/storage/memorystorage"
2425
"github.com/clusterpedia-io/clusterpedia/pkg/synchromanager/clustersynchro/informer"
2526
"github.com/clusterpedia-io/clusterpedia/pkg/synchromanager/clustersynchro/queue"
2627
"github.com/clusterpedia-io/clusterpedia/pkg/synchromanager/features"
@@ -67,6 +68,8 @@ type ResourceSynchro struct {
6768

6869
// for debug
6970
runningStage string
71+
72+
transDeleteObject bool
7073
}
7174

7275
func newResourceSynchro(cluster string, syncResource schema.GroupVersionResource, kind string, lw cache.ListerWatcher, rvs map[string]interface{},
@@ -95,6 +98,8 @@ func newResourceSynchro(cluster string, syncResource schema.GroupVersionResource
9598

9699
closer: make(chan struct{}),
97100
closed: make(chan struct{}),
101+
102+
transDeleteObject: storage.GetStorageName() != memorystorage.StorageName,
98103
}
99104
close(synchro.runnableForStorage)
100105
synchro.ctx, synchro.cancel = context.WithCancel(context.Background())
@@ -317,6 +322,12 @@ func (synchro *ResourceSynchro) OnDelete(obj interface{}) {
317322
return
318323
}
319324

325+
if !synchro.transDeleteObject {
326+
synchro.pruneObject(obj.(*unstructured.Unstructured))
327+
_ = synchro.queue.Delete(obj)
328+
return
329+
}
330+
320331
key, err := cache.DeletionHandlingMetaNamespaceKeyFunc(obj)
321332
if err != nil {
322333
return

0 commit comments

Comments
 (0)