diff --git a/pkg/synchromanager/clustersynchro/cluster_synchro.go b/pkg/synchromanager/clustersynchro/cluster_synchro.go index 533b5a8e7..5f8e53bff 100644 --- a/pkg/synchromanager/clustersynchro/cluster_synchro.go +++ b/pkg/synchromanager/clustersynchro/cluster_synchro.go @@ -153,6 +153,7 @@ func (s *ClusterSynchro) initWithResourceVersions(resourceversions map[schema.Gr } type syncConfig struct { + kind string syncResource schema.GroupVersionResource storageResource schema.GroupVersionResource convertor runtime.ObjectConvertor @@ -258,6 +259,7 @@ func (s *ClusterSynchro) SetResources(clusterResources []clustersv1alpha1.Cluste storageResource := storageConfig.StorageGroupResource.WithVersion(storageConfig.StorageVersion.Version) if _, ok := configs[storageResource]; !ok { config := &syncConfig{ + kind: info.Kind, syncResource: syncResource, storageResource: storageResource, storageConfig: storageConfig, @@ -340,7 +342,8 @@ func (s *ClusterSynchro) SetResources(clusterResources []clustersv1alpha1.Cluste s.resourceVersionCaches[gvr] = resourceVersionCache } - synchro := newResourceSynchro(s.name, + syncKind := config.syncResource.GroupVersion().WithKind(config.kind) + synchro := newResourceSynchro(s.name, syncKind, s.listerWatcherFactory.ForResource(metav1.NamespaceAll, config.syncResource), resourceVersionCache, config.convertor, diff --git a/pkg/synchromanager/clustersynchro/resource_synchro.go b/pkg/synchromanager/clustersynchro/resource_synchro.go index 3cc41d1a4..dca96953f 100644 --- a/pkg/synchromanager/clustersynchro/resource_synchro.go +++ b/pkg/synchromanager/clustersynchro/resource_synchro.go @@ -26,7 +26,9 @@ import ( ) type ResourceSynchro struct { - cluster string + cluster string + + syncKind schema.GroupVersionKind storageResource schema.GroupResource queue queue.EventQueue @@ -49,12 +51,13 @@ type ResourceSynchro struct { closed chan struct{} } -func newResourceSynchro(cluster string, lw cache.ListerWatcher, rvcache *informer.ResourceVersionStorage, +func newResourceSynchro(cluster string, syncKind schema.GroupVersionKind, lw cache.ListerWatcher, rvcache *informer.ResourceVersionStorage, convertor runtime.ObjectConvertor, storage storage.ResourceStorage, ) *ResourceSynchro { ctx, cancel := context.WithCancel(context.Background()) synchro := &ResourceSynchro{ cluster: cluster, + syncKind: syncKind, storageResource: storage.GetStorageConfig().StorageGroupResource, listerWatcher: lw, @@ -139,11 +142,14 @@ func (synchro *ResourceSynchro) Run(stopCh <-chan struct{}) { } synchro.status.Store(status) + exampleObj := &unstructured.Unstructured{} + exampleObj.SetGroupVersionKind(synchro.syncKind) + informer.NewResourceVersionInformer( synchro.cluster, synchro.listerWatcher, synchro.cache, - &unstructured.Unstructured{}, + exampleObj, synchro, ).Run(synchro.syncWithLastResourceVersion, informerStopCh)