From e118c7909ed5d29bbea093b5b6042191c1f6fd31 Mon Sep 17 00:00:00 2001 From: changzhen Date: Sun, 26 Sep 2021 20:38:50 +0800 Subject: [PATCH] fix an error when karmada-controller-manager restart Signed-off-by: changzhen --- pkg/controllers/mcs/service_export_controller.go | 5 ----- pkg/controllers/status/workstatus_controller.go | 6 ------ pkg/util/helper/cache.go | 8 +++++++- 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/pkg/controllers/mcs/service_export_controller.go b/pkg/controllers/mcs/service_export_controller.go index 579b7c3ab..c1025ad0a 100644 --- a/pkg/controllers/mcs/service_export_controller.go +++ b/pkg/controllers/mcs/service_export_controller.go @@ -285,11 +285,6 @@ func (c *ServiceExportController) handleEndpointSliceEvent(endpointSliceKey keys return err } - if endpointSliceObj == nil { - klog.V(2).Infof("Ignore the event key %s which not listened by karmada.", endpointSliceKey) - return nil - } - if err = c.reportEndpointSliceWithEndpointSliceCreateOrUpdate(endpointSliceKey.Cluster, endpointSliceObj); err != nil { klog.Errorf("Failed to handle endpointSlice(%s) event, Error: %v", endpointSliceKey.NamespaceKey(), err) diff --git a/pkg/controllers/status/workstatus_controller.go b/pkg/controllers/status/workstatus_controller.go index e29e4a3e7..af71f1860 100644 --- a/pkg/controllers/status/workstatus_controller.go +++ b/pkg/controllers/status/workstatus_controller.go @@ -159,12 +159,6 @@ func (c *WorkStatusController) syncWorkStatus(key util.QueueKey) error { return err } - if obj == nil { - // Ignore the object which not managed by current karmada. - klog.V(2).Infof("Ignore the event key %s which not managed by karmada.", key) - return nil - } - workNamespace := util.GetLabelValue(obj.GetLabels(), workv1alpha1.WorkNamespaceLabel) workName := util.GetLabelValue(obj.GetLabels(), workv1alpha1.WorkNameLabel) if len(workNamespace) == 0 || len(workName) == 0 { diff --git a/pkg/util/helper/cache.go b/pkg/util/helper/cache.go index 416d4cac7..8621d7ce3 100644 --- a/pkg/util/helper/cache.go +++ b/pkg/util/helper/cache.go @@ -1,6 +1,8 @@ package helper import ( + "fmt" + apierrors "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/api/meta" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" @@ -23,7 +25,11 @@ func GetObjectFromCache(restMapper meta.RESTMapper, manager informermanager.Mult singleClusterManager := manager.GetSingleClusterManager(fedKey.Cluster) if singleClusterManager == nil { - return nil, nil + // That may happen in case of multi-controllers sharing one informer. For example: + // controller-A takes responsibility of initialize informer for clusters, but controller-B consumes + // the informer before the initialization. + // Usually this error will be eliminated during the controller reconciling loop. + return nil, fmt.Errorf("the informer of cluster(%s) has not been initialized", fedKey.Cluster) } var obj runtime.Object lister := singleClusterManager.Lister(gvr)