Skip to content

Commit

Permalink
Wait for cache sync for lister resources (#291)
Browse files Browse the repository at this point in the history
Signed-off-by: zhujian <[email protected]>
  • Loading branch information
zhujian7 authored Nov 29, 2024
1 parent a3a8096 commit 57b1d28
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 6 deletions.
2 changes: 2 additions & 0 deletions pkg/addonmanager/controllers/addonconfig/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ func NewAddonConfigController(
return []string{key}
}, addonInformers.Informer()).
WithBareInformers(configInformers...).
// clusterManagementAddonLister is used, so wait for cache sync
WithBareInformers(clusterManagementAddonInformers.Informer()).
WithSync(c.sync).ToController(controllerName)
}

Expand Down
12 changes: 6 additions & 6 deletions pkg/addonmanager/controllers/agentdeploy/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ func NewAddonDeployController(
agentAddons: agentAddons,
}

c.setClusterInformerHandler(clusterInformers)

f := factory.New().WithSyncContext(syncCtx).
WithFilteredEventsInformersQueueKeysFunc(
func(obj runtime.Object) []string {
Expand Down Expand Up @@ -126,23 +128,21 @@ func NewAddonDeployController(
},
workInformers.Informer(),
).
WithBareInformers(clusterInformers.Informer()).
WithSync(c.sync)

if c.watchManagedCluster(clusterInformers) {
f.WithBareInformers(clusterInformers.Informer())
}
return f.ToController(controllerName)
}

func (c addonDeployController) watchManagedCluster(clusterInformers clusterinformers.ManagedClusterInformer) bool {
func (c addonDeployController) setClusterInformerHandler(clusterInformers clusterinformers.ManagedClusterInformer) {
var filters []func(old, new *clusterv1.ManagedCluster) bool
for _, addon := range c.agentAddons {
if addon.GetAgentAddonOptions().AgentDeployTriggerClusterFilter != nil {
filters = append(filters, addon.GetAgentAddonOptions().AgentDeployTriggerClusterFilter)
}
}
if len(filters) == 0 {
return false
return
}

_, err := clusterInformers.Informer().AddEventHandler(
Expand All @@ -169,8 +169,8 @@ func (c addonDeployController) watchManagedCluster(clusterInformers clusterinfor
if err != nil {
utilruntime.HandleError(err)
}
return true
}

func (c *addonDeployController) enqueueAddOnsByCluster() func(obj interface{}) {
return func(obj interface{}) {
accessor, _ := meta.Accessor(obj)
Expand Down
2 changes: 2 additions & 0 deletions pkg/addonmanager/controllers/certificate/csrapprove.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ func NewCSRApprovingController(
return true
},
csrInformer).
// clusterLister and addonLister are used, so wait for cache sync
WithBareInformers(clusterInformers.Informer(), addonInformers.Informer()).
WithSync(c.sync).
ToController("CSRApprovingController")
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/addonmanager/controllers/certificate/csrsign.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ func NewCSRSignController(
return true
},
csrInformer.Informer()).
// clusterLister and addonLister are used, so wait for cache sync
WithBareInformers(clusterInformers.Informer(), addonInformers.Informer()).
WithSync(c.sync).
ToController("CSRSignController")
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/addonmanager/controllers/registration/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ func NewAddonRegistrationController(
return true
},
addonInformers.Informer()).
// clusterLister is used, so wait for cache sync
WithBareInformers(clusterInformers.Informer()).
WithSync(c.sync).ToController("addon-registration-controller")
}

Expand Down

0 comments on commit 57b1d28

Please sign in to comment.