@@ -31,6 +31,8 @@ import (
31
31
"time"
32
32
33
33
dsciv1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/dscinitialization/v1"
34
+ networkingv1 "k8s.io/api/networking/v1"
35
+
34
36
rayv1 "github.com/ray-project/kuberay/ray-operator/apis/ray/v1"
35
37
36
38
corev1 "k8s.io/api/core/v1"
@@ -48,6 +50,8 @@ import (
48
50
ctrl "sigs.k8s.io/controller-runtime"
49
51
"sigs.k8s.io/controller-runtime/pkg/client"
50
52
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
53
+ "sigs.k8s.io/controller-runtime/pkg/handler"
54
+ "sigs.k8s.io/controller-runtime/pkg/reconcile"
51
55
52
56
routev1 "github.com/openshift/api/route/v1"
53
57
routev1ac "github.com/openshift/client-go/route/applyconfigurations/route/v1"
@@ -88,12 +92,12 @@ var (
88
92
// +kubebuilder:rbac:groups=ray.io,resources=rayclusters,verbs=get;list;watch;create;update;patch;delete
89
93
// +kubebuilder:rbac:groups=ray.io,resources=rayclusters/status,verbs=get;update;patch
90
94
// +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
97
101
// +kubebuilder:rbac:groups=authentication.k8s.io,resources=tokenreviews,verbs=create;
98
102
// +kubebuilder:rbac:groups=authorization.k8s.io,resources=subjectaccessreviews,verbs=create;
99
103
// +kubebuilder:rbac:groups=dscinitialization.opendatahub.io,resources=dscinitializations,verbs=get;list;watch
@@ -301,7 +305,7 @@ func crbNameFromCluster(cluster *rayv1.RayCluster) string {
301
305
func desiredOAuthClusterRoleBinding (cluster * rayv1.RayCluster ) * rbacv1ac.ClusterRoleBindingApplyConfiguration {
302
306
return rbacv1ac .ClusterRoleBinding (
303
307
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 }).
305
309
WithSubjects (
306
310
rbacv1ac .Subject ().
307
311
WithKind ("ServiceAccount" ).
@@ -322,7 +326,7 @@ func oauthServiceAccountNameFromCluster(cluster *rayv1.RayCluster) string {
322
326
323
327
func desiredServiceAccount (cluster * rayv1.RayCluster ) * corev1ac.ServiceAccountApplyConfiguration {
324
328
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 }).
326
330
WithAnnotations (map [string ]string {
327
331
"serviceaccounts.openshift.io/oauth-redirectreference.first" : "" +
328
332
`{"kind":"OAuthRedirectReference","apiVersion":"v1",` +
@@ -343,7 +347,7 @@ func rayClientNameFromCluster(cluster *rayv1.RayCluster) string {
343
347
344
348
func desiredClusterRoute (cluster * rayv1.RayCluster ) * routev1ac.RouteApplyConfiguration {
345
349
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 }).
347
351
WithSpec (routev1ac .RouteSpec ().
348
352
WithTo (routev1ac .RouteTargetReference ().WithKind ("Service" ).WithName (oauthServiceNameFromCluster (cluster ))).
349
353
WithPort (routev1ac .RoutePort ().WithTargetPort (intstr .FromString ((oAuthServicePortName )))).
@@ -367,7 +371,7 @@ func oauthServiceTLSSecretName(cluster *rayv1.RayCluster) string {
367
371
368
372
func desiredOAuthService (cluster * rayv1.RayCluster ) * corev1ac.ServiceApplyConfiguration {
369
373
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 }).
371
375
WithAnnotations (map [string ]string {"service.beta.openshift.io/serving-cert-secret-name" : oauthServiceTLSSecretName (cluster )}).
372
376
WithSpec (
373
377
corev1ac .ServiceSpec ().
@@ -397,7 +401,7 @@ func desiredOAuthSecret(cluster *rayv1.RayCluster, cookieSalt string) *corev1ac.
397
401
cookieSecret := base64 .StdEncoding .EncodeToString (hasher .Sum (nil ))
398
402
399
403
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 }).
401
405
WithStringData (map [string ]string {"cookie_secret" : cookieSecret }).
402
406
WithOwnerReferences (
403
407
metav1ac .OwnerReference ().WithUID (cluster .UID ).WithName (cluster .Name ).WithKind (cluster .Kind ).WithAPIVersion (cluster .APIVersion ),
@@ -410,7 +414,7 @@ func caSecretNameFromCluster(cluster *rayv1.RayCluster) string {
410
414
411
415
func desiredCASecret (cluster * rayv1.RayCluster , key , cert []byte ) * corev1ac.SecretApplyConfiguration {
412
416
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 }).
414
418
WithData (map [string ][]byte {
415
419
CAPrivateKeyKey : key ,
416
420
CACertKey : cert ,
@@ -466,7 +470,7 @@ func generateCACertificate() ([]byte, []byte, error) {
466
470
}
467
471
func desiredWorkersNetworkPolicy (cluster * rayv1.RayCluster ) * networkingv1ac.NetworkPolicyApplyConfiguration {
468
472
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 }).
470
474
WithSpec (networkingv1ac .NetworkPolicySpec ().
471
475
WithPodSelector (metav1ac .LabelSelector ().WithMatchLabels (map [string ]string {"ray.io/cluster" : cluster .Name , "ray.io/node-type" : "worker" })).
472
476
WithIngress (
@@ -488,7 +492,7 @@ func desiredHeadNetworkPolicy(cluster *rayv1.RayCluster, cfg *config.KubeRayConf
488
492
allSecuredPorts = append (allSecuredPorts , networkingv1ac .NetworkPolicyPort ().WithProtocol (corev1 .ProtocolTCP ).WithPort (intstr .FromInt (10001 )))
489
493
}
490
494
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 }).
492
496
WithSpec (networkingv1ac .NetworkPolicySpec ().
493
497
WithPodSelector (metav1ac .LabelSelector ().WithMatchLabels (map [string ]string {"ray.io/cluster" : cluster .Name , "ray.io/node-type" : "head" })).
494
498
WithIngress (
@@ -551,5 +555,27 @@ func (r *RayClusterReconciler) SetupWithManager(mgr ctrl.Manager) error {
551
555
return ctrl .NewControllerManagedBy (mgr ).
552
556
Named (controllerName ).
553
557
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
+ ).
554
580
Complete (r )
555
581
}
0 commit comments