Skip to content

Commit

Permalink
set the gvk of the unstructured example object
Browse files Browse the repository at this point in the history
  • Loading branch information
Iceber committed Dec 14, 2021
1 parent a5acce8 commit f0fb6d1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
5 changes: 4 additions & 1 deletion pkg/synchromanager/clustersynchro/cluster_synchro.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
12 changes: 9 additions & 3 deletions pkg/synchromanager/clustersynchro/resource_synchro.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ import (
)

type ResourceSynchro struct {
cluster string
cluster string

syncKind schema.GroupVersionKind
storageResource schema.GroupResource

queue queue.EventQueue
Expand All @@ -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,
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit f0fb6d1

Please sign in to comment.