-
Notifications
You must be signed in to change notification settings - Fork 452
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[fix][kubectl-plugin] set worker group CPU limit (#2958)
when creating a new worker group with `kubectl ray create workergroup`. Write a unit test. I noticed we are setting resource limits equal to resource requests everywhere else but in this command. I have a K8s [LimitRange] that prevented the creation of these worker Pods that had CPU limit defaulting to less than their CPU requests. Describing the RayCluster showed this warning event. `Failed to create worker Pod hyperkube/, Pod "dxia-test-other-group-worker-pm2sh" is invalid: spec.containers[0].resources.requests: Invalid value: "2": must be less than or equal to cpu limit of 250m` Signed-off-by: David Xia <[email protected]> [LimitRange]: https://kubernetes.io/docs/concepts/policy/limit-range/
- Loading branch information
Showing
2 changed files
with
77 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package create | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
corev1 "k8s.io/api/core/v1" | ||
"k8s.io/apimachinery/pkg/api/resource" | ||
"k8s.io/utils/ptr" | ||
|
||
rayv1 "github.com/ray-project/kuberay/ray-operator/apis/ray/v1" | ||
) | ||
|
||
func TestCreateWorkerGroupSpec(t *testing.T) { | ||
options := &CreateWorkerGroupOptions{ | ||
groupName: "example-group", | ||
image: "DEADBEEF", | ||
workerReplicas: 3, | ||
workerMinReplicas: 1, | ||
workerMaxReplicas: 5, | ||
workerCPU: "2", | ||
workerMemory: "5Gi", | ||
workerGPU: "1", | ||
} | ||
|
||
expected := rayv1.WorkerGroupSpec{ | ||
RayStartParams: map[string]string{}, | ||
GroupName: "example-group", | ||
Template: corev1.PodTemplateSpec{ | ||
Spec: corev1.PodSpec{ | ||
Containers: []corev1.Container{ | ||
{ | ||
Name: "ray-worker", | ||
Image: "DEADBEEF", | ||
Resources: corev1.ResourceRequirements{ | ||
Requests: corev1.ResourceList{ | ||
corev1.ResourceCPU: resource.MustParse("2"), | ||
corev1.ResourceMemory: resource.MustParse("5Gi"), | ||
resourceNvidiaGPU: resource.MustParse("1"), | ||
}, | ||
Limits: corev1.ResourceList{ | ||
corev1.ResourceCPU: resource.MustParse("2"), | ||
corev1.ResourceMemory: resource.MustParse("5Gi"), | ||
resourceNvidiaGPU: resource.MustParse("1"), | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
Replicas: ptr.To[int32](3), | ||
MinReplicas: ptr.To[int32](1), | ||
MaxReplicas: ptr.To[int32](5), | ||
} | ||
|
||
assert.Equal(t, expected, createWorkerGroupSpec(options)) | ||
} |