@@ -19,7 +19,6 @@ import (
1919 "open-cluster-management.io/addon-framework/pkg/addonfactory"
2020 "open-cluster-management.io/addon-framework/pkg/addonmanager"
2121 "open-cluster-management.io/addon-framework/pkg/utils"
22- addonapiv1alpha1 "open-cluster-management.io/api/addon/v1alpha1"
2322 addonv1alpha1 "open-cluster-management.io/api/addon/v1alpha1"
2423 addonv1alpha1client "open-cluster-management.io/api/client/addon/clientset/versioned"
2524 addoninformers "open-cluster-management.io/api/client/addon/informers/externalversions"
@@ -34,11 +33,6 @@ import (
3433 "open-cluster-management.io/ocm/pkg/common/queue"
3534)
3635
37- const (
38- // requeueDelay is the delay for requeuing when ManagedClusterAddOns still exist
39- requeueDelay = 10 * time .Second
40- )
41-
4236// addonTemplateController monitors ManagedClusterAddOns on hub to get all the in-used addon templates,
4337// and starts an addon manager for every addon template to handle agent requests deployed by this template
4438type addonTemplateController struct {
@@ -96,9 +90,28 @@ func NewAddonTemplateController(
9690 // easy to mock in unit tests
9791 c .runControllerFunc = c .runController
9892 }
99- return factory .New ().WithInformersQueueKeysFunc (
100- queue .QueueKeyByMetaNamespaceName ,
101- addonInformers .Addon ().V1alpha1 ().ClusterManagementAddOns ().Informer ()).
93+ return factory .New ().
94+ WithInformersQueueKeysFunc (
95+ queue .QueueKeyByMetaNamespaceName ,
96+ addonInformers .Addon ().V1alpha1 ().ClusterManagementAddOns ().Informer ()).
97+ WithFilteredEventsInformersQueueKeysFunc (
98+ queue .QueueKeyByMetaName ,
99+ func (obj interface {}) bool {
100+ mca , ok := obj .(* addonv1alpha1.ManagedClusterAddOn )
101+ if ! ok {
102+ return false
103+ }
104+
105+ // Only process ManagedClusterAddOns that reference AddOnTemplates
106+ for _ , configRef := range mca .Status .ConfigReferences {
107+ if configRef .ConfigGroupResource .Group == "addon.open-cluster-management.io" &&
108+ configRef .ConfigGroupResource .Resource == "addontemplates" {
109+ return true
110+ }
111+ }
112+ return false
113+ },
114+ addonInformers .Addon ().V1alpha1 ().ManagedClusterAddOns ().Informer ()).
102115 WithBareInformers (
103116 // do not need to queue, just make sure the controller reconciles after the addonTemplate cache is synced
104117 // otherwise, there will be "xx-addon-template" not found" errors in the log as the controller uses the
@@ -123,8 +136,7 @@ func (c *addonTemplateController) stopUnusedManagers(
123136 if len (addons ) > 0 {
124137 logger .Info ("ManagedClusterAddOn still exists, waiting for deletion" ,
125138 "addonName" , addOnName , "count" , len (addons ))
126- // Requeue to check again later
127- syncCtx .Queue ().AddAfter (addOnName , requeueDelay )
139+ // No need to requeue since we now watch ManagedClusterAddon events
128140 return nil
129141 }
130142
@@ -213,7 +225,7 @@ func (c *addonTemplateController) runController(ctx context.Context, addonName s
213225 listOptions .LabelSelector = metav1 .FormatLabelSelector (selector )
214226 }),
215227 )
216- getValuesClosure := func (cluster * clusterv1.ManagedCluster , addon * addonapiv1alpha1 .ManagedClusterAddOn ) (addonfactory.Values , error ) {
228+ getValuesClosure := func (cluster * clusterv1.ManagedCluster , addon * addonv1alpha1 .ManagedClusterAddOn ) (addonfactory.Values , error ) {
217229 return templateagent .GetAddOnRegistriesPrivateValuesFromClusterAnnotation (klog .FromContext (ctx ), cluster , addon )
218230 }
219231 agentAddon := templateagent .NewCRDTemplateAgentAddon (
0 commit comments