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 {
|
func NewCmdCreateCronJob(f cmdutil.Factory, ioStreams genericclioptions.IOStreams) *cobra.Command {
|
||||||
o := NewCreateCronJobOptions(ioStreams)
|
o := NewCreateCronJobOptions(ioStreams)
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "cronjob NAME --image=image --schedule='0/5 * * * ?' -- [COMMAND] [args...]",
|
Use: "cronjob NAME --image=image --schedule='0/5 * * * ?' -- [COMMAND] [args...]",
|
||||||
Aliases: []string{"cj"},
|
DisableFlagsInUseLine: false,
|
||||||
Short: cronjobLong,
|
Aliases: []string{"cj"},
|
||||||
Long: cronjobLong,
|
Short: cronjobLong,
|
||||||
Example: cronjobExample,
|
Long: cronjobLong,
|
||||||
|
Example: cronjobExample,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
cmdutil.CheckErr(o.Complete(f, cmd, args))
|
cmdutil.CheckErr(o.Complete(f, cmd, args))
|
||||||
cmdutil.CheckErr(o.Validate())
|
|
||||||
cmdutil.CheckErr(o.Run())
|
cmdutil.CheckErr(o.Run())
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -98,7 +98,9 @@ func NewCmdCreateCronJob(f cmdutil.Factory, ioStreams genericclioptions.IOStream
|
||||||
cmdutil.AddValidateFlags(cmd)
|
cmdutil.AddValidateFlags(cmd)
|
||||||
cmdutil.AddDryRunFlag(cmd)
|
cmdutil.AddDryRunFlag(cmd)
|
||||||
cmd.Flags().StringVar(&o.Image, "image", o.Image, "Image name to run.")
|
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.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")
|
cmd.Flags().StringVar(&o.Restart, "restart", o.Restart, "job's restart policy. supported values: OnFailure, Never")
|
||||||
cmdutil.AddFieldManagerFlagVar(cmd, &o.FieldManager, "kubectl-create")
|
cmdutil.AddFieldManagerFlagVar(cmd, &o.FieldManager, "kubectl-create")
|
||||||
|
|
||||||
|
@ -158,20 +160,8 @@ func (o *CreateCronJobOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, a
|
||||||
return nil
|
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 {
|
func (o *CreateCronJobOptions) Run() error {
|
||||||
var cronjob *batchv1beta1.CronJob
|
cronjob := o.createCronJob()
|
||||||
cronjob = o.createCronJob()
|
|
||||||
|
|
||||||
if o.DryRunStrategy != cmdutil.DryRunClient {
|
if o.DryRunStrategy != cmdutil.DryRunClient {
|
||||||
createOptions := metav1.CreateOptions{}
|
createOptions := metav1.CreateOptions{}
|
||||||
if o.FieldManager != "" {
|
if o.FieldManager != "" {
|
||||||
|
|
|
@ -85,10 +85,11 @@ func NewCreateJobOptions(ioStreams genericclioptions.IOStreams) *CreateJobOption
|
||||||
func NewCmdCreateJob(f cmdutil.Factory, ioStreams genericclioptions.IOStreams) *cobra.Command {
|
func NewCmdCreateJob(f cmdutil.Factory, ioStreams genericclioptions.IOStreams) *cobra.Command {
|
||||||
o := NewCreateJobOptions(ioStreams)
|
o := NewCreateJobOptions(ioStreams)
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "job NAME --image=image [--from=cronjob/name] -- [COMMAND] [args...]",
|
Use: "job NAME --image=image [--from=cronjob/name] -- [COMMAND] [args...]",
|
||||||
Short: jobLong,
|
DisableFlagsInUseLine: true,
|
||||||
Long: jobLong,
|
Short: jobLong,
|
||||||
Example: jobExample,
|
Long: jobLong,
|
||||||
|
Example: jobExample,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
cmdutil.CheckErr(o.Complete(f, cmd, args))
|
cmdutil.CheckErr(o.Complete(f, cmd, args))
|
||||||
cmdutil.CheckErr(o.Validate())
|
cmdutil.CheckErr(o.Validate())
|
||||||
|
|
Loading…
Reference in New Issue