Skip to content

Commit

Permalink
search add check member cluster api enable
Browse files Browse the repository at this point in the history
Signed-off-by: huangyanfeng <[email protected]>
  • Loading branch information
yanfeng1992 committed Jan 16, 2024
1 parent 04779a2 commit b12603d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
14 changes: 12 additions & 2 deletions pkg/search/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import (
"github.com/karmada-io/karmada/pkg/util/fedinformer"
"github.com/karmada-io/karmada/pkg/util/fedinformer/genericmanager"
"github.com/karmada-io/karmada/pkg/util/gclient"
"github.com/karmada-io/karmada/pkg/util/helper"
"github.com/karmada-io/karmada/pkg/util/restmapper"
)

Expand Down Expand Up @@ -401,10 +402,18 @@ func (c *Controller) doCacheCluster(cluster string) error {

sci := c.InformerManager.GetSingleClusterManager(cluster)
for gvr := range cr.resources {
gvk, err := c.restMapper.KindFor(gvr)
if err != nil {
klog.Errorf("Failed to get gvk: %v", err)
continue
}
if !helper.IsAPIEnabled(cls.Status.APIEnablements, gvk.GroupVersion().String(), gvk.Kind) {
klog.Warningf("Resource %s is not enabled for cluster %s", gvr.String(), cluster)
continue
}
klog.Infof("Add informer for %s, %v", cluster, gvr)
sci.ForResource(gvr, handler)
}

klog.Infof("Start informer for %s", cluster)
sci.Start()
_ = sci.WaitForCacheSync()
Expand Down Expand Up @@ -486,7 +495,8 @@ func (c *Controller) updateCluster(oldObj, curObj interface{}) {
c.queue.Add(curCluster.GetName())
}

if !reflect.DeepEqual(curCluster.Spec, oldCluster.Spec) || !reflect.DeepEqual(curCluster.Labels, oldCluster.Labels) {
if !reflect.DeepEqual(curCluster.Spec, oldCluster.Spec) || !reflect.DeepEqual(curCluster.Labels, oldCluster.Labels) ||
!reflect.DeepEqual(curCluster.Status.APIEnablements, oldCluster.Status.APIEnablements) {
c.queue.Add(curCluster.GetName())
}
}
Expand Down
10 changes: 10 additions & 0 deletions pkg/search/proxy/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import (
pluginruntime "github.com/karmada-io/karmada/pkg/search/proxy/framework/runtime"
"github.com/karmada-io/karmada/pkg/search/proxy/store"
"github.com/karmada-io/karmada/pkg/util"
"github.com/karmada-io/karmada/pkg/util/helper"
"github.com/karmada-io/karmada/pkg/util/lifted"
"github.com/karmada-io/karmada/pkg/util/restmapper"
)
Expand Down Expand Up @@ -223,6 +224,15 @@ func (ctl *Controller) reconcile(util.QueueKey) error {
}

for resource, multiNS := range matchedResources {
gvk, err := ctl.restMapper.KindFor(resource)
if err != nil {
klog.Errorf("Failed to get gvk: %v", err)
continue
}
if !helper.IsAPIEnabled(cluster.Status.APIEnablements, gvk.GroupVersion().String(), gvk.Kind) {
klog.Warningf("Resource %s is not enabled for cluster %s", resource.String(), cluster)
continue
}
resourcesByClusters[cluster.Name][resource] = multiNS
}
}
Expand Down

0 comments on commit b12603d

Please sign in to comment.