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
6 changes: 2 additions & 4 deletions pkg/cmd/clustertask/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,8 @@ func startClusterTask(opt startOptions, args []string) error {
if err != nil {
return err
}
tr.Spec.Resources = trLast.Spec.Resources
tr.Spec.Params = trLast.Spec.Params
tr.Spec.ServiceAccountName = trLast.Spec.ServiceAccountName
tr.Spec.Workspaces = trLast.Spec.Workspaces
// Copy over spec from last TaskRun to use same values for this TaskRun
tr.Spec = trLast.Spec
}

if tr.Spec.Resources == nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ spec:
taskRef:
kind: ClusterTask
name: clustertask-1
timeout: 1h0m0s
workspaces:
- emptyDir: {}
name: test
Expand Down
9 changes: 2 additions & 7 deletions pkg/cmd/pipeline/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,13 +253,8 @@ func (opt *startOptions) startPipeline(pipelineStart *v1beta1.Pipeline) error {
} else if opt.PrefixName == "" {
pr.ObjectMeta.GenerateName = usepr.ObjectMeta.Name + "-"
}
pr.Spec.Resources = usepr.Spec.Resources
pr.Spec.Params = usepr.Spec.Params
// If the usepr is a "new" PR, let's populate those fields too
pr.Spec.ServiceAccountName = usepr.Spec.ServiceAccountName
pr.Spec.ServiceAccountNames = usepr.Spec.ServiceAccountNames
pr.Spec.Workspaces = usepr.Spec.Workspaces
pr.Spec.Timeout = usepr.Spec.Timeout
// Copy over spec from last or previous PipelineRun to use same values for this PipelineRun
pr.Spec = usepr.Spec
}

if err := mergeRes(pr, opt.Resources); err != nil {
Expand Down
9 changes: 2 additions & 7 deletions pkg/cmd/task/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,13 +250,8 @@ func useTaskRunFrom(opt startOptions, tr *v1beta1.TaskRun, cs *cli.Clients, tnam
} else if opt.PrefixName == "" {
tr.ObjectMeta.GenerateName = trUsed.ObjectMeta.Name + "-"
}

tr.Spec.Resources = trUsed.Spec.Resources
tr.Spec.Params = trUsed.Spec.Params
tr.Spec.ServiceAccountName = trUsed.Spec.ServiceAccountName
tr.Spec.Workspaces = trUsed.Spec.Workspaces
tr.Spec.Timeout = trUsed.Spec.Timeout

// Copy over spec from last or previous TaskRun to use same values for this TaskRun
tr.Spec = trUsed.Spec
return nil
}

Expand Down
28 changes: 28 additions & 0 deletions test/e2e/clustertask/start_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ package clustertask

import (
"testing"
"time"

"github.com/AlecAivazis/survey/v2/terminal"
"github.com/Netflix/go-expect"
"github.com/google/go-cmp/cmp"
"github.com/tektoncd/cli/test/builder"
"github.com/tektoncd/cli/test/cli"
"github.com/tektoncd/cli/test/framework"
Expand Down Expand Up @@ -204,4 +206,30 @@ Waiting for logs to be available...
t.Errorf("Error waiting for TaskRun to Succeed: %s", err)
}
})

