Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automated cherry pick of #4554: search add check member cluster api enable #4590

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion pkg/search/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,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 @@ -225,6 +226,15 @@ func (c *Controller) doCacheCluster(cluster string) error {
continue
}

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)
}
Expand Down Expand Up @@ -403,7 +413,7 @@ func (c *Controller) updateCluster(oldObj, curObj interface{}) {
c.queue.Add(curCluster.GetName())
}

if !reflect.DeepEqual(curCluster.Spec, oldCluster.Spec) {
if !reflect.DeepEqual(curCluster.Spec, oldCluster.Spec) || !reflect.DeepEqual(curCluster.Status.APIEnablements, oldCluster.Status.APIEnablements) {
// Cluster.Spec is changed, rebuild informer.
c.InformerManager.Stop(curCluster.GetName())
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 @@ -31,6 +31,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 @@ -207,6 +208,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
19 changes: 19 additions & 0 deletions pkg/search/proxy/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -494,9 +494,28 @@ func TestController_Connect_Error(t *testing.T) {

func newCluster(name string) *clusterv1alpha1.Cluster {
c := &clusterv1alpha1.Cluster{}
clusterEnablements := []clusterv1alpha1.APIEnablement{
{
GroupVersion: "v1",
Resources: []clusterv1alpha1.APIResource{
{
Kind: "Pod",
},
},
},
{
GroupVersion: "v1",
Resources: []clusterv1alpha1.APIResource{
{
Kind: "Node",
},
},
},
}
c.Name = name
conditions := make([]metav1.Condition, 0, 1)
conditions = append(conditions, util.NewCondition(clusterv1alpha1.ClusterConditionReady, "", "", metav1.ConditionTrue))
c.Status.Conditions = conditions
c.Status.APIEnablements = clusterEnablements
return c
}
Loading