Skip to content

Commit 893375a

Browse files
authored
[fix][plugin] add missing CLI flags for create cluster cmd (#3237)
1 parent 7f33c1d commit 893375a

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

Diff for: kubectl-plugin/pkg/cmd/create/create_cluster.go

+6
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ import (
2222
type CreateClusterOptions struct {
2323
cmdFactory cmdutil.Factory
2424
ioStreams *genericclioptions.IOStreams
25+
labels map[string]string
26+
annotations map[string]string
2527
workerRayStartParams map[string]string
2628
headRayStartParams map[string]string
2729
headNodeSelectors map[string]string
@@ -109,6 +111,8 @@ func NewCreateClusterCommand(cmdFactory cmdutil.Factory, streams genericclioptio
109111
cmd.Flags().DurationVar(&options.timeout, "timeout", defaultProvisionedTimeout, "the timeout for --wait")
110112
cmd.Flags().StringToStringVar(&options.headNodeSelectors, "head-node-selectors", nil, "Node selectors to apply to all head pods in the cluster (e.g. --head-node-selectors cloud.google.com/gke-accelerator=nvidia-l4,cloud.google.com/gke-nodepool=my-node-pool)")
111113
cmd.Flags().StringToStringVar(&options.workerNodeSelectors, "worker-node-selectors", nil, "Node selectors to apply to all worker pods in the cluster (e.g. --worker-node-selectors cloud.google.com/gke-accelerator=nvidia-l4,cloud.google.com/gke-nodepool=my-node-pool)")
114+
cmd.Flags().StringToStringVar(&options.labels, "labels", nil, "K8s labels (e.g. --labels app=ray,env=dev)")
115+
cmd.Flags().StringToStringVar(&options.annotations, "annotations", nil, "K8s annotations (e.g. --annotations ttl-hours=24,owner=chthulu)")
112116

113117
return cmd
114118
}
@@ -168,6 +172,8 @@ func (options *CreateClusterOptions) Run(ctx context.Context, k8sClient client.C
168172
rayClusterSpecObject := generation.RayClusterSpecObject{
169173
Namespace: &options.namespace,
170174
Name: &options.clusterName,
175+
Labels: options.labels,
176+
Annotations: options.annotations,
171177
RayVersion: &options.rayVersion,
172178
Image: &options.image,
173179
HeadCPU: &options.headCPU,

Diff for: kubectl-plugin/pkg/cmd/create/create_cluster_test.go

+33
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ func TestRayClusterCreateClusterRun(t *testing.T) {
7272
options := CreateClusterOptions{
7373
cmdFactory: cmdFactory,
7474
clusterName: clusterName,
75+
labels: map[string]string{"app": "ray", "env": "dev"},
76+
annotations: map[string]string{"ttl-hours": "24", "owner": "chthulu"},
7577
headCPU: "1",
7678
headMemory: "1Gi",
7779
headGPU: "0",
@@ -98,3 +100,34 @@ func TestRayClusterCreateClusterRun(t *testing.T) {
98100
require.Error(t, err)
99101
})
100102
}
103+
104+
func TestNewCreateClusterCommand(t *testing.T) {
105+
testStreams, _, _, _ := genericclioptions.NewTestIOStreams()
106+
cmd := NewCreateClusterCommand(cmdutil.NewFactory(genericclioptions.NewConfigFlags(true)), testStreams)
107+
cmd.Flags().StringP("namespace", "n", "", "")
108+
109+
cmd.SetArgs([]string{
110+
"sample-cluster",
111+
"--ray-version", "2.44.0",
112+
"--image", "rayproject/ray:2.44.0",
113+
"--head-cpu", "1",
114+
"--head-memory", "5Gi",
115+
"--head-gpu", "1",
116+
"--head-ephemeral-storage", "10Gi",
117+
"--head-ray-start-params", "metrics-export-port=8080,num-cpus=2",
118+
"--head-node-selectors", "app=ray,env=dev",
119+
"--worker-replicas", "3",
120+
"--worker-cpu", "1",
121+
"--worker-memory", "5Gi",
122+
"--worker-gpu", "1",
123+
"--worker-ephemeral-storage", "10Gi",
124+
"--worker-ray-start-params", "metrics-export-port=8081,num-cpus=2",
125+
"--worker-node-selectors", "app=ray,env=dev",
126+
"--labels", "app=ray,env=dev",
127+
"--annotations", "ttl-hours=24,owner=chthulu",
128+
"--dry-run",
129+
"--wait",
130+
"--timeout", "10s",
131+
})
132+
require.NoError(t, cmd.Execute())
133+
}

0 commit comments

Comments
 (0)