From 5ab346b5b7cad4478399d15041d13919b2ad2121 Mon Sep 17 00:00:00 2001 From: vinamra28 Date: Mon, 11 Jul 2022 10:10:19 +0530 Subject: [PATCH] Add different timeout flags for Pipeline start cmd 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 --- docs/cmd/tkn_pipeline_start.md | 4 +++- docs/man/man1/tkn-pipeline-start.1 | 10 +++++++++- pkg/cmd/pipeline/start.go | 31 ++++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 2 deletions(-) diff --git a/docs/cmd/tkn_pipeline_start.md b/docs/cmd/tkn_pipeline_start.md index 1f57e7fe03..268411c4e6 100644 --- a/docs/cmd/tkn_pipeline_start.md +++ b/docs/cmd/tkn_pipeline_start.md @@ -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 @@ -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 diff --git a/docs/man/man1/tkn-pipeline-start.1 b/docs/man/man1/tkn-pipeline-start.1 index 6251b8eb9e..0cd46fd708 100644 --- a/docs/man/man1/tkn-pipeline-start.1 +++ b/docs/man/man1/tkn-pipeline-start.1 @@ -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 @@ -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] diff --git a/pkg/cmd/pipeline/start.go b/pkg/cmd/pipeline/start.go index b3e4d85834..b00ce4eeff 100644 --- a/pkg/cmd/pipeline/start.go +++ b/pkg/cmd/pipeline/start.go @@ -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 @@ -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") @@ -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 }