Skip to content

Commit

Permalink
Start an addon informor for each addon
Browse files Browse the repository at this point in the history
Signed-off-by: zhujian <[email protected]>
  • Loading branch information
zhujian7 committed Nov 29, 2024
1 parent 9a6189b commit 140c196
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
27 changes: 24 additions & 3 deletions pkg/addon/controllers/addontemplate/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import (

"open-cluster-management.io/addon-framework/pkg/addonfactory"
"open-cluster-management.io/addon-framework/pkg/addonmanager"
"open-cluster-management.io/addon-framework/pkg/index"
"open-cluster-management.io/addon-framework/pkg/utils"
addonapiv1alpha1 "open-cluster-management.io/api/addon/v1alpha1"
addonv1alpha1 "open-cluster-management.io/api/addon/v1alpha1"
addonv1alpha1client "open-cluster-management.io/api/client/addon/clientset/versioned"
addoninformers "open-cluster-management.io/api/client/addon/informers/externalversions"
Expand Down Expand Up @@ -193,7 +193,7 @@ func (c *addonTemplateController) runController(
listOptions.LabelSelector = metav1.FormatLabelSelector(selector)
}),
)
getValuesClosure := func(cluster *clusterv1.ManagedCluster, addon *addonapiv1alpha1.ManagedClusterAddOn) (addonfactory.Values, error) {
getValuesClosure := func(cluster *clusterv1.ManagedCluster, addon *addonv1alpha1.ManagedClusterAddOn) (addonfactory.Values, error) {
return templateagent.GetAddOnRegistriesPrivateValuesFromClusterAnnotation(klog.FromContext(ctx), cluster, addon)
}
agentAddon := templateagent.NewCRDTemplateAgentAddon(
Expand All @@ -219,13 +219,34 @@ func (c *addonTemplateController) runController(
return err
}

// not share the addon informers
addonInformerFactory := addoninformers.NewSharedInformerFactory(c.addonClient, 10*time.Minute)
err = addonInformerFactory.Addon().V1alpha1().ManagedClusterAddOns().Informer().AddIndexers(
cache.Indexers{
index.ManagedClusterAddonByNamespace: index.IndexManagedClusterAddonByNamespace, // agentDeployController
index.AddonByConfig: index.IndexAddonByConfig, // addonConfigController
},
)
if err != nil {
return err
}

// managementAddonConfigController
err = addonInformerFactory.Addon().V1alpha1().ClusterManagementAddOns().Informer().AddIndexers(
cache.Indexers{
index.ClusterManagementAddonByConfig: index.IndexClusterManagementAddonByConfig, // cmaConfigController
})
if err != nil {
return err
}
err = mgr.StartWithInformers(ctx, c.workClient, c.workInformers.Work().V1().ManifestWorks(),
kubeInformers, c.addonInformers, c.clusterInformers, c.dynamicInformers)
kubeInformers, addonInformerFactory, c.clusterInformers, c.dynamicInformers)
if err != nil {
return err
}

kubeInformers.Start(ctx.Done())
addonInformerFactory.Start(ctx.Done())

return nil
}
7 changes: 2 additions & 5 deletions pkg/addon/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,7 @@ func RunControllerManagerWithInformers(

err = addonInformers.Addon().V1alpha1().ManagedClusterAddOns().Informer().AddIndexers(
cache.Indexers{
index.ManagedClusterAddonByNamespace: index.IndexManagedClusterAddonByNamespace, // addonDeployController
index.ManagedClusterAddonByName: index.IndexManagedClusterAddonByName, // addonConfigController
index.AddonByConfig: index.IndexAddonByConfig, // addonConfigController
index.ManagedClusterAddonByName: index.IndexManagedClusterAddonByName, // addonConfigurationController, addonManagementController
},
)
if err != nil {
Expand All @@ -124,8 +122,7 @@ func RunControllerManagerWithInformers(
// managementAddonConfigController
err = addonInformers.Addon().V1alpha1().ClusterManagementAddOns().Informer().AddIndexers(
cache.Indexers{
index.ClusterManagementAddonByConfig: index.IndexClusterManagementAddonByConfig,
index.ClusterManagementAddonByPlacement: index.IndexClusterManagementAddonByPlacement,
index.ClusterManagementAddonByPlacement: index.IndexClusterManagementAddonByPlacement, // addonConfigurationController, addonManagementController
})
if err != nil {
return err
Expand Down

0 comments on commit 140c196

Please sign in to comment.