Skip to content

Commit

Permalink
Change timeout to string for tkn task start
Browse files Browse the repository at this point in the history
Close #730

this change timeout type from `int64` to string for tkn task start
command which enables user to give input as string like `1h2m3s`
default value set is `1h`

Signed-off-by: Pradeep Kumar <[email protected]>
  • Loading branch information
pradeepitm12 authored and tekton-robot committed Mar 5, 2020
1 parent 80a30cd commit a5375e1
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 16 deletions.
2 changes: 1 addition & 1 deletion docs/cmd/tkn_task_start.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ like cat,foo,bar
--prefix-name string specify a prefix for the taskrun name (must be lowercase alphanumeric characters)
-s, --serviceaccount string pass the serviceaccount name
--showlog show logs right after starting the task
--timeout int timeout for taskrun in seconds (default 3600)
--timeout string timeout for taskrun (default "1h")
--use-taskrun string specify a taskrun name to use its values to re-run the taskrun
```

Expand Down
4 changes: 2 additions & 2 deletions docs/man/man1/tkn-task-start.1
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ Start tasks
show logs right after starting the task

.PP
\fB\-\-timeout\fP=3600
timeout for taskrun in seconds
\fB\-\-timeout\fP="1h"
timeout for taskrun

.PP
\fB\-\-use\-taskrun\fP=""
Expand Down
17 changes: 8 additions & 9 deletions pkg/cmd/task/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"encoding/json"
"errors"
"fmt"
"log"
"strings"
"time"

Expand Down Expand Up @@ -55,7 +54,7 @@ type startOptions struct {
Labels []string
ShowLog bool
Filename string
TimeOut int64
TimeOut string
DryRun bool
Output string
UseTaskRun string
Expand Down Expand Up @@ -113,10 +112,6 @@ like cat,foo,bar
`,
SilenceUsage: true,
Args: func(cmd *cobra.Command, args []string) error {
if opt.TimeOut != 3600 {
log.Println("WARNING: The --timeout flag will no longer be specified in seconds in v0.9.0. Learn more here: https://github.com/tektoncd/cli/issues/730")
log.Println("WARNING: The -t shortand for --timeout will no longer be available in v0.9.0.")
}
if err := flags.InitParams(p, cmd); err != nil {
return err
}
Expand Down Expand Up @@ -156,7 +151,7 @@ like cat,foo,bar
c.Flags().StringSliceVarP(&opt.Labels, "labels", "l", []string{}, "pass labels as label=value.")
c.Flags().BoolVarP(&opt.ShowLog, "showlog", "", false, "show logs right after starting the task")
c.Flags().StringVarP(&opt.Filename, "filename", "f", "", "local or remote file name containing a task definition")
c.Flags().Int64VarP(&opt.TimeOut, "timeout", "", 3600, "timeout for taskrun in seconds")
c.Flags().StringVarP(&opt.TimeOut, "timeout", "", "1h", "timeout for taskrun")
c.Flags().BoolVarP(&opt.DryRun, "dry-run", "", false, "preview taskrun without running it")
c.Flags().StringVarP(&opt.Output, "output", "", "", "format of taskrun dry-run (yaml or json)")
c.Flags().StringVarP(&opt.PrefixName, "prefix-name", "", "", "specify a prefix for the taskrun name (must be lowercase alphanumeric characters)")
Expand Down Expand Up @@ -223,7 +218,12 @@ func startTask(opt startOptions, args []string) error {
}

var tname string
timeoutSeconds := time.Duration(opt.TimeOut) * time.Second

timeoutDuration, err := time.ParseDuration(opt.TimeOut)
if err != nil {
return err
}
tr.Spec.Timeout = &metav1.Duration{Duration: timeoutDuration}

if len(args) > 0 {
tname = args[0]
Expand All @@ -240,7 +240,6 @@ func startTask(opt startOptions, args []string) error {
TaskSpec: &task.Spec,
}
}
tr.Spec.Timeout = &metav1.Duration{Duration: timeoutSeconds}

if opt.PrefixName == "" {
tr.ObjectMeta.GenerateName = tname + "-run-"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,5 @@ spec:
image: gcr.io/kaniko-project/executor:v0.14.0
name: build-and-push
resources: {}
timeout: 1h0m0s
status:
podName: ""
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,5 @@ spec:
serviceAccountName: svc1
taskRef:
name: task-1
timeout: 1h0m0s
status:
podName: ""
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@
"serviceAccountName": "svc1",
"taskRef": {
"name": "task-1"
},
"timeout": "1h0m0s"
}
},
"status": {
"podName": ""
Expand Down

0 comments on commit a5375e1

Please sign in to comment.