diff --git a/docs/cmd/tkn_clustertask_start.md b/docs/cmd/tkn_clustertask_start.md index 2dd137300..5757f9272 100644 --- a/docs/cmd/tkn_clustertask_start.md +++ b/docs/cmd/tkn_clustertask_start.md @@ -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 diff --git a/docs/man/man1/tkn-clustertask-start.1 b/docs/man/man1/tkn-clustertask-start.1 index 78f08afff..0e39c89c8 100644 --- a/docs/man/man1/tkn-clustertask-start.1 +++ b/docs/man/man1/tkn-clustertask-start.1 @@ -60,7 +60,7 @@ Start clustertasks show logs right after starting the clustertask .PP -\fB\-\-timeout\fP="1h" +\fB\-\-timeout\fP="" timeout for taskrun diff --git a/pkg/cmd/clustertask/start.go b/pkg/cmd/clustertask/start.go index ac8abd2e9..07c509bc7 100644 --- a/pkg/cmd/clustertask/start.go +++ b/pkg/cmd/clustertask/start.go @@ -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)") @@ -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 diff --git a/pkg/cmd/clustertask/start_test.go b/pkg/cmd/clustertask/start_test.go index 1b7d846e8..f2d517607 100644 --- a/pkg/cmd/clustertask/start_test.go +++ b/pkg/cmd/clustertask/start_test.go @@ -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 { diff --git a/pkg/cmd/clustertask/testdata/Test_ClusterTask_Start-Dry_run_with_--last.golden b/pkg/cmd/clustertask/testdata/Test_ClusterTask_Start-Dry_run_with_--last.golden index 2d2d823f1..28e7f36b7 100644 --- a/pkg/cmd/clustertask/testdata/Test_ClusterTask_Start-Dry_run_with_--last.golden +++ b/pkg/cmd/clustertask/testdata/Test_ClusterTask_Start-Dry_run_with_--last.golden @@ -31,7 +31,6 @@ spec: taskRef: kind: ClusterTask name: clustertask-1 - timeout: 1h0m0s workspaces: - emptyDir: {} name: test diff --git a/pkg/cmd/clustertask/testdata/Test_ClusterTask_Start-Dry_run_with_no_output.golden b/pkg/cmd/clustertask/testdata/Test_ClusterTask_Start-Dry_run_with_no_output.golden index 19f298dc7..1bb005092 100644 --- a/pkg/cmd/clustertask/testdata/Test_ClusterTask_Start-Dry_run_with_no_output.golden +++ b/pkg/cmd/clustertask/testdata/Test_ClusterTask_Start-Dry_run_with_no_output.golden @@ -20,6 +20,5 @@ spec: taskRef: kind: ClusterTask name: clustertask-2 - timeout: 1h0m0s status: podName: "" diff --git a/pkg/cmd/clustertask/testdata/Test_ClusterTask_Start-Dry_run_with_no_output_v1beta1.golden b/pkg/cmd/clustertask/testdata/Test_ClusterTask_Start-Dry_run_with_no_output_v1beta1.golden index f52e3d826..63e8a9aff 100644 --- a/pkg/cmd/clustertask/testdata/Test_ClusterTask_Start-Dry_run_with_no_output_v1beta1.golden +++ b/pkg/cmd/clustertask/testdata/Test_ClusterTask_Start-Dry_run_with_no_output_v1beta1.golden @@ -19,6 +19,5 @@ spec: taskRef: kind: ClusterTask name: clustertask-2 - timeout: 1h0m0s status: podName: "" diff --git a/pkg/cmd/clustertask/testdata/Test_ClusterTask_Start-Dry_run_with_output=json.golden b/pkg/cmd/clustertask/testdata/Test_ClusterTask_Start-Dry_run_with_output=json.golden index d457ac656..109d60fb2 100644 --- a/pkg/cmd/clustertask/testdata/Test_ClusterTask_Start-Dry_run_with_output=json.golden +++ b/pkg/cmd/clustertask/testdata/Test_ClusterTask_Start-Dry_run_with_output=json.golden @@ -14,7 +14,6 @@ "name": "clustertask-2", "kind": "ClusterTask" }, - "timeout": "1h0m0s", "inputs": { "resources": [ { diff --git a/pkg/cmd/clustertask/testdata/Test_ClusterTask_Start_v1beta1-Dry_run_with_--last.golden b/pkg/cmd/clustertask/testdata/Test_ClusterTask_Start_v1beta1-Dry_run_with_--last.golden index 45fff5f20..96d943d42 100644 --- a/pkg/cmd/clustertask/testdata/Test_ClusterTask_Start_v1beta1-Dry_run_with_--last.golden +++ b/pkg/cmd/clustertask/testdata/Test_ClusterTask_Start_v1beta1-Dry_run_with_--last.golden @@ -27,7 +27,6 @@ spec: taskRef: kind: ClusterTask name: clustertask-1 - timeout: 1h0m0s workspaces: - emptyDir: {} name: test diff --git a/pkg/cmd/clustertask/testdata/Test_ClusterTask_Start_v1beta1-Dry_run_with_--timeout_v1beta1.golden b/pkg/cmd/clustertask/testdata/Test_ClusterTask_Start_v1beta1-Dry_run_with_--timeout_v1beta1.golden new file mode 100644 index 000000000..e0609f1dc --- /dev/null +++ b/pkg/cmd/clustertask/testdata/Test_ClusterTask_Start_v1beta1-Dry_run_with_--timeout_v1beta1.golden @@ -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: "" diff --git a/pkg/cmd/clustertask/testdata/Test_ClusterTask_Start_v1beta1-Dry_run_with_no_output.golden b/pkg/cmd/clustertask/testdata/Test_ClusterTask_Start_v1beta1-Dry_run_with_no_output.golden index f52e3d826..63e8a9aff 100644 --- a/pkg/cmd/clustertask/testdata/Test_ClusterTask_Start_v1beta1-Dry_run_with_no_output.golden +++ b/pkg/cmd/clustertask/testdata/Test_ClusterTask_Start_v1beta1-Dry_run_with_no_output.golden @@ -19,6 +19,5 @@ spec: taskRef: kind: ClusterTask name: clustertask-2 - timeout: 1h0m0s status: podName: "" diff --git a/pkg/cmd/clustertask/testdata/Test_ClusterTask_Start_v1beta1-Dry_run_with_no_output_v1beta1.golden b/pkg/cmd/clustertask/testdata/Test_ClusterTask_Start_v1beta1-Dry_run_with_no_output_v1beta1.golden index f52e3d826..63e8a9aff 100644 --- a/pkg/cmd/clustertask/testdata/Test_ClusterTask_Start_v1beta1-Dry_run_with_no_output_v1beta1.golden +++ b/pkg/cmd/clustertask/testdata/Test_ClusterTask_Start_v1beta1-Dry_run_with_no_output_v1beta1.golden @@ -19,6 +19,5 @@ spec: taskRef: kind: ClusterTask name: clustertask-2 - timeout: 1h0m0s status: podName: "" diff --git a/pkg/cmd/clustertask/testdata/Test_ClusterTask_Start_v1beta1-Dry_run_with_timeout_v1beta1.golden b/pkg/cmd/clustertask/testdata/Test_ClusterTask_Start_v1beta1-Dry_run_with_timeout_v1beta1.golden new file mode 100644 index 000000000..e0609f1dc --- /dev/null +++ b/pkg/cmd/clustertask/testdata/Test_ClusterTask_Start_v1beta1-Dry_run_with_timeout_v1beta1.golden @@ -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: "" diff --git a/pkg/cmd/pipeline/start_test.go b/pkg/cmd/pipeline/start_test.go index 221f752f2..4fb1e9786 100644 --- a/pkg/cmd/pipeline/start_test.go +++ b/pkg/cmd/pipeline/start_test.go @@ -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 { diff --git a/pkg/cmd/task/start_test.go b/pkg/cmd/task/start_test.go index 97f377714..48e334560 100644 --- a/pkg/cmd/task/start_test.go +++ b/pkg/cmd/task/start_test.go @@ -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",