From be2ad25db1e54b30386186ee899d61fe17e16dd9 Mon Sep 17 00:00:00 2001 From: "You-Cheng Lin (Owen)" Date: Tue, 26 Aug 2025 08:33:49 +0000 Subject: [PATCH 1/3] moved Signed-off-by: You-Cheng Lin (Owen) --- .../controllers/ray/utils/dashboard_httpclient.go | 9 --------- ray-operator/controllers/ray/utils/util.go | 9 +++++++++ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/ray-operator/controllers/ray/utils/dashboard_httpclient.go b/ray-operator/controllers/ray/utils/dashboard_httpclient.go index a6e82775d45..10f437ecaf7 100644 --- a/ray-operator/controllers/ray/utils/dashboard_httpclient.go +++ b/ray-operator/controllers/ray/utils/dashboard_httpclient.go @@ -10,7 +10,6 @@ import ( "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/util/json" - "k8s.io/apimachinery/pkg/util/yaml" ctrl "sigs.k8s.io/controller-runtime" rayv1 "github.com/ray-project/kuberay/ray-operator/apis/ray/v1" @@ -434,11 +433,3 @@ func ConvertRayJobToReq(rayJob *rayv1.RayJob) (*RayJobRequest, error) { } return req, nil } - -func UnmarshalRuntimeEnvYAML(runtimeEnvYAML string) (RuntimeEnvType, error) { - var runtimeEnv RuntimeEnvType - if err := yaml.Unmarshal([]byte(runtimeEnvYAML), &runtimeEnv); err != nil { - return nil, fmt.Errorf("failed to unmarshal RuntimeEnvYAML: %v: %w", runtimeEnvYAML, err) - } - return runtimeEnv, nil -} diff --git a/ray-operator/controllers/ray/utils/util.go b/ray-operator/controllers/ray/utils/util.go index df2efe0fc39..5653904bd0d 100644 --- a/ray-operator/controllers/ray/utils/util.go +++ b/ray-operator/controllers/ray/utils/util.go @@ -18,6 +18,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/json" "k8s.io/apimachinery/pkg/util/rand" + "k8s.io/apimachinery/pkg/util/yaml" "k8s.io/client-go/discovery" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" @@ -754,3 +755,11 @@ func FetchHeadServiceURL(ctx context.Context, cli client.Client, rayCluster *ray port) return headServiceURL, nil } + +func UnmarshalRuntimeEnvYAML(runtimeEnvYAML string) (RuntimeEnvType, error) { + var runtimeEnv RuntimeEnvType + if err := yaml.Unmarshal([]byte(runtimeEnvYAML), &runtimeEnv); err != nil { + return nil, fmt.Errorf("failed to unmarshal RuntimeEnvYAML: %v: %w", runtimeEnvYAML, err) + } + return runtimeEnv, nil +} From 19af4b0a43a9ef0cee6c24e05ce012521fd89bd1 Mon Sep 17 00:00:00 2001 From: "You-Cheng Lin (Owen)" Date: Thu, 28 Aug 2025 01:23:23 +0000 Subject: [PATCH 2/3] remove-unmarshall-envyaml Signed-off-by: You-Cheng Lin (Owen) --- ray-operator/apis/ray/v1/rayjob_types.go | 2 + .../ray/utils/dashboard_httpclient.go | 5 ++- ray-operator/controllers/ray/utils/util.go | 9 ----- .../controllers/ray/utils/util_test.go | 38 ------------------- .../controllers/ray/utils/validation.go | 4 +- 5 files changed, 8 insertions(+), 50 deletions(-) diff --git a/ray-operator/apis/ray/v1/rayjob_types.go b/ray-operator/apis/ray/v1/rayjob_types.go index 1ada1e1ae7d..35e3ca01a97 100644 --- a/ray-operator/apis/ray/v1/rayjob_types.go +++ b/ray-operator/apis/ray/v1/rayjob_types.go @@ -281,6 +281,8 @@ type RayJobList struct { Items []RayJob `json:"items"` } +type RuntimeEnvType map[string]interface{} + func init() { SchemeBuilder.Register(&RayJob{}, &RayJobList{}) } diff --git a/ray-operator/controllers/ray/utils/dashboard_httpclient.go b/ray-operator/controllers/ray/utils/dashboard_httpclient.go index 10f437ecaf7..31838974d9b 100644 --- a/ray-operator/controllers/ray/utils/dashboard_httpclient.go +++ b/ray-operator/controllers/ray/utils/dashboard_httpclient.go @@ -10,6 +10,7 @@ import ( "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/util/json" + "k8s.io/apimachinery/pkg/util/yaml" ctrl "sigs.k8s.io/controller-runtime" rayv1 "github.com/ray-project/kuberay/ray-operator/apis/ray/v1" @@ -418,8 +419,8 @@ func ConvertRayJobToReq(rayJob *rayv1.RayJob) (*RayJobRequest, error) { Metadata: rayJob.Spec.Metadata, } if len(rayJob.Spec.RuntimeEnvYAML) != 0 { - runtimeEnv, err := UnmarshalRuntimeEnvYAML(rayJob.Spec.RuntimeEnvYAML) - if err != nil { + var runtimeEnv RuntimeEnvType + if err := yaml.Unmarshal([]byte(rayJob.Spec.RuntimeEnvYAML), &runtimeEnv); err != nil { return nil, err } req.RuntimeEnv = runtimeEnv diff --git a/ray-operator/controllers/ray/utils/util.go b/ray-operator/controllers/ray/utils/util.go index 5653904bd0d..df2efe0fc39 100644 --- a/ray-operator/controllers/ray/utils/util.go +++ b/ray-operator/controllers/ray/utils/util.go @@ -18,7 +18,6 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/json" "k8s.io/apimachinery/pkg/util/rand" - "k8s.io/apimachinery/pkg/util/yaml" "k8s.io/client-go/discovery" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" @@ -755,11 +754,3 @@ func FetchHeadServiceURL(ctx context.Context, cli client.Client, rayCluster *ray port) return headServiceURL, nil } - -func UnmarshalRuntimeEnvYAML(runtimeEnvYAML string) (RuntimeEnvType, error) { - var runtimeEnv RuntimeEnvType - if err := yaml.Unmarshal([]byte(runtimeEnvYAML), &runtimeEnv); err != nil { - return nil, fmt.Errorf("failed to unmarshal RuntimeEnvYAML: %v: %w", runtimeEnvYAML, err) - } - return runtimeEnv, nil -} diff --git a/ray-operator/controllers/ray/utils/util_test.go b/ray-operator/controllers/ray/utils/util_test.go index 15e5729edda..920d8a9aa57 100644 --- a/ray-operator/controllers/ray/utils/util_test.go +++ b/ray-operator/controllers/ray/utils/util_test.go @@ -794,44 +794,6 @@ func TestCalculateDesiredReplicas(t *testing.T) { } } -func TestUnmarshalRuntimeEnv(t *testing.T) { - tests := []struct { - name string - runtimeEnvYAML string - isErrorNil bool - }{ - { - name: "Empty runtimeEnvYAML", - runtimeEnvYAML: "", - isErrorNil: true, - }, - { - name: "Valid runtimeEnvYAML", - runtimeEnvYAML: ` -env_vars: - counter_name: test_counter -`, - isErrorNil: true, - }, - { - name: "Invalid runtimeEnvYAML", - runtimeEnvYAML: `invalid_yaml_str`, - isErrorNil: false, - }, - } - - for _, tc := range tests { - t.Run(tc.name, func(t *testing.T) { - _, err := UnmarshalRuntimeEnvYAML(tc.runtimeEnvYAML) - if tc.isErrorNil { - require.NoError(t, err) - } else { - require.Error(t, err) - } - }) - } -} - func TestFindHeadPodReadyCondition(t *testing.T) { tests := []struct { name string diff --git a/ray-operator/controllers/ray/utils/validation.go b/ray-operator/controllers/ray/utils/validation.go index 88e3c0cd1c5..d90e0fbb1ba 100644 --- a/ray-operator/controllers/ray/utils/validation.go +++ b/ray-operator/controllers/ray/utils/validation.go @@ -8,6 +8,7 @@ import ( "k8s.io/apimachinery/pkg/api/meta" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/validation" + "k8s.io/apimachinery/pkg/util/yaml" rayv1 "github.com/ray-project/kuberay/ray-operator/apis/ray/v1" "github.com/ray-project/kuberay/ray-operator/pkg/features" @@ -190,7 +191,8 @@ func ValidateRayJobSpec(rayJob *rayv1.RayJob) error { // Validate whether RuntimeEnvYAML is a valid YAML string. Note that this only checks its validity // as a YAML string, not its adherence to the runtime environment schema. - if _, err := UnmarshalRuntimeEnvYAML(rayJob.Spec.RuntimeEnvYAML); err != nil { + var runtimeEnv RuntimeEnvType + if err := yaml.Unmarshal([]byte(rayJob.Spec.RuntimeEnvYAML), &runtimeEnv); err != nil { return err } if rayJob.Spec.ActiveDeadlineSeconds != nil && *rayJob.Spec.ActiveDeadlineSeconds <= 0 { From e9d9f0dd4dcf1c97e9ce5718adb506971da3dc0e Mon Sep 17 00:00:00 2001 From: "You-Cheng Lin (Owen)" Date: Thu, 28 Aug 2025 01:47:19 +0000 Subject: [PATCH 3/3] move RuntimeEnvType in to utiltype package Signed-off-by: You-Cheng Lin (Owen) --- .../ray_job_submission_service_server_test.go | 3 +- ray-operator/apis/ray/v1/rayjob_types.go | 2 - .../ray/utils/dashboard_httpclient.go | 39 +++++++++---------- .../ray/utils/types/dashboard_httpclient.go | 3 ++ .../controllers/ray/utils/validation.go | 4 +- 5 files changed, 26 insertions(+), 25 deletions(-) create mode 100644 ray-operator/controllers/ray/utils/types/dashboard_httpclient.go diff --git a/apiserver/pkg/server/ray_job_submission_service_server_test.go b/apiserver/pkg/server/ray_job_submission_service_server_test.go index 33bf3980409..7eab9332c68 100644 --- a/apiserver/pkg/server/ray_job_submission_service_server_test.go +++ b/apiserver/pkg/server/ray_job_submission_service_server_test.go @@ -18,6 +18,7 @@ import ( api "github.com/ray-project/kuberay/proto/go_client" rayv1 "github.com/ray-project/kuberay/ray-operator/apis/ray/v1" "github.com/ray-project/kuberay/ray-operator/controllers/ray/utils" + utiltypes "github.com/ray-project/kuberay/ray-operator/controllers/ray/utils/types" fakeclientset "github.com/ray-project/kuberay/ray-operator/pkg/client/clientset/versioned/fake" ) @@ -179,7 +180,7 @@ func TestConvertNodeInfo(t *testing.T) { metadata := map[string]string{ "foo": "boo", } - runtimeEnv := utils.RuntimeEnvType{ + runtimeEnv := utiltypes.RuntimeEnvType{ "working_dir": "/tmp/workdir", "pip": []string{"numpy", "pandas"}, } diff --git a/ray-operator/apis/ray/v1/rayjob_types.go b/ray-operator/apis/ray/v1/rayjob_types.go index 35e3ca01a97..1ada1e1ae7d 100644 --- a/ray-operator/apis/ray/v1/rayjob_types.go +++ b/ray-operator/apis/ray/v1/rayjob_types.go @@ -281,8 +281,6 @@ type RayJobList struct { Items []RayJob `json:"items"` } -type RuntimeEnvType map[string]interface{} - func init() { SchemeBuilder.Register(&RayJob{}, &RayJobList{}) } diff --git a/ray-operator/controllers/ray/utils/dashboard_httpclient.go b/ray-operator/controllers/ray/utils/dashboard_httpclient.go index 31838974d9b..58ad14cdd3e 100644 --- a/ray-operator/controllers/ray/utils/dashboard_httpclient.go +++ b/ray-operator/controllers/ray/utils/dashboard_httpclient.go @@ -14,6 +14,7 @@ import ( ctrl "sigs.k8s.io/controller-runtime" rayv1 "github.com/ray-project/kuberay/ray-operator/apis/ray/v1" + utiltypes "github.com/ray-project/kuberay/ray-operator/controllers/ray/utils/types" ) var ( @@ -166,35 +167,33 @@ func (r *RayDashboardClient) ConvertServeDetailsToApplicationStatuses(serveDetai return applicationStatuses, nil } -type RuntimeEnvType map[string]interface{} - // RayJobInfo is the response of "ray job status" api. // Reference to https://docs.ray.io/en/latest/cluster/running-applications/job-submission/rest.html#ray-job-rest-api-spec // Reference to https://github.com/ray-project/ray/blob/cfbf98c315cfb2710c56039a3c96477d196de049/dashboard/modules/job/pydantic_models.py#L38-L107 type RayJobInfo struct { - ErrorType *string `json:"error_type,omitempty"` - Metadata map[string]string `json:"metadata,omitempty"` - RuntimeEnv RuntimeEnvType `json:"runtime_env,omitempty"` - JobStatus rayv1.JobStatus `json:"status,omitempty"` - Entrypoint string `json:"entrypoint,omitempty"` - JobId string `json:"job_id,omitempty"` - SubmissionId string `json:"submission_id,omitempty"` - Message string `json:"message,omitempty"` - StartTime uint64 `json:"start_time,omitempty"` - EndTime uint64 `json:"end_time,omitempty"` + ErrorType *string `json:"error_type,omitempty"` + Metadata map[string]string `json:"metadata,omitempty"` + RuntimeEnv utiltypes.RuntimeEnvType `json:"runtime_env,omitempty"` + JobStatus rayv1.JobStatus `json:"status,omitempty"` + Entrypoint string `json:"entrypoint,omitempty"` + JobId string `json:"job_id,omitempty"` + SubmissionId string `json:"submission_id,omitempty"` + Message string `json:"message,omitempty"` + StartTime uint64 `json:"start_time,omitempty"` + EndTime uint64 `json:"end_time,omitempty"` } // RayJobRequest is the request body to submit. // Reference to https://docs.ray.io/en/latest/cluster/running-applications/job-submission/rest.html#ray-job-rest-api-spec // Reference to https://github.com/ray-project/ray/blob/cfbf98c315cfb2710c56039a3c96477d196de049/dashboard/modules/job/common.py#L325-L353 type RayJobRequest struct { - RuntimeEnv RuntimeEnvType `json:"runtime_env,omitempty"` - Metadata map[string]string `json:"metadata,omitempty"` - Resources map[string]float32 `json:"entrypoint_resources,omitempty"` - Entrypoint string `json:"entrypoint"` - SubmissionId string `json:"submission_id,omitempty"` - NumCpus float32 `json:"entrypoint_num_cpus,omitempty"` - NumGpus float32 `json:"entrypoint_num_gpus,omitempty"` + RuntimeEnv utiltypes.RuntimeEnvType `json:"runtime_env,omitempty"` + Metadata map[string]string `json:"metadata,omitempty"` + Resources map[string]float32 `json:"entrypoint_resources,omitempty"` + Entrypoint string `json:"entrypoint"` + SubmissionId string `json:"submission_id,omitempty"` + NumCpus float32 `json:"entrypoint_num_cpus,omitempty"` + NumGpus float32 `json:"entrypoint_num_gpus,omitempty"` } type RayJobResponse struct { @@ -419,7 +418,7 @@ func ConvertRayJobToReq(rayJob *rayv1.RayJob) (*RayJobRequest, error) { Metadata: rayJob.Spec.Metadata, } if len(rayJob.Spec.RuntimeEnvYAML) != 0 { - var runtimeEnv RuntimeEnvType + var runtimeEnv utiltypes.RuntimeEnvType if err := yaml.Unmarshal([]byte(rayJob.Spec.RuntimeEnvYAML), &runtimeEnv); err != nil { return nil, err } diff --git a/ray-operator/controllers/ray/utils/types/dashboard_httpclient.go b/ray-operator/controllers/ray/utils/types/dashboard_httpclient.go new file mode 100644 index 00000000000..2173bf72f14 --- /dev/null +++ b/ray-operator/controllers/ray/utils/types/dashboard_httpclient.go @@ -0,0 +1,3 @@ +package types + +type RuntimeEnvType map[string]interface{} diff --git a/ray-operator/controllers/ray/utils/validation.go b/ray-operator/controllers/ray/utils/validation.go index d90e0fbb1ba..808e8a85885 100644 --- a/ray-operator/controllers/ray/utils/validation.go +++ b/ray-operator/controllers/ray/utils/validation.go @@ -11,6 +11,7 @@ import ( "k8s.io/apimachinery/pkg/util/yaml" rayv1 "github.com/ray-project/kuberay/ray-operator/apis/ray/v1" + utiltypes "github.com/ray-project/kuberay/ray-operator/controllers/ray/utils/types" "github.com/ray-project/kuberay/ray-operator/pkg/features" ) @@ -191,8 +192,7 @@ func ValidateRayJobSpec(rayJob *rayv1.RayJob) error { // Validate whether RuntimeEnvYAML is a valid YAML string. Note that this only checks its validity // as a YAML string, not its adherence to the runtime environment schema. - var runtimeEnv RuntimeEnvType - if err := yaml.Unmarshal([]byte(rayJob.Spec.RuntimeEnvYAML), &runtimeEnv); err != nil { + if err := yaml.Unmarshal([]byte(rayJob.Spec.RuntimeEnvYAML), &utiltypes.RuntimeEnvType{}); err != nil { return err } if rayJob.Spec.ActiveDeadlineSeconds != nil && *rayJob.Spec.ActiveDeadlineSeconds <= 0 {