Skip to content

Commit 8ad2c1b

Browse files
authored
[Bug] Add default value for entrypoint flags in job_submit.go (#3808)
* [Bug] Add default-zero-value for entrypoint flags in job_submit.go Signed-off-by: 400Ping <[email protected]> * [Chore] Update golangci-lint Signed-off-by: 400Ping <[email protected]> * [Bug] Add default-value for entrypoint flags in job_submit.go Signed-off-by: 400Ping <[email protected]> * [Chore] Rename test func name Signed-off-by: 400Ping <[email protected]> --------- Signed-off-by: 400Ping <[email protected]>
1 parent d4ae4e3 commit 8ad2c1b

File tree

2 files changed

+29
-15
lines changed

2 files changed

+29
-15
lines changed

kubectl-plugin/pkg/cmd/job/job_submit.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -148,21 +148,21 @@ func NewJobSubmitCommand(cmdFactory cmdutil.Factory, streams genericclioptions.I
148148
return options.Run(cmd.Context(), cmdFactory)
149149
},
150150
}
151-
cmd.Flags().StringVarP(&options.fileName, "filename", "f", options.fileName, "Path and name of the Ray Job YAML file")
152-
cmd.Flags().StringVar(&options.submissionID, "submission-id", options.submissionID, "ID to specify for the Ray job. If not provided, one will be generated")
153-
cmd.Flags().StringVar(&options.runtimeEnv, "runtime-env", options.runtimeEnv, "Path and name to the runtime env YAML file.")
154-
cmd.Flags().StringVar(&options.workingDir, "working-dir", options.workingDir, "Directory containing files that your job will run in")
155-
cmd.Flags().StringVar(&options.headers, "headers", options.headers, "Used to pass headers through http/s to Ray Cluster. Must be JSON formatting")
156-
cmd.Flags().StringVar(&options.runtimeEnvJson, "runtime-env-json", options.runtimeEnvJson, "JSON-serialized runtime_env dictionary. Precedence over Ray job CR.")
157-
cmd.Flags().StringVar(&options.verify, "verify", options.verify, "Boolean indication to verify the server's TLS certificate or a path to a file or directory of trusted certificates.")
158-
cmd.Flags().StringVar(&options.entryPointResource, "entrypoint-resources", options.entryPointResource, "JSON-serialized dictionary mapping resource name to resource quantity")
159-
cmd.Flags().StringVar(&options.metadataJson, "metadata-json", options.metadataJson, "JSON-serialized dictionary of metadata to attach to the job.")
160-
cmd.Flags().StringVar(&options.logStyle, "log-style", options.logStyle, "Specific to 'ray job submit'. Options are 'auto | record | pretty'")
161-
cmd.Flags().StringVar(&options.logColor, "log-color", options.logColor, "Specific to 'ray job submit'. Options are 'auto | false | true'")
162-
cmd.Flags().Float32Var(&options.entryPointCPU, "entrypoint-num-cpus", options.entryPointCPU, "Number of CPUs reserved for the for the entrypoint command")
163-
cmd.Flags().Float32Var(&options.entryPointGPU, "entrypoint-num-gpus", options.entryPointGPU, "Number of GPUs reserved for the for the entrypoint command")
164-
cmd.Flags().IntVar(&options.entryPointMemory, "entrypoint-memory", options.entryPointMemory, "Amount of memory reserved for the entrypoint command")
165-
cmd.Flags().BoolVar(&options.noWait, "no-wait", options.noWait, "If present, will not stream logs and wait for job to finish")
151+
cmd.Flags().StringVarP(&options.fileName, "filename", "f", "", "Path and name of the Ray Job YAML file")
152+
cmd.Flags().StringVar(&options.submissionID, "submission-id", "", "ID to specify for the Ray job. If not provided, one will be generated")
153+
cmd.Flags().StringVar(&options.runtimeEnv, "runtime-env", "", "Path and name to the runtime env YAML file.")
154+
cmd.Flags().StringVar(&options.workingDir, "working-dir", "", "Directory containing files that your job will run in")
155+
cmd.Flags().StringVar(&options.headers, "headers", "", "Used to pass headers through http/s to Ray Cluster. Must be JSON formatting")
156+
cmd.Flags().StringVar(&options.runtimeEnvJson, "runtime-env-json", "", "JSON-serialized runtime_env dictionary. Precedence over Ray job CR.")
157+
cmd.Flags().StringVar(&options.verify, "verify", "", "Boolean indication to verify the server's TLS certificate or a path to a file or directory of trusted certificates.")
158+
cmd.Flags().StringVar(&options.entryPointResource, "entrypoint-resources", "", "JSON-serialized dictionary mapping resource name to resource quantity")
159+
cmd.Flags().StringVar(&options.metadataJson, "metadata-json", "", "JSON-serialized dictionary of metadata to attach to the job.")
160+
cmd.Flags().StringVar(&options.logStyle, "log-style", "", "Specific to 'ray job submit'. Options are 'auto | record | pretty'")
161+
cmd.Flags().StringVar(&options.logColor, "log-color", "", "Specific to 'ray job submit'. Options are 'auto | false | true'")
162+
cmd.Flags().Float32Var(&options.entryPointCPU, "entrypoint-num-cpus", 0, "Number of CPUs reserved for the entrypoint command")
163+
cmd.Flags().Float32Var(&options.entryPointGPU, "entrypoint-num-gpus", 0, "Number of GPUs reserved for the entrypoint command")
164+
cmd.Flags().IntVar(&options.entryPointMemory, "entrypoint-memory", 0, "Amount of memory reserved for the entrypoint command")
165+
cmd.Flags().BoolVar(&options.noWait, "no-wait", false, "If present, will not stream logs and wait for job to finish")
166166

167167
cmd.Flags().StringVar(&options.rayjobName, "name", "", "Ray job name")
168168
cmd.Flags().StringVar(&options.rayVersion, "ray-version", util.RayVersion, "Ray version to use")

kubectl-plugin/pkg/cmd/job/job_submit_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,3 +475,17 @@ func TestRaySubmitCmd(t *testing.T) {
475475

476476
assert.Equal(t, expectedCmd, actualCmd)
477477
}
478+
479+
func TestRayJobSubmit_FlagsHaveDefaults(t *testing.T) {
480+
streams, _, _, _ := genericclioptions.NewTestIOStreams()
481+
factory := cmdutil.NewFactory(genericclioptions.NewConfigFlags(true))
482+
opts := NewJobSubmitOptions(factory, streams)
483+
484+
cmd := NewJobSubmitCommand(factory, streams)
485+
require.NoError(t, cmd.ParseFlags([]string{}))
486+
487+
assert.InDelta(t, float32(0), opts.entryPointCPU, 1e-6, "default entrypoint-num-cpus should be 0")
488+
assert.InDelta(t, float32(0), opts.entryPointGPU, 1e-6, "default entrypoint-num-gpus should be 0")
489+
assert.Equal(t, 0, opts.entryPointMemory, "default entrypoint-memory should be 0")
490+
assert.False(t, opts.noWait, "default no-wait should be false")
491+
}

0 commit comments

Comments
 (0)