Skip to content

Commit

Permalink
Simplify installer watchers (#180)
Browse files Browse the repository at this point in the history
Signed-off-by: Tamal Saha <[email protected]>
  • Loading branch information
tamalsaha authored Mar 8, 2024
1 parent 7491951 commit b0cc356
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 105 deletions.
32 changes: 27 additions & 5 deletions pkg/proxyserver/controllers/service_resolver_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import (
utilerrors "k8s.io/apimachinery/pkg/util/errors"
clusterv1beta2 "open-cluster-management.io/api/cluster/v1beta2"
proxyv1alpha1 "open-cluster-management.io/cluster-proxy/pkg/apis/proxy/v1alpha1"
"open-cluster-management.io/cluster-proxy/pkg/proxyserver/operator/eventhandler"
"open-cluster-management.io/cluster-proxy/pkg/util"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/handler"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
)

Expand All @@ -35,13 +35,35 @@ func (c *ServiceResolverReconciler) SetupWithManager(mgr ctrl.Manager) error {
For(&proxyv1alpha1.ManagedProxyServiceResolver{}).
Watches(
&proxyv1alpha1.ManagedProxyServiceResolver{},
&eventhandler.ProxyServiceResolverHandler{},
handler.EnqueueRequestsFromMapFunc(func(ctx context.Context, object client.Object) []reconcile.Request {
return []reconcile.Request{
{NamespacedName: types.NamespacedName{Name: object.GetName()}},
}
}),
).
Watches(
&clusterv1beta2.ManagedClusterSet{},
&eventhandler.ClustersetHandler{
Client: mgr.GetClient(),
},
handler.EnqueueRequestsFromMapFunc(func(ctx context.Context, object client.Object) []reconcile.Request {
var reqs []reconcile.Request
// Check whether the clusterset is related with any managedproxyserviceresolver.
mpsrList := &proxyv1alpha1.ManagedProxyServiceResolverList{}
err := mgr.GetClient().List(context.TODO(), mpsrList, &client.ListOptions{})
if err != nil {
return reqs
}
for _, mpsr := range mpsrList.Items {
if !util.IsServiceResolverLegal(&mpsr) {
continue
}
if mpsr.Spec.ManagedClusterSelector.ManagedClusterSet.Name == object.GetName() {
req := reconcile.Request{}
req.Name = mpsr.Name
reqs = append(reqs, req)
break
}
}
return reqs
}),
).
Complete(c)
}
Expand Down
62 changes: 0 additions & 62 deletions pkg/proxyserver/operator/eventhandler/clusterset_event.go

This file was deleted.

This file was deleted.

0 comments on commit b0cc356

Please sign in to comment.