Skip to content

Commit 7bca5c8

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

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

pkg/controllers/raycluster_controller.go

Lines changed: 17 additions & 1 deletion
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,19 @@ 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(&rbacv1.ClusterRoleBinding{}).
348+
Owns(&corev1.Secret{}).
349+
Owns(&routev1.Route{}).
350+
Watches(&rbacv1.ClusterRoleBinding{}, handler.EnqueueRequestsFromMapFunc(
351+
func(c context.Context, o client.Object) []reconcile.Request {
352+
return []reconcile.Request{{
353+
NamespacedName: client.ObjectKey{
354+
Name: o.GetLabels()["ray.io/cluster-name"],
355+
Namespace: o.GetLabels()["ray.io/cluster-namespace"],
356+
}}}
357+
}),
358+
).
343359
Complete(r)
344360
}

0 commit comments

Comments
 (0)