Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🌱 Wait for cache sync for lister resources #291

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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