Skip to content

Commit

Permalink
resource synch process for delete event
Browse files Browse the repository at this point in the history
Signed-off-by: huiwq1990 <[email protected]>
  • Loading branch information
huiwq1990 committed Nov 15, 2023
1 parent 41975c5 commit eef9a52
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/storage/internalstorage/resource_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,10 @@ func (s *ResourceStorage) Watch(_ context.Context, _ *internal.ListOptions) (wat
return nil, apierrors.NewMethodNotSupported(s.storageGroupResource, "watch")
}

func (s *ResourceStorage) GetStorageName() string {
return StorageName
}

func applyListOptionsToResourceQuery(db *gorm.DB, query *gorm.DB, opts *internal.ListOptions) (int64, *int64, *gorm.DB, error) {
applyFn := func(query *gorm.DB, opts *internal.ListOptions) (*gorm.DB, error) {
query, err := applyOwnerToResourceQuery(db, query, opts)
Expand Down
4 changes: 4 additions & 0 deletions pkg/storage/memorystorage/memory_resource_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,10 @@ func (s *ResourceStorage) Watch(ctx context.Context, options *internal.ListOptio
return watcher, nil
}

func (s *ResourceStorage) GetStorageName() string {
return StorageName
}

type errWatcher struct {
result chan watch.Event
}
Expand Down
1 change: 1 addition & 0 deletions pkg/storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type StorageFactory interface {

type ResourceStorage interface {
GetStorageConfig() *ResourceStorageConfig
GetStorageName() string

Get(ctx context.Context, cluster, namespace, name string, obj runtime.Object) error
List(ctx context.Context, listObj runtime.Object, opts *internal.ListOptions) error
Expand Down
11 changes: 11 additions & 0 deletions pkg/synchromanager/clustersynchro/resource_synchro.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
clusterv1alpha2 "github.com/clusterpedia-io/api/cluster/v1alpha2"
kubestatemetrics "github.com/clusterpedia-io/clusterpedia/pkg/kube_state_metrics"
"github.com/clusterpedia-io/clusterpedia/pkg/storage"
"github.com/clusterpedia-io/clusterpedia/pkg/storage/memorystorage"
"github.com/clusterpedia-io/clusterpedia/pkg/synchromanager/clustersynchro/informer"
"github.com/clusterpedia-io/clusterpedia/pkg/synchromanager/clustersynchro/queue"
"github.com/clusterpedia-io/clusterpedia/pkg/synchromanager/features"
Expand Down Expand Up @@ -67,6 +68,8 @@ type ResourceSynchro struct {

// for debug
runningStage string

transDeleteObject bool
}

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

closer: make(chan struct{}),
closed: make(chan struct{}),

transDeleteObject: storage.GetStorageName() != memorystorage.StorageName,
}
close(synchro.runnableForStorage)
synchro.ctx, synchro.cancel = context.WithCancel(context.Background())
Expand Down Expand Up @@ -317,6 +322,12 @@ func (synchro *ResourceSynchro) OnDelete(obj interface{}) {
return
}

if !synchro.transDeleteObject {
synchro.pruneObject(obj.(*unstructured.Unstructured))
_ = synchro.queue.Delete(obj)
return
}

key, err := cache.DeletionHandlingMetaNamespaceKeyFunc(obj)
if err != nil {
return
Expand Down

0 comments on commit eef9a52

Please sign in to comment.