Skip to content

Commit

Permalink
Merge pull request #542 from jiangkaihua/master
Browse files Browse the repository at this point in the history
modify the 'vcctl job run' function
  • Loading branch information
volcano-sh-bot authored Nov 27, 2019
2 parents 89e93e2 + aa70e97 commit 024f005
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
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

0 comments on commit 024f005

Please sign in to comment.