Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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"},
}
Expand Down
49 changes: 20 additions & 29 deletions ray-operator/controllers/ray/utils/dashboard_httpclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,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 (
Expand Down Expand Up @@ -122,35 +123,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 {
Expand Down Expand Up @@ -375,8 +374,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 utiltypes.RuntimeEnvType
if err := yaml.Unmarshal([]byte(rayJob.Spec.RuntimeEnvYAML), &runtimeEnv); err != nil {
return nil, err
}
req.RuntimeEnv = runtimeEnv
Expand All @@ -390,11 +389,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
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package types

type RuntimeEnvType map[string]interface{}
38 changes: 0 additions & 38 deletions ray-operator/controllers/ray/utils/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion ray-operator/controllers/ray/utils/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ 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"
utiltypes "github.com/ray-project/kuberay/ray-operator/controllers/ray/utils/types"
"github.com/ray-project/kuberay/ray-operator/pkg/features"
)

Expand Down Expand Up @@ -190,7 +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.
if _, err := UnmarshalRuntimeEnvYAML(rayJob.Spec.RuntimeEnvYAML); 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 {
Expand Down
Loading