Set schedule and image flags required for create cronjob
Kubernetes-commit: 9e7ca872b4e2c9c95f7e7c224bc79c1b698789b9
This commit is contained in:
parent
9078885794
commit
731925c63c
|
@ -80,14 +80,14 @@ func NewCreateCronJobOptions(ioStreams genericclioptions.IOStreams) *CreateCronJ
|
|||
func NewCmdCreateCronJob(f cmdutil.Factory, ioStreams genericclioptions.IOStreams) *cobra.Command {
|
||||
o := NewCreateCronJobOptions(ioStreams)
|
||||
cmd := &cobra.Command{
|
||||
Use: "cronjob NAME --image=image --schedule='0/5 * * * ?' -- [COMMAND] [args...]",
|
||||
Aliases: []string{"cj"},
|
||||
Short: cronjobLong,
|
||||
Long: cronjobLong,
|
||||
Example: cronjobExample,
|
||||
Use: "cronjob NAME --image=image --schedule='0/5 * * * ?' -- [COMMAND] [args...]",
|
||||
DisableFlagsInUseLine: false,
|
||||
Aliases: []string{"cj"},
|
||||
Short: cronjobLong,
|
||||
Long: cronjobLong,
|
||||
Example: cronjobExample,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
cmdutil.CheckErr(o.Complete(f, cmd, args))
|
||||
cmdutil.CheckErr(o.Validate())
|
||||
cmdutil.CheckErr(o.Run())
|
||||
},
|
||||
}
|
||||
|
@ -98,7 +98,9 @@ func NewCmdCreateCronJob(f cmdutil.Factory, ioStreams genericclioptions.IOStream
|
|||
cmdutil.AddValidateFlags(cmd)
|
||||
cmdutil.AddDryRunFlag(cmd)
|
||||
cmd.Flags().StringVar(&o.Image, "image", o.Image, "Image name to run.")
|
||||
cmd.MarkFlagRequired("image")
|
||||
cmd.Flags().StringVar(&o.Schedule, "schedule", o.Schedule, "A schedule in the Cron format the job should be run with.")
|
||||
cmd.MarkFlagRequired("schedule")
|
||||
cmd.Flags().StringVar(&o.Restart, "restart", o.Restart, "job's restart policy. supported values: OnFailure, Never")
|
||||
cmdutil.AddFieldManagerFlagVar(cmd, &o.FieldManager, "kubectl-create")
|
||||
|
||||
|
@ -158,20 +160,8 @@ func (o *CreateCronJobOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, a
|
|||
return nil
|
||||
}
|
||||
|
||||
func (o *CreateCronJobOptions) Validate() error {
|
||||
if len(o.Image) == 0 {
|
||||
return fmt.Errorf("--image must be specified")
|
||||
}
|
||||
if len(o.Schedule) == 0 {
|
||||
return fmt.Errorf("--schedule must be specified")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o *CreateCronJobOptions) Run() error {
|
||||
var cronjob *batchv1beta1.CronJob
|
||||
cronjob = o.createCronJob()
|
||||
|
||||
cronjob := o.createCronJob()
|
||||
if o.DryRunStrategy != cmdutil.DryRunClient {
|
||||
createOptions := metav1.CreateOptions{}
|
||||
if o.FieldManager != "" {
|
||||
|
|
|
@ -85,10 +85,11 @@ func NewCreateJobOptions(ioStreams genericclioptions.IOStreams) *CreateJobOption
|
|||
func NewCmdCreateJob(f cmdutil.Factory, ioStreams genericclioptions.IOStreams) *cobra.Command {
|
||||
o := NewCreateJobOptions(ioStreams)
|
||||
cmd := &cobra.Command{
|
||||
Use: "job NAME --image=image [--from=cronjob/name] -- [COMMAND] [args...]",
|
||||
Short: jobLong,
|
||||
Long: jobLong,
|
||||
Example: jobExample,
|
||||
Use: "job NAME --image=image [--from=cronjob/name] -- [COMMAND] [args...]",
|
||||
DisableFlagsInUseLine: true,
|
||||
Short: jobLong,
|
||||
Long: jobLong,
|
||||
Example: jobExample,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
cmdutil.CheckErr(o.Complete(f, cmd, args))
|
||||
cmdutil.CheckErr(o.Validate())
|
||||
|
|
Loading…
Reference in New Issue