@@ -18,15 +18,20 @@ package e2e
1818
1919import (
2020 "encoding/base64"
21+ "net/url"
2122 "testing"
2223
2324 . "github.com/onsi/gomega"
2425 mcadv1beta1 "github.com/project-codeflare/multi-cluster-app-dispatcher/pkg/apis/controller/v1beta1"
2526 rayv1alpha1 "github.com/ray-project/kuberay/ray-operator/apis/ray/v1alpha1"
2627
2728 corev1 "k8s.io/api/core/v1"
29+ networkingv1 "k8s.io/api/networking/v1"
2830 "k8s.io/apimachinery/pkg/api/resource"
2931 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
32+ "k8s.io/apimachinery/pkg/util/intstr"
33+
34+ routev1 "github.com/openshift/api/route/v1"
3035
3136 . "github.com/project-codeflare/codeflare-operator/test/support"
3237)
@@ -252,8 +257,104 @@ func TestMNISTRayJobMCADRayCluster(t *testing.T) {
252257 test .Expect (err ).NotTo (HaveOccurred ())
253258 test .T ().Logf ("Created RayJob %s/%s successfully" , rayJob .Namespace , rayJob .Name )
254259
260+ var rayDashboardURL url.URL
261+ if IsOpenShift (test ) {
262+ // Create a route to expose the Ray cluster API
263+ route := & routev1.Route {
264+ TypeMeta : metav1.TypeMeta {
265+ APIVersion : routev1 .GroupVersion .String (),
266+ Kind : "Route" ,
267+ },
268+ ObjectMeta : metav1.ObjectMeta {
269+ Namespace : namespace .Name ,
270+ Name : "ray-dashboard" ,
271+ },
272+ Spec : routev1.RouteSpec {
273+ To : routev1.RouteTargetReference {
274+ Name : "raycluster-head-svc" ,
275+ },
276+ Port : & routev1.RoutePort {
277+ TargetPort : intstr .FromString ("dashboard" ),
278+ },
279+ },
280+ }
281+
282+ _ , err := test .Client ().Route ().RouteV1 ().Routes (namespace .Name ).Create (test .Ctx (), route , metav1.CreateOptions {})
283+ test .Expect (err ).NotTo (HaveOccurred ())
284+ test .T ().Logf ("Created Route %s/%s successfully" , route .Namespace , route .Name )
285+
286+ test .T ().Logf ("Waiting for Route %s/%s to be admitted" , route .Namespace , route .Name )
287+ test .Eventually (Route (test , route .Namespace , route .Name ), TestTimeoutMedium ).
288+ Should (WithTransform (ConditionStatus (routev1 .RouteAdmitted ), Equal (corev1 .ConditionTrue )))
289+
290+ route = GetRoute (test , route .Namespace , route .Name )
291+
292+ rayDashboardURL = url.URL {
293+ Scheme : "http" ,
294+ Host : route .Status .Ingress [0 ].Host ,
295+ }
296+ } else {
297+ ingress := & networkingv1.Ingress {
298+ TypeMeta : metav1.TypeMeta {
299+ APIVersion : networkingv1 .SchemeGroupVersion .String (),
300+ Kind : "Ingress" ,
301+ },
302+ ObjectMeta : metav1.ObjectMeta {
303+ Namespace : namespace .Name ,
304+ Name : "ray-dashboard" ,
305+ Annotations : map [string ]string {
306+ "nginx.ingress.kubernetes.io/use-regex" : "true" ,
307+ "nginx.ingress.kubernetes.io/rewrite-target" : "/$2" ,
308+ },
309+ },
310+ Spec : networkingv1.IngressSpec {
311+ Rules : []networkingv1.IngressRule {
312+ {
313+ IngressRuleValue : networkingv1.IngressRuleValue {
314+ HTTP : & networkingv1.HTTPIngressRuleValue {
315+ Paths : []networkingv1.HTTPIngressPath {
316+ {
317+ Path : "/ray-dashboard(/|$)(.*)" ,
318+ PathType : Ptr (networkingv1 .PathTypePrefix ),
319+ Backend : networkingv1.IngressBackend {
320+ Service : & networkingv1.IngressServiceBackend {
321+ Name : "raycluster-head-svc" ,
322+ Port : networkingv1.ServiceBackendPort {
323+ Name : "dashboard" ,
324+ },
325+ },
326+ },
327+ },
328+ },
329+ },
330+ },
331+ },
332+ },
333+ },
334+ }
335+
336+ _ , err := test .Client ().Core ().NetworkingV1 ().Ingresses (ingress .Namespace ).Create (test .Ctx (), ingress , metav1.CreateOptions {})
337+ test .Expect (err ).NotTo (HaveOccurred ())
338+ test .T ().Logf ("Created Ingress %s/%s successfully" , ingress .Namespace , ingress .Name )
339+
340+ test .T ().Logf ("Waiting for Ingress %s/%s to be admitted" , ingress .Namespace , ingress .Name )
341+ test .Eventually (Ingress (test , ingress .Namespace , ingress .Name ), TestTimeoutMedium ).
342+ Should (WithTransform (LoadBalancerIngresses , HaveLen (1 )))
343+
344+ ingress = GetIngress (test , ingress .Namespace , ingress .Name )
345+
346+ rayDashboardURL = url.URL {
347+ Scheme : "http" ,
348+ Host : ingress .Status .LoadBalancer .Ingress [0 ].IP ,
349+ Path : "ray-dashboard" ,
350+ }
351+ }
352+
353+ test .T ().Logf ("Connecting to Ray cluster at: %s" , rayDashboardURL .String ())
354+ rayClient := NewRayClusterClient (rayDashboardURL )
355+
255356 // Retrieving the job logs once it has completed or timed out
256- defer WriteRayJobLogs (test , rayJob .Namespace , rayJob .Name )
357+ defer WriteRayJobAPILogs (test , rayClient , GetRayJobId ( test , rayJob .Namespace , rayJob .Name ) )
257358
258359 test .T ().Logf ("Waiting for RayJob %s/%s to complete" , rayJob .Namespace , rayJob .Name )
259360 test .Eventually (RayJob (test , rayJob .Namespace , rayJob .Name ), TestTimeoutLong ).
0 commit comments