diff --git a/pkg/search/controller.go b/pkg/search/controller.go index ef372c0e12f2..21b58c5e5bb0 100644 --- a/pkg/search/controller.go +++ b/pkg/search/controller.go @@ -171,7 +171,7 @@ func (c *Controller) doCacheCluster(cluster string) error { return nil } - // STEP1: stop informer manager for the cluster which does not exist anymore. + // STEP1: stop informer manager for the cluster which does not exist anymore or is not ready. cls, err := c.clusterLister.Get(cluster) if err != nil { if apierrors.IsNotFound(err) { @@ -188,6 +188,12 @@ func (c *Controller) doCacheCluster(cluster string) error { return nil } + if !util.IsClusterReady(&cls.Status) { + klog.Warningf("cluster %s is notReady try to stop this cluster informer", cluster) + c.InformerManager.Stop(cluster) + return nil + } + // STEP2: added/updated cluster, builds an informer manager for a specific cluster. if !c.InformerManager.IsManagerExist(cluster) { klog.Info("try to build informer manager for cluster ", cluster) diff --git a/pkg/search/proxy/controller.go b/pkg/search/proxy/controller.go index 8ab4825a2c9f..d70d46161ee4 100644 --- a/pkg/search/proxy/controller.go +++ b/pkg/search/proxy/controller.go @@ -182,6 +182,12 @@ func (ctl *Controller) reconcile(util.QueueKey) error { if !util.ClusterMatches(cluster, registry.Spec.TargetCluster) { continue } + + if !util.IsClusterReady(&cluster.Status) { + klog.Warningf("cluster %s is notReady", cluster.Name) + continue + } + if _, exist := resourcesByClusters[cluster.Name]; !exist { resourcesByClusters[cluster.Name] = make(map[schema.GroupVersionResource]struct{}) } diff --git a/pkg/search/proxy/controller_test.go b/pkg/search/proxy/controller_test.go index 64b4b6f006fb..c80441473094 100644 --- a/pkg/search/proxy/controller_test.go +++ b/pkg/search/proxy/controller_test.go @@ -29,6 +29,7 @@ import ( "github.com/karmada-io/karmada/pkg/search/proxy/framework" pluginruntime "github.com/karmada-io/karmada/pkg/search/proxy/framework/runtime" proxytest "github.com/karmada-io/karmada/pkg/search/proxy/testing" + "github.com/karmada-io/karmada/pkg/util" ) func TestController(t *testing.T) { @@ -493,5 +494,8 @@ func TestController_Connect_Error(t *testing.T) { func newCluster(name string) *clusterv1alpha1.Cluster { c := &clusterv1alpha1.Cluster{} c.Name = name + conditions := make([]metav1.Condition, 0, 1) + conditions = append(conditions, util.NewCondition(clusterv1alpha1.ClusterConditionReady, "", "", metav1.ConditionTrue)) + c.Status.Conditions = conditions return c }