t.Run("Start TaskRun using tkn ct start with --last option", func(t *testing.T) {
// Get last TaskRun for read-clustertask
lastTaskRun := builder.GetTaskRunListWithName(c, "read-clustertask", true).Items[0]

// Start TaskRun using --last
tkn.MustSucceed(t, "ct", "start", "read-clustertask",
"--last",
"--showlog")

// Sleep to make make sure TaskRun is created/running
time.Sleep(1 * time.Second)

// Get name of most recent TaskRun and wait for it to succeed
taskRunUsingLast := builder.GetTaskRunListWithName(c, "read-clustertask", true).Items[0]
if err := wait.ForTaskRunState(c, taskRunUsingLast.Name, wait.TaskRunSucceed(taskRunUsingLast.Name), "TaskRunSucceeded"); err != nil {
t.Errorf("Error waiting for TaskRun to Succeed: %s", err)
}

// Expect that previous TaskRun spec will match most recent TaskRun spec
expected := lastTaskRun.Spec
got := taskRunUsingLast.Spec
if d := cmp.Diff(got, expected); d != "" {
t.Fatalf("-got, +want: %v", d)
}
})
}
28 changes: 28 additions & 0 deletions test/e2e/pipeline/pipeline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (

"github.com/AlecAivazis/survey/v2/terminal"
"github.com/Netflix/go-expect"
"github.com/google/go-cmp/cmp"
"github.com/tektoncd/cli/test/builder"
"github.com/tektoncd/cli/test/cli"
"github.com/tektoncd/cli/test/framework"
Expand Down Expand Up @@ -252,6 +253,33 @@ Waiting for logs to be available...
}})
})

t.Run("Start PipelineRun with tkn pipeline start --last", func(t *testing.T) {
// Get last PipelineRun for output-pipeline
pipelineRunLast := builder.GetPipelineRunListWithName(c, tePipelineName, true).Items[0]

// Start PipelineRun using --last
tkn.MustSucceed(t, "pipeline", "start", tePipelineName,
"--last",
"--showlog")

// Sleep to make make sure PipelineRun is created/running
time.Sleep(1 * time.Second)

// Get name of most recent PipelineRun and wait for it to succeed
pipelineRunUsingLast := builder.GetPipelineRunListWithName(c, tePipelineName, true).Items[0]
timeout := 5 * time.Minute
if err := wait.ForPipelineRunState(c, pipelineRunUsingLast.Name, timeout, wait.PipelineRunSucceed(pipelineRunUsingLast.Name), "PipelineRunSucceeded"); err != nil {
t.Errorf("Error waiting for PipelineRun to fail: %s", err)
}

// Expect that previous PipelineRun spec will match most recent PipelineRun spec
expected := pipelineRunLast.Spec
got := pipelineRunUsingLast.Spec
if d := cmp.Diff(got, expected); d != "" {
t.Fatalf("-got, +want: %v", d)
}
})

t.Logf("Creating Pipeline pipeline-with-workspace in namespace: %s", namespace)
kubectl.MustSucceed(t, "create", "-f", helper.GetResourcePath("pipeline-with-workspace.yaml"))

Expand Down
28 changes: 28 additions & 0 deletions test/e2e/task/start_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ package task

import (
"testing"
"time"

"github.com/AlecAivazis/survey/v2/terminal"
"github.com/Netflix/go-expect"
"github.com/google/go-cmp/cmp"
"github.com/tektoncd/cli/test/builder"
"github.com/tektoncd/cli/test/cli"
"github.com/tektoncd/cli/test/framework"
Expand Down Expand Up @@ -228,4 +230,30 @@ Waiting for logs to be available...
t.Errorf("Error waiting for TaskRun to Succeed: %s", err)
}
})

t.Run("Start TaskRun using tkn task start with --last option", func(t *testing.T) {
// Get last TaskRun for read-task
lastTaskRun := builder.GetTaskRunListWithName(c, "read-task", true).Items[0]

// Start TaskRun using --last
tkn.MustSucceed(t, "task", "start", "read-task",
"--last",
"--showlog")

// Sleep to make make sure TaskRun is created/running
time.Sleep(1 * time.Second)

// Get name of most recent TaskRun and wait for it to succeed
taskRunUsingLast := builder.GetTaskRunListWithName(c, "read-task", true).Items[0]
if err := wait.ForTaskRunState(c, taskRunUsingLast.Name, wait.TaskRunSucceed(taskRunUsingLast.Name), "TaskRunSucceeded"); err != nil {
t.Errorf("Error waiting for TaskRun to Succeed: %s", err)
}

// Expect that previous TaskRun spec will match most recent TaskRun spec
expected := lastTaskRun.Spec
got := taskRunUsingLast.Spec
if d := cmp.Diff(got, expected); d != "" {
t.Fatalf("-got, +want: %v", d)
}
})
}