Skip to content

Commit 3d5c9e6

Browse files
authored
[refactor][6/N] Move types in ray-operator utils into new package (#3979)
* update Signed-off-by: You-Cheng Lin (Owen) <[email protected]> * rename package Signed-off-by: You-Cheng Lin (Owen) <[email protected]> * rename package name to types Signed-off-by: You-Cheng Lin (Owen) <[email protected]> * update pkg name alias in other dirs Signed-off-by: You-Cheng Lin (Owen) <[email protected]> * apply reuian's suggestion Signed-off-by: You-Cheng Lin (Owen) <[email protected]> --------- Signed-off-by: You-Cheng Lin (Owen) <[email protected]>
1 parent c30fae2 commit 3d5c9e6

12 files changed

+132
-118
lines changed

apiserver/pkg/server/ray_job_submission_service_server.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
api "github.com/ray-project/kuberay/proto/go_client"
2121
rayv1 "github.com/ray-project/kuberay/ray-operator/apis/ray/v1"
2222
"github.com/ray-project/kuberay/ray-operator/controllers/ray/utils"
23+
utiltypes "github.com/ray-project/kuberay/ray-operator/controllers/ray/utils/types"
2324
)
2425

2526
type RayJobSubmissionServiceServerOptions struct {
@@ -54,7 +55,7 @@ func (s *RayJobSubmissionServiceServer) SubmitRayJob(ctx context.Context, req *a
5455
if err != nil {
5556
return nil, err
5657
}
57-
request := &utils.RayJobRequest{Entrypoint: req.Jobsubmission.Entrypoint}
58+
request := &utiltypes.RayJobRequest{Entrypoint: req.Jobsubmission.Entrypoint}
5859
if req.Jobsubmission.SubmissionId != "" {
5960
request.SubmissionId = req.Jobsubmission.SubmissionId
6061
}
@@ -216,7 +217,7 @@ func (s *RayJobSubmissionServiceServer) getRayClusterURL(ctx context.Context, re
216217
}
217218

218219
// Internal method to convert RayJobInfo to JobSubmissionInfo
219-
func convertNodeInfo(info *utils.RayJobInfo) *api.JobSubmissionInfo {
220+
func convertNodeInfo(info *utiltypes.RayJobInfo) *api.JobSubmissionInfo {
220221
jsi := api.JobSubmissionInfo{
221222
Entrypoint: info.Entrypoint,
222223
JobId: info.JobId,

apiserver/pkg/server/ray_job_submission_service_server_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717
"github.com/ray-project/kuberay/apiserver/pkg/util"
1818
api "github.com/ray-project/kuberay/proto/go_client"
1919
rayv1 "github.com/ray-project/kuberay/ray-operator/apis/ray/v1"
20-
"github.com/ray-project/kuberay/ray-operator/controllers/ray/utils"
20+
utiltypes "github.com/ray-project/kuberay/ray-operator/controllers/ray/utils/types"
2121
fakeclientset "github.com/ray-project/kuberay/ray-operator/pkg/client/clientset/versioned/fake"
2222
)
2323

@@ -179,7 +179,7 @@ func TestConvertNodeInfo(t *testing.T) {
179179
metadata := map[string]string{
180180
"foo": "boo",
181181
}
182-
runtimeEnv := utils.RuntimeEnvType{
182+
runtimeEnv := utiltypes.RuntimeEnvType{
183183
"working_dir": "/tmp/workdir",
184184
"pip": []string{"numpy", "pandas"},
185185
}
@@ -188,7 +188,7 @@ func TestConvertNodeInfo(t *testing.T) {
188188
"pip": "[numpy pandas]",
189189
}
190190

191-
rayJobInfo := utils.RayJobInfo{
191+
rayJobInfo := utiltypes.RayJobInfo{
192192
Entrypoint: entrypoint,
193193
JobId: jobID,
194194
SubmissionId: submissionID,

ray-operator/controllers/ray/rayjob_controller_test.go

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import (
3434
rayv1 "github.com/ray-project/kuberay/ray-operator/apis/ray/v1"
3535
"github.com/ray-project/kuberay/ray-operator/controllers/ray/common"
3636
"github.com/ray-project/kuberay/ray-operator/controllers/ray/utils"
37+
utiltypes "github.com/ray-project/kuberay/ray-operator/controllers/ray/utils/types"
3738
"github.com/ray-project/kuberay/ray-operator/pkg/features"
3839
"github.com/ray-project/kuberay/ray-operator/test/support"
3940
)
@@ -270,8 +271,8 @@ var _ = Context("RayJob with different submission modes", func() {
270271

271272
It("RayJobs's JobDeploymentStatus transitions from Running to Complete.", func() {
272273
// Update fake dashboard client to return job info with "Succeeded" status.
273-
getJobInfo := func(context.Context, string) (*utils.RayJobInfo, error) { //nolint:unparam // This is a mock function so parameters are required
274-
return &utils.RayJobInfo{JobStatus: rayv1.JobStatusSucceeded, EndTime: uint64(time.Now().UnixMilli())}, nil
274+
getJobInfo := func(context.Context, string) (*utiltypes.RayJobInfo, error) { //nolint:unparam // This is a mock function so parameters are required
275+
return &utiltypes.RayJobInfo{JobStatus: rayv1.JobStatusSucceeded, EndTime: uint64(time.Now().UnixMilli())}, nil
275276
}
276277
fakeRayDashboardClient.GetJobInfoMock.Store(&getJobInfo)
277278
defer fakeRayDashboardClient.GetJobInfoMock.Store(nil)
@@ -495,8 +496,8 @@ var _ = Context("RayJob with different submission modes", func() {
495496

496497
It("RayJobs's JobDeploymentStatus transitions from Running to Complete.", func() {
497498
// Update fake dashboard client to return job info with "Succeeded" status.
498-
getJobInfo := func(context.Context, string) (*utils.RayJobInfo, error) { //nolint:unparam // This is a mock function so parameters are required
499-
return &utils.RayJobInfo{JobStatus: rayv1.JobStatusSucceeded, EndTime: uint64(time.Now().UnixMilli())}, nil
499+
getJobInfo := func(context.Context, string) (*utiltypes.RayJobInfo, error) { //nolint:unparam // This is a mock function so parameters are required
500+
return &utiltypes.RayJobInfo{JobStatus: rayv1.JobStatusSucceeded, EndTime: uint64(time.Now().UnixMilli())}, nil
500501
}
501502
fakeRayDashboardClient.GetJobInfoMock.Store(&getJobInfo)
502503
defer fakeRayDashboardClient.GetJobInfoMock.Store(nil)
@@ -660,8 +661,8 @@ var _ = Context("RayJob with different submission modes", func() {
660661
It("RayJobs's JobDeploymentStatus transitions from Running -> Retrying -> New -> Initializing", func() {
661662
// Update fake dashboard client to return job info with "Failed" status.
662663
//nolint:unparam // this is a mock and the function signature cannot change
663-
getJobInfo := func(context.Context, string) (*utils.RayJobInfo, error) {
664-
return &utils.RayJobInfo{JobStatus: rayv1.JobStatusFailed, EndTime: uint64(time.Now().UnixMilli())}, nil
664+
getJobInfo := func(context.Context, string) (*utiltypes.RayJobInfo, error) {
665+
return &utiltypes.RayJobInfo{JobStatus: rayv1.JobStatusFailed, EndTime: uint64(time.Now().UnixMilli())}, nil
665666
}
666667
fakeRayDashboardClient.GetJobInfoMock.Store(&getJobInfo)
667668
defer fakeRayDashboardClient.GetJobInfoMock.Store(nil)
@@ -755,8 +756,8 @@ var _ = Context("RayJob with different submission modes", func() {
755756
It("RayJobs's JobDeploymentStatus transitions from Running -> Complete (attempt 2)", func() {
756757
// Update fake dashboard client to return job info with "Failed" status.
757758
//nolint:unparam // this is a mock and the function signature cannot change
758-
getJobInfo := func(context.Context, string) (*utils.RayJobInfo, error) {
759-
return &utils.RayJobInfo{JobStatus: rayv1.JobStatusSucceeded, EndTime: uint64(time.Now().UnixMilli())}, nil
759+
getJobInfo := func(context.Context, string) (*utiltypes.RayJobInfo, error) {
760+
return &utiltypes.RayJobInfo{JobStatus: rayv1.JobStatusSucceeded, EndTime: uint64(time.Now().UnixMilli())}, nil
760761
}
761762
fakeRayDashboardClient.GetJobInfoMock.Store(&getJobInfo)
762763
defer fakeRayDashboardClient.GetJobInfoMock.Store(nil)
@@ -982,8 +983,8 @@ var _ = Context("RayJob with different submission modes", func() {
982983

983984
By("RayJobs's JobDeploymentStatus transitions from Running to Complete.", func() {
984985
// Update fake dashboard client to return job info with "Succeeded" status.
985-
getJobInfo := func(context.Context, string) (*utils.RayJobInfo, error) { //nolint:unparam // This is a mock function so parameters are required
986-
return &utils.RayJobInfo{JobStatus: rayv1.JobStatusSucceeded, EndTime: uint64(time.Now().UnixMilli())}, nil
986+
getJobInfo := func(context.Context, string) (*utiltypes.RayJobInfo, error) { //nolint:unparam // This is a mock function so parameters are required
987+
return &utiltypes.RayJobInfo{JobStatus: rayv1.JobStatusSucceeded, EndTime: uint64(time.Now().UnixMilli())}, nil
987988
}
988989
fakeRayDashboardClient.GetJobInfoMock.Store(&getJobInfo)
989990
defer fakeRayDashboardClient.GetJobInfoMock.Store(nil)
@@ -1121,8 +1122,8 @@ var _ = Context("RayJob with different submission modes", func() {
11211122

11221123
By("RayJobs's JobDeploymentStatus transitions from Running to Complete.", func() {
11231124
// Update fake dashboard client to return job info with "Failed" status.
1124-
getJobInfo := func(context.Context, string) (*utils.RayJobInfo, error) { //nolint:unparam // This is a mock function so parameters are required
1125-
return &utils.RayJobInfo{JobStatus: rayv1.JobStatusFailed, EndTime: uint64(time.Now().UnixMilli())}, nil
1125+
getJobInfo := func(context.Context, string) (*utiltypes.RayJobInfo, error) { //nolint:unparam // This is a mock function so parameters are required
1126+
return &utiltypes.RayJobInfo{JobStatus: rayv1.JobStatusFailed, EndTime: uint64(time.Now().UnixMilli())}, nil
11261127
}
11271128
fakeRayDashboardClient.GetJobInfoMock.Store(&getJobInfo)
11281129
defer fakeRayDashboardClient.GetJobInfoMock.Store(nil)
@@ -1260,8 +1261,8 @@ var _ = Context("RayJob with different submission modes", func() {
12601261

12611262
By("RayJobs's JobDeploymentStatus transitions from Running to Complete.", func() {
12621263
// Update fake dashboard client to return job info with "Succeeded" status.
1263-
getJobInfo := func(context.Context, string) (*utils.RayJobInfo, error) { //nolint:unparam // This is a mock function so parameters are required
1264-
return &utils.RayJobInfo{JobStatus: rayv1.JobStatusSucceeded, EndTime: uint64(time.Now().UnixMilli())}, nil
1264+
getJobInfo := func(context.Context, string) (*utiltypes.RayJobInfo, error) { //nolint:unparam // This is a mock function so parameters are required
1265+
return &utiltypes.RayJobInfo{JobStatus: rayv1.JobStatusSucceeded, EndTime: uint64(time.Now().UnixMilli())}, nil
12651266
}
12661267
fakeRayDashboardClient.GetJobInfoMock.Store(&getJobInfo)
12671268
defer fakeRayDashboardClient.GetJobInfoMock.Store(nil)
@@ -1416,8 +1417,8 @@ var _ = Context("RayJob with different submission modes", func() {
14161417

14171418
By("RayJobs's JobDeploymentStatus transitions from Running to Complete.", func() {
14181419
// Update fake dashboard client to return job info with "Failed" status.
1419-
getJobInfo := func(context.Context, string) (*utils.RayJobInfo, error) { //nolint:unparam // This is a mock function so parameters are required
1420-
return &utils.RayJobInfo{JobStatus: rayv1.JobStatusFailed, EndTime: uint64(time.Now().UnixMilli())}, nil
1420+
getJobInfo := func(context.Context, string) (*utiltypes.RayJobInfo, error) { //nolint:unparam // This is a mock function so parameters are required
1421+
return &utiltypes.RayJobInfo{JobStatus: rayv1.JobStatusFailed, EndTime: uint64(time.Now().UnixMilli())}, nil
14211422
}
14221423
fakeRayDashboardClient.GetJobInfoMock.Store(&getJobInfo)
14231424
defer fakeRayDashboardClient.GetJobInfoMock.Store(nil)
@@ -1561,8 +1562,8 @@ var _ = Context("RayJob with different submission modes", func() {
15611562

15621563
By("RayJobs's JobDeploymentStatus transitions from Running to Complete.", func() {
15631564
// Update fake dashboard client to return job info with "Succeeded" status.
1564-
getJobInfo := func(context.Context, string) (*utils.RayJobInfo, error) { //nolint:unparam // This is a mock function so parameters are required
1565-
return &utils.RayJobInfo{JobStatus: rayv1.JobStatusSucceeded, EndTime: uint64(time.Now().UnixMilli())}, nil
1565+
getJobInfo := func(context.Context, string) (*utiltypes.RayJobInfo, error) { //nolint:unparam // This is a mock function so parameters are required
1566+
return &utiltypes.RayJobInfo{JobStatus: rayv1.JobStatusSucceeded, EndTime: uint64(time.Now().UnixMilli())}, nil
15661567
}
15671568
fakeRayDashboardClient.GetJobInfoMock.Store(&getJobInfo)
15681569

@@ -1677,8 +1678,8 @@ var _ = Context("RayJob with different submission modes", func() {
16771678

16781679
By("RayJobs's JobDeploymentStatus transitions from Running to Complete.", func() {
16791680
// Update fake dashboard client to return job info with "Failed" status.
1680-
getJobInfo := func(context.Context, string) (*utils.RayJobInfo, error) { //nolint:unparam // This is a mock function so parameters are required
1681-
return &utils.RayJobInfo{JobStatus: rayv1.JobStatusFailed, EndTime: uint64(time.Now().UnixMilli())}, nil
1681+
getJobInfo := func(context.Context, string) (*utiltypes.RayJobInfo, error) { //nolint:unparam // This is a mock function so parameters are required
1682+
return &utiltypes.RayJobInfo{JobStatus: rayv1.JobStatusFailed, EndTime: uint64(time.Now().UnixMilli())}, nil
16821683
}
16831684
fakeRayDashboardClient.GetJobInfoMock.Store(&getJobInfo)
16841685

@@ -1804,8 +1805,8 @@ var _ = Context("RayJob with different submission modes", func() {
18041805

18051806
By("RayJobs's JobDeploymentStatus transitions from Running to Complete.", func() {
18061807
// Update fake dashboard client to return job info with "Succeeded" status.
1807-
getJobInfo := func(context.Context, string) (*utils.RayJobInfo, error) { //nolint:unparam // This is a mock function so parameters are required
1808-
return &utils.RayJobInfo{JobStatus: rayv1.JobStatusSucceeded, EndTime: uint64(time.Now().UnixMilli())}, nil
1808+
getJobInfo := func(context.Context, string) (*utiltypes.RayJobInfo, error) { //nolint:unparam // This is a mock function so parameters are required
1809+
return &utiltypes.RayJobInfo{JobStatus: rayv1.JobStatusSucceeded, EndTime: uint64(time.Now().UnixMilli())}, nil
18091810
}
18101811
fakeRayDashboardClient.GetJobInfoMock.Store(&getJobInfo)
18111812
defer fakeRayDashboardClient.GetJobInfoMock.Store(nil)
@@ -1965,8 +1966,8 @@ var _ = Context("RayJob with different submission modes", func() {
19651966

19661967
By("RayJobs's JobDeploymentStatus transitions from Running to Complete.", func() {
19671968
// Update fake dashboard client to return job info with "Failed" status.
1968-
getJobInfo := func(context.Context, string) (*utils.RayJobInfo, error) { //nolint:unparam // This is a mock function so parameters are required
1969-
return &utils.RayJobInfo{JobStatus: rayv1.JobStatusFailed, EndTime: uint64(time.Now().UnixMilli())}, nil
1969+
getJobInfo := func(context.Context, string) (*utiltypes.RayJobInfo, error) { //nolint:unparam // This is a mock function so parameters are required
1970+
return &utiltypes.RayJobInfo{JobStatus: rayv1.JobStatusFailed, EndTime: uint64(time.Now().UnixMilli())}, nil
19701971
}
19711972
fakeRayDashboardClient.GetJobInfoMock.Store(&getJobInfo)
19721973
defer fakeRayDashboardClient.GetJobInfoMock.Store(nil)

ray-operator/controllers/ray/rayservice_controller.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232
rayv1 "github.com/ray-project/kuberay/ray-operator/apis/ray/v1"
3333
"github.com/ray-project/kuberay/ray-operator/controllers/ray/common"
3434
"github.com/ray-project/kuberay/ray-operator/controllers/ray/utils"
35+
utiltypes "github.com/ray-project/kuberay/ray-operator/controllers/ray/utils/types"
3536
"github.com/ray-project/kuberay/ray-operator/pkg/features"
3637
)
3738

@@ -773,7 +774,7 @@ func (r *RayServiceReconciler) updateServeDeployment(ctx context.Context, raySer
773774
// (3) `err`: If `err` is not nil, it means that KubeRay failed to get Serve application statuses from the dashboard.
774775
func getAndCheckServeStatus(ctx context.Context, dashboardClient utils.RayDashboardClientInterface) (bool, map[string]rayv1.AppStatus, error) {
775776
logger := ctrl.LoggerFrom(ctx)
776-
var serveAppStatuses map[string]*utils.ServeApplicationStatus
777+
var serveAppStatuses map[string]*utiltypes.ServeApplicationStatus
777778
var err error
778779
if serveAppStatuses, err = dashboardClient.GetMultiApplicationStatus(ctx); err != nil {
779780
err = fmt.Errorf(

ray-operator/controllers/ray/rayservice_controller_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import (
3434

3535
rayv1 "github.com/ray-project/kuberay/ray-operator/apis/ray/v1"
3636
"github.com/ray-project/kuberay/ray-operator/controllers/ray/utils"
37+
utiltypes "github.com/ray-project/kuberay/ray-operator/controllers/ray/utils/types"
3738
"github.com/ray-project/kuberay/ray-operator/test/support"
3839
)
3940

@@ -405,7 +406,7 @@ var _ = Context("RayService env tests", func() {
405406

406407
// Update the fake Ray dashboard client to return serve application statuses with the new serve application.
407408
healthyStatus := generateServeStatus(rayv1.DeploymentStatusEnum.HEALTHY, rayv1.ApplicationStatusEnum.RUNNING)
408-
fakeRayDashboardClient.SetMultiApplicationStatuses(map[string]*utils.ServeApplicationStatus{newServeAppName: &healthyStatus})
409+
fakeRayDashboardClient.SetMultiApplicationStatuses(map[string]*utiltypes.ServeApplicationStatus{newServeAppName: &healthyStatus})
409410
})
410411

411412
It("New serve application should be shown in the RayService status", func() {

ray-operator/controllers/ray/rayservice_controller_unit_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
rayv1 "github.com/ray-project/kuberay/ray-operator/apis/ray/v1"
2525
"github.com/ray-project/kuberay/ray-operator/controllers/ray/common"
2626
"github.com/ray-project/kuberay/ray-operator/controllers/ray/utils"
27+
utiltypes "github.com/ray-project/kuberay/ray-operator/controllers/ray/utils/types"
2728
"github.com/ray-project/kuberay/ray-operator/pkg/client/clientset/versioned/scheme"
2829
"github.com/ray-project/kuberay/ray-operator/test/support"
2930
)
@@ -588,7 +589,7 @@ func TestReconcileRayCluster_UpdatePendingCluster(t *testing.T) {
588589
func initFakeDashboardClient(appName string, deploymentStatus string, appStatus string) utils.RayDashboardClientInterface {
589590
fakeDashboardClient := utils.FakeRayDashboardClient{}
590591
status := generateServeStatus(deploymentStatus, appStatus)
591-
fakeDashboardClient.SetMultiApplicationStatuses(map[string]*utils.ServeApplicationStatus{appName: &status})
592+
fakeDashboardClient.SetMultiApplicationStatuses(map[string]*utiltypes.ServeApplicationStatus{appName: &status})
592593
return &fakeDashboardClient
593594
}
594595

ray-operator/controllers/ray/suite_helpers_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
rayv1 "github.com/ray-project/kuberay/ray-operator/apis/ray/v1"
1616
"github.com/ray-project/kuberay/ray-operator/controllers/ray/common"
1717
"github.com/ray-project/kuberay/ray-operator/controllers/ray/utils"
18+
utiltypes "github.com/ray-project/kuberay/ray-operator/controllers/ray/utils/types"
1819
)
1920

2021
func getResourceFunc(ctx context.Context, key client.ObjectKey, obj client.Object) func() error {
@@ -133,15 +134,15 @@ func prepareFakeRayDashboardClient() *utils.FakeRayDashboardClient {
133134
client := &utils.FakeRayDashboardClient{}
134135

135136
healthyStatus := generateServeStatus(rayv1.DeploymentStatusEnum.HEALTHY, rayv1.ApplicationStatusEnum.RUNNING)
136-
client.SetMultiApplicationStatuses(map[string]*utils.ServeApplicationStatus{"app": &healthyStatus})
137+
client.SetMultiApplicationStatuses(map[string]*utiltypes.ServeApplicationStatus{"app": &healthyStatus})
137138

138139
return client
139140
}
140141

141-
func generateServeStatus(deploymentStatus string, applicationStatus string) utils.ServeApplicationStatus {
142-
return utils.ServeApplicationStatus{
142+
func generateServeStatus(deploymentStatus string, applicationStatus string) utiltypes.ServeApplicationStatus {
143+
return utiltypes.ServeApplicationStatus{
143144
Status: applicationStatus,
144-
Deployments: map[string]utils.ServeDeploymentStatus{
145+
Deployments: map[string]utiltypes.ServeDeploymentStatus{
145146
"shallow": {
146147
Name: "shallow",
147148
Status: deploymentStatus,

0 commit comments

Comments
 (0)