Skip to content

Commit

Permalink
Add different timeout flags for Pipeline start cmd
Browse files Browse the repository at this point in the history
With Pipelines release v0.36.0, Timeouts was moved out of feature flags
and existing Timeout was deprecated.

This PR updates the timeouts flags of `tkn pipeline start` to allow user
to pass the different timeouts for `Pipeline`, `PipelineTask` and
`FinallyTask` before starting a `Pipeline` using CLI.

Signed-off-by: vinamra28 <[email protected]>
  • Loading branch information
vinamra28 committed Jul 13, 2022
1 parent 9980d32 commit 5ab346b
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
4 changes: 3 additions & 1 deletion docs/cmd/tkn_pipeline_start.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ my-secret, my-empty-dir and my-volume-claim-template)
```
--dry-run preview PipelineRun without running it
-f, --filename string local or remote file name containing a Pipeline definition to start a PipelineRun
--finally-timeout string timeout for Finally Tasks
-h, --help help for start
-l, --labels strings pass labels as label=value.
-L, --last re-run the Pipeline using last PipelineRun values
Expand All @@ -65,7 +66,8 @@ my-secret, my-empty-dir and my-volume-claim-template)
--showlog show logs right after starting the Pipeline
--skip-optional-workspace skips the prompt for optional workspaces
--task-serviceaccount strings pass the service account corresponding to the task
--timeout string timeout for PipelineRun
--tasks-timeout string timeout for Pipeline Tasks
--timeout string timeout for Pipeline
--use-param-defaults use default parameter values without prompting for input
--use-pipelinerun string use this pipelinerun values to re-run the pipeline.
-w, --workspace stringArray pass one or more workspaces to map to the corresponding physical volumes
Expand Down
10 changes: 9 additions & 1 deletion docs/man/man1/tkn-pipeline-start.1
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ Parameters, at least those that have no default value
\fB\-f\fP, \fB\-\-filename\fP=""
local or remote file name containing a Pipeline definition to start a PipelineRun

.PP
\fB\-\-finally\-timeout\fP=""
timeout for Finally Tasks

.PP
\fB\-h\fP, \fB\-\-help\fP[=false]
help for start
Expand Down Expand Up @@ -83,9 +87,13 @@ Parameters, at least those that have no default value
\fB\-\-task\-serviceaccount\fP=[]
pass the service account corresponding to the task

.PP
\fB\-\-tasks\-timeout\fP=""
timeout for Pipeline Tasks

.PP
\fB\-\-timeout\fP=""
timeout for PipelineRun
timeout for Pipeline

.PP
\fB\-\-use\-param\-defaults\fP[=false]
Expand Down
31 changes: 31 additions & 0 deletions pkg/cmd/pipeline/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ type startOptions struct {
Output string
PrefixName string
TimeOut string
PipelineTimeOut string
TasksTimeOut string
FinallyTimeOut string
Filename string
Workspaces []string
UseParamDefaults bool
Expand Down Expand Up @@ -189,6 +192,10 @@ For passing the workspaces via flags:
c.Flags().StringVarP(&opt.Output, "output", "o", "", "format of PipelineRun (yaml, json or name)")
c.Flags().StringVarP(&opt.PrefixName, "prefix-name", "", "", "specify a prefix for the PipelineRun name (must be lowercase alphanumeric characters)")
c.Flags().StringVarP(&opt.TimeOut, "timeout", "", "", "timeout for PipelineRun")
c.Flags().MarkDeprecated("timeout", "please use --pipeline-timeout flag instead of this")
c.Flags().StringVarP(&opt.PipelineTimeOut, "pipeline-timeout", "", "", "timeout for Pipeline")
c.Flags().StringVarP(&opt.TasksTimeOut, "tasks-timeout", "", "", "timeout for Pipeline Tasks")
c.Flags().StringVarP(&opt.FinallyTimeOut, "finally-timeout", "", "", "timeout for Finally Tasks")
c.Flags().StringVarP(&opt.Filename, "filename", "f", "", "local or remote file name containing a Pipeline definition to start a PipelineRun")
c.Flags().BoolVarP(&opt.UseParamDefaults, "use-param-defaults", "", false, "use default parameter values without prompting for input")
c.Flags().StringVar(&opt.PodTemplate, "pod-template", "", "local or remote file containing a PodTemplate definition")
Expand Down Expand Up @@ -292,6 +299,30 @@ func (opt *startOptions) startPipeline(pipelineStart *v1beta1.Pipeline) error {
pr.Spec.Timeout = &metav1.Duration{Duration: timeoutDuration}
}

if opt.PipelineTimeOut != "" {
timeoutDuration, err := time.ParseDuration(opt.PipelineTimeOut)
if err != nil {
return err
}
pr.Spec.Timeouts.Pipeline = &metav1.Duration{Duration: timeoutDuration}
}

if opt.TasksTimeOut != "" {
timeoutDuration, err := time.ParseDuration(opt.TasksTimeOut)
if err != nil {
return err
}
pr.Spec.Timeouts.Tasks = &metav1.Duration{Duration: timeoutDuration}
}

if opt.FinallyTimeOut != "" {
timeoutDuration, err := time.ParseDuration(opt.FinallyTimeOut)
if err != nil {
return err
}
pr.Spec.Timeouts.Finally = &metav1.Duration{Duration: timeoutDuration}
}

if err := mergeRes(pr, opt.Resources); err != nil {
return err
}
Expand Down

0 comments on commit 5ab346b

Please sign in to comment.