Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pkg/cmd/pipeline/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
37 changes: 28 additions & 9 deletions pkg/cmd/pipeline/start_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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),
Expand All @@ -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),
),
),
}
Expand Down Expand Up @@ -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",
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The unit test for tkn p start --last wasn't really testing the feature since it overwrites many runtime values. The point of the test is to see whether the last pipelinerun's values are used, so I removed everything except --last.

"-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)
Expand All @@ -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) {
Expand Down Expand Up @@ -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",
Expand All @@ -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),
),
),
}
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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: {}
14 changes: 7 additions & 7 deletions pkg/cmd/task/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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{
Expand All @@ -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 {
Expand Down
24 changes: 24 additions & 0 deletions pkg/cmd/task/start_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"reflect"
"strings"
"testing"
"time"

"github.com/google/go-cmp/cmp"
"github.com/tektoncd/cli/pkg/test"
Expand Down Expand Up @@ -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"),
Expand All @@ -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),
),
),
}
Expand Down Expand Up @@ -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) {
Expand All @@ -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"),
Expand All @@ -403,6 +410,7 @@ func Test_start_use_taskrun(t *testing.T) {
tb.TaskRunSpec(
tb.TaskRunTaskRef("task"),
tb.TaskRunServiceAccountName("camper"),
tb.TaskRunTimeout(timeoutDuration),
),
),
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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: ""
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,6 @@ 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,5 +18,6 @@ spec:
serviceAccountName: svc1
taskRef:
name: task-1
timeout: 1h0m0s
status:
podName: ""
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"taskRef": {
"name": "task-1"
},
"timeout": "1h0m0s",
"inputs": {
"resources": [
{
Expand Down