diff --git a/pkg/addonmanager/controllers/addonconfig/controller.go b/pkg/addonmanager/controllers/addonconfig/controller.go index 68718580..2a39dff4 100644 --- a/pkg/addonmanager/controllers/addonconfig/controller.go +++ b/pkg/addonmanager/controllers/addonconfig/controller.go @@ -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) } diff --git a/pkg/addonmanager/controllers/agentdeploy/controller.go b/pkg/addonmanager/controllers/agentdeploy/controller.go index 23018b0c..550d80a5 100644 --- a/pkg/addonmanager/controllers/agentdeploy/controller.go +++ b/pkg/addonmanager/controllers/agentdeploy/controller.go @@ -76,6 +76,8 @@ func NewAddonDeployController( agentAddons: agentAddons, } + c.setClusterInformerHandler(clusterInformers) + f := factory.New().WithSyncContext(syncCtx). WithFilteredEventsInformersQueueKeysFunc( func(obj runtime.Object) []string { @@ -126,15 +128,13 @@ 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 { @@ -142,7 +142,7 @@ func (c addonDeployController) watchManagedCluster(clusterInformers clusterinfor } } if len(filters) == 0 { - return false + return } _, err := clusterInformers.Informer().AddEventHandler( @@ -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) diff --git a/pkg/addonmanager/controllers/certificate/csrapprove.go b/pkg/addonmanager/controllers/certificate/csrapprove.go index 91d52dcf..29372d04 100644 --- a/pkg/addonmanager/controllers/certificate/csrapprove.go +++ b/pkg/addonmanager/controllers/certificate/csrapprove.go @@ -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") } diff --git a/pkg/addonmanager/controllers/certificate/csrsign.go b/pkg/addonmanager/controllers/certificate/csrsign.go index 30badd28..e690e383 100644 --- a/pkg/addonmanager/controllers/certificate/csrsign.go +++ b/pkg/addonmanager/controllers/certificate/csrsign.go @@ -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") } diff --git a/pkg/addonmanager/controllers/registration/controller.go b/pkg/addonmanager/controllers/registration/controller.go index a3833256..1f98be33 100644 --- a/pkg/addonmanager/controllers/registration/controller.go +++ b/pkg/addonmanager/controllers/registration/controller.go @@ -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") }