Skip to content

Commit 0b0573b

Browse files
authored
[refactor][4/N] Remove ctrl in dashboard http client in dashboard-httpclient.go (#4009)
Signed-off-by: You-Cheng Lin (Owen) <[email protected]>
1 parent a614b1d commit 0b0573b

File tree

3 files changed

+9
-23
lines changed

3 files changed

+9
-23
lines changed

apiserver/pkg/server/ray_job_submission_service_server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func (s *RayJobSubmissionServiceServer) SubmitRayJob(ctx context.Context, req *a
8989
}
9090
}
9191

92-
sid, err := rayDashboardClient.SubmitJobReq(ctx, request, nil)
92+
sid, err := rayDashboardClient.SubmitJobReq(ctx, request)
9393
if err != nil {
9494
return nil, err
9595
}

ray-operator/controllers/ray/utils/dashboard_httpclient.go

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"k8s.io/apimachinery/pkg/api/errors"
1111
"k8s.io/apimachinery/pkg/util/json"
1212
"k8s.io/apimachinery/pkg/util/yaml"
13-
ctrl "sigs.k8s.io/controller-runtime"
1413

1514
rayv1 "github.com/ray-project/kuberay/ray-operator/apis/ray/v1"
1615
)
@@ -31,7 +30,7 @@ type RayDashboardClientInterface interface {
3130
GetJobInfo(ctx context.Context, jobId string) (*RayJobInfo, error)
3231
ListJobs(ctx context.Context) (*[]RayJobInfo, error)
3332
SubmitJob(ctx context.Context, rayJob *rayv1.RayJob) (string, error)
34-
SubmitJobReq(ctx context.Context, request *RayJobRequest, name *string) (string, error)
33+
SubmitJobReq(ctx context.Context, request *RayJobRequest) (string, error)
3534
GetJobLog(ctx context.Context, jobName string) (*string, error)
3635
StopJob(ctx context.Context, jobName string) error
3736
DeleteJob(ctx context.Context, jobName string) error
@@ -72,7 +71,7 @@ func (r *RayDashboardClient) UpdateDeployments(ctx context.Context, configJson [
7271
func (r *RayDashboardClient) GetMultiApplicationStatus(ctx context.Context) (map[string]*ServeApplicationStatus, error) {
7372
serveDetails, err := r.GetServeDetails(ctx)
7473
if err != nil {
75-
return nil, fmt.Errorf("Failed to get serve details: %w", err)
74+
return nil, fmt.Errorf("failed to get serve details: %w", err)
7675
}
7776

7877
return r.ConvertServeDetailsToApplicationStatuses(serveDetails)
@@ -111,12 +110,12 @@ func (r *RayDashboardClient) GetServeDetails(ctx context.Context) (*ServeDetails
111110
func (r *RayDashboardClient) ConvertServeDetailsToApplicationStatuses(serveDetails *ServeDetails) (map[string]*ServeApplicationStatus, error) {
112111
detailsJson, err := json.Marshal(serveDetails.Applications)
113112
if err != nil {
114-
return nil, fmt.Errorf("Failed to marshal serve details: %v", serveDetails.Applications)
113+
return nil, fmt.Errorf("failed to marshal serve details: %v", serveDetails.Applications)
115114
}
116115

117116
applicationStatuses := map[string]*ServeApplicationStatus{}
118117
if err = json.Unmarshal(detailsJson, &applicationStatuses); err != nil {
119-
return nil, fmt.Errorf("Failed to unmarshal serve details bytes into map of application statuses: %w. Bytes: %s", err, string(detailsJson))
118+
return nil, fmt.Errorf("failed to unmarshal serve details bytes into map of application statuses: %w. Bytes: %s", err, string(detailsJson))
120119
}
121120

122121
return applicationStatuses, nil
@@ -232,18 +231,14 @@ func (r *RayDashboardClient) SubmitJob(ctx context.Context, rayJob *rayv1.RayJob
232231
if err != nil {
233232
return "", err
234233
}
235-
return r.SubmitJobReq(ctx, request, &rayJob.Name)
234+
return r.SubmitJobReq(ctx, request)
236235
}
237236

238-
func (r *RayDashboardClient) SubmitJobReq(ctx context.Context, request *RayJobRequest, name *string) (jobId string, err error) {
239-
log := ctrl.LoggerFrom(ctx)
237+
func (r *RayDashboardClient) SubmitJobReq(ctx context.Context, request *RayJobRequest) (jobId string, err error) {
240238
rayJobJson, err := json.Marshal(request)
241239
if err != nil {
242240
return
243241
}
244-
if name != nil {
245-
log.Info("Submit a ray job", "rayJob", name, "jobInfo", string(rayJobJson))
246-
}
247242

248243
req, err := http.NewRequestWithContext(ctx, http.MethodPost, r.dashboardURL+JobPath, bytes.NewBuffer(rayJobJson))
249244
if err != nil {
@@ -277,9 +272,6 @@ func (r *RayDashboardClient) SubmitJobReq(ctx context.Context, request *RayJobRe
277272

278273
// Get Job Log
279274
func (r *RayDashboardClient) GetJobLog(ctx context.Context, jobName string) (*string, error) {
280-
log := ctrl.LoggerFrom(ctx)
281-
log.Info("Get ray job log", "rayJob", jobName)
282-
283275
req, err := http.NewRequestWithContext(ctx, http.MethodGet, r.dashboardURL+JobPath+jobName+"/logs", nil)
284276
if err != nil {
285277
return nil, err
@@ -311,9 +303,6 @@ func (r *RayDashboardClient) GetJobLog(ctx context.Context, jobName string) (*st
311303
}
312304

313305
func (r *RayDashboardClient) StopJob(ctx context.Context, jobName string) (err error) {
314-
log := ctrl.LoggerFrom(ctx)
315-
log.Info("Stop a ray job", "rayJob", jobName)
316-
317306
req, err := http.NewRequestWithContext(ctx, http.MethodPost, r.dashboardURL+JobPath+jobName+"/stop", nil)
318307
if err != nil {
319308
return err
@@ -343,16 +332,13 @@ func (r *RayDashboardClient) StopJob(ctx context.Context, jobName string) (err e
343332
}
344333
// StopJob only returns an error when JobStatus is not in terminal states (STOPPED / SUCCEEDED / FAILED)
345334
if !rayv1.IsJobTerminal(jobInfo.JobStatus) {
346-
return fmt.Errorf("Failed to stopped job: %v", jobInfo)
335+
return fmt.Errorf("failed to stop job: %v", jobInfo)
347336
}
348337
}
349338
return nil
350339
}
351340

352341
func (r *RayDashboardClient) DeleteJob(ctx context.Context, jobName string) error {
353-
log := ctrl.LoggerFrom(ctx)
354-
log.Info("Delete a ray job", "rayJob", jobName)
355-
356342
req, err := http.NewRequestWithContext(ctx, http.MethodDelete, r.dashboardURL+JobPath+jobName, nil)
357343
if err != nil {
358344
return err

ray-operator/controllers/ray/utils/fake_serve_httpclient.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func (r *FakeRayDashboardClient) SubmitJob(_ context.Context, _ *rayv1.RayJob) (
5555
return "", nil
5656
}
5757

58-
func (r *FakeRayDashboardClient) SubmitJobReq(_ context.Context, _ *RayJobRequest, _ *string) (string, error) {
58+
func (r *FakeRayDashboardClient) SubmitJobReq(_ context.Context, _ *RayJobRequest) (string, error) {
5959
return "", nil
6060
}
6161

0 commit comments

Comments
 (0)