diff --git a/pkg/cmd/clustertask/start.go b/pkg/cmd/clustertask/start.go index 5a56fe5be4..acb4aded2f 100644 --- a/pkg/cmd/clustertask/start.go +++ b/pkg/cmd/clustertask/start.go @@ -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 { 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 28e7f36b73..2d2d823f1c 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,6 +31,7 @@ spec: taskRef: kind: ClusterTask name: clustertask-1 + timeout: 1h0m0s workspaces: - emptyDir: {} name: test diff --git a/pkg/cmd/pipeline/start.go b/pkg/cmd/pipeline/start.go index 3e10a6e8c9..e9d835caa3 100644 --- a/pkg/cmd/pipeline/start.go +++ b/pkg/cmd/pipeline/start.go @@ -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 { diff --git a/pkg/cmd/task/start.go b/pkg/cmd/task/start.go index 16719c3ab4..eecb955276 100644 --- a/pkg/cmd/task/start.go +++ b/pkg/cmd/task/start.go @@ -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 } diff --git a/test/e2e/clustertask/start_test.go b/test/e2e/clustertask/start_test.go index 69bae1f8e8..9a6d0338ba 100644 --- a/test/e2e/clustertask/start_test.go +++ b/test/e2e/clustertask/start_test.go @@ -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" @@ -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) + } + }) } diff --git a/test/e2e/pipeline/pipeline_test.go b/test/e2e/pipeline/pipeline_test.go index 04be0144e1..f1684a7496 100644 --- a/test/e2e/pipeline/pipeline_test.go +++ b/test/e2e/pipeline/pipeline_test.go @@ -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" @@ -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")) diff --git a/test/e2e/task/start_test.go b/test/e2e/task/start_test.go index 7601499346..4c47989338 100644 --- a/test/e2e/task/start_test.go +++ b/test/e2e/task/start_test.go @@ -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" @@ -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) + } + }) }