Skip to content

Commit 74c88a6

Browse files
authored
[feat][kubectl-plugin] add get workergroup cmd (ray-project#2996)
We plan to add a [command to scale a worker group][1] in an existing RayCluster, e.g. `kubectl ray scale cluster (CLUSTER_NAME) (WORKER_GROUP)`. This requires the user to know the group name. There's currently no way to get the worker group names in a RayCluster other than getting the resource with kubectl and looking for or parsing out the names. A command to get worker groups details for a cluster might be helpful. ## Example Usage ```console $ kubectl ray get workergroups -A NAMESPACE NAME REPLICAS CPUS GPUS TPUS MEMORY CLUSTER default default-group 1/1 2 0 0 4Gi dxia-test explorer-one gpuWorker 1/1 36 4 0 256Gi yzhao foundation-models cpuWorker 1/1 20 0 0 200Gi jacquelinew-v3 foundation-models gpuWorker 1/1 200 8 0 1000Gi jacquelinew-v3 foundation-models redis 1/1 13 0 0 112Gi jacquelinew-v3 $ kubectl ray get workergroups -n default NAME REPLICAS CPUS GPUS TPUS MEMORY CLUSTER default-group 1/1 2 0 0 4Gi dxia-test $ kubectl ray get workergroups -n foundation-models -c jacquelinew-v3 NAME REPLICAS CPUS GPUS TPUS MEMORY CLUSTER cpuWorker 1/1 20 0 0 200Gi jacquelinew-v3 gpuWorker 1/1 200 8 0 1000Gi jacquelinew-v3 redis 1/1 13 0 0 112Gi jacquelinew-v3 $ kubectl ray get workergroups gpuWorker -A NAMESPACE NAME REPLICAS CPUS GPUS TPUS MEMORY CLUSTER explorer-one gpuWorker 1/1 36 4 0 256Gi yzhao foundation-models gpuWorker 1/1 200 8 0 1000Gi jacquelinew-v3 ``` [1]: ray-project#2926 Signed-off-by: David Xia <david@davidxia.com>
1 parent 3e931a2 commit 74c88a6

File tree

8 files changed

+1284
-20
lines changed

8 files changed

+1284
-20
lines changed

kubectl-plugin/pkg/cmd/create/create_workergroup.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@ import (
2020
"k8s.io/kubectl/pkg/util/templates"
2121
)
2222

23-
const (
24-
resourceNvidiaGPU = "nvidia.com/gpu"
25-
)
26-
2723
type CreateWorkerGroupOptions struct {
2824
configFlags *genericclioptions.ConfigFlags
2925
ioStreams *genericclioptions.IOStreams
@@ -176,8 +172,8 @@ func createWorkerGroupSpec(options *CreateWorkerGroupOptions) rayv1.WorkerGroupS
176172

177173
gpuResource := resource.MustParse(options.workerGPU)
178174
if !gpuResource.IsZero() {
179-
podTemplate.Spec.Containers[0].Resources.Requests[corev1.ResourceName(resourceNvidiaGPU)] = gpuResource
180-
podTemplate.Spec.Containers[0].Resources.Limits[corev1.ResourceName(resourceNvidiaGPU)] = gpuResource
175+
podTemplate.Spec.Containers[0].Resources.Requests[corev1.ResourceName(util.ResourceNvidiaGPU)] = gpuResource
176+
podTemplate.Spec.Containers[0].Resources.Limits[corev1.ResourceName(util.ResourceNvidiaGPU)] = gpuResource
181177
}
182178

183179
return rayv1.WorkerGroupSpec{

kubectl-plugin/pkg/cmd/create/create_workergroup_test.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import (
88
"k8s.io/apimachinery/pkg/api/resource"
99
"k8s.io/utils/ptr"
1010

11+
"github.com/ray-project/kuberay/kubectl-plugin/pkg/util"
12+
1113
rayv1 "github.com/ray-project/kuberay/ray-operator/apis/ray/v1"
1214
)
1315

@@ -34,14 +36,14 @@ func TestCreateWorkerGroupSpec(t *testing.T) {
3436
Image: "DEADBEEF",
3537
Resources: corev1.ResourceRequirements{
3638
Requests: corev1.ResourceList{
37-
corev1.ResourceCPU: resource.MustParse("2"),
38-
corev1.ResourceMemory: resource.MustParse("5Gi"),
39-
resourceNvidiaGPU: resource.MustParse("1"),
39+
corev1.ResourceCPU: resource.MustParse("2"),
40+
corev1.ResourceMemory: resource.MustParse("5Gi"),
41+
util.ResourceNvidiaGPU: resource.MustParse("1"),
4042
},
4143
Limits: corev1.ResourceList{
42-
corev1.ResourceCPU: resource.MustParse("2"),
43-
corev1.ResourceMemory: resource.MustParse("5Gi"),
44-
resourceNvidiaGPU: resource.MustParse("1"),
44+
corev1.ResourceCPU: resource.MustParse("2"),
45+
corev1.ResourceMemory: resource.MustParse("5Gi"),
46+
util.ResourceNvidiaGPU: resource.MustParse("1"),
4547
},
4648
},
4749
},

kubectl-plugin/pkg/cmd/get/get.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,6 @@ func NewGetCommand(streams genericclioptions.IOStreams) *cobra.Command {
2424
}
2525

2626
cmd.AddCommand(NewGetClusterCommand(streams))
27+
cmd.AddCommand(NewGetWorkerGroupCommand(streams))
2728
return cmd
2829
}

kubectl-plugin/pkg/cmd/get/get_cluster.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ func NewGetClusterCommand(streams genericclioptions.IOStreams) *cobra.Command {
4141

4242
cmd := &cobra.Command{
4343
Use: "cluster [NAME]",
44+
Aliases: []string{"clusters"},
4445
Short: "Get cluster information.",
4546
SilenceUsage: true,
4647
ValidArgsFunction: completion.RayClusterCompletionFunc(cmdFactory),

0 commit comments

Comments
 (0)