Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Default 1h for clustertask --timeout #952

Merged
merged 1 commit into from
Apr 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/cmd/tkn_clustertask_start.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ like cat,foo,bar
-p, --param stringArray pass the param as key=value for string type, or key=value1,value2,... for array type
-s, --serviceaccount string pass the serviceaccount name
--showlog show logs right after starting the clustertask
--timeout string timeout for taskrun (default "1h")
--timeout string timeout for taskrun
```

### Options inherited from parent commands
Expand Down
2 changes: 1 addition & 1 deletion docs/man/man1/tkn-clustertask-start.1
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Start clustertasks
show logs right after starting the clustertask

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


Expand Down
19 changes: 11 additions & 8 deletions pkg/cmd/clustertask/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ like cat,foo,bar
c.Flags().BoolVarP(&opt.Last, "last", "L", false, "re-run the clustertask using last taskrun values")
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 clustertask")
c.Flags().StringVar(&opt.TimeOut, "timeout", "1h", "timeout for taskrun")
c.Flags().StringVar(&opt.TimeOut, "timeout", "", "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)")

Expand All @@ -162,19 +162,22 @@ func startClusterTask(opt startOptions, args []string) error {
return err
}

var ctname string
timeout, err := time.ParseDuration(opt.TimeOut)
if err != nil {
return err
}
ctname = args[0]
ctname := args[0]
tr.Spec = v1beta1.TaskRunSpec{
TaskRef: &v1beta1.TaskRef{
Name: ctname,
Kind: v1beta1.ClusterTaskKind, //Specify TaskRun is for a ClusterTask kind
},
Timeout: &metav1.Duration{Duration: timeout},
}

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

tr.ObjectMeta.GenerateName = ctname + "-run-"

//TaskRuns are namespaced so using same LastRun method as Task
Expand Down
32 changes: 32 additions & 0 deletions pkg/cmd/clustertask/start_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -956,6 +956,38 @@ func Test_ClusterTask_Start_v1beta1(t *testing.T) {
wantError: false,
goldenFile: true,
},
{
name: "Dry run with --timeout v1beta1",
command: []string{"start", "clustertask-2",
"-i", "my-repo=git",
"-o", "code-image=output-image",
"-l", "key=value",
"-s=svc1",
"--dry-run",
"--timeout", "5s",
},
dynamic: seeds[4].dynamicClient,
input: seeds[4].pipelineClient,
inputStream: nil,
wantError: false,
goldenFile: true,
},
{
name: "Dry run with invalide --timeout v1beta1",
command: []string{"start", "clustertask-2",
"-i", "my-repo=git",
"-o", "code-image=output-image",
"-l", "key=value",
"-s=svc1",
"--dry-run",
"--timeout", "5d",
},
dynamic: seeds[4].dynamicClient,
input: seeds[4].pipelineClient,
inputStream: nil,
wantError: true,
want: "time: unknown unit d in duration 5d",
},
}

for _, tp := range testParams {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ spec:
taskRef:
kind: ClusterTask
name: clustertask-1
timeout: 1h0m0s
workspaces:
- emptyDir: {}
name: test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,5 @@ spec:
taskRef:
kind: ClusterTask
name: clustertask-2
timeout: 1h0m0s
status:
podName: ""
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,5 @@ spec:
taskRef:
kind: ClusterTask
name: clustertask-2
timeout: 1h0m0s
status:
podName: ""
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
"name": "clustertask-2",
"kind": "ClusterTask"
},
"timeout": "1h0m0s",
"inputs": {
"resources": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ spec:
taskRef:
kind: ClusterTask
name: clustertask-1
timeout: 1h0m0s
workspaces:
- emptyDir: {}
name: test
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: tekton.dev/v1beta1
kind: TaskRun
metadata:
creationTimestamp: null
generateName: clustertask-2-run-
labels:
key: value
spec:
resources:
inputs:
- name: my-repo
resourceRef:
name: git
outputs:
- name: code-image
resourceRef:
name: output-image
serviceAccountName: svc1
taskRef:
kind: ClusterTask
name: clustertask-2
timeout: 5s
status:
podName: ""
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,5 @@ spec:
taskRef:
kind: ClusterTask
name: clustertask-2
timeout: 1h0m0s
status:
podName: ""
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,5 @@ spec:
taskRef:
kind: ClusterTask
name: clustertask-2
timeout: 1h0m0s
status:
podName: ""
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: tekton.dev/v1beta1
kind: TaskRun
metadata:
creationTimestamp: null
generateName: clustertask-2-run-
labels:
key: value
spec:
resources:
inputs:
- name: my-repo
resourceRef:
name: git
outputs:
- name: code-image
resourceRef:
name: output-image
serviceAccountName: svc1
taskRef:
kind: ClusterTask
name: clustertask-2
timeout: 5s
status:
podName: ""
16 changes: 16 additions & 0 deletions pkg/cmd/pipeline/start_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1276,6 +1276,22 @@ func TestPipelineV1beta1Start_ExecuteCommand(t *testing.T) {
wantError: false,
goldenFile: true,
},
{
name: "Dry Run with invalid --timeout specified",
command: []string{"start", "test-pipeline",
"-s=svc1",
"-r=source=scaffold-git",
"-p=pipeline-param=value1",
"-l=jemange=desfrites",
"-n", "ns",
"--dry-run",
"--timeout", "5d",
},
namespace: "",
input: c2,
wantError: true,
want: "time: unknown unit d in duration 5d",
},
}

for _, tp := range testParams {
Expand Down
15 changes: 15 additions & 0 deletions pkg/cmd/task/start_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4031,6 +4031,21 @@ func TestTaskStart_ExecuteCommand_v1beta1(t *testing.T) {
wantError: false,
goldenFile: true,
},
{
name: "Dry Run with invalid --timeout specified",
command: []string{"start", "task-1",
"-i=my-repo=git-repo",
"-o=code-image=output-image",
"-s=svc1",
"-n", "ns",
"--dry-run",
"--timeout", "5d"},
namespace: "",
dynamic: dc,
input: cs,
wantError: true,
want: "time: unknown unit d in duration 5d",
},
{
name: "Dry Run with output=json -f v1beta1",
command: []string{"start",
Expand Down