Skip to content

Commit c8a4fa7

Browse files
zhujian7claude
andauthored
✨ Add template-based addon handling to prevent premature processing (open-cluster-management-io#334)
* Rename addonFilterFunc to cmaFilterFunc for clarity The filter function parameter is specifically used for ClusterManagementAddon objects, so the new name cmaFilterFunc is more descriptive and accurate than the generic addonFilterFunc. Signed-off-by: Claude <[email protected]> 🤖 Generated with Claude Code Co-Authored-By: Claude <[email protected]> Signed-off-by: zhujian <[email protected]> * Add ManagedClusterAddOn filter functionality to addon framework This commit introduces a new filtering mechanism for ManagedClusterAddOn objects to enable selective processing of addons based on custom criteria. Key changes: 1. Created pkg/utils/addon.go with filter functions: - ManagedClusterAddOnFilterFunc type for custom filtering - AllowAllAddOns function that accepts all addons - FilterTemplateBasedAddOns function that filters template-based addons 2. Updated all addon controllers to accept and use the filter function: - addonconfig controller - agentdeploy controller - certificate controllers (CSR approve/sign) - registration controller 3. Added comprehensive test coverage in pkg/utils/addon_test.go 4. Updated BaseAddonManager interface to include mcaFilterFunc parameter This enables selective processing of addons, particularly useful for filtering template-based addons vs regular addons based on their status.configReferences. 🤖 Generated with Claude Code Co-Authored-By: Claude <[email protected]> Signed-off-by: zhujian <[email protected]> * Fix error handling in registration controller Improve error handling in addonRegistrationController.sync() by: - Only returning errors when operations actually fail - Adding proper error wrapping with descriptive messages - Returning nil when operations succeed 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]> Signed-off-by: zhujian <[email protected]> * Improve templateBasedAddOn parameter documentation and implementation - Rename parameter from templateAddOn to templateBasedAddOn for clarity - Add comprehensive documentation explaining the parameter's purpose - Update comments to explain why addon-config-controller bypasses filtering - Remove mcaFilterFunc parameter from addon-config-controller - Reference GitHub issue #1181 for additional context - Fix typos and improve comment readability This change helps prevent premature processing of template-based addons before their configurations are ready, reducing unnecessary errors. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]> Signed-off-by: zhujian <[email protected]> * Refactor template-based addon handling to avoid breaking interface changes - Move templateBasedAddOn parameter from interface to concrete implementation - Add SetTemplateBasedAddOn() method to BaseAddonManager interface - Add templateBasedAddOn field to BaseAddonManagerImpl struct - Revert StartWithInformers interface to original signature - Update all callers to use the original interface method - Maintain backward compatibility while providing new functionality This allows users to configure template-based addon handling through the public API without breaking existing external implementations: manager, _ := addonmanager.New(config) manager.SetTemplateBasedAddOn(true) // Enable template filtering manager.StartWithInformers(ctx, ...) // Uses configured setting 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]> Signed-off-by: zhujian <[email protected]> * Rename SetTemplateBasedAddOn to SetTemplateMode for better clarity - Update method name from SetTemplateBasedAddOn to SetTemplateMode - Change parameter name from templateBasedAddOn to enabled - Keep existing comments and documentation unchanged - Provides cleaner, more intuitive API naming Usage becomes: manager.SetTemplateMode(true) // Enable template mode 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]> Signed-off-by: zhujian <[email protected]> * Refactor to use constructor options pattern to avoid breaking interface changes - Remove SetTemplateMode method from BaseAddonManager interface - Add Option type and WithTemplateMode(bool) constructor option - Update NewBaseAddonManagerImpl to accept ...Option parameters - Add NewWithOptions function for public API with options - Preserve existing New() function for backward compatibility - Remove SetTemplateMode method from implementation This maintains full backward compatibility while providing template mode configuration through constructor options: // Existing usage unchanged manager, _ := addonmanager.New(config) // New usage with template mode manager, _ := addonmanager.NewWithOptions(config, addonmanager.WithTemplateMode(true)) 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]> Signed-off-by: zhujian <[email protected]> * Implement public Option struct with OptionFunc pattern - Add public Option struct with public TemplateBasedAddOn field - Add OptionFunc type and WithTemplateMode function - Add WithOption helper to bridge struct and functional patterns - Remove NewWithOptions in favor of unified NewWithOptionFuncs - Remove ApplyOptions method to keep cleaner API - Fix tautological condition warning This provides flexible configuration supporting both patterns: // Functional pattern manager, _ := addonmanager.NewWithOptionFuncs(config, addonmanager.WithTemplateMode(true)) // Struct pattern with helper opt := &addonmanager.Option{TemplateBasedAddOn: true} manager, _ := addonmanager.NewWithOptionFuncs(config, addonmanager.WithOption(opt)) 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]> Signed-off-by: zhujian <[email protected]> --------- Signed-off-by: zhujian <[email protected]> Co-authored-by: Claude <[email protected]>
1 parent 7f19b89 commit c8a4fa7

