6
6
"strconv"
7
7
"strings"
8
8
9
- "github.com/go-logr/logr"
10
9
rayv1 "github.com/ray-project/kuberay/ray-operator/apis/ray/v1"
11
10
12
11
networkingv1 "k8s.io/api/networking/v1"
@@ -27,26 +26,11 @@ func serviceNameFromCluster(cluster *rayv1.RayCluster) string {
27
26
return cluster .Name + "-head-svc"
28
27
}
29
28
30
- func createRoute (cluster * rayv1.RayCluster ) * routeapply.RouteApplyConfiguration {
31
- return routeapply .Route (dashboardNameFromCluster (cluster ), cluster .Namespace ).
32
- WithLabels (map [string ]string {"ray.io/cluster-name" : cluster .Name }).
33
- WithSpec (routeapply .RouteSpec ().
34
- WithTo (routeapply .RouteTargetReference ().WithKind ("Service" ).WithName (serviceNameFromCluster (cluster ))).
35
- WithPort (routeapply .RoutePort ().WithTargetPort (intstr .FromString (regularServicePortName ))).
36
- WithTLS (routeapply .TLSConfig ().
37
- WithTermination ("edge" )),
38
- ).
39
- WithOwnerReferences (
40
- v1 .OwnerReference ().WithUID (cluster .UID ).WithName (cluster .Name ).WithKind (cluster .Kind ).WithAPIVersion (cluster .APIVersion ),
41
- )
42
- }
43
-
44
- func createRayClientRoute (cluster * rayv1.RayCluster ) * routeapply.RouteApplyConfiguration {
45
- ingress_domain := cluster .ObjectMeta .Annotations ["sdk.codeflare.dev/ingress_domain" ]
29
+ func desiredRayClientRoute (cluster * rayv1.RayCluster ) * routeapply.RouteApplyConfiguration {
46
30
return routeapply .Route (rayClientNameFromCluster (cluster ), cluster .Namespace ).
47
31
WithLabels (map [string ]string {"ray.io/cluster-name" : cluster .Name }).
48
32
WithSpec (routeapply .RouteSpec ().
49
- WithHost (rayClientNameFromCluster (cluster ) + "-" + cluster .Namespace + "." + ingress_domain ).
33
+ WithHost (rayClientNameFromCluster (cluster ) + "-" + cluster .Namespace ).
50
34
WithTo (routeapply .RouteTargetReference ().WithKind ("Service" ).WithName (serviceNameFromCluster (cluster )).WithWeight (100 )).
51
35
WithPort (routeapply .RoutePort ().WithTargetPort (intstr .FromString ("client" ))).
52
36
WithTLS (routeapply .TLSConfig ().WithTermination ("passthrough" )),
@@ -57,8 +41,7 @@ func createRayClientRoute(cluster *rayv1.RayCluster) *routeapply.RouteApplyConfi
57
41
}
58
42
59
43
// Create an Ingress object for the RayCluster
60
- func createRayClientIngress (cluster * rayv1.RayCluster ) * networkingv1ac.IngressApplyConfiguration {
61
- ingress_domain := cluster .ObjectMeta .Annotations ["sdk.codeflare.dev/ingress_domain" ]
44
+ func desiredRayClientIngress (cluster * rayv1.RayCluster , ingressDomain string ) * networkingv1ac.IngressApplyConfiguration {
62
45
return networkingv1ac .Ingress (rayClientNameFromCluster (cluster ), cluster .Namespace ).
63
46
WithLabels (map [string ]string {"ray.io/cluster-name" : cluster .Name }).
64
47
WithAnnotations (map [string ]string {
@@ -74,7 +57,7 @@ func createRayClientIngress(cluster *rayv1.RayCluster) *networkingv1ac.IngressAp
74
57
WithSpec (networkingv1ac .IngressSpec ().
75
58
WithIngressClassName ("nginx" ).
76
59
WithRules (networkingv1ac .IngressRule ().
77
- WithHost (rayClientNameFromCluster (cluster ) + "-" + cluster .Namespace + "." + ingress_domain ).
60
+ WithHost (rayClientNameFromCluster (cluster ) + "-" + cluster .Namespace + "." + ingressDomain ).
78
61
WithHTTP (networkingv1ac .HTTPIngressRuleValue ().
79
62
WithPaths (networkingv1ac .HTTPIngressPath ().
80
63
WithPath ("/" ).
@@ -94,7 +77,7 @@ func createRayClientIngress(cluster *rayv1.RayCluster) *networkingv1ac.IngressAp
94
77
}
95
78
96
79
// Create an Ingress object for the RayCluster
97
- func createIngressApplyConfiguration (cluster * rayv1.RayCluster , ingressHost string ) * networkingv1ac.IngressApplyConfiguration {
80
+ func desiredClusterIngress (cluster * rayv1.RayCluster , ingressHost string ) * networkingv1ac.IngressApplyConfiguration {
98
81
return networkingv1ac .Ingress (dashboardNameFromCluster (cluster ), cluster .Namespace ).
99
82
WithLabels (map [string ]string {"ray.io/cluster-name" : cluster .Name }).
100
83
WithOwnerReferences (v1 .OwnerReference ().
@@ -104,7 +87,7 @@ func createIngressApplyConfiguration(cluster *rayv1.RayCluster, ingressHost stri
104
87
WithUID (types .UID (cluster .UID ))).
105
88
WithSpec (networkingv1ac .IngressSpec ().
106
89
WithRules (networkingv1ac .IngressRule ().
107
- WithHost (ingressHost ). // kind host name or ingress_domain
90
+ WithHost (ingressHost ). // KinD hostname or ingressDomain
108
91
WithHTTP (networkingv1ac .HTTPIngressRuleValue ().
109
92
WithPaths (networkingv1ac .HTTPIngressPath ().
110
93
WithPath ("/" ).
@@ -113,7 +96,7 @@ func createIngressApplyConfiguration(cluster *rayv1.RayCluster, ingressHost stri
113
96
WithService (networkingv1ac .IngressServiceBackend ().
114
97
WithName (serviceNameFromCluster (cluster )).
115
98
WithPort (networkingv1ac .ServiceBackendPort ().
116
- WithName (regularServicePortName ),
99
+ WithName (ingressServicePortName ),
117
100
),
118
101
),
119
102
),
@@ -143,59 +126,56 @@ func getDiscoveryClient(config *rest.Config) (*discovery.DiscoveryClient, error)
143
126
144
127
// Check where we are running. We are trying to distinguish here whether
145
128
// this is vanilla kubernetes cluster or Openshift
146
- func getClusterType (logger logr. Logger , clientset * kubernetes.Clientset , cluster * rayv1.RayCluster ) (bool , string ) {
129
+ func getClusterType (ctx context. Context , clientset * kubernetes.Clientset , cluster * rayv1.RayCluster , ingressDomain string ) (bool , string ) {
147
130
// The discovery package is used to discover APIs supported by a Kubernetes API server.
148
- ingress_domain := cluster . ObjectMeta . Annotations [ "sdk.codeflare.dev/ingress_domain" ]
131
+ logger := ctrl . LoggerFrom ( ctx )
149
132
config , err := ctrl .GetConfig ()
150
- if err == nil && config != nil {
151
- dclient , err := getDiscoveryClient (config )
152
- if err == nil && dclient != nil {
153
- apiGroupList , err := dclient .ServerGroups ()
154
- if err != nil {
155
- logger .Info ("Error while querying ServerGroups, assuming we're on Vanilla Kubernetes" )
156
- return false , ""
157
- } else {
158
- for i := 0 ; i < len (apiGroupList .Groups ); i ++ {
159
- if strings .HasSuffix (apiGroupList .Groups [i ].Name , ".openshift.io" ) {
160
- logger .Info ("We detected being on OpenShift!" )
161
- return true , ""
162
- }
163
- }
164
- onKind , _ := isOnKindCluster (clientset )
165
- if onKind && ingress_domain == "" {
166
- logger .Info ("We detected being on a KinD cluster!" )
167
- return false , "kind"
168
- } else {
169
- logger .Info ("We detected being on Vanilla Kubernetes!" )
170
- return false , fmt .Sprintf ("ray-dashboard-%s-%s.%s" , cluster .Name , cluster .Namespace , ingress_domain )
171
- }
172
- }
173
- } else {
174
- logger .Info ("Cannot retrieve a DiscoveryClient, assuming we're on Vanilla Kubernetes" )
175
- return false , fmt .Sprintf ("ray-dashboard-%s-%s.%s" , cluster .Name , cluster .Namespace , ingress_domain )
176
- }
177
- } else {
133
+ if err != nil && config == nil {
178
134
logger .Info ("Cannot retrieve config, assuming we're on Vanilla Kubernetes" )
179
- return false , fmt .Sprintf ("ray-dashboard-%s-%s.%s" , cluster .Name , cluster .Namespace , ingress_domain )
135
+ return false , fmt .Sprintf ("ray-dashboard-%s-%s.%s" , cluster .Name , cluster .Namespace , ingressDomain )
180
136
}
137
+ dclient , err := getDiscoveryClient (config )
138
+ if err != nil && dclient == nil {
139
+ logger .Info ("Cannot retrieve a DiscoveryClient, assuming we're on Vanilla Kubernetes" )
140
+ return false , fmt .Sprintf ("ray-dashboard-%s-%s.%s" , cluster .Name , cluster .Namespace , ingressDomain )
141
+ }
142
+ apiGroupList , err := dclient .ServerGroups ()
143
+ if err != nil {
144
+ logger .Info ("Error while querying ServerGroups, assuming we're on Vanilla Kubernetes" )
145
+ return false , ""
146
+ }
147
+ for i := 0 ; i < len (apiGroupList .Groups ); i ++ {
148
+ if strings .HasSuffix (apiGroupList .Groups [i ].Name , ".openshift.io" ) {
149
+ logger .Info ("We detected being on OpenShift!" )
150
+ return true , ""
151
+ }
152
+ }
153
+ onKind , _ := isOnKindCluster (clientset )
154
+ if onKind && ingressDomain == "" {
155
+ logger .Info ("We detected being on a KinD cluster!" )
156
+ return false , "kind"
157
+ }
158
+ logger .Info ("We detected being on Vanilla Kubernetes!" )
159
+ return false , fmt .Sprintf ("ray-dashboard-%s-%s.%s" , cluster .Name , cluster .Namespace , ingressDomain )
181
160
}
182
161
183
- func isRayDashboardOAuthEnabled () bool {
184
- if configInstance . KubeRay != nil && configInstance .KubeRay .RayDashboardOAuthEnabled != nil {
185
- return * configInstance .KubeRay .RayDashboardOAuthEnabled
162
+ func ( r * RayClusterReconciler ) isRayDashboardOAuthEnabled () bool {
163
+ if r . Config != nil && r . Config . KubeRay != nil && r . Config .KubeRay .RayDashboardOAuthEnabled != nil {
164
+ return * r . Config .KubeRay .RayDashboardOAuthEnabled
186
165
}
187
166
return true
188
167
}
189
168
190
- func annotationBoolVal (logger logr.Logger , cluster * rayv1.RayCluster , annotation string ) bool {
191
- val := cluster .ObjectMeta .Annotations [annotation ]
169
+ func annotationBoolVal (ctx context.Context , cluster * rayv1.RayCluster , annotation string , defaultValue bool ) bool {
170
+ logger := ctrl .LoggerFrom (ctx )
171
+ val , exists := cluster .ObjectMeta .Annotations [annotation ]
172
+ if ! exists || val == "" {
173
+ return defaultValue
174
+ }
192
175
boolVal , err := strconv .ParseBool (val )
193
176
if err != nil {
194
- logger .Error (err , "Could not convert" , annotation , "value to bool" , val )
195
- }
196
- if boolVal {
197
- return true
198
- } else {
199
- return false
177
+ logger .Error (err , "Could not convert annotation value to bool" , "annotation" , annotation , "value" , val )
178
+ return defaultValue
200
179
}
180
+ return boolVal
201
181
}
0 commit comments