diff --git a/pkg/cmd/pipeline/start.go b/pkg/cmd/pipeline/start.go index e772b65ddb..cd28cf5d59 100644 --- a/pkg/cmd/pipeline/start.go +++ b/pkg/cmd/pipeline/start.go @@ -238,6 +238,7 @@ func (opt *startOptions) startPipeline(pipelineStart *v1alpha1.Pipeline) error { pr.Spec.ServiceAccountName = usepr.Spec.ServiceAccountName pr.Spec.ServiceAccountNames = usepr.Spec.ServiceAccountNames pr.Spec.Workspaces = usepr.Spec.Workspaces + pr.Spec.Timeout = usepr.Spec.Timeout } if err := mergeRes(pr, opt.Resources); err != nil { diff --git a/pkg/cmd/pipeline/start_test.go b/pkg/cmd/pipeline/start_test.go index 29fb378c68..cec8fc465e 100644 --- a/pkg/cmd/pipeline/start_test.go +++ b/pkg/cmd/pipeline/start_test.go @@ -492,6 +492,22 @@ func TestPipelineStart_ExecuteCommand(t *testing.T) { wantError: true, want: "cannot use --last option with --filename option", }, + { + name: "Dry Run with --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", "1s", + }, + namespace: "", + input: cs2, + wantError: false, + goldenFile: true, + }, } for _, tp := range testParams { @@ -1831,6 +1847,8 @@ func Test_start_pipeline_last(t *testing.T) { ), // pipeline } + timeoutDuration, _ := time.ParseDuration("10s") + prs := []*v1alpha1.PipelineRun{ tb.PipelineRun("test-pipeline-run-123", "ns", tb.PipelineRunLabel("tekton.dev/pipeline", pipelineName), @@ -1841,6 +1859,7 @@ func Test_start_pipeline_last(t *testing.T) { tb.PipelineRunParam("pipeline-param-1", "somethingmorefun"), tb.PipelineRunParam("rev-param", "revision1"), tb.PipelineRunWorkspaceBindingEmptyDir("test-new"), + tb.PipelineRunTimeout(timeoutDuration), ), ), } @@ -1869,12 +1888,8 @@ func Test_start_pipeline_last(t *testing.T) { pipeline := Command(p) got, _ := test.ExecuteCommand(pipeline, "start", pipelineName, "--last", - "-r=git-repo=scaffold-git", - "-p=rev-param=revision2", - "-s=svc1", - "--task-serviceaccount=task3=task3svc3", - "--task-serviceaccount=task5=task3svc5", - "-n", "ns") + "-n", "ns", + ) expected := "Pipelinerun started: random\n\nIn order to track the pipelinerun progress run:\ntkn pipelinerun logs random -f -n ns\n" test.AssertOutput(t, expected, got) @@ -1886,19 +1901,20 @@ func Test_start_pipeline_last(t *testing.T) { for _, v := range pr.Spec.Resources { if v.Name == "git-repo" { - test.AssertOutput(t, "scaffold-git", v.ResourceRef.Name) + test.AssertOutput(t, "some-repo", v.ResourceRef.Name) } } test.AssertOutput(t, 2, len(pr.Spec.Params)) for _, v := range pr.Spec.Params { if v.Name == "rev-param" { - test.AssertOutput(t, v1alpha1.ArrayOrString{Type: v1alpha1.ParamTypeString, StringVal: "revision2"}, v.Value) + test.AssertOutput(t, v1alpha1.ArrayOrString{Type: v1alpha1.ParamTypeString, StringVal: "revision1"}, v.Value) } } - test.AssertOutput(t, "svc1", pr.Spec.ServiceAccountName) + test.AssertOutput(t, "test-sa", pr.Spec.ServiceAccountName) test.AssertOutput(t, "test-new", pr.Spec.Workspaces[0].Name) + test.AssertOutput(t, timeoutDuration, pr.Spec.Timeout.Duration) } func Test_start_pipeline_last_without_res_param(t *testing.T) { @@ -2101,6 +2117,7 @@ func Test_start_pipeline_use_pipelinerun(t *testing.T) { ), // pipeline } + timeoutDuration, _ := time.ParseDuration("10s") theonename := "test-pipeline-run-be-the-one" prs := []*v1alpha1.PipelineRun{ tb.PipelineRun("dont-bother-me-trying", "ns", @@ -2111,6 +2128,7 @@ func Test_start_pipeline_use_pipelinerun(t *testing.T) { tb.PipelineRunLabel("tekton.dev/pipeline", pipelineName), tb.PipelineRunSpec(pipelineName, tb.PipelineRunParam("brush", "teeth"), + tb.PipelineRunTimeout(timeoutDuration), ), ), } @@ -2147,6 +2165,7 @@ func Test_start_pipeline_use_pipelinerun(t *testing.T) { } test.AssertOutput(t, pr.Spec.Params[0].Name, "brush") test.AssertOutput(t, pr.Spec.Params[0].Value, v1alpha1.ArrayOrString{Type: "string", StringVal: "teeth"}) + test.AssertOutput(t, timeoutDuration, pr.Spec.Timeout.Duration) } func Test_start_pipeline_allkindparam(t *testing.T) { diff --git a/pkg/cmd/pipeline/testdata/TestPipelineStart_ExecuteCommand-Dry_Run_with_--timeout_specified.golden b/pkg/cmd/pipeline/testdata/TestPipelineStart_ExecuteCommand-Dry_Run_with_--timeout_specified.golden new file mode 100644 index 0000000000..2d4ac40cd5 --- /dev/null +++ b/pkg/cmd/pipeline/testdata/TestPipelineStart_ExecuteCommand-Dry_Run_with_--timeout_specified.golden @@ -0,0 +1,21 @@ +apiVersion: tekton.dev/v1alpha1 +kind: PipelineRun +metadata: + creationTimestamp: null + generateName: test-pipeline-run- + labels: + jemange: desfrites + namespace: ns +spec: + params: + - name: pipeline-param + value: value1 + pipelineRef: + name: test-pipeline + resources: + - name: source + resourceRef: + name: scaffold-git + serviceAccountName: svc1 + timeout: 1s +status: {} diff --git a/pkg/cmd/task/start.go b/pkg/cmd/task/start.go index 4e63713a65..128a4251e4 100644 --- a/pkg/cmd/task/start.go +++ b/pkg/cmd/task/start.go @@ -206,6 +206,7 @@ func useTaskRunFrom(opt startOptions, tr *v1alpha1.TaskRun, cs *cli.Clients, tna tr.Spec.Outputs = trUsed.Spec.Outputs tr.Spec.ServiceAccountName = trUsed.Spec.ServiceAccountName tr.Spec.Workspaces = trUsed.Spec.Workspaces + tr.Spec.Timeout = trUsed.Spec.Timeout return nil } @@ -222,13 +223,6 @@ func startTask(opt startOptions, args []string) error { } var tname string - - 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] tr.Spec = v1alpha1.TaskRunSpec{ @@ -245,6 +239,12 @@ func startTask(opt startOptions, args []string) error { } } + timeoutDuration, err := time.ParseDuration(opt.TimeOut) + if err != nil { + return err + } + tr.Spec.Timeout = &metav1.Duration{Duration: timeoutDuration} + if opt.PrefixName == "" { tr.ObjectMeta.GenerateName = tname + "-run-" } else { diff --git a/pkg/cmd/task/start_test.go b/pkg/cmd/task/start_test.go index 9475c94a63..85104f42ed 100644 --- a/pkg/cmd/task/start_test.go +++ b/pkg/cmd/task/start_test.go @@ -19,6 +19,7 @@ import ( "reflect" "strings" "testing" + "time" "github.com/google/go-cmp/cmp" "github.com/tektoncd/cli/pkg/test" @@ -291,6 +292,8 @@ func Test_start_task_last(t *testing.T) { ), } + timeoutDuration, _ := time.ParseDuration("10s") + taskruns := []*v1alpha1.TaskRun{ tb.TaskRun("taskrun-123", "ns", tb.TaskRunLabel("tekton.dev/task", "task"), @@ -302,6 +305,7 @@ func Test_start_task_last(t *testing.T) { tb.TaskRunInputs(tb.TaskRunInputsResource("my-repo", tb.TaskResourceBindingRef("git"))), tb.TaskRunOutputs(tb.TaskRunOutputsResource("code-image", tb.TaskResourceBindingRef("image"))), tb.TaskRunWorkspaceEmptyDir("test", ""), + tb.TaskRunTimeout(timeoutDuration), ), ), } @@ -366,6 +370,7 @@ func Test_start_task_last(t *testing.T) { test.AssertOutput(t, "svc", tr.Spec.ServiceAccountName) test.AssertOutput(t, "test", tr.Spec.Workspaces[0].Name) test.AssertOutput(t, "", tr.Spec.Workspaces[0].SubPath) + test.AssertOutput(t, timeoutDuration, tr.Spec.Timeout.Duration) } func Test_start_use_taskrun(t *testing.T) { @@ -391,6 +396,8 @@ func Test_start_use_taskrun(t *testing.T) { ), } + timeoutDuration, _ := time.ParseDuration("10s") + taskruns := []*v1alpha1.TaskRun{ tb.TaskRun("happy", "ns", tb.TaskRunLabel("tekton.dev/task", "task"), @@ -403,6 +410,7 @@ func Test_start_use_taskrun(t *testing.T) { tb.TaskRunSpec( tb.TaskRunTaskRef("task"), tb.TaskRunServiceAccountName("camper"), + tb.TaskRunTimeout(timeoutDuration), ), ), } @@ -441,6 +449,7 @@ func Test_start_use_taskrun(t *testing.T) { } test.AssertOutput(t, "camper", tr.Spec.ServiceAccountName) + test.AssertOutput(t, timeoutDuration, tr.Spec.Timeout.Duration) } func Test_start_task_last_generate_name(t *testing.T) { @@ -1389,6 +1398,21 @@ func TestTaskStart_ExecuteCommand(t *testing.T) { wantError: false, goldenFile: true, }, + { + name: "Dry Run with --timeout specified", + command: []string{"start", "task-1", + "-i=my-repo=git-repo", + "-o=code-image=output-image", + "-s=svc1", + "-n", "ns", + "--dry-run", + "--timeout", "1s", + }, + namespace: "", + input: cs, + wantError: false, + goldenFile: true, + }, } for _, tp := range testParams { diff --git a/pkg/cmd/task/testdata/TestTaskStart_ExecuteCommand-Dry_Run_with_--timeout_specified.golden b/pkg/cmd/task/testdata/TestTaskStart_ExecuteCommand-Dry_Run_with_--timeout_specified.golden new file mode 100644 index 0000000000..b8fdcc9785 --- /dev/null +++ b/pkg/cmd/task/testdata/TestTaskStart_ExecuteCommand-Dry_Run_with_--timeout_specified.golden @@ -0,0 +1,23 @@ +apiVersion: tekton.dev/v1alpha1 +kind: TaskRun +metadata: + creationTimestamp: null + generateName: task-1-run- + namespace: ns +spec: + inputs: + resources: + - name: my-repo + resourceRef: + name: git-repo + outputs: + resources: + - name: code-image + resourceRef: + name: output-image + serviceAccountName: svc1 + taskRef: + name: task-1 + timeout: 1s +status: + podName: "" diff --git a/pkg/cmd/task/testdata/TestTaskStart_ExecuteCommand-Dry_Run_with_-f.golden b/pkg/cmd/task/testdata/TestTaskStart_ExecuteCommand-Dry_Run_with_-f.golden index f488af48bd..b44413b049 100644 --- a/pkg/cmd/task/testdata/TestTaskStart_ExecuteCommand-Dry_Run_with_-f.golden +++ b/pkg/cmd/task/testdata/TestTaskStart_ExecuteCommand-Dry_Run_with_-f.golden @@ -47,5 +47,6 @@ spec: image: gcr.io/kaniko-project/executor:v0.14.0 name: build-and-push resources: {} + timeout: 1h0m0s status: podName: "" diff --git a/pkg/cmd/task/testdata/TestTaskStart_ExecuteCommand-Dry_Run_with_only_--dry-run_specified.golden b/pkg/cmd/task/testdata/TestTaskStart_ExecuteCommand-Dry_Run_with_only_--dry-run_specified.golden index e5d72489d0..7fa3e6dde7 100644 --- a/pkg/cmd/task/testdata/TestTaskStart_ExecuteCommand-Dry_Run_with_only_--dry-run_specified.golden +++ b/pkg/cmd/task/testdata/TestTaskStart_ExecuteCommand-Dry_Run_with_only_--dry-run_specified.golden @@ -18,5 +18,6 @@ spec: serviceAccountName: svc1 taskRef: name: task-1 + timeout: 1h0m0s status: podName: "" diff --git a/pkg/cmd/task/testdata/TestTaskStart_ExecuteCommand-Dry_Run_with_output=json.golden b/pkg/cmd/task/testdata/TestTaskStart_ExecuteCommand-Dry_Run_with_output=json.golden index 09f59f2b2c..72abd8256b 100644 --- a/pkg/cmd/task/testdata/TestTaskStart_ExecuteCommand-Dry_Run_with_output=json.golden +++ b/pkg/cmd/task/testdata/TestTaskStart_ExecuteCommand-Dry_Run_with_output=json.golden @@ -11,6 +11,7 @@ "taskRef": { "name": "task-1" }, + "timeout": "1h0m0s", "inputs": { "resources": [ {