Skip to content

Commit

Permalink
Merge pull request #3019 from yanfeng1992/automated-cherry-pick-of-#3…
Browse files Browse the repository at this point in the history
…010-upstream-release-1.3

Automated cherry pick of #3010: search filter out not ready cluster
  • Loading branch information
karmada-bot authored Jan 4, 2023
2 parents 869a712 + 1fb96ae commit ee53894
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 @@ -177,7 +177,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 @@ -194,6 +194,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 @@ -136,6 +136,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 @@ -21,6 +21,7 @@ import (
karmadafake "github.com/karmada-io/karmada/pkg/generated/clientset/versioned/fake"
karmadainformers "github.com/karmada-io/karmada/pkg/generated/informers/externalversions"
"github.com/karmada-io/karmada/pkg/search/proxy/store"
"github.com/karmada-io/karmada/pkg/util"
)

var (
Expand Down Expand Up @@ -245,6 +246,9 @@ func TestController_reconcile(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
}

Expand Down

0 comments on commit ee53894

Please sign in to comment.