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

modify the 'vcctl job run' function #542

Merged
merged 1 commit into from
Nov 27, 2019
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
20 changes: 17 additions & 3 deletions pkg/cli/job/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func InitRunFlags(cmd *cobra.Command) {

cmd.Flags().StringVarP(&launchJobFlags.Image, "image", "i", "busybox", "the container image of job")
cmd.Flags().StringVarP(&launchJobFlags.Namespace, "namespace", "n", "default", "the namespace of job")
cmd.Flags().StringVarP(&launchJobFlags.Name, "name", "N", "test", "the name of job")
cmd.Flags().StringVarP(&launchJobFlags.Name, "name", "N", "", "the name of job")
cmd.Flags().IntVarP(&launchJobFlags.MinAvailable, "min", "m", 1, "the minimal available tasks of job")
cmd.Flags().IntVarP(&launchJobFlags.Replicas, "replicas", "r", 1, "the total tasks of job")
cmd.Flags().StringVarP(&launchJobFlags.Requests, "requests", "R", "cpu=1000m,memory=100Mi", "the resource request of the task")
Expand All @@ -72,14 +72,28 @@ func RunJob() error {
return err
}

if launchJobFlags.Name == "" {
err = fmt.Errorf("job name cannot be left blank")
return err
}

req, err := populateResourceListV1(launchJobFlags.Requests)
if err != nil {
return err
}

limit, err := populateResourceListV1(launchJobFlags.Limits)
if err != nil {
return err
}

job, err := readFile(launchJobFlags.FileName)
if err != nil {
return err
}

if job == nil {
fmt.Printf("Error: job script (specified by --filename or -f) is mandatory to run a particular job")
return nil
job = constructLaunchJobFlagsJob(launchJobFlags, req, limit)
}

jobClient := versioned.NewForConfigOrDie(config)
Expand Down
4 changes: 1 addition & 3 deletions pkg/cli/job/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ func TestCreateJob(t *testing.T) {
commonFlags: commonFlags{
Master: server.URL,
},
Name: "test",
Namespace: "test",
Requests: "cpu=1000m,memory=100Mi",
}
Expand Down Expand Up @@ -105,9 +106,6 @@ func TestInitRunFlags(t *testing.T) {
if cmd.Flag("replicas") == nil {
t.Errorf("Could not find the flag replicas")
}
if cmd.Flag("name") == nil {
t.Errorf("Could not find the flag name")
}
if cmd.Flag("min") == nil {
t.Errorf("Could not find the flag min")
}
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/vcctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ Flags:
-L, --limits string the resource limit of the task (default "cpu=1000m,memory=100Mi")
-s, --master string the address of apiserver
-m, --min int the minimal available tasks of job (default 1)
-N, --name string the name of job (default "test")
-N, --name string the name of job
-n, --namespace string the namespace of job (default "default")
-r, --replicas int the total tasks of job (default 1)
-R, --requests string the resource request of the task (default "cpu=1000m,memory=100Mi")
Expand Down