Skip to content

Commit

Permalink
search filter out not ready cluster
Browse files Browse the repository at this point in the history
Signed-off-by: huangyanfeng <[email protected]>

search filter out not ready cluster fix ut

Signed-off-by: huangyanfeng <[email protected]>

search filter out not ready cluster fix lint

Signed-off-by: huangyanfeng <[email protected]>

search filter out not ready cluster fix log and add comment

Signed-off-by: huangyanfeng <[email protected]>

search filter out not ready cluster fix  comment

Signed-off-by: huangyanfeng <[email protected]>
  • Loading branch information
yanfeng1992 committed Dec 30, 2022
1 parent eda7814 commit 04d16b4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
8 changes: 7 additions & 1 deletion pkg/search/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions pkg/search/proxy/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{})
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/search/proxy/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
}

0 comments on commit 04d16b4

Please sign in to comment.