File tree

17 files changed

+407
-34
lines changed

17 files changed

+407
-34
lines changed

pkg/addonmanager/base_manager.go

Lines changed: 66 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,47 @@ import (
2626
"open-cluster-management.io/sdk-go/pkg/basecontroller/factory"
2727
)
2828

29+
// Option contains configuration options for BaseAddonManagerImpl.
30+
type Option struct {
31+
// TemplateBasedAddOn configures whether the manager is handling template-based addons.
32+
// - true: all ManagedClusterAddOn controllers except "addon-config-controller" will only process addons
33+
// when the referenced AddOnTemplate resources in their status.configReferences are properly set;
34+
// the "addon-config-controller" is responsible for setting these values
35+
// - false: process all addons without waiting for template configuration
36+
//
37+
// This prevents premature processing of template-based addons before their configurations
38+
// are fully ready, avoiding unnecessary errors and retries.
39+
// See https://github.com/open-cluster-management-io/ocm/issues/1181 for more context.
40+
TemplateBasedAddOn bool
41+
}
42+
43+
// OptionFunc is a function that modifies Option.
44+
type OptionFunc func(*Option)
45+
46+
// WithTemplateMode returns an OptionFunc that sets the template mode.
47+
func WithTemplateMode(enabled bool) OptionFunc {
48+
return func(option *Option) {
49+
option.TemplateBasedAddOn = enabled
50+
}
51+
}
52+
53+
// WithOption returns an OptionFunc that applies the given Option struct.
54+
func WithOption(opt *Option) OptionFunc {
55+
return func(option *Option) {
56+
if opt != nil {
57+
*option = *opt
58+
}
59+
}
60+
}
61+
2962
// BaseAddonManagerImpl is the base implementation of BaseAddonManager
3063
// that manages the addon agents and configs.
3164
type BaseAddonManagerImpl struct {
32-
addonAgents map[string]agent.AgentAddon
33-
addonConfigs map[schema.GroupVersionResource]bool
34-
config *rest.Config
35-
syncContexts []factory.SyncContext
65+
addonAgents map[string]agent.AgentAddon
66+
addonConfigs map[schema.GroupVersionResource]bool
67+
config *rest.Config
68+
syncContexts []factory.SyncContext
69+
templateBasedAddOn bool
3670
}
3771

3872
// NewBaseAddonManagerImpl creates a new BaseAddonManagerImpl instance with the given config.
@@ -45,6 +79,15 @@ func NewBaseAddonManagerImpl(config *rest.Config) *BaseAddonManagerImpl {
4579
}
4680
}
4781

82+
// ApplyOptionFuncs applies OptionFunc functions to create and configure options.
83+
func (a *BaseAddonManagerImpl) ApplyOptionFuncs(optionFuncs ...OptionFunc) {
84+
option := &Option{}
85+
for _, fn := range optionFuncs {
86+
fn(option)
87+
}
88+
a.templateBasedAddOn = option.TemplateBasedAddOn
89+
}
90+
4891
func (a *BaseAddonManagerImpl) GetConfig() *rest.Config {
4992
return a.config
5093
}
@@ -77,7 +120,13 @@ func (a *BaseAddonManagerImpl) StartWithInformers(ctx context.Context,
77120
kubeInformers kubeinformers.SharedInformerFactory,
78121
addonInformers addoninformers.SharedInformerFactory,
79122
clusterInformers clusterv1informers.SharedInformerFactory,
80-
dynamicInformers dynamicinformer.DynamicSharedInformerFactory) error {
123+
dynamicInformers dynamicinformer.DynamicSharedInformerFactory,
124+
) error {
125+
// Determine the appropriate filter function based on templateBasedAddOn field
126+
mcaFilterFunc := utils.AllowAllAddOns
127+
if a.templateBasedAddOn {
128+
mcaFilterFunc = utils.FilterTemplateBasedAddOns
129+
}
81130

82131
kubeClient, err := kubernetes.NewForConfig(a.config)
83132
if err != nil {
@@ -107,13 +156,15 @@ func (a *BaseAddonManagerImpl) StartWithInformers(ctx context.Context,
107156
addonInformers.Addon().V1alpha1().ManagedClusterAddOns(),
108157
workInformers,
109158
a.addonAgents,
159+
mcaFilterFunc,
110160
)
111161

112162
registrationController := registration.NewAddonRegistrationController(
113163
addonClient,
114164
clusterInformers.Cluster().V1().ManagedClusters(),
115165
addonInformers.Addon().V1alpha1().ManagedClusterAddOns(),
116166
a.addonAgents,
167+
mcaFilterFunc,
117168
)
118169

119170
// This controller is used during migrating addons to be managed by addon-manager.
@@ -128,6 +179,13 @@ func (a *BaseAddonManagerImpl) StartWithInformers(ctx context.Context,
128179

129180
var addonConfigController, managementAddonConfigController factory.Controller
130181
if len(a.addonConfigs) != 0 {
182+
// ManagedClusterAddOn filter is intentionally disabled for the addon-config-controller.
183+
// This is because template-based addons require this controller to set the specHash in
184+
// managedclusteraddon.status.configReferences for addontemplates. Without this, all other
185+
// ManagedClusterAddOn controllers would wait indefinitely for the template configurations
186+
// to be applied.
187+
// Consider moving the logic of setting managedclusteraddon.status.configReferences
188+
// for addontemplates to the ocm addon-manager.
131189
addonConfigController = addonconfig.NewAddonConfigController(
132190
addonClient,
133191
addonInformers.Addon().V1alpha1().ManagedClusterAddOns(),
@@ -159,13 +217,15 @@ func (a *BaseAddonManagerImpl) StartWithInformers(ctx context.Context,
159217
nil,
160218
addonInformers.Addon().V1alpha1().ManagedClusterAddOns(),
161219
a.addonAgents,
220+
mcaFilterFunc,
162221
)
163222
csrSignController = certificate.NewCSRSignController(
164223
kubeClient,
165224
clusterInformers.Cluster().V1().ManagedClusters(),
166225
kubeInformers.Certificates().V1().CertificateSigningRequests(),
167226
addonInformers.Addon().V1alpha1().ManagedClusterAddOns(),
168227
a.addonAgents,
228+
mcaFilterFunc,
169229
)
170230
} else if v1beta1Supported {
171231
csrApproveController = certificate.NewCSRApprovingController(
@@ -175,6 +235,7 @@ func (a *BaseAddonManagerImpl) StartWithInformers(ctx context.Context,
175235
kubeInformers.Certificates().V1beta1().CertificateSigningRequests(),
176236
addonInformers.Addon().V1alpha1().ManagedClusterAddOns(),
177237
a.addonAgents,
238+
mcaFilterFunc,
178239
)
179240
}
180241

pkg/addonmanager/cloudevents/manager.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,8 @@ func (a *cloudeventsAddonManager) Start(ctx context.Context) error {
176176
return err
177177
}
178178

179-
err = a.StartWithInformers(ctx, workClient, workInformers, kubeInformers, addonInformers, clusterInformers, dynamicInformers)
179+
err = a.StartWithInformers(ctx, workClient, workInformers, kubeInformers, addonInformers, clusterInformers,
180+
dynamicInformers)
180181
if err != nil {
181182
return err
182183
}

pkg/addonmanager/controllers/addonconfig/controller.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ type addonConfigController struct {
3636
addonIndexer cache.Indexer
3737
configListers map[schema.GroupResource]dynamiclister.Lister
3838
queue workqueue.TypedRateLimitingInterface[string]
39-
addonFilterFunc factory.EventFilterFunc
39+
cmaFilterFunc factory.EventFilterFunc
4040
configGVRs map[schema.GroupVersionResource]bool
4141
clusterManagementAddonLister addonlisterv1alpha1.ClusterManagementAddOnLister
4242
}
@@ -47,7 +47,7 @@ func NewAddonConfigController(
4747
clusterManagementAddonInformers addoninformerv1alpha1.ClusterManagementAddOnInformer,
4848
configInformerFactory dynamicinformer.DynamicSharedInformerFactory,
4949
configGVRs map[schema.GroupVersionResource]bool,
50-
addonFilterFunc factory.EventFilterFunc,
50+
cmaFilterFunc factory.EventFilterFunc,
5151
) factory.Controller {
5252
syncCtx := factory.NewSyncContext(controllerName)
5353

@@ -57,7 +57,7 @@ func NewAddonConfigController(
5757
addonIndexer: addonInformers.Informer().GetIndexer(),
5858
configListers: map[schema.GroupResource]dynamiclister.Lister{},
5959
queue: syncCtx.Queue(),
60-
addonFilterFunc: addonFilterFunc,
60+
cmaFilterFunc: cmaFilterFunc,
6161
configGVRs: configGVRs,
6262
clusterManagementAddonLister: clusterManagementAddonInformers.Lister(),
6363
}
@@ -153,7 +153,7 @@ func (c *addonConfigController) sync(ctx context.Context, syncCtx factory.SyncCo
153153
return err
154154
}
155155

156-
if !c.addonFilterFunc(cma) {
156+
if c.cmaFilterFunc != nil && !c.cmaFilterFunc(cma) {
157157
return nil
158158
}
159159

pkg/addonmanager/controllers/addonconfig/controller_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ func TestSync(t *testing.T) {
371371
addonLister: addonInformers.Addon().V1alpha1().ManagedClusterAddOns().Lister(),
372372
clusterManagementAddonLister: addonInformers.Addon().V1alpha1().ClusterManagementAddOns().Lister(),
373373
configListers: map[schema.GroupResource]dynamiclister.Lister{},
374-
addonFilterFunc: func(obj interface{}) bool { return true },
374+
cmaFilterFunc: func(obj interface{}) bool { return true },
375375
configGVRs: map[schema.GroupVersionResource]bool{fakeGVR: true},
376376
}
377377

pkg/addonmanager/controllers/agentdeploy/controller.go

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232
"open-cluster-management.io/addon-framework/pkg/addonmanager/constants"
3333
"open-cluster-management.io/addon-framework/pkg/agent"
3434
"open-cluster-management.io/addon-framework/pkg/index"
35+
"open-cluster-management.io/addon-framework/pkg/utils"
3536
"open-cluster-management.io/sdk-go/pkg/basecontroller/factory"
3637
)
3738

@@ -50,6 +51,7 @@ type addonDeployController struct {
5051
workIndexer cache.Indexer
5152
agentAddons map[string]agent.AgentAddon
5253
queue workqueue.TypedRateLimitingInterface[string]
54+
mcaFilterFunc utils.ManagedClusterAddOnFilterFunc
5355
}
5456

5557
func NewAddonDeployController(
@@ -59,6 +61,7 @@ func NewAddonDeployController(
5961
addonInformers addoninformerv1alpha1.ManagedClusterAddOnInformer,
6062
workInformers workinformers.ManifestWorkInformer,
6163
agentAddons map[string]agent.AgentAddon,
64+
mcaFilterFunc utils.ManagedClusterAddOnFilterFunc,
6265
) factory.Controller {
6366
syncCtx := factory.NewSyncContext(controllerName)
6467

@@ -74,6 +77,7 @@ func NewAddonDeployController(
7477
managedClusterAddonIndexer: addonInformers.Informer().GetIndexer(),
7578
workIndexer: workInformers.Informer().GetIndexer(),
7679
agentAddons: agentAddons,
80+
mcaFilterFunc: mcaFilterFunc,
7781
}
7882

7983
c.setClusterInformerHandler(clusterInformers)
@@ -235,6 +239,10 @@ func (c *addonDeployController) sync(ctx context.Context, syncCtx factory.SyncCo
235239
return err
236240
}
237241

242+
if c.mcaFilterFunc != nil && !c.mcaFilterFunc(addon) {
243+
return nil
244+
}
245+
238246
// to deploy agents if there is RegistrationApplied condition.
239247
if meta.FindStatusCondition(addon.Status.Conditions, addonapiv1alpha1.ManagedClusterAddOnRegistrationApplied) == nil {
240248
return nil
@@ -307,7 +315,7 @@ func (c *addonDeployController) sync(ctx context.Context, syncCtx factory.SyncCo
307315
}
308316

309317
if err = c.updateAddon(ctx, addon, oldAddon); err != nil {
310-
return err
318+
return fmt.Errorf("failed to update addon %s/%s: %w", addon.Namespace, addon.Name, err)
311319
}
312320
return errorsutil.NewAggregate(errs)
313321
}
@@ -317,7 +325,10 @@ func (c *addonDeployController) sync(ctx context.Context, syncCtx factory.SyncCo
317325
func (c *addonDeployController) updateAddon(ctx context.Context, new, old *addonapiv1alpha1.ManagedClusterAddOn) error {
318326
if !equality.Semantic.DeepEqual(new.GetFinalizers(), old.GetFinalizers()) {
319327
_, err := c.addonClient.AddonV1alpha1().ManagedClusterAddOns(new.Namespace).Update(ctx, new, metav1.UpdateOptions{})
320-
return err
328+
if err != nil {
329+
return fmt.Errorf("failed to update addon finalizers: %w", err)
330+
}
331+
return nil
321332
}
322333

323334
addonPatcher := patcher.NewPatcher[
@@ -326,7 +337,10 @@ func (c *addonDeployController) updateAddon(ctx context.Context, new, old *addon
326337
addonapiv1alpha1.ManagedClusterAddOnStatus](c.addonClient.AddonV1alpha1().ManagedClusterAddOns(new.Namespace))
327338

328339
_, err := addonPatcher.PatchStatus(ctx, new, new.Status, old.Status)
329-
return err
340+
if err != nil {
341+
return fmt.Errorf("failed to update addon status: %w", err)
342+
}
343+
return nil
330344
}
331345

332346
func (c *addonDeployController) applyWork(ctx context.Context, appliedType string,

pkg/addonmanager/controllers/certificate/csrapprove.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
clusterv1 "open-cluster-management.io/api/cluster/v1"
2828

2929
"open-cluster-management.io/addon-framework/pkg/agent"
30+
"open-cluster-management.io/addon-framework/pkg/utils"
3031
"open-cluster-management.io/sdk-go/pkg/basecontroller/factory"
3132
)
3233

@@ -58,6 +59,7 @@ type csrApprovingController struct {
5859
managedClusterAddonLister addonlisterv1alpha1.ManagedClusterAddOnLister
5960
csrLister certificateslisters.CertificateSigningRequestLister
6061
csrListerBeta v1beta1certificateslisters.CertificateSigningRequestLister
62+
mcaFilterFunc utils.ManagedClusterAddOnFilterFunc
6163
}
6264

6365
// NewCSRApprovingController creates a new csr approving controller
@@ -68,6 +70,7 @@ func NewCSRApprovingController(
6870
csrBetaInformer v1beta1certificatesinformers.CertificateSigningRequestInformer,
6971
addonInformers addoninformerv1alpha1.ManagedClusterAddOnInformer,
7072
agentAddons map[string]agent.AgentAddon,
73+
mcaFilterFunc utils.ManagedClusterAddOnFilterFunc,
7174
) factory.Controller {
7275
if (csrV1Informer != nil) == (csrBetaInformer != nil) {
7376
klog.Fatalf("V1 and V1beta1 CSR informer cannot be present or absent at the same time")
@@ -77,6 +80,7 @@ func NewCSRApprovingController(
7780
agentAddons: agentAddons,
7881
managedClusterLister: clusterInformers.Lister(),
7982
managedClusterAddonLister: addonInformers.Lister(),
83+
mcaFilterFunc: mcaFilterFunc,
8084
}
8185
var csrInformer cache.SharedIndexInformer
8286
if csrV1Informer != nil {
@@ -162,6 +166,9 @@ func (c *csrApprovingController) sync(ctx context.Context, syncCtx factory.SyncC
162166
if err != nil {
163167
return err
164168
}
169+
if c.mcaFilterFunc != nil && !c.mcaFilterFunc(managedClusterAddon) {
170+
return nil
171+
}
165172

166173
if registrationOption.CSRApproveCheck == nil {
167174
klog.V(4).Infof("addon csr %q cannont be auto approved due to approve check not defined", csr.GetName())

pkg/addonmanager/controllers/certificate/csrsign.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
clusterv1 "open-cluster-management.io/api/cluster/v1"
2323

2424
"open-cluster-management.io/addon-framework/pkg/agent"
25+
"open-cluster-management.io/addon-framework/pkg/utils"
2526
"open-cluster-management.io/sdk-go/pkg/basecontroller/factory"
2627
)
2728

@@ -32,6 +33,7 @@ type csrSignController struct {
3233
managedClusterLister clusterlister.ManagedClusterLister
3334
managedClusterAddonLister addonlisterv1alpha1.ManagedClusterAddOnLister
3435
csrLister certificateslisters.CertificateSigningRequestLister
36+
mcaFilterFunc utils.ManagedClusterAddOnFilterFunc
3537
}
3638

3739
// NewCSRApprovingController creates a new csr approving controller
@@ -41,13 +43,15 @@ func NewCSRSignController(
4143
csrInformer certificatesinformers.CertificateSigningRequestInformer,
4244
addonInformers addoninformerv1alpha1.ManagedClusterAddOnInformer,
4345
agentAddons map[string]agent.AgentAddon,
46+
mcaFilterFunc utils.ManagedClusterAddOnFilterFunc,
4447
) factory.Controller {
4548
c := &csrSignController{
4649
kubeClient: kubeClient,
4750
agentAddons: agentAddons,
4851
managedClusterLister: clusterInformers.Lister(),
4952
managedClusterAddonLister: addonInformers.Lister(),
5053
csrLister: csrInformer.Lister(),
54+
mcaFilterFunc: mcaFilterFunc,
5155
}
5256
return factory.New().
5357
WithFilteredEventsInformersQueueKeysFunc(
@@ -131,6 +135,9 @@ func (c *csrSignController) sync(ctx context.Context, syncCtx factory.SyncContex
131135
if err != nil {
132136
return err
133137
}
138+
if c.mcaFilterFunc != nil && !c.mcaFilterFunc(addon) {
139+
return nil
140+
}
134141

135142
if registrationOption.CSRSign == nil {
136143
return nil

pkg/addonmanager/controllers/cmaconfig/controller.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ type cmaConfigController struct {
3737
clusterManagementAddonIndexer cache.Indexer
3838
configListers map[schema.GroupResource]dynamiclister.Lister
3939
queue workqueue.TypedRateLimitingInterface[string]
40-
addonFilterFunc factory.EventFilterFunc
40+
cmaFilterFunc factory.EventFilterFunc
4141
configGVRs map[schema.GroupVersionResource]bool
4242
addonPatcher patcher.Patcher[*addonapiv1alpha1.ClusterManagementAddOn,
4343
addonapiv1alpha1.ClusterManagementAddOnSpec,
@@ -49,7 +49,7 @@ func NewCMAConfigController(
4949
clusterManagementAddonInformers addoninformerv1alpha1.ClusterManagementAddOnInformer,
5050
configInformerFactory dynamicinformer.DynamicSharedInformerFactory,
5151
configGVRs map[schema.GroupVersionResource]bool,
52-
addonFilterFunc factory.EventFilterFunc,
52+
cmaFilterFunc factory.EventFilterFunc,
5353
) factory.Controller {
5454
syncCtx := factory.NewSyncContext(controllerName)
5555

@@ -59,7 +59,7 @@ func NewCMAConfigController(
5959
clusterManagementAddonIndexer: clusterManagementAddonInformers.Informer().GetIndexer(),
6060
configListers: map[schema.GroupResource]dynamiclister.Lister{},
6161
queue: syncCtx.Queue(),
62-
addonFilterFunc: addonFilterFunc,
62+
cmaFilterFunc: cmaFilterFunc,
6363
configGVRs: configGVRs,
6464
addonPatcher: patcher.NewPatcher[*addonapiv1alpha1.ClusterManagementAddOn,
6565
addonapiv1alpha1.ClusterManagementAddOnSpec,
@@ -145,7 +145,7 @@ func (c *cmaConfigController) sync(ctx context.Context, syncCtx factory.SyncCont
145145
return err
146146
}
147147

148-
if !c.addonFilterFunc(cma) {
148+
if c.cmaFilterFunc != nil && !c.cmaFilterFunc(cma) {
149149
return nil
150150
}
151151

pkg/addonmanager/controllers/cmaconfig/controller_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ func TestSync(t *testing.T) {
259259
addonClient: fakeAddonClient,
260260
clusterManagementAddonLister: addonInformers.Addon().V1alpha1().ClusterManagementAddOns().Lister(),
261261
configListers: map[schema.GroupResource]dynamiclister.Lister{},
262-
addonFilterFunc: func(obj interface{}) bool { return true },
262+
cmaFilterFunc: func(obj interface{}) bool { return true },
263263
configGVRs: map[schema.GroupVersionResource]bool{fakeGVR: true},
264264
addonPatcher: patcher.NewPatcher[*addonapiv1alpha1.ClusterManagementAddOn,
265265
addonapiv1alpha1.ClusterManagementAddOnSpec,

0 commit comments

Comments
 (0)