@@ -31,6 +31,8 @@ import (
3131 "time"
3232
3333 dsciv1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/dscinitialization/v1"
34+ networkingv1 "k8s.io/api/networking/v1"
35+
3436 rayv1 "github.com/ray-project/kuberay/ray-operator/apis/ray/v1"
3537
3638 corev1 "k8s.io/api/core/v1"
@@ -48,6 +50,8 @@ import (
4850 ctrl "sigs.k8s.io/controller-runtime"
4951 "sigs.k8s.io/controller-runtime/pkg/client"
5052 "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
53+ "sigs.k8s.io/controller-runtime/pkg/handler"
54+ "sigs.k8s.io/controller-runtime/pkg/reconcile"
5155
5256 routev1 "github.com/openshift/api/route/v1"
5357 routev1ac "github.com/openshift/client-go/route/applyconfigurations/route/v1"
@@ -88,12 +92,12 @@ var (
8892// +kubebuilder:rbac:groups=ray.io,resources=rayclusters,verbs=get;list;watch;create;update;patch;delete
8993// +kubebuilder:rbac:groups=ray.io,resources=rayclusters/status,verbs=get;update;patch
9094// +kubebuilder:rbac:groups=ray.io,resources=rayclusters/finalizers,verbs=update
91- // +kubebuilder:rbac:groups=route.openshift.io,resources=routes;routes/custom-host,verbs=get;create;update;patch;delete
92- // +kubebuilder:rbac:groups=networking.k8s.io,resources=ingresses,verbs=get;create;update;patch;delete
93- // +kubebuilder:rbac:groups=core,resources=secrets,verbs=get;create;patch;delete;get
94- // +kubebuilder:rbac:groups=core,resources=services,verbs=get;create;update;patch;delete
95- // +kubebuilder:rbac:groups=core,resources=serviceaccounts,verbs=get;create;update;patch;delete
96- // +kubebuilder:rbac:groups=rbac.authorization.k8s.io,resources=clusterrolebindings,verbs=get;create;update;patch;delete
95+ // +kubebuilder:rbac:groups=route.openshift.io,resources=routes;routes/custom-host,verbs=get;create;update;patch;delete;watch
96+ // +kubebuilder:rbac:groups=networking.k8s.io,resources=ingresses,verbs=get;create;update;patch;delete;watch
97+ // +kubebuilder:rbac:groups=core,resources=secrets,verbs=get;create;patch;delete;get;watch
98+ // +kubebuilder:rbac:groups=core,resources=services,verbs=get;create;update;patch;delete;watch
99+ // +kubebuilder:rbac:groups=core,resources=serviceaccounts,verbs=get;create;update;patch;delete;watch
100+ // +kubebuilder:rbac:groups=rbac.authorization.k8s.io,resources=clusterrolebindings,verbs=get;create;update;patch;delete;watch
97101// +kubebuilder:rbac:groups=authentication.k8s.io,resources=tokenreviews,verbs=create;
98102// +kubebuilder:rbac:groups=authorization.k8s.io,resources=subjectaccessreviews,verbs=create;
99103// +kubebuilder:rbac:groups=dscinitialization.opendatahub.io,resources=dscinitializations,verbs=get;list;watch
@@ -301,7 +305,7 @@ func crbNameFromCluster(cluster *rayv1.RayCluster) string {
301305func desiredOAuthClusterRoleBinding (cluster * rayv1.RayCluster ) * rbacv1ac.ClusterRoleBindingApplyConfiguration {
302306 return rbacv1ac .ClusterRoleBinding (
303307 crbNameFromCluster (cluster )).
304- WithLabels (map [string ]string {"ray.io /cluster-name" : cluster .Name }).
308+ WithLabels (map [string ]string {"ray.openshift.ai /cluster-name" : cluster .Name , "ray.openshift.ai/cluster-namespace" : cluster . Namespace }).
305309 WithSubjects (
306310 rbacv1ac .Subject ().
307311 WithKind ("ServiceAccount" ).
@@ -322,7 +326,7 @@ func oauthServiceAccountNameFromCluster(cluster *rayv1.RayCluster) string {
322326
323327func desiredServiceAccount (cluster * rayv1.RayCluster ) * corev1ac.ServiceAccountApplyConfiguration {
324328 return corev1ac .ServiceAccount (oauthServiceAccountNameFromCluster (cluster ), cluster .Namespace ).
325- WithLabels (map [string ]string {"ray.io /cluster-name" : cluster .Name }).
329+ WithLabels (map [string ]string {"ray.openshift.ai /cluster-name" : cluster .Name }).
326330 WithAnnotations (map [string ]string {
327331 "serviceaccounts.openshift.io/oauth-redirectreference.first" : "" +
328332 `{"kind":"OAuthRedirectReference","apiVersion":"v1",` +
@@ -343,7 +347,7 @@ func rayClientNameFromCluster(cluster *rayv1.RayCluster) string {
343347
344348func desiredClusterRoute (cluster * rayv1.RayCluster ) * routev1ac.RouteApplyConfiguration {
345349 return routev1ac .Route (dashboardNameFromCluster (cluster ), cluster .Namespace ).
346- WithLabels (map [string ]string {"ray.io /cluster-name" : cluster .Name }).
350+ WithLabels (map [string ]string {"ray.openshift.ai /cluster-name" : cluster .Name }).
347351 WithSpec (routev1ac .RouteSpec ().
348352 WithTo (routev1ac .RouteTargetReference ().WithKind ("Service" ).WithName (oauthServiceNameFromCluster (cluster ))).
349353 WithPort (routev1ac .RoutePort ().WithTargetPort (intstr .FromString ((oAuthServicePortName )))).
@@ -367,7 +371,7 @@ func oauthServiceTLSSecretName(cluster *rayv1.RayCluster) string {
367371
368372func desiredOAuthService (cluster * rayv1.RayCluster ) * corev1ac.ServiceApplyConfiguration {
369373 return corev1ac .Service (oauthServiceNameFromCluster (cluster ), cluster .Namespace ).
370- WithLabels (map [string ]string {"ray.io /cluster-name" : cluster .Name }).
374+ WithLabels (map [string ]string {"ray.openshift.ai /cluster-name" : cluster .Name }).
371375 WithAnnotations (map [string ]string {"service.beta.openshift.io/serving-cert-secret-name" : oauthServiceTLSSecretName (cluster )}).
372376 WithSpec (
373377 corev1ac .ServiceSpec ().
@@ -397,7 +401,7 @@ func desiredOAuthSecret(cluster *rayv1.RayCluster, cookieSalt string) *corev1ac.
397401 cookieSecret := base64 .StdEncoding .EncodeToString (hasher .Sum (nil ))
398402
399403 return corev1ac .Secret (oauthSecretNameFromCluster (cluster ), cluster .Namespace ).
400- WithLabels (map [string ]string {"ray.io /cluster-name" : cluster .Name }).
404+ WithLabels (map [string ]string {"ray.openshift.ai /cluster-name" : cluster .Name }).
401405 WithStringData (map [string ]string {"cookie_secret" : cookieSecret }).
402406 WithOwnerReferences (
403407 metav1ac .OwnerReference ().WithUID (cluster .UID ).WithName (cluster .Name ).WithKind (cluster .Kind ).WithAPIVersion (cluster .APIVersion ),
@@ -410,7 +414,7 @@ func caSecretNameFromCluster(cluster *rayv1.RayCluster) string {
410414
411415func desiredCASecret (cluster * rayv1.RayCluster , key , cert []byte ) * corev1ac.SecretApplyConfiguration {
412416 return corev1ac .Secret (caSecretNameFromCluster (cluster ), cluster .Namespace ).
413- WithLabels (map [string ]string {"ray.io /cluster-name" : cluster .Name }).
417+ WithLabels (map [string ]string {"ray.openshift.ai /cluster-name" : cluster .Name }).
414418 WithData (map [string ][]byte {
415419 CAPrivateKeyKey : key ,
416420 CACertKey : cert ,
@@ -466,7 +470,7 @@ func generateCACertificate() ([]byte, []byte, error) {
466470}
467471func desiredWorkersNetworkPolicy (cluster * rayv1.RayCluster ) * networkingv1ac.NetworkPolicyApplyConfiguration {
468472 return networkingv1ac .NetworkPolicy (cluster .Name + "-workers" , cluster .Namespace ).
469- WithLabels (map [string ]string {"ray.io /cluster-name" : cluster .Name }).
473+ WithLabels (map [string ]string {"ray.openshift.ai /cluster-name" : cluster .Name }).
470474 WithSpec (networkingv1ac .NetworkPolicySpec ().
471475 WithPodSelector (metav1ac .LabelSelector ().WithMatchLabels (map [string ]string {"ray.io/cluster" : cluster .Name , "ray.io/node-type" : "worker" })).
472476 WithIngress (
@@ -488,7 +492,7 @@ func desiredHeadNetworkPolicy(cluster *rayv1.RayCluster, cfg *config.KubeRayConf
488492 allSecuredPorts = append (allSecuredPorts , networkingv1ac .NetworkPolicyPort ().WithProtocol (corev1 .ProtocolTCP ).WithPort (intstr .FromInt (10001 )))
489493 }
490494 return networkingv1ac .NetworkPolicy (cluster .Name + "-head" , cluster .Namespace ).
491- WithLabels (map [string ]string {"ray.io /cluster-name" : cluster .Name }).
495+ WithLabels (map [string ]string {"ray.openshift.ai /cluster-name" : cluster .Name }).
492496 WithSpec (networkingv1ac .NetworkPolicySpec ().
493497 WithPodSelector (metav1ac .LabelSelector ().WithMatchLabels (map [string ]string {"ray.io/cluster" : cluster .Name , "ray.io/node-type" : "head" })).
494498 WithIngress (
@@ -551,5 +555,27 @@ func (r *RayClusterReconciler) SetupWithManager(mgr ctrl.Manager) error {
551555 return ctrl .NewControllerManagedBy (mgr ).
552556 Named (controllerName ).
553557 For (& rayv1.RayCluster {}).
558+ Owns (& corev1.ServiceAccount {}).
559+ Owns (& corev1.Service {}).
560+ Owns (& corev1.Secret {}).
561+ Owns (& routev1.Route {}).
562+ Owns (& networkingv1.Ingress {}).
563+ Watches (& rbacv1.ClusterRoleBinding {}, handler .EnqueueRequestsFromMapFunc (
564+ func (c context.Context , o client.Object ) []reconcile.Request {
565+ name , ok := o .GetLabels ()["ray.openshift.ai/cluster-name" ]
566+ if ! ok {
567+ return []reconcile.Request {}
568+ }
569+ namespace , ok := o .GetLabels ()["ray.openshift.ai/cluster-namespace" ]
570+ if ! ok {
571+ return []reconcile.Request {}
572+ }
573+ return []reconcile.Request {{
574+ NamespacedName : client.ObjectKey {
575+ Name : name ,
576+ Namespace : namespace ,
577+ }}}
578+ }),
579+ ).
554580 Complete (r )
555581}
0 commit comments