@@ -22,29 +22,22 @@ import (
22
22
"crypto/sha1"
23
23
"encoding/base64"
24
24
25
- "fmt"
26
25
"strconv"
27
- "strings"
28
26
29
27
"github.com/go-logr/logr"
30
28
"github.com/project-codeflare/codeflare-operator/pkg/config"
31
29
rayv1 "github.com/ray-project/kuberay/ray-operator/apis/ray/v1"
32
30
33
31
corev1 "k8s.io/api/core/v1"
34
- networkingv1 "k8s.io/api/networking/v1"
35
32
rbacv1 "k8s.io/api/rbac/v1"
36
33
"k8s.io/apimachinery/pkg/api/errors"
37
34
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
38
35
"k8s.io/apimachinery/pkg/runtime"
39
- "k8s.io/apimachinery/pkg/types"
40
36
"k8s.io/apimachinery/pkg/util/intstr"
41
37
coreapply "k8s.io/client-go/applyconfigurations/core/v1"
42
38
v1 "k8s.io/client-go/applyconfigurations/meta/v1"
43
- networkingv1ac "k8s.io/client-go/applyconfigurations/networking/v1"
44
39
rbacapply "k8s.io/client-go/applyconfigurations/rbac/v1"
45
- "k8s.io/client-go/discovery"
46
40
"k8s.io/client-go/kubernetes"
47
- "k8s.io/client-go/rest"
48
41
ctrl "sigs.k8s.io/controller-runtime"
49
42
"sigs.k8s.io/controller-runtime/pkg/client"
50
43
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
@@ -352,168 +345,3 @@ func (r *RayClusterReconciler) SetupWithManager(mgr ctrl.Manager) error {
352
345
Complete (r )
353
346
}
354
347
355
- func serviceNameFromCluster (cluster * rayv1.RayCluster ) string {
356
- return cluster .Name + "-head-svc"
357
- }
358
-
359
- func createRoute (cluster * rayv1.RayCluster ) * routeapply.RouteApplyConfiguration {
360
- return routeapply .Route (dashboardNameFromCluster (cluster ), cluster .Namespace ).
361
- WithLabels (map [string ]string {"ray.io/cluster-name" : cluster .Name }).
362
- WithSpec (routeapply .RouteSpec ().
363
- WithTo (routeapply .RouteTargetReference ().WithKind ("Service" ).WithName (serviceNameFromCluster (cluster ))).
364
- WithPort (routeapply .RoutePort ().WithTargetPort (intstr .FromString (regularServicePortName ))).
365
- WithTLS (routeapply .TLSConfig ().
366
- WithTermination ("edge" )),
367
- ).
368
- WithOwnerReferences (
369
- v1 .OwnerReference ().WithUID (cluster .UID ).WithName (cluster .Name ).WithKind (cluster .Kind ).WithAPIVersion (cluster .APIVersion ),
370
- )
371
- }
372
-
373
- func createRayClientRoute (cluster * rayv1.RayCluster ) * routeapply.RouteApplyConfiguration {
374
- ingress_domain := cluster .ObjectMeta .Annotations ["sdk.codeflare.dev/ingress_domain" ]
375
- return routeapply .Route (rayClientNameFromCluster (cluster ), cluster .Namespace ).
376
- WithLabels (map [string ]string {"ray.io/cluster-name" : cluster .Name }).
377
- WithSpec (routeapply .RouteSpec ().
378
- WithHost (rayClientNameFromCluster (cluster ) + "-" + cluster .Namespace + "." + ingress_domain ).
379
- WithTo (routeapply .RouteTargetReference ().WithKind ("Service" ).WithName (serviceNameFromCluster (cluster )).WithWeight (100 )).
380
- WithPort (routeapply .RoutePort ().WithTargetPort (intstr .FromString ("client" ))).
381
- WithTLS (routeapply .TLSConfig ().WithTermination ("passthrough" )),
382
- ).
383
- WithOwnerReferences (
384
- v1 .OwnerReference ().WithUID (cluster .UID ).WithName (cluster .Name ).WithKind (cluster .Kind ).WithAPIVersion (cluster .APIVersion ),
385
- )
386
- }
387
-
388
- // Create an Ingress object for the RayCluster
389
- func createRayClientIngress (cluster * rayv1.RayCluster ) * networkingv1ac.IngressApplyConfiguration {
390
- ingress_domain := cluster .ObjectMeta .Annotations ["sdk.codeflare.dev/ingress_domain" ]
391
- return networkingv1ac .Ingress (rayClientNameFromCluster (cluster ), cluster .Namespace ).
392
- WithLabels (map [string ]string {"ray.io/cluster-name" : cluster .Name }).
393
- WithAnnotations (map [string ]string {
394
- "nginx.ingress.kubernetes.io/rewrite-target" : "/" ,
395
- "nginx.ingress.kubernetes.io/ssl-redirect" : "true" ,
396
- "nginx.ingress.kubernetes.io/ssl-passthrough" : "true" ,
397
- }).
398
- WithOwnerReferences (v1 .OwnerReference ().
399
- WithAPIVersion (cluster .APIVersion ).
400
- WithKind (cluster .Kind ).
401
- WithName (cluster .Name ).
402
- WithUID (types .UID (cluster .UID ))).
403
- WithSpec (networkingv1ac .IngressSpec ().
404
- WithIngressClassName ("nginx" ).
405
- WithRules (networkingv1ac .IngressRule ().
406
- WithHost (rayClientNameFromCluster (cluster ) + "-" + cluster .Namespace + "." + ingress_domain ).
407
- WithHTTP (networkingv1ac .HTTPIngressRuleValue ().
408
- WithPaths (networkingv1ac .HTTPIngressPath ().
409
- WithPath ("/" ).
410
- WithPathType (networkingv1 .PathTypeImplementationSpecific ).
411
- WithBackend (networkingv1ac .IngressBackend ().
412
- WithService (networkingv1ac .IngressServiceBackend ().
413
- WithName (serviceNameFromCluster (cluster )).
414
- WithPort (networkingv1ac .ServiceBackendPort ().
415
- WithNumber (10001 ),
416
- ),
417
- ),
418
- ),
419
- ),
420
- ),
421
- ),
422
- )
423
- // Optionally, add TLS configuration here if needed
424
- }
425
-
426
- // Create an Ingress object for the RayCluster
427
- func createIngressApplyConfiguration (cluster * rayv1.RayCluster , ingressHost string ) * networkingv1ac.IngressApplyConfiguration {
428
- return networkingv1ac .Ingress (dashboardNameFromCluster (cluster ), cluster .Namespace ).
429
- WithLabels (map [string ]string {"ray.io/cluster-name" : cluster .Name }).
430
- WithOwnerReferences (v1 .OwnerReference ().
431
- WithAPIVersion (cluster .APIVersion ).
432
- WithKind (cluster .Kind ).
433
- WithName (cluster .Name ).
434
- WithUID (types .UID (cluster .UID ))).
435
- WithSpec (networkingv1ac .IngressSpec ().
436
- WithRules (networkingv1ac .IngressRule ().
437
- WithHost (ingressHost ). // kind host name or ingress_domain
438
- WithHTTP (networkingv1ac .HTTPIngressRuleValue ().
439
- WithPaths (networkingv1ac .HTTPIngressPath ().
440
- WithPath ("/" ).
441
- WithPathType (networkingv1 .PathTypePrefix ).
442
- WithBackend (networkingv1ac .IngressBackend ().
443
- WithService (networkingv1ac .IngressServiceBackend ().
444
- WithName (serviceNameFromCluster (cluster )).
445
- WithPort (networkingv1ac .ServiceBackendPort ().
446
- WithName (regularServicePortName ),
447
- ),
448
- ),
449
- ),
450
- ),
451
- ),
452
- ),
453
- )
454
- // Optionally, add TLS configuration here if needed
455
- }
456
-
457
- // isOnKindCluster checks if the current cluster is a KinD cluster.
458
- // It searches for a node with a label commonly used by KinD clusters.
459
- func isOnKindCluster (clientset * kubernetes.Clientset ) (bool , error ) {
460
- nodes , err := clientset .CoreV1 ().Nodes ().List (context .TODO (), metav1.ListOptions {
461
- LabelSelector : "kubernetes.io/hostname=kind-control-plane" ,
462
- })
463
- if err != nil {
464
- return false , err
465
- }
466
- // If we find one or more nodes with the label, assume it's a KinD cluster.
467
- return len (nodes .Items ) > 0 , nil
468
- }
469
-
470
- // getDiscoveryClient returns a discovery client for the current reconciler
471
- func getDiscoveryClient (config * rest.Config ) (* discovery.DiscoveryClient , error ) {
472
- return discovery .NewDiscoveryClientForConfig (config )
473
- }
474
-
475
- // Check where we are running. We are trying to distinguish here whether
476
- // this is vanilla kubernetes cluster or Openshift
477
- func getClusterType (logger logr.Logger , clientset * kubernetes.Clientset , cluster * rayv1.RayCluster ) (bool , string ) {
478
- // The discovery package is used to discover APIs supported by a Kubernetes API server.
479
- ingress_domain := cluster .ObjectMeta .Annotations ["sdk.codeflare.dev/ingress_domain" ]
480
- config , err := ctrl .GetConfig ()
481
- if err == nil && config != nil {
482
- dclient , err := getDiscoveryClient (config )
483
- if err == nil && dclient != nil {
484
- apiGroupList , err := dclient .ServerGroups ()
485
- if err != nil {
486
- logger .Info ("Error while querying ServerGroups, assuming we're on Vanilla Kubernetes" )
487
- return false , ""
488
- } else {
489
- for i := 0 ; i < len (apiGroupList .Groups ); i ++ {
490
- if strings .HasSuffix (apiGroupList .Groups [i ].Name , ".openshift.io" ) {
491
- logger .Info ("We detected being on OpenShift!" )
492
- return true , ""
493
- }
494
- }
495
- onKind , _ := isOnKindCluster (clientset )
496
- if onKind && ingress_domain == "" {
497
- logger .Info ("We detected being on a KinD cluster!" )
498
- return false , "kind"
499
- } else {
500
- logger .Info ("We detected being on Vanilla Kubernetes!" )
501
- return false , fmt .Sprintf ("ray-dashboard-%s-%s.%s" , cluster .Name , cluster .Namespace , ingress_domain )
502
- }
503
- }
504
- } else {
505
- logger .Info ("Cannot retrieve a DiscoveryClient, assuming we're on Vanilla Kubernetes" )
506
- return false , fmt .Sprintf ("ray-dashboard-%s-%s.%s" , cluster .Name , cluster .Namespace , ingress_domain )
507
- }
508
- } else {
509
- logger .Info ("Cannot retrieve config, assuming we're on Vanilla Kubernetes" )
510
- return false , fmt .Sprintf ("ray-dashboard-%s-%s.%s" , cluster .Name , cluster .Namespace , ingress_domain )
511
- }
512
- }
513
-
514
- func isRayDashboardOAuthEnabled () bool {
515
- if configInstance .KubeRay != nil && configInstance .KubeRay .RayDashboardOAuthEnabled != nil {
516
- return * configInstance .KubeRay .RayDashboardOAuthEnabled
517
- }
518
- return true
519
- }
0 commit comments