Skip to content

Commit a822747

Browse files
sutaakaropenshift-merge-robot
authored andcommitted
Add Ray cluster REST API support in test support package
1 parent c9929bd commit a822747

File tree

9 files changed

+236
-8
lines changed

9 files changed

+236
-8
lines changed

go.mod

+4-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ require (
88
github.com/manifestival/manifestival v0.7.2
99
github.com/onsi/ginkgo/v2 v2.9.2
1010
github.com/onsi/gomega v1.27.6
11+
github.com/openshift/api v0.0.0-20230213134911-7ba313770556
12+
github.com/openshift/client-go v0.0.0-20221019143426-16aed247da5c
1113
github.com/project-codeflare/multi-cluster-app-dispatcher v1.32.0
1214
github.com/ray-project/kuberay/ray-operator v0.0.0-20230614221720-085c29d40fa9
1315
go.uber.org/zap v1.24.0
@@ -36,7 +38,7 @@ require (
3638
github.com/golang/protobuf v1.5.3 // indirect
3739
github.com/google/gnostic v0.5.7-v3refs // indirect
3840
github.com/google/go-cmp v0.5.9 // indirect
39-
github.com/google/gofuzz v1.1.0 // indirect
41+
github.com/google/gofuzz v1.2.0 // indirect
4042
github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38 // indirect
4143
github.com/google/uuid v1.1.2 // indirect
4244
github.com/imdario/mergo v0.3.12 // indirect
@@ -56,7 +58,7 @@ require (
5658
go.uber.org/atomic v1.7.0 // indirect
5759
go.uber.org/multierr v1.6.0 // indirect
5860
golang.org/x/net v0.8.0 // indirect
59-
golang.org/x/oauth2 v0.0.0-20220223155221-ee480838109b // indirect
61+
golang.org/x/oauth2 v0.0.0-20220411215720-9780585627b5 // indirect
6062
golang.org/x/sys v0.6.0 // indirect
6163
golang.org/x/term v0.6.0 // indirect
6264
golang.org/x/text v0.8.0 // indirect

go.sum

+8-2
Original file line numberDiff line numberDiff line change
@@ -280,8 +280,9 @@ github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
280280
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
281281
github.com/google/gofuzz v0.0.0-20170612174753-24818f796faf/go.mod h1:HP5RmnzzSNb993RKQDq4+1A4ia9nllfqcQFTQJedwGI=
282282
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
283-
github.com/google/gofuzz v1.1.0 h1:Hsa8mG0dQ46ij8Sl2AYJDUv1oA9/d6Vk+3LG99Oe02g=
284283
github.com/google/gofuzz v1.1.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
284+
github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0=
285+
github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
285286
github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=
286287
github.com/google/martian/v3 v3.0.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0=
287288
github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc=
@@ -418,6 +419,10 @@ github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1y
418419
github.com/onsi/gomega v1.10.2/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
419420
github.com/onsi/gomega v1.27.6 h1:ENqfyGeS5AX/rlXDd/ETokDz93u0YufY1Pgxuy/PvWE=
420421
github.com/onsi/gomega v1.27.6/go.mod h1:PIQNjfQwkP3aQAH7lf7j87O/5FiNr+ZR8+ipb+qQlhg=
422+
github.com/openshift/api v0.0.0-20230213134911-7ba313770556 h1:7W2fOhJicyEff24VaF7ASNzPtYvr+iSCVft4SIBAzaE=
423+
github.com/openshift/api v0.0.0-20230213134911-7ba313770556/go.mod h1:aQ6LDasvHMvHZXqLHnX2GRmnfTWCF/iIwz8EMTTIE9A=
424+
github.com/openshift/client-go v0.0.0-20221019143426-16aed247da5c h1:CV76yFOTXmq9VciBR3Bve5ZWzSxdft7gaMVB3kS0rwg=
425+
github.com/openshift/client-go v0.0.0-20221019143426-16aed247da5c/go.mod h1:lFMO8mLHXWFzSdYvGNo8ivF9SfF6zInA8ZGw4phRnUE=
421426
github.com/pborman/uuid v1.2.0/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtPdI/k=
422427
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
423428
github.com/peterbourgon/diskv v2.0.1+incompatible/go.mod h1:uqqh8zWWbv1HBMNONnaR/tNboyR3/BZd58JJSHlUSCU=
@@ -635,8 +640,9 @@ golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4Iltr
635640
golang.org/x/oauth2 v0.0.0-20191202225959-858c2ad4c8b6/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
636641
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
637642
golang.org/x/oauth2 v0.0.0-20210514164344-f6687ab2804c/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A=
638-
golang.org/x/oauth2 v0.0.0-20220223155221-ee480838109b h1:clP8eMhB30EHdc0bd2Twtq6kgU7yl5ub2cQLSdrv1Dg=
639643
golang.org/x/oauth2 v0.0.0-20220223155221-ee480838109b/go.mod h1:DAh4E804XQdzx2j+YRIaUnCqCV2RuMz24cGBJ5QYIrc=
644+
golang.org/x/oauth2 v0.0.0-20220411215720-9780585627b5 h1:OSnWWcOd/CtWQC2cYSBgbTSJv3ciqd8r54ySIW2y3RE=
645+
golang.org/x/oauth2 v0.0.0-20220411215720-9780585627b5/go.mod h1:DAh4E804XQdzx2j+YRIaUnCqCV2RuMz24cGBJ5QYIrc=
640646
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
641647
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
642648
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=

test/support/client.go

+14
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,24 @@ import (
2424
"k8s.io/client-go/kubernetes"
2525
"k8s.io/client-go/tools/clientcmd"
2626

27+
routev1 "github.com/openshift/client-go/route/clientset/versioned"
28+
2729
codeflareclient "github.com/project-codeflare/codeflare-operator/client/clientset/versioned"
2830
mcadclient "github.com/project-codeflare/multi-cluster-app-dispatcher/pkg/client/clientset/controller-versioned"
2931
rayclient "github.com/ray-project/kuberay/ray-operator/pkg/client/clientset/versioned"
3032
)
3133

3234
type Client interface {
3335
Core() kubernetes.Interface
36+
Route() routev1.Interface
3437
CodeFlare() codeflareclient.Interface
3538
MCAD() mcadclient.Interface
3639
Ray() rayclient.Interface
3740
}
3841

3942
type testClient struct {
4043
core kubernetes.Interface
44+
route routev1.Interface
4145
codeflare codeflareclient.Interface
4246
mcad mcadclient.Interface
4347
ray rayclient.Interface
@@ -49,6 +53,10 @@ func (t *testClient) Core() kubernetes.Interface {
4953
return t.core
5054
}
5155

56+
func (t *testClient) Route() routev1.Interface {
57+
return t.route
58+
}
59+
5260
func (t *testClient) CodeFlare() codeflareclient.Interface {
5361
return t.codeflare
5462
}
@@ -75,6 +83,11 @@ func newTestClient() (Client, error) {
7583
return nil, err
7684
}
7785

86+
routeClient, err := routev1.NewForConfig(cfg)
87+
if err != nil {
88+
return nil, err
89+
}
90+
7891
codeFlareClient, err := codeflareclient.NewForConfig(cfg)
7992
if err != nil {
8093
return nil, err
@@ -92,6 +105,7 @@ func newTestClient() (Client, error) {
92105

93106
return &testClient{
94107
core: kubeClient,
108+
route: routeClient,
95109
codeflare: codeFlareClient,
96110
mcad: mcadClient,
97111
ray: rayClient,

test/support/conditions.go

+15
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import (
2121
appsv1 "k8s.io/api/apps/v1"
2222
batchv1 "k8s.io/api/batch/v1"
2323
corev1 "k8s.io/api/core/v1"
24+
25+
routev1 "github.com/openshift/api/route/v1"
2426
)
2527

2628
type conditionType interface {
@@ -39,6 +41,10 @@ func ConditionStatus[T conditionType](conditionType T) func(any) corev1.Conditio
3941
if c := getDeploymentCondition(o.Status.Conditions, appsv1.DeploymentConditionType(conditionType)); c != nil {
4042
return c.Status
4143
}
44+
case *routev1.Route:
45+
if c := getRouteCondition(o.Status.Ingress[0].Conditions, routev1.RouteIngressConditionType(conditionType)); c != nil {
46+
return c.Status
47+
}
4248
}
4349

4450
return corev1.ConditionUnknown
@@ -64,3 +70,12 @@ func getDeploymentCondition(conditions []appsv1.DeploymentCondition, conditionTy
6470
}
6571
return nil
6672
}
73+
74+
func getRouteCondition(conditions []routev1.RouteIngressCondition, conditionType routev1.RouteIngressConditionType) *routev1.RouteIngressCondition {
75+
for _, c := range conditions {
76+
if c.Type == conditionType {
77+
return &c
78+
}
79+
}
80+
return nil
81+
}

test/support/mcad.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,10 @@ package support
1818

1919
import (
2020
"github.com/onsi/gomega"
21+
mcadv1beta1 "github.com/project-codeflare/multi-cluster-app-dispatcher/pkg/apis/controller/v1beta1"
2122

2223
corev1 "k8s.io/api/core/v1"
2324
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
24-
25-
mcadv1beta1 "github.com/project-codeflare/multi-cluster-app-dispatcher/pkg/apis/controller/v1beta1"
2625
)
2726

2827
func AppWrapper(t Test, namespace *corev1.Namespace, name string) func(g gomega.Gomega) *mcadv1beta1.AppWrapper {

test/support/ray.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,9 @@ import (
2020
"encoding/json"
2121

2222
"github.com/onsi/gomega"
23+
rayv1alpha1 "github.com/ray-project/kuberay/ray-operator/apis/ray/v1alpha1"
2324

2425
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
25-
26-
rayv1alpha1 "github.com/ray-project/kuberay/ray-operator/apis/ray/v1alpha1"
2726
)
2827

2928
const RayJobDefaultClusterSelectorKey = "ray.io/cluster"

test/support/ray_api.go

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
Copyright 2023.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package support
18+
19+
import (
20+
"github.com/onsi/gomega"
21+
)
22+
23+
func GetRayJobAPIDetails(t Test, rayClient RayClusterClient, jobID string) *RayJobDetailsResponse {
24+
t.T().Helper()
25+
return RayJobAPIDetails(t, rayClient, jobID)(t)
26+
}
27+
28+
func WriteRayJobAPILogs(t Test, rayClient RayClusterClient, jobID string) {
29+
t.T().Helper()
30+
logs, err := rayClient.GetJobLogs(jobID)
31+
t.Expect(err).NotTo(gomega.HaveOccurred())
32+
WriteToOutputDir(t, jobID, Log, []byte(logs))
33+
}
34+
35+
func RayJobAPIDetails(t Test, rayClient RayClusterClient, jobID string) func(g gomega.Gomega) *RayJobDetailsResponse {
36+
return func(g gomega.Gomega) *RayJobDetailsResponse {
37+
jobDetails, err := rayClient.GetJobDetails(jobID)
38+
t.Expect(err).NotTo(gomega.HaveOccurred())
39+
return jobDetails
40+
}
41+
}
42+
43+
func GetRayJobAPIDetailsStatus(jobDetails *RayJobDetailsResponse) string {
44+
return jobDetails.Status
45+
}

test/support/ray_cluster_client.go

+115
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
/*
2+
Copyright 2023.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package support
18+
19+
import (
20+
"bytes"
21+
"encoding/json"
22+
"io/ioutil"
23+
"net/http"
24+
"net/url"
25+
)
26+
27+
type RayJobSetup struct {
28+
EntryPoint string `json:"entrypoint"`
29+
RuntimeEnv map[string]any `json:"runtime_env"`
30+
}
31+
32+
type RayJobResponse struct {
33+
JobID string `json:"job_id"`
34+
SubmissionID string `json:"submission_id"`
35+
}
36+
37+
type RayJobDetailsResponse struct {
38+
JobID string `json:"job_id"`
39+
SubmissionID string `json:"submission_id"`
40+
Status string `json:"status"`
41+
}
42+
43+
type RayJobLogsResponse struct {
44+
Logs string `json:"logs"`
45+
}
46+
47+
var _ RayClusterClient = (*rayClusterClient)(nil)
48+
49+
type rayClusterClient struct {
50+
endpoint url.URL
51+
}
52+
53+
type RayClusterClient interface {
54+
CreateJob(job *RayJobSetup) (*RayJobResponse, error)
55+
GetJobDetails(jobID string) (*RayJobDetailsResponse, error)
56+
GetJobLogs(jobID string) (string, error)
57+
}
58+
59+
func NewRayClusterClient(dashboardEndpoint url.URL) RayClusterClient {
60+
return &rayClusterClient{endpoint: dashboardEndpoint}
61+
}
62+
63+
func (client *rayClusterClient) CreateJob(job *RayJobSetup) (response *RayJobResponse, err error) {
64+
marshalled, err := json.Marshal(job)
65+
if err != nil {
66+
return
67+
}
68+
69+
createJobURL := client.endpoint.String() + "/api/jobs/"
70+
resp, err := http.Post(createJobURL, "application/json", bytes.NewReader(marshalled))
71+
if err != nil {
72+
return
73+
}
74+
75+
respData, err := ioutil.ReadAll(resp.Body)
76+
if err != nil {
77+
return
78+
}
79+
80+
err = json.Unmarshal(respData, &response)
81+
return
82+
}
83+
84+
func (client *rayClusterClient) GetJobDetails(jobID string) (response *RayJobDetailsResponse, err error) {
85+
createJobURL := client.endpoint.String() + "/api/jobs/" + jobID
86+
resp, err := http.Get(createJobURL)
87+
if err != nil {
88+
return
89+
}
90+
91+
respData, err := ioutil.ReadAll(resp.Body)
92+
if err != nil {
93+
return
94+
}
95+
96+
err = json.Unmarshal(respData, &response)
97+
return
98+
}
99+
100+
func (client *rayClusterClient) GetJobLogs(jobID string) (logs string, err error) {
101+
createJobURL := client.endpoint.String() + "/api/jobs/" + jobID + "/logs"
102+
resp, err := http.Get(createJobURL)
103+
if err != nil {
104+
return
105+
}
106+
107+
respData, err := ioutil.ReadAll(resp.Body)
108+
if err != nil {
109+
return
110+
}
111+
112+
jobLogs := RayJobLogsResponse{}
113+
err = json.Unmarshal(respData, &jobLogs)
114+
return jobLogs.Logs, err
115+
}

test/support/route.go

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
Copyright 2023.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package support
18+
19+
import (
20+
"github.com/onsi/gomega"
21+
22+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
23+
24+
routev1 "github.com/openshift/api/route/v1"
25+
)
26+
27+
func Route(t Test, namespace, name string) func(g gomega.Gomega) *routev1.Route {
28+
return func(g gomega.Gomega) *routev1.Route {
29+
route, err := t.Client().Route().RouteV1().Routes(namespace).Get(t.Ctx(), name, metav1.GetOptions{})
30+
g.Expect(err).NotTo(gomega.HaveOccurred())
31+
return route
32+
}
33+
}

0 commit comments

Comments
 (0)