From bc01437ad314680d69237f4cca34df0ea8b83f26 Mon Sep 17 00:00:00 2001 From: Jian Zhu Date: Fri, 18 Oct 2024 12:06:24 +0800 Subject: [PATCH] Ensure one cma is processed by one addon worker at the same time (#654) Signed-off-by: zhujian --- .../controllers/addonconfiguration/controller.go | 11 +++-------- pkg/addon/controllers/addonmanagement/controller.go | 8 +------- pkg/addon/controllers/addontemplate/controller.go | 8 +------- 3 files changed, 5 insertions(+), 22 deletions(-) diff --git a/pkg/addon/controllers/addonconfiguration/controller.go b/pkg/addon/controllers/addonconfiguration/controller.go index 88a2857b6..f477f7d39 100644 --- a/pkg/addon/controllers/addonconfiguration/controller.go +++ b/pkg/addon/controllers/addonconfiguration/controller.go @@ -90,7 +90,7 @@ func NewAddonConfigurationController( queue.QueueKeyByMetaNamespaceName, c.addonFilterFunc, clusterManagementAddonInformers.Informer()). - WithInformersQueueKeysFunc(queue.QueueKeyByMetaNamespaceName, addonInformers.Informer()). + WithInformersQueueKeysFunc(queue.QueueKeyByMetaName, addonInformers.Informer()). WithInformersQueueKeysFunc( index.ClusterManagementAddonByPlacementDecisionQueueKey(clusterManagementAddonInformers), placementDecisionInformer.Informer()). WithInformersQueueKeysFunc( @@ -101,12 +101,7 @@ func NewAddonConfigurationController( func (c *addonConfigurationController) sync(ctx context.Context, syncCtx factory.SyncContext) error { logger := klog.FromContext(ctx) - key := syncCtx.QueueKey() - _, addonName, err := cache.SplitMetaNamespaceKey(key) - if err != nil { - // ignore addon whose key is invalid - return nil - } + addonName := syncCtx.QueueKey() logger.V(4).Info("Reconciling addon", "addonName", addonName) cma, err := c.clusterManagementAddonLister.Get(addonName) @@ -157,7 +152,7 @@ func (c *addonConfigurationController) sync(ctx context.Context, syncCtx factory } if minRequeue < maxRequeueTime { - syncCtx.Queue().AddAfter(key, minRequeue) + syncCtx.Queue().AddAfter(addonName, minRequeue) } return nil diff --git a/pkg/addon/controllers/addonmanagement/controller.go b/pkg/addon/controllers/addonmanagement/controller.go index 6dc53452e..ef013ba3b 100644 --- a/pkg/addon/controllers/addonmanagement/controller.go +++ b/pkg/addon/controllers/addonmanagement/controller.go @@ -81,13 +81,7 @@ func NewAddonManagementController( func (c *addonManagementController) sync(ctx context.Context, syncCtx factory.SyncContext) error { logger := klog.FromContext(ctx) - key := syncCtx.QueueKey() - _, addonName, err := cache.SplitMetaNamespaceKey(key) - if err != nil { - // ignore addon whose key is invalid - return nil - } - + addonName := syncCtx.QueueKey() logger.V(4).Info("Reconciling addon", "addonName", addonName) cma, err := c.clusterManagementAddonLister.Get(addonName) diff --git a/pkg/addon/controllers/addontemplate/controller.go b/pkg/addon/controllers/addontemplate/controller.go index 569a22e48..64f5cfcca 100644 --- a/pkg/addon/controllers/addontemplate/controller.go +++ b/pkg/addon/controllers/addontemplate/controller.go @@ -13,7 +13,6 @@ import ( kubeinformers "k8s.io/client-go/informers" "k8s.io/client-go/kubernetes" "k8s.io/client-go/rest" - "k8s.io/client-go/tools/cache" "k8s.io/klog/v2" "open-cluster-management.io/addon-framework/pkg/addonfactory" @@ -106,12 +105,7 @@ func (c *addonTemplateController) stopUnusedManagers( func (c *addonTemplateController) sync(ctx context.Context, syncCtx factory.SyncContext) error { logger := klog.FromContext(ctx) - key := syncCtx.QueueKey() - _, addonName, err := cache.SplitMetaNamespaceKey(key) - if err != nil { - // ignore addon whose key is not in format: namespace/name - return nil - } + addonName := syncCtx.QueueKey() cma, err := c.cmaLister.Get(addonName) if err != nil {