Skip to content

Commit f1a8a13

Browse files
committed
add watches for owned resources and CRBs
Signed-off-by: Kevin <[email protected]>
1 parent 3f1166c commit f1a8a13

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

pkg/controllers/raycluster_controller.go

+16-1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ import (
3737
ctrl "sigs.k8s.io/controller-runtime"
3838
"sigs.k8s.io/controller-runtime/pkg/client"
3939
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
40+
"sigs.k8s.io/controller-runtime/pkg/handler"
41+
"sigs.k8s.io/controller-runtime/pkg/reconcile"
4042

4143
routev1 "github.com/openshift/api/route/v1"
4244
routeapply "github.com/openshift/client-go/route/applyconfigurations/route/v1"
@@ -220,7 +222,7 @@ func crbNameFromCluster(cluster *rayv1.RayCluster) string {
220222
func desiredOAuthClusterRoleBinding(cluster *rayv1.RayCluster) *rbacapply.ClusterRoleBindingApplyConfiguration {
221223
return rbacapply.ClusterRoleBinding(
222224
crbNameFromCluster(cluster)).
223-
WithLabels(map[string]string{"ray.io/cluster-name": cluster.Name}).
225+
WithLabels(map[string]string{"ray.io/cluster-name": cluster.Name, "ray.io/cluster-namespace": cluster.Namespace}).
224226
WithSubjects(
225227
rbacapply.Subject().
226228
WithKind("ServiceAccount").
@@ -340,5 +342,18 @@ func (r *RayClusterReconciler) SetupWithManager(mgr ctrl.Manager) error {
340342
return ctrl.NewControllerManagedBy(mgr).
341343
Named(controllerName).
342344
For(&rayv1.RayCluster{}).
345+
Owns(&corev1.ServiceAccount{}).
346+
Owns(&corev1.Service{}).
347+
Owns(&corev1.Secret{}).
348+
Owns(&routev1.Route{}).
349+
Watches(&rbacv1.ClusterRoleBinding{}, handler.EnqueueRequestsFromMapFunc(
350+
func(c context.Context, o client.Object) []reconcile.Request {
351+
return []reconcile.Request{{
352+
NamespacedName: client.ObjectKey{
353+
Name: o.GetLabels()["ray.io/cluster-name"],
354+
Namespace: o.GetLabels()["ray.io/cluster-namespace"],
355+
}}}
356+
}),
357+
).
343358
Complete(r)
344359
}

0 commit comments

Comments
 (0)