Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add resource command #170

Merged
merged 8 commits into from
Mar 10, 2022
Merged
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
7 changes: 7 additions & 0 deletions ray-operator/config/samples/ray-cluster.mini.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ spec:
valueFrom:
fieldRef:
fieldPath: status.podIP
resources:
limits:
cpu: 1
memory: 2Gi
requests:
cpu: 1
memory: 2Gi
ports:
- containerPort: 6379
name: redis
Expand Down
28 changes: 26 additions & 2 deletions ray-operator/controllers/common/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func BuildPod(podTemplateSpec v1.PodTemplateSpec, rayNodeType rayiov1alpha1.RayN
cmd += convertCmdToString(pod.Spec.Containers[index].Args)
}
if !strings.Contains(cmd, "ray start") {
cont := concatenateContainerCommand(rayNodeType, rayStartParams)
cont := concatenateContainerCommand(rayNodeType, rayStartParams, pod.Spec.Containers[index].Resources)
// replacing the old command
pod.Spec.Containers[index].Command = []string{"/bin/bash", "-c", "--"}
if cmd != "" {
Expand Down Expand Up @@ -260,7 +260,31 @@ func setMissingRayStartParams(rayStartParams map[string]string, nodeType rayiov1
}

// concatenateContainerCommand with ray start
func concatenateContainerCommand(nodeType rayiov1alpha1.RayNodeType, rayStartParams map[string]string) (fullCmd string) {
func concatenateContainerCommand(nodeType rayiov1alpha1.RayNodeType, rayStartParams map[string]string, resource v1.ResourceRequirements) (fullCmd string) {

if _, ok := rayStartParams["num-cpus"]; !ok {
cpu := resource.Limits[v1.ResourceCPU]
if !cpu.IsZero() {
rayStartParams["num-cpus"] = strconv.FormatInt(cpu.Value(), 10)
}
}

if _, ok := rayStartParams["memory"]; !ok {
memory := resource.Limits[v1.ResourceMemory]
if !memory.IsZero() {
rayStartParams["memory"] = strconv.FormatInt(memory.Value(), 10)
}
}

if _, ok := rayStartParams["num-gpus"]; !ok {
gpu := resource.Limits["gpu"]
if !gpu.IsZero() {
rayStartParams["num-gpus"] = strconv.FormatInt(gpu.Value(), 10)
}
}

log.V(10).Info("concatenate container command", "ray start params", rayStartParams)

switch nodeType {
case rayiov1alpha1.HeadNode:
return fmt.Sprintf("ulimit -n 65536; ray start --head %s", convertParamMap(rayStartParams))
Expand Down
4 changes: 2 additions & 2 deletions ray-operator/controllers/common/pod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,9 @@ func TestBuildPod(t *testing.T) {
t.Fatalf("Expected `%v` but got `%v`", expectedResult, actualResult)
}

expectedCommandArg := splitAndSort("ulimit -n 65536; ray start --block --num-cpus=1 --address=raycluster-sample-head-svc:6379 --port=6379 --redis-password=LetMeInRay")
expectedCommandArg := splitAndSort("ulimit -n 65536; ray start --block --num-cpus=1 --address=raycluster-sample-head-svc:6379 --port=6379 --redis-password=LetMeInRay")
if !reflect.DeepEqual(expectedCommandArg, splitAndSort(pod.Spec.Containers[0].Args[0])) {
t.Fatalf("Expected `%v` but got `%v`", expectedCommandArg, pod.Spec.Containers[0].Args)
t.Fatalf("Expected `%v` but got `%v`", expectedCommandArg, pod.Spec.Containers[0].Args[0])
}
}

Expand Down