diff --git a/pkg/cli/job/run.go b/pkg/cli/job/run.go index 889bcf87d2..4a0ab8bbdf 100644 --- a/pkg/cli/job/run.go +++ b/pkg/cli/job/run.go @@ -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") @@ -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) diff --git a/pkg/cli/job/run_test.go b/pkg/cli/job/run_test.go index 61cf78d56c..06fea59b9f 100644 --- a/pkg/cli/job/run_test.go +++ b/pkg/cli/job/run_test.go @@ -77,6 +77,7 @@ func TestCreateJob(t *testing.T) { commonFlags: commonFlags{ Master: server.URL, }, + Name: "test", Namespace: "test", Requests: "cpu=1000m,memory=100Mi", } @@ -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") } diff --git a/test/e2e/vcctl.go b/test/e2e/vcctl.go index e141229aba..0e83575d0e 100644 --- a/test/e2e/vcctl.go +++ b/test/e2e/vcctl.go @@ -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")