From f4d092c77d359a48dfdecf708f72293ebf872f5a Mon Sep 17 00:00:00 2001 From: Piyush Garg Date: Tue, 14 Mar 2023 19:22:28 +0530 Subject: [PATCH] Move pr desc to v1 CRDs This will move pr desc to v1 CRD and remove resources and timeouts field Also move serviceaccountname and pipelineresults to respective new fields use childreferences for taskrun status and expand params for object type too Part of #1804 --- pkg/cmd/pipelinerun/cancel.go | 28 +- pkg/cmd/pipelinerun/delete.go | 4 +- pkg/cmd/pipelinerun/describe.go | 7 +- pkg/cmd/pipelinerun/describe_test.go | 426 +-- pkg/cmd/pipelinerun/describe_v1_test.go | 2745 +++++++++++++++++ ....golden => TestPipelineRunDescribe.golden} | 6 - ...ipelineRunDescribeWithSkippedTasks.golden} | 6 - ...RunDescribeWithSkippedTasks_v1beta1.golden | 29 + ...TestPipelineRunDescribeWithTimeouts.golden | 6 - ...lineRunDescribeWithTimeouts_v1beta1.golden | 33 + ...neRunDescribe_cancelled_pipelinerun.golden | 10 +- ...celled_pipelinerun_multiple_taskrun.golden | 10 +- ...ipelinerun_multiple_taskrun_v1beta1.golden | 24 + ...cribe_cancelled_pipelinerun_v1beta1.golden | 22 + ...tPipelineRunDescribe_custom_timeout.golden | 10 +- ...eRunDescribe_custom_timeout_v1beta1.golden | 11 + .../TestPipelineRunDescribe_failed.golden | 12 +- ...tPipelineRunDescribe_failed_v1beta1.golden | 24 + ...nDescribe_failed_withoutPRCondition.golden | 12 +- ...e_failed_withoutPRCondition_v1beta1.golden | 19 + ...nDescribe_failed_withoutTRCondition.golden | 12 +- ...e_failed_withoutTRCondition_v1beta1.golden | 23 + ...en => TestPipelineRunDescribe_last.golden} | 6 - ...estPipelineRunDescribe_last_v1beta1.golden | 22 + ...nDescribe_multiple_taskrun_ordering.golden | 10 +- ...e_multiple_taskrun_ordering_v1beta1.golden | 19 + ...ibe_multiple_taskrun_without_status.golden | 11 +- ...iple_taskrun_without_status_v1beta1.golden | 19 + ...tPipelineRunDescribe_no_resourceref.golden | 15 +- ...eRunDescribe_no_resourceref_v1beta1.golden | 26 + ...estPipelineRunDescribe_only_taskrun.golden | 10 +- ...ineRunDescribe_only_taskrun_v1beta1.golden | 18 + ...RunDescribe_taskrun_with_no_status.golden} | 7 +- ...ribe_taskrun_with_no_status_v1beta1.golden | 22 + .../TestPipelineRunDescribe_v1beta1.golden | 22 + ...unDescribe_with_annotations_v1beta1.golden | 10 + ...eRunDescribe_with_resources_taskrun.golden | 15 +- ...ribe_with_resources_taskrun_v1beta1.golden | 26 + ...stPipelineRunDescribe_with_results.golden} | 5 - ...ineRunDescribe_with_results_v1beta1.golden | 26 + ...ipelineRunDescribe_with_workspaces.golden} | 5 - ...RunDescribe_with_workspaces_v1beta1.golden | 33 + ...fOnlyOnePipelineRunPresent_v1beta1.golden} | 2 + ...escribe_without_pipelineref_v1beta1.golden | 9 + ...elineRunDescribe_without_start_time.golden | 10 +- ...Describe_without_start_time_v1beta1.golden | 13 + ...neRunDescribe_without_tr_start_time.golden | 10 +- ...cribe_without_tr_start_time_v1beta1.golden | 18 + ...estPipelineRunDescribe_zero_timeout.golden | 3 + ...ineRunDescribe_zero_timeout_v1beta1.golden | 11 + pkg/cmd/taskrun/delete.go | 4 +- pkg/cmd/taskrun/taskrun.go | 1 + pkg/formatted/description.go | 10 + pkg/formatted/description_test.go | 31 +- pkg/formatted/results.go | 9 - pkg/formatted/workspace.go | 30 +- pkg/formatted/workspace_test.go | 4 +- pkg/options/describe.go | 8 +- pkg/options/logs.go | 8 +- .../{description => }/description.go | 210 +- .../{description => }/description_test.go | 100 +- pkg/pipelinerun/pipelinerun.go | 10 +- pkg/pipelinerun/pipelinerun_test.go | 99 +- pkg/taskrun/description/description.go | 2 +- 64 files changed, 3895 insertions(+), 513 deletions(-) create mode 100644 pkg/cmd/pipelinerun/describe_v1_test.go rename pkg/cmd/pipelinerun/testdata/{TestPipelineRunDescribeV1beta1.golden => TestPipelineRunDescribe.golden} (85%) rename pkg/cmd/pipelinerun/testdata/{TestPipelineRunDescribeWithSkippedTasksV1beta1.golden => TestPipelineRunDescribeWithSkippedTasks.golden} (87%) create mode 100644 pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribeWithSkippedTasks_v1beta1.golden create mode 100644 pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribeWithTimeouts_v1beta1.golden create mode 100644 pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_cancelled_pipelinerun_multiple_taskrun_v1beta1.golden create mode 100644 pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_cancelled_pipelinerun_v1beta1.golden create mode 100644 pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_custom_timeout_v1beta1.golden create mode 100644 pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_failed_v1beta1.golden create mode 100644 pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_failed_withoutPRCondition_v1beta1.golden create mode 100644 pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_failed_withoutTRCondition_v1beta1.golden rename pkg/cmd/pipelinerun/testdata/{TestPipelineRunDescribe_lastV1beta1.golden => TestPipelineRunDescribe_last.golden} (84%) create mode 100644 pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_last_v1beta1.golden create mode 100644 pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_multiple_taskrun_ordering_v1beta1.golden create mode 100644 pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_multiple_taskrun_without_status_v1beta1.golden create mode 100644 pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_no_resourceref_v1beta1.golden create mode 100644 pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_only_taskrun_v1beta1.golden rename pkg/cmd/pipelinerun/testdata/{TestPipelineRunDescribeV1beta1_taskrun_with_no_status.golden => TestPipelineRunDescribe_taskrun_with_no_status.golden} (83%) create mode 100644 pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_taskrun_with_no_status_v1beta1.golden create mode 100644 pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_v1beta1.golden create mode 100644 pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_with_annotations_v1beta1.golden create mode 100644 pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_with_resources_taskrun_v1beta1.golden rename pkg/cmd/pipelinerun/testdata/{TestPipelineRunDescribe_v1beta1_with_results.golden => TestPipelineRunDescribe_with_results.golden} (88%) create mode 100644 pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_with_results_v1beta1.golden rename pkg/cmd/pipelinerun/testdata/{TestPipelineRunDescribe_v1beta1_with_workspaces.golden => TestPipelineRunDescribe_with_workspaces.golden} (91%) create mode 100644 pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_with_workspaces_v1beta1.golden rename pkg/cmd/pipelinerun/testdata/{TestPipelineRunDescribeV1beta1_withoutNameOfOnlyOnePipelineRunPresent.golden => TestPipelineRunDescribe_withoutNameOfOnlyOnePipelineRunPresent_v1beta1.golden} (73%) create mode 100644 pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_without_pipelineref_v1beta1.golden create mode 100644 pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_without_start_time_v1beta1.golden create mode 100644 pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_without_tr_start_time_v1beta1.golden create mode 100644 pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_zero_timeout_v1beta1.golden rename pkg/pipelinerun/{description => }/description.go (53%) rename pkg/pipelinerun/{description => }/description_test.go (52%) diff --git a/pkg/cmd/pipelinerun/cancel.go b/pkg/cmd/pipelinerun/cancel.go index 521c93f99..7b1e3c5f1 100644 --- a/pkg/cmd/pipelinerun/cancel.go +++ b/pkg/cmd/pipelinerun/cancel.go @@ -19,10 +19,11 @@ import ( "strings" "github.com/spf13/cobra" + "github.com/tektoncd/cli/pkg/actions" "github.com/tektoncd/cli/pkg/cli" "github.com/tektoncd/cli/pkg/formatted" - "github.com/tektoncd/cli/pkg/pipelinerun" - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" + pipelinerunpkg "github.com/tektoncd/cli/pkg/pipelinerun" + v1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -39,7 +40,7 @@ Set to 'CancelledRunFinally' if you want to cancel the current running task and Set to 'StoppedRunFinally' if you want to cancel the remaining non-final task and directly run the finally tasks. ` - cancelStatus := "" + graceCancelStatus := "" c := &cobra.Command{ Use: "cancel", @@ -60,11 +61,11 @@ Set to 'StoppedRunFinally' if you want to cancel the remaining non-final task an Err: cmd.OutOrStderr(), } - return cancelPipelineRun(p, s, pr, cancelStatus) + return cancelPipelineRun(p, s, pr, graceCancelStatus) }, } - c.Flags().StringVarP(&cancelStatus, "grace", "", "", graceCancelDescription) + c.Flags().StringVarP(&graceCancelStatus, "grace", "", "", graceCancelDescription) return c } @@ -74,7 +75,8 @@ func cancelPipelineRun(p cli.Params, s *cli.Stream, prName string, graceCancelSt return fmt.Errorf("failed to create tekton client") } - pr, err := pipelinerun.Get(cs, prName, metav1.GetOptions{}, p.Namespace()) + var pr *v1.PipelineRun + err = actions.GetV1(pipelineRunGroupResource, cs, prName, p.Namespace(), metav1.GetOptions{}, &pr) if err != nil { return fmt.Errorf("failed to find PipelineRun: %s", prName) } @@ -85,17 +87,15 @@ func cancelPipelineRun(p cli.Params, s *cli.Stream, prName string, graceCancelSt } } - // nolint: staticcheck - cancelStatus := v1beta1.PipelineRunSpecStatusCancelled - + cancelStatus := v1.PipelineRunSpecStatusCancelled switch strings.ToLower(graceCancelStatus) { - case strings.ToLower(v1beta1.PipelineRunSpecStatusCancelledRunFinally): - cancelStatus = v1beta1.PipelineRunSpecStatusCancelledRunFinally - case strings.ToLower(v1beta1.PipelineRunSpecStatusStoppedRunFinally): - cancelStatus = v1beta1.PipelineRunSpecStatusStoppedRunFinally + case strings.ToLower(v1.PipelineRunSpecStatusCancelledRunFinally): + cancelStatus = v1.PipelineRunSpecStatusCancelledRunFinally + case strings.ToLower(v1.PipelineRunSpecStatusStoppedRunFinally): + cancelStatus = v1.PipelineRunSpecStatusStoppedRunFinally } - if _, err = pipelinerun.Cancel(cs, prName, metav1.PatchOptions{}, cancelStatus, p.Namespace()); err != nil { + if _, err = pipelinerunpkg.Cancel(cs, prName, metav1.PatchOptions{}, cancelStatus, p.Namespace()); err != nil { return fmt.Errorf("failed to cancel PipelineRun: %s: %v", prName, err) } diff --git a/pkg/cmd/pipelinerun/delete.go b/pkg/cmd/pipelinerun/delete.go index ae7d14a3c..5ebb1d36c 100644 --- a/pkg/cmd/pipelinerun/delete.go +++ b/pkg/cmd/pipelinerun/delete.go @@ -26,7 +26,6 @@ import ( "github.com/tektoncd/cli/pkg/deleter" "github.com/tektoncd/cli/pkg/formatted" "github.com/tektoncd/cli/pkg/options" - pr "github.com/tektoncd/cli/pkg/pipelinerun" prsort "github.com/tektoncd/cli/pkg/pipelinerun/sort" v1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" "go.uber.org/multierr" @@ -46,7 +45,8 @@ func prExists(args []string, p cli.Params) ([]string, error) { var errorList error ns := p.Namespace() for _, name := range args { - _, err := pr.Get(c, name, metav1.GetOptions{}, ns) + var pr *v1.PipelineRun + err := actions.GetV1(pipelineRunGroupResource, c, name, ns, metav1.GetOptions{}, &pr) if err != nil { errorList = multierr.Append(errorList, err) continue diff --git a/pkg/cmd/pipelinerun/describe.go b/pkg/cmd/pipelinerun/describe.go index e65aeeb5c..f1c9bf2ad 100644 --- a/pkg/cmd/pipelinerun/describe.go +++ b/pkg/cmd/pipelinerun/describe.go @@ -25,9 +25,7 @@ import ( "github.com/tektoncd/cli/pkg/formatted" "github.com/tektoncd/cli/pkg/options" pipelinerunpkg "github.com/tektoncd/cli/pkg/pipelinerun" - prdesc "github.com/tektoncd/cli/pkg/pipelinerun/description" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime/schema" cliopts "k8s.io/cli-runtime/pkg/genericclioptions" ) @@ -110,11 +108,10 @@ or } if output != "" { - pipelineRunGroupResource := schema.GroupVersionResource{Group: "tekton.dev", Resource: "pipelineruns"} - return actions.PrintObject(pipelineRunGroupResource, opts.PipelineRunName, cmd.OutOrStdout(), cs.Dynamic, cs.Tekton.Discovery(), f, p.Namespace()) + return actions.PrintObjectV1(pipelineRunGroupResource, opts.PipelineRunName, cmd.OutOrStdout(), cs, f, p.Namespace()) } - return prdesc.PrintPipelineRunDescription(s, opts.PipelineRunName, p) + return pipelinerunpkg.PrintPipelineRunDescription(s.Out, cs, opts.Params.Namespace(), opts.PipelineRunName, opts.Params.Time()) }, } diff --git a/pkg/cmd/pipelinerun/describe_test.go b/pkg/cmd/pipelinerun/describe_test.go index 49b3a25dd..746086791 100644 --- a/pkg/cmd/pipelinerun/describe_test.go +++ b/pkg/cmd/pipelinerun/describe_test.go @@ -25,16 +25,17 @@ import ( cb "github.com/tektoncd/cli/pkg/test/builder" testDynamic "github.com/tektoncd/cli/pkg/test/dynamic" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" - pipelinev1beta1test "github.com/tektoncd/pipeline/test" + pipelinetest "github.com/tektoncd/pipeline/test" "gotest.tools/v3/golden" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/selection" "knative.dev/pkg/apis" duckv1 "knative.dev/pkg/apis/duck/v1" ) -func TestPipelineRunDescribe_invalid_namespace(t *testing.T) { +func TestPipelineRunDescribe_not_found_v1beta1(t *testing.T) { ns := []*corev1.Namespace{ { ObjectMeta: metav1.ObjectMeta{ @@ -43,28 +44,7 @@ func TestPipelineRunDescribe_invalid_namespace(t *testing.T) { }, } - cs, _ := test.SeedV1beta1TestData(t, pipelinev1beta1test.Data{Namespaces: ns}) - p := &test.Params{Tekton: cs.Pipeline, Kube: cs.Kube} - - pipelinerun := Command(p) - out, err := test.ExecuteCommand(pipelinerun, "desc", "bar", "-n", "invalid") - if err == nil { - t.Errorf("Expected error for invalid namespace") - } - expected := "Error: failed to find pipelinerun \"bar\"\n" - test.AssertOutput(t, expected, out) -} - -func TestPipelineRunDescribe_not_found(t *testing.T) { - ns := []*corev1.Namespace{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: "ns", - }, - }, - } - - cs, _ := test.SeedV1beta1TestData(t, pipelinev1beta1test.Data{Namespaces: ns}) + cs, _ := test.SeedV1beta1TestData(t, pipelinetest.Data{Namespaces: ns}) cs.Pipeline.Resources = cb.APIResourceList("v1beta1", []string{"pipelinerun"}) tdc := testDynamic.Options{} dynamic, err := tdc.Client() @@ -82,7 +62,7 @@ func TestPipelineRunDescribe_not_found(t *testing.T) { test.AssertOutput(t, expected, err.Error()) } -func TestPipelineRunDescribe_only_taskrun(t *testing.T) { +func TestPipelineRunDescribe_only_taskrun_v1beta1(t *testing.T) { clock := clockwork.NewFakeClock() trs := []*v1beta1.TaskRun{ @@ -124,8 +104,14 @@ func TestPipelineRunDescribe_only_taskrun(t *testing.T) { }, Status: v1beta1.PipelineRunStatus{ PipelineRunStatusFields: v1beta1.PipelineRunStatusFields{ - TaskRuns: map[string]*v1beta1.PipelineRunTaskRunStatus{ - "tr-1": {PipelineTaskName: "t-1", Status: &trs[0].Status}, + ChildReferences: []v1beta1.ChildStatusReference{ + { + Name: "tr-1", + PipelineTaskName: "t-1", + TypeMeta: runtime.TypeMeta{ + Kind: "TaskRun", + }, + }, }, StartTime: &metav1.Time{Time: clock.Now()}, CompletionTime: &metav1.Time{Time: clock.Now().Add(5 * time.Minute)}, @@ -159,7 +145,7 @@ func TestPipelineRunDescribe_only_taskrun(t *testing.T) { if err != nil { t.Errorf("unable to create dynamic client: %v", err) } - cs, _ := test.SeedV1beta1TestData(t, pipelinev1beta1test.Data{Namespaces: namespaces, PipelineRuns: pipelineRuns, + cs, _ := test.SeedV1beta1TestData(t, pipelinetest.Data{Namespaces: namespaces, PipelineRuns: pipelineRuns, TaskRuns: trs, }) cs.Pipeline.Resources = cb.APIResourceList(version, []string{"pipelinerun", "taskrun"}) @@ -174,7 +160,7 @@ func TestPipelineRunDescribe_only_taskrun(t *testing.T) { golden.Assert(t, actual, fmt.Sprintf("%s.golden", t.Name())) } -func TestPipelineRunDescribe_multiple_taskrun_ordering(t *testing.T) { +func TestPipelineRunDescribe_multiple_taskrun_ordering_v1beta1(t *testing.T) { clock := clockwork.NewFakeClock() trs := []*v1beta1.TaskRun{ @@ -236,9 +222,21 @@ func TestPipelineRunDescribe_multiple_taskrun_ordering(t *testing.T) { }, Status: v1beta1.PipelineRunStatus{ PipelineRunStatusFields: v1beta1.PipelineRunStatusFields{ - TaskRuns: map[string]*v1beta1.PipelineRunTaskRunStatus{ - "tr-1": {PipelineTaskName: "t-1", Status: &trs[0].Status}, - "tr-2": {PipelineTaskName: "t-2", Status: &trs[1].Status}, + ChildReferences: []v1beta1.ChildStatusReference{ + { + Name: "tr-1", + PipelineTaskName: "t-1", + TypeMeta: runtime.TypeMeta{ + Kind: "TaskRun", + }, + }, + { + Name: "tr-2", + PipelineTaskName: "t-2", + TypeMeta: runtime.TypeMeta{ + Kind: "TaskRun", + }, + }, }, StartTime: &metav1.Time{Time: clock.Now()}, CompletionTime: &metav1.Time{Time: clock.Now().Add(15 * time.Minute)}, @@ -273,7 +271,7 @@ func TestPipelineRunDescribe_multiple_taskrun_ordering(t *testing.T) { if err != nil { t.Errorf("unable to create dynamic client: %v", err) } - cs, _ := test.SeedV1beta1TestData(t, pipelinev1beta1test.Data{Namespaces: namespaces, PipelineRuns: pipelineRuns, + cs, _ := test.SeedV1beta1TestData(t, pipelinetest.Data{Namespaces: namespaces, PipelineRuns: pipelineRuns, TaskRuns: trs, }) cs.Pipeline.Resources = cb.APIResourceList(version, []string{"pipelinerun", "taskrun"}) @@ -289,7 +287,7 @@ func TestPipelineRunDescribe_multiple_taskrun_ordering(t *testing.T) { } -func TestPipelineRunDescribe_multiple_taskrun_without_status(t *testing.T) { +func TestPipelineRunDescribe_multiple_taskrun_without_status_v1beta1(t *testing.T) { clock := clockwork.NewFakeClock() trs := []*v1beta1.TaskRun{ @@ -313,6 +311,13 @@ func TestPipelineRunDescribe_multiple_taskrun_without_status(t *testing.T) { }, }, }, + { + ObjectMeta: metav1.ObjectMeta{ + Name: "tr-0", + Namespace: "ns", + }, + Status: v1beta1.TaskRunStatus{}, + }, } pipelineRuns := []*v1beta1.PipelineRun{ @@ -331,9 +336,21 @@ func TestPipelineRunDescribe_multiple_taskrun_without_status(t *testing.T) { }, Status: v1beta1.PipelineRunStatus{ PipelineRunStatusFields: v1beta1.PipelineRunStatusFields{ - TaskRuns: map[string]*v1beta1.PipelineRunTaskRunStatus{ - "tr-0": {PipelineTaskName: "t-0"}, - "tr-1": {PipelineTaskName: "t-1", Status: &trs[0].Status}, + ChildReferences: []v1beta1.ChildStatusReference{ + { + Name: "tr-1", + PipelineTaskName: "t-1", + TypeMeta: runtime.TypeMeta{ + Kind: "TaskRun", + }, + }, + { + Name: "tr-0", + PipelineTaskName: "t-0", + TypeMeta: runtime.TypeMeta{ + Kind: "TaskRun", + }, + }, }, StartTime: &metav1.Time{Time: clock.Now()}, CompletionTime: &metav1.Time{Time: clock.Now().Add(5 * time.Minute)}, @@ -363,11 +380,12 @@ func TestPipelineRunDescribe_multiple_taskrun_without_status(t *testing.T) { dynamic, err := tdc.Client( cb.UnstructuredV1beta1PR(pipelineRuns[0], version), cb.UnstructuredV1beta1TR(trs[0], version), + cb.UnstructuredV1beta1TR(trs[1], version), ) if err != nil { t.Errorf("unable to create dynamic client: %v", err) } - cs, _ := test.SeedV1beta1TestData(t, pipelinev1beta1test.Data{Namespaces: namespaces, PipelineRuns: pipelineRuns, + cs, _ := test.SeedV1beta1TestData(t, pipelinetest.Data{Namespaces: namespaces, PipelineRuns: pipelineRuns, TaskRuns: trs, }) cs.Pipeline.Resources = cb.APIResourceList(version, []string{"pipelinerun", "taskrun"}) @@ -382,7 +400,7 @@ func TestPipelineRunDescribe_multiple_taskrun_without_status(t *testing.T) { golden.Assert(t, actual, fmt.Sprintf("%s.golden", t.Name())) } -func TestPipelineRunDescribe_failed(t *testing.T) { +func TestPipelineRunDescribe_failed_v1beta1(t *testing.T) { clock := clockwork.NewFakeClock() trs := []*v1beta1.TaskRun{ @@ -426,8 +444,14 @@ func TestPipelineRunDescribe_failed(t *testing.T) { }, Status: v1beta1.PipelineRunStatus{ PipelineRunStatusFields: v1beta1.PipelineRunStatusFields{ - TaskRuns: map[string]*v1beta1.PipelineRunTaskRunStatus{ - "tr-1": {PipelineTaskName: "t-1", Status: &trs[0].Status}, + ChildReferences: []v1beta1.ChildStatusReference{ + { + Name: "tr-1", + PipelineTaskName: "t-1", + TypeMeta: runtime.TypeMeta{ + Kind: "TaskRun", + }, + }, }, StartTime: &metav1.Time{Time: clock.Now()}, CompletionTime: &metav1.Time{Time: clock.Now().Add(5 * time.Minute)}, @@ -462,7 +486,7 @@ func TestPipelineRunDescribe_failed(t *testing.T) { if err != nil { t.Errorf("unable to create dynamic client: %v", err) } - cs, _ := test.SeedV1beta1TestData(t, pipelinev1beta1test.Data{Namespaces: namespaces, PipelineRuns: pipelineRuns, + cs, _ := test.SeedV1beta1TestData(t, pipelinetest.Data{Namespaces: namespaces, PipelineRuns: pipelineRuns, TaskRuns: trs, }) cs.Pipeline.Resources = cb.APIResourceList(version, []string{"pipelinerun", "taskrun"}) @@ -477,7 +501,7 @@ func TestPipelineRunDescribe_failed(t *testing.T) { golden.Assert(t, actual, fmt.Sprintf("%s.golden", t.Name())) } -func TestPipelineRunDescribe_last_no_PipelineRun_present(t *testing.T) { +func TestPipelineRunDescribe_last_no_PipelineRun_present_v1beta1(t *testing.T) { pipelineRuns := []*v1beta1.PipelineRun{} namespaces := []*corev1.Namespace{ { @@ -493,7 +517,7 @@ func TestPipelineRunDescribe_last_no_PipelineRun_present(t *testing.T) { if err != nil { t.Errorf("unable to create dynamic client: %v", err) } - cs, _ := test.SeedV1beta1TestData(t, pipelinev1beta1test.Data{Namespaces: namespaces, PipelineRuns: pipelineRuns}) + cs, _ := test.SeedV1beta1TestData(t, pipelinetest.Data{Namespaces: namespaces, PipelineRuns: pipelineRuns}) cs.Pipeline.Resources = cb.APIResourceList(version, []string{"pipelinerun"}) p := &test.Params{Tekton: cs.Pipeline, Kube: cs.Kube, Dynamic: dynamic} @@ -507,7 +531,7 @@ func TestPipelineRunDescribe_last_no_PipelineRun_present(t *testing.T) { test.AssertOutput(t, expected, out) } -func TestPipelineRunDescribe_failed_withoutTRCondition(t *testing.T) { +func TestPipelineRunDescribe_failed_withoutTRCondition_v1beta1(t *testing.T) { clock := clockwork.NewFakeClock() trs := []*v1beta1.TaskRun{ @@ -542,8 +566,14 @@ func TestPipelineRunDescribe_failed_withoutTRCondition(t *testing.T) { }, Status: v1beta1.PipelineRunStatus{ PipelineRunStatusFields: v1beta1.PipelineRunStatusFields{ - TaskRuns: map[string]*v1beta1.PipelineRunTaskRunStatus{ - "tr-1": {PipelineTaskName: "t-1", Status: &trs[0].Status}, + ChildReferences: []v1beta1.ChildStatusReference{ + { + Name: "tr-1", + PipelineTaskName: "t-1", + TypeMeta: runtime.TypeMeta{ + Kind: "TaskRun", + }, + }, }, StartTime: &metav1.Time{Time: clock.Now()}, CompletionTime: &metav1.Time{Time: clock.Now().Add(5 * time.Minute)}, @@ -578,7 +608,7 @@ func TestPipelineRunDescribe_failed_withoutTRCondition(t *testing.T) { if err != nil { t.Errorf("unable to create dynamic client: %v", err) } - cs, _ := test.SeedV1beta1TestData(t, pipelinev1beta1test.Data{Namespaces: namespaces, PipelineRuns: pipelineRuns, + cs, _ := test.SeedV1beta1TestData(t, pipelinetest.Data{Namespaces: namespaces, PipelineRuns: pipelineRuns, TaskRuns: trs, }) cs.Pipeline.Resources = cb.APIResourceList(version, []string{"pipelinerun", "taskrun"}) @@ -593,7 +623,7 @@ func TestPipelineRunDescribe_failed_withoutTRCondition(t *testing.T) { golden.Assert(t, actual, fmt.Sprintf("%s.golden", t.Name())) } -func TestPipelineRunDescribe_failed_withoutPRCondition(t *testing.T) { +func TestPipelineRunDescribe_failed_withoutPRCondition_v1beta1(t *testing.T) { clock := clockwork.NewFakeClock() trs := []*v1beta1.TaskRun{ @@ -628,8 +658,14 @@ func TestPipelineRunDescribe_failed_withoutPRCondition(t *testing.T) { }, Status: v1beta1.PipelineRunStatus{ PipelineRunStatusFields: v1beta1.PipelineRunStatusFields{ - TaskRuns: map[string]*v1beta1.PipelineRunTaskRunStatus{ - "tr-1": {PipelineTaskName: "t-1", Status: &trs[0].Status}, + ChildReferences: []v1beta1.ChildStatusReference{ + { + Name: "tr-1", + PipelineTaskName: "t-1", + TypeMeta: runtime.TypeMeta{ + Kind: "TaskRun", + }, + }, }, StartTime: &metav1.Time{Time: clock.Now()}, CompletionTime: &metav1.Time{Time: clock.Now().Add(5 * time.Minute)}, @@ -655,7 +691,7 @@ func TestPipelineRunDescribe_failed_withoutPRCondition(t *testing.T) { if err != nil { t.Errorf("unable to create dynamic client: %v", err) } - cs, _ := test.SeedV1beta1TestData(t, pipelinev1beta1test.Data{Namespaces: namespaces, PipelineRuns: pipelineRuns, + cs, _ := test.SeedV1beta1TestData(t, pipelinetest.Data{Namespaces: namespaces, PipelineRuns: pipelineRuns, TaskRuns: trs, }) cs.Pipeline.Resources = cb.APIResourceList(version, []string{"pipelinerun", "taskrun"}) @@ -670,7 +706,7 @@ func TestPipelineRunDescribe_failed_withoutPRCondition(t *testing.T) { golden.Assert(t, actual, fmt.Sprintf("%s.golden", t.Name())) } -func TestPipelineRunDescribe_with_resources_taskrun(t *testing.T) { +func TestPipelineRunDescribe_with_resources_taskrun_v1beta1(t *testing.T) { clock := clockwork.NewFakeClock() trs := []*v1beta1.TaskRun{ @@ -730,8 +766,14 @@ func TestPipelineRunDescribe_with_resources_taskrun(t *testing.T) { }, Status: v1beta1.PipelineRunStatus{ PipelineRunStatusFields: v1beta1.PipelineRunStatusFields{ - TaskRuns: map[string]*v1beta1.PipelineRunTaskRunStatus{ - "tr-1": {PipelineTaskName: "t-1", Status: &trs[0].Status}, + ChildReferences: []v1beta1.ChildStatusReference{ + { + Name: "tr-1", + PipelineTaskName: "t-1", + TypeMeta: runtime.TypeMeta{ + Kind: "TaskRun", + }, + }, }, StartTime: &metav1.Time{Time: clock.Now()}, CompletionTime: &metav1.Time{Time: clock.Now().Add(5 * time.Minute)}, @@ -765,7 +807,7 @@ func TestPipelineRunDescribe_with_resources_taskrun(t *testing.T) { if err != nil { t.Errorf("unable to create dynamic client: %v", err) } - cs, _ := test.SeedV1beta1TestData(t, pipelinev1beta1test.Data{Namespaces: namespaces, PipelineRuns: pipelineRuns, + cs, _ := test.SeedV1beta1TestData(t, pipelinetest.Data{Namespaces: namespaces, PipelineRuns: pipelineRuns, TaskRuns: trs, }) cs.Pipeline.Resources = cb.APIResourceList(version, []string{"pipelinerun", "taskrun"}) @@ -780,7 +822,7 @@ func TestPipelineRunDescribe_with_resources_taskrun(t *testing.T) { golden.Assert(t, actual, fmt.Sprintf("%s.golden", t.Name())) } -func TestPipelineRunDescribe_without_start_time(t *testing.T) { +func TestPipelineRunDescribe_without_start_time_v1beta1(t *testing.T) { clock := clockwork.NewFakeClock() pipelineRuns := []*v1beta1.PipelineRun{ @@ -816,7 +858,7 @@ func TestPipelineRunDescribe_without_start_time(t *testing.T) { if err != nil { t.Errorf("unable to create dynamic client: %v", err) } - cs, _ := test.SeedV1beta1TestData(t, pipelinev1beta1test.Data{Namespaces: namespaces, PipelineRuns: pipelineRuns}) + cs, _ := test.SeedV1beta1TestData(t, pipelinetest.Data{Namespaces: namespaces, PipelineRuns: pipelineRuns}) cs.Pipeline.Resources = cb.APIResourceList(version, []string{"pipelinerun", "taskrun"}) p := &test.Params{Tekton: cs.Pipeline, Kube: cs.Kube, Dynamic: dynamic, Clock: clock} @@ -829,7 +871,7 @@ func TestPipelineRunDescribe_without_start_time(t *testing.T) { golden.Assert(t, actual, fmt.Sprintf("%s.golden", t.Name())) } -func TestPipelineRunDescribe_without_pipelineref(t *testing.T) { +func TestPipelineRunDescribe_without_pipelineref_v1beta1(t *testing.T) { clock := clockwork.NewFakeClock() pipelineRuns := []*v1beta1.PipelineRun{ @@ -859,7 +901,7 @@ func TestPipelineRunDescribe_without_pipelineref(t *testing.T) { if err != nil { t.Errorf("unable to create dynamic client: %v", err) } - cs, _ := test.SeedV1beta1TestData(t, pipelinev1beta1test.Data{Namespaces: namespaces, PipelineRuns: pipelineRuns}) + cs, _ := test.SeedV1beta1TestData(t, pipelinetest.Data{Namespaces: namespaces, PipelineRuns: pipelineRuns}) cs.Pipeline.Resources = cb.APIResourceList(version, []string{"pipelinerun", "taskrun"}) p := &test.Params{Tekton: cs.Pipeline, Kube: cs.Kube, Dynamic: dynamic, Clock: clock} @@ -872,7 +914,7 @@ func TestPipelineRunDescribe_without_pipelineref(t *testing.T) { golden.Assert(t, actual, fmt.Sprintf("%s.golden", t.Name())) } -func TestPipelineRunDescribe_withoutNameOfOnlyOnePipelineRunPresent(t *testing.T) { +func TestPipelineRunDescribe_withoutNameOfOnlyOnePipelineRunPresent_v1beta1(t *testing.T) { clock := clockwork.NewFakeClock() pipelineRuns := []*v1beta1.PipelineRun{ @@ -902,7 +944,7 @@ func TestPipelineRunDescribe_withoutNameOfOnlyOnePipelineRunPresent(t *testing.T if err != nil { t.Errorf("unable to create dynamic client: %v", err) } - cs, _ := test.SeedV1beta1TestData(t, pipelinev1beta1test.Data{Namespaces: namespaces, PipelineRuns: pipelineRuns}) + cs, _ := test.SeedV1beta1TestData(t, pipelinetest.Data{Namespaces: namespaces, PipelineRuns: pipelineRuns}) cs.Pipeline.Resources = cb.APIResourceList(version, []string{"pipelinerun", "taskrun"}) p := &test.Params{Tekton: cs.Pipeline, Kube: cs.Kube, Dynamic: dynamic, Clock: clock} p.SetNamespace("ns") @@ -915,7 +957,7 @@ func TestPipelineRunDescribe_withoutNameOfOnlyOnePipelineRunPresent(t *testing.T golden.Assert(t, actual, fmt.Sprintf("%s.golden", t.Name())) } -func TestPipelineRunDescribe_no_resourceref(t *testing.T) { +func TestPipelineRunDescribe_no_resourceref_v1beta1(t *testing.T) { clock := clockwork.NewFakeClock() trs := []*v1beta1.TaskRun{ @@ -972,8 +1014,14 @@ func TestPipelineRunDescribe_no_resourceref(t *testing.T) { }, Status: v1beta1.PipelineRunStatus{ PipelineRunStatusFields: v1beta1.PipelineRunStatusFields{ - TaskRuns: map[string]*v1beta1.PipelineRunTaskRunStatus{ - "tr-1": {PipelineTaskName: "t-1", Status: &trs[0].Status}, + ChildReferences: []v1beta1.ChildStatusReference{ + { + Name: "tr-1", + PipelineTaskName: "t-1", + TypeMeta: runtime.TypeMeta{ + Kind: "TaskRun", + }, + }, }, StartTime: &metav1.Time{Time: clock.Now()}, CompletionTime: &metav1.Time{Time: clock.Now().Add(5 * time.Minute)}, @@ -1007,7 +1055,7 @@ func TestPipelineRunDescribe_no_resourceref(t *testing.T) { if err != nil { t.Errorf("unable to create dynamic client: %v", err) } - cs, _ := test.SeedV1beta1TestData(t, pipelinev1beta1test.Data{Namespaces: namespaces, PipelineRuns: pipelineRuns, + cs, _ := test.SeedV1beta1TestData(t, pipelinetest.Data{Namespaces: namespaces, PipelineRuns: pipelineRuns, TaskRuns: trs, }) cs.Pipeline.Resources = cb.APIResourceList(version, []string{"pipelinerun", "taskrun"}) @@ -1022,7 +1070,7 @@ func TestPipelineRunDescribe_no_resourceref(t *testing.T) { golden.Assert(t, actual, fmt.Sprintf("%s.golden", t.Name())) } -func TestPipelineRunDescribe_cancelled_pipelinerun(t *testing.T) { +func TestPipelineRunDescribe_cancelled_pipelinerun_v1beta1(t *testing.T) { clock := clockwork.NewFakeClock() trs := []*v1beta1.TaskRun{ @@ -1064,8 +1112,14 @@ func TestPipelineRunDescribe_cancelled_pipelinerun(t *testing.T) { }, Status: v1beta1.PipelineRunStatus{ PipelineRunStatusFields: v1beta1.PipelineRunStatusFields{ - TaskRuns: map[string]*v1beta1.PipelineRunTaskRunStatus{ - "tr-1": {PipelineTaskName: "t-1", Status: &trs[0].Status}, + ChildReferences: []v1beta1.ChildStatusReference{ + { + Name: "tr-1", + PipelineTaskName: "t-1", + TypeMeta: runtime.TypeMeta{ + Kind: "TaskRun", + }, + }, }, StartTime: &metav1.Time{Time: clock.Now()}, CompletionTime: &metav1.Time{Time: clock.Now().Add(5 * time.Minute)}, @@ -1100,7 +1154,7 @@ func TestPipelineRunDescribe_cancelled_pipelinerun(t *testing.T) { if err != nil { t.Errorf("unable to create dynamic client: %v", err) } - cs, _ := test.SeedV1beta1TestData(t, pipelinev1beta1test.Data{Namespaces: namespaces, PipelineRuns: pipelineRuns, + cs, _ := test.SeedV1beta1TestData(t, pipelinetest.Data{Namespaces: namespaces, PipelineRuns: pipelineRuns, TaskRuns: trs, }) cs.Pipeline.Resources = cb.APIResourceList(version, []string{"pipelinerun", "taskrun"}) @@ -1115,7 +1169,7 @@ func TestPipelineRunDescribe_cancelled_pipelinerun(t *testing.T) { golden.Assert(t, actual, fmt.Sprintf("%s.golden", t.Name())) } -func TestPipelineRunDescribe_without_tr_start_time(t *testing.T) { +func TestPipelineRunDescribe_without_tr_start_time_v1beta1(t *testing.T) { clock := clockwork.NewFakeClock() trs := []*v1beta1.TaskRun{ @@ -1153,8 +1207,14 @@ func TestPipelineRunDescribe_without_tr_start_time(t *testing.T) { }, Status: v1beta1.PipelineRunStatus{ PipelineRunStatusFields: v1beta1.PipelineRunStatusFields{ - TaskRuns: map[string]*v1beta1.PipelineRunTaskRunStatus{ - "tr-1": {PipelineTaskName: "t-1", Status: &trs[0].Status}, + ChildReferences: []v1beta1.ChildStatusReference{ + { + Name: "tr-1", + PipelineTaskName: "t-1", + TypeMeta: runtime.TypeMeta{ + Kind: "TaskRun", + }, + }, }, StartTime: &metav1.Time{Time: clock.Now()}, }, @@ -1187,7 +1247,7 @@ func TestPipelineRunDescribe_without_tr_start_time(t *testing.T) { if err != nil { t.Errorf("unable to create dynamic client: %v", err) } - cs, _ := test.SeedV1beta1TestData(t, pipelinev1beta1test.Data{Namespaces: namespaces, PipelineRuns: pipelineRuns, + cs, _ := test.SeedV1beta1TestData(t, pipelinetest.Data{Namespaces: namespaces, PipelineRuns: pipelineRuns, TaskRuns: trs, }) cs.Pipeline.Resources = cb.APIResourceList(version, []string{"pipelinerun", "taskrun"}) @@ -1202,7 +1262,7 @@ func TestPipelineRunDescribe_without_tr_start_time(t *testing.T) { golden.Assert(t, actual, fmt.Sprintf("%s.golden", t.Name())) } -func TestPipelineRunDescribe_custom_timeout(t *testing.T) { +func TestPipelineRunDescribe_custom_timeout_v1beta1(t *testing.T) { prun := []*v1beta1.PipelineRun{ { ObjectMeta: metav1.ObjectMeta{ @@ -1236,7 +1296,7 @@ func TestPipelineRunDescribe_custom_timeout(t *testing.T) { if err != nil { t.Errorf("unable to create dynamic client: %v", err) } - cs, _ := test.SeedV1beta1TestData(t, pipelinev1beta1test.Data{Namespaces: namespaces, PipelineRuns: prun}) + cs, _ := test.SeedV1beta1TestData(t, pipelinetest.Data{Namespaces: namespaces, PipelineRuns: prun}) cs.Pipeline.Resources = cb.APIResourceList(version, []string{"pipelinerun", "taskrun"}) p := &test.Params{Tekton: cs.Pipeline, Kube: cs.Kube, Dynamic: dynamic} @@ -1248,7 +1308,7 @@ func TestPipelineRunDescribe_custom_timeout(t *testing.T) { golden.Assert(t, actual, fmt.Sprintf("%s.golden", t.Name())) } -func TestPipelineRunDescribeV1beta1_custom_output(t *testing.T) { +func TestPipelineRunDescribe_custom_output_v1beta1(t *testing.T) { pipelinerunname := "pipeline-run" expected := "pipelinerun.tekton.dev/" + pipelinerunname prun := []*v1beta1.PipelineRun{ @@ -1275,7 +1335,7 @@ func TestPipelineRunDescribeV1beta1_custom_output(t *testing.T) { if err != nil { t.Errorf("unable to create dynamic client: %v", err) } - cs, _ := test.SeedV1beta1TestData(t, pipelinev1beta1test.Data{Namespaces: namespaces, PipelineRuns: prun}) + cs, _ := test.SeedV1beta1TestData(t, pipelinetest.Data{Namespaces: namespaces, PipelineRuns: prun}) cs.Pipeline.Resources = cb.APIResourceList(version, []string{"pipelinerun", "taskrun"}) p := &test.Params{Tekton: cs.Pipeline, Kube: cs.Kube, Dynamic: dynamic} @@ -1290,7 +1350,7 @@ func TestPipelineRunDescribeV1beta1_custom_output(t *testing.T) { } } -func TestPipelineRunDescribeV1beta1(t *testing.T) { +func TestPipelineRunDescribe_v1beta1(t *testing.T) { clock := clockwork.NewFakeClock() pipelinerunname := "pipeline-run" taskRuns := []*v1beta1.TaskRun{ @@ -1402,14 +1462,20 @@ func TestPipelineRunDescribeV1beta1(t *testing.T) { PipelineRunStatusFields: v1beta1.PipelineRunStatusFields{ StartTime: &metav1.Time{Time: clock.Now()}, CompletionTime: &metav1.Time{Time: clock.Now().Add(20 * time.Minute)}, - TaskRuns: map[string]*v1beta1.PipelineRunTaskRunStatus{ - "tr-1": { + ChildReferences: []v1beta1.ChildStatusReference{ + { + Name: "tr-1", PipelineTaskName: "t-1", - Status: &taskRuns[0].Status, + TypeMeta: runtime.TypeMeta{ + Kind: "TaskRun", + }, }, - "tr-2": { + { + Name: "tr-2", PipelineTaskName: "t-2", - Status: &taskRuns[1].Status, + TypeMeta: runtime.TypeMeta{ + Kind: "TaskRun", + }, }, }, }, @@ -1435,7 +1501,7 @@ func TestPipelineRunDescribeV1beta1(t *testing.T) { if err != nil { t.Errorf("unable to create dynamic client: %v", err) } - cs, _ := test.SeedV1beta1TestData(t, pipelinev1beta1test.Data{Namespaces: namespaces, PipelineRuns: prun, TaskRuns: taskRuns}) + cs, _ := test.SeedV1beta1TestData(t, pipelinetest.Data{Namespaces: namespaces, PipelineRuns: prun, TaskRuns: taskRuns}) cs.Pipeline.Resources = cb.APIResourceList(version, []string{"pipelinerun", "taskrun"}) p := &test.Params{Tekton: cs.Pipeline, Kube: cs.Kube, Dynamic: dynamic} @@ -1447,7 +1513,7 @@ func TestPipelineRunDescribeV1beta1(t *testing.T) { golden.Assert(t, got, fmt.Sprintf("%s.golden", t.Name())) } -func TestPipelineRunDescribeV1beta1_taskrun_with_no_status(t *testing.T) { +func TestPipelineRunDescribe_taskrun_with_no_status_v1beta1(t *testing.T) { clock := clockwork.NewFakeClock() pipelinerunname := "pipeline-run" taskRuns := []*v1beta1.TaskRun{ @@ -1545,13 +1611,20 @@ func TestPipelineRunDescribeV1beta1_taskrun_with_no_status(t *testing.T) { PipelineRunStatusFields: v1beta1.PipelineRunStatusFields{ StartTime: &metav1.Time{Time: clock.Now()}, CompletionTime: &metav1.Time{Time: clock.Now().Add(20 * time.Minute)}, - TaskRuns: map[string]*v1beta1.PipelineRunTaskRunStatus{ - "tr-1": { + ChildReferences: []v1beta1.ChildStatusReference{ + { + Name: "tr-1", PipelineTaskName: "t-1", - Status: &taskRuns[0].Status, + TypeMeta: runtime.TypeMeta{ + Kind: "TaskRun", + }, }, - "tr-2": { + { + Name: "tr-2", PipelineTaskName: "t-2", + TypeMeta: runtime.TypeMeta{ + Kind: "TaskRun", + }, }, }, }, @@ -1577,7 +1650,7 @@ func TestPipelineRunDescribeV1beta1_taskrun_with_no_status(t *testing.T) { if err != nil { t.Errorf("unable to create dynamic client: %v", err) } - cs, _ := test.SeedV1beta1TestData(t, pipelinev1beta1test.Data{Namespaces: namespaces, PipelineRuns: prun, TaskRuns: taskRuns}) + cs, _ := test.SeedV1beta1TestData(t, pipelinetest.Data{Namespaces: namespaces, PipelineRuns: prun, TaskRuns: taskRuns}) cs.Pipeline.Resources = cb.APIResourceList(version, []string{"pipelinerun", "taskrun"}) p := &test.Params{Tekton: cs.Pipeline, Kube: cs.Kube, Dynamic: dynamic} @@ -1589,7 +1662,7 @@ func TestPipelineRunDescribeV1beta1_taskrun_with_no_status(t *testing.T) { golden.Assert(t, got, fmt.Sprintf("%s.golden", t.Name())) } -func TestPipelineRunDescribe_lastV1beta1(t *testing.T) { +func TestPipelineRunDescribe_last_v1beta1(t *testing.T) { clock := clockwork.NewFakeClock() pipelinerunname1 := "pipeline-run" pipelinerunname2 := "pipeline-run2" @@ -1702,14 +1775,20 @@ func TestPipelineRunDescribe_lastV1beta1(t *testing.T) { PipelineRunStatusFields: v1beta1.PipelineRunStatusFields{ StartTime: &metav1.Time{Time: clock.Now().Add(-10 * time.Minute)}, CompletionTime: &metav1.Time{Time: clock.Now().Add(10 * time.Minute)}, - TaskRuns: map[string]*v1beta1.PipelineRunTaskRunStatus{ - "tr-1": { + ChildReferences: []v1beta1.ChildStatusReference{ + { + Name: "tr-1", PipelineTaskName: "t-1", - Status: &taskRuns[0].Status, + TypeMeta: runtime.TypeMeta{ + Kind: "TaskRun", + }, }, - "tr-2": { + { + Name: "tr-2", PipelineTaskName: "t-2", - Status: &taskRuns[1].Status, + TypeMeta: runtime.TypeMeta{ + Kind: "TaskRun", + }, }, }, }, @@ -1768,14 +1847,20 @@ func TestPipelineRunDescribe_lastV1beta1(t *testing.T) { PipelineRunStatusFields: v1beta1.PipelineRunStatusFields{ StartTime: &metav1.Time{Time: clock.Now()}, CompletionTime: &metav1.Time{Time: clock.Now().Add(20 * time.Minute)}, - TaskRuns: map[string]*v1beta1.PipelineRunTaskRunStatus{ - "tr-1": { + ChildReferences: []v1beta1.ChildStatusReference{ + { + Name: "tr-1", PipelineTaskName: "t-1", - Status: &taskRuns[0].Status, + TypeMeta: runtime.TypeMeta{ + Kind: "TaskRun", + }, }, - "tr-2": { + { + Name: "tr-2", PipelineTaskName: "t-2", - Status: &taskRuns[1].Status, + TypeMeta: runtime.TypeMeta{ + Kind: "TaskRun", + }, }, }, }, @@ -1802,7 +1887,7 @@ func TestPipelineRunDescribe_lastV1beta1(t *testing.T) { if err != nil { t.Errorf("unable to create dynamic client: %v", err) } - cs, _ := test.SeedV1beta1TestData(t, pipelinev1beta1test.Data{Namespaces: namespaces, PipelineRuns: prun, TaskRuns: taskRuns}) + cs, _ := test.SeedV1beta1TestData(t, pipelinetest.Data{Namespaces: namespaces, PipelineRuns: prun, TaskRuns: taskRuns}) cs.Pipeline.Resources = cb.APIResourceList(version, []string{"pipelinerun", "taskrun"}) p := &test.Params{Tekton: cs.Pipeline, Kube: cs.Kube, Dynamic: dynamic} @@ -1814,7 +1899,7 @@ func TestPipelineRunDescribe_lastV1beta1(t *testing.T) { golden.Assert(t, got, fmt.Sprintf("%s.golden", t.Name())) } -func TestPipelineRunDescribe_v1beta1_with_results(t *testing.T) { +func TestPipelineRunDescribe_with_results_v1beta1(t *testing.T) { clock := clockwork.NewFakeClock() pipelinerunname := "pipeline-run" taskRuns := []*v1beta1.TaskRun{ @@ -1887,10 +1972,13 @@ func TestPipelineRunDescribe_v1beta1_with_results(t *testing.T) { PipelineRunStatusFields: v1beta1.PipelineRunStatusFields{ StartTime: &metav1.Time{Time: clock.Now().Add(-10 * time.Minute)}, CompletionTime: &metav1.Time{Time: clock.Now().Add(10 * time.Minute)}, - TaskRuns: map[string]*v1beta1.PipelineRunTaskRunStatus{ - "tr-1": { + ChildReferences: []v1beta1.ChildStatusReference{ + { + Name: "tr-1", PipelineTaskName: "t-1", - Status: &taskRuns[0].Status, + TypeMeta: runtime.TypeMeta{ + Kind: "TaskRun", + }, }, }, PipelineResults: []v1beta1.PipelineRunResult{ @@ -1931,7 +2019,7 @@ func TestPipelineRunDescribe_v1beta1_with_results(t *testing.T) { if err != nil { t.Errorf("unable to create dynamic client: %v", err) } - cs, _ := test.SeedV1beta1TestData(t, pipelinev1beta1test.Data{Namespaces: namespaces, PipelineRuns: prun, TaskRuns: taskRuns}) + cs, _ := test.SeedV1beta1TestData(t, pipelinetest.Data{Namespaces: namespaces, PipelineRuns: prun, TaskRuns: taskRuns}) cs.Pipeline.Resources = cb.APIResourceList(version, []string{"pipelinerun", "taskrun"}) p := &test.Params{Tekton: cs.Pipeline, Kube: cs.Kube, Dynamic: dynamic} @@ -1943,7 +2031,7 @@ func TestPipelineRunDescribe_v1beta1_with_results(t *testing.T) { golden.Assert(t, got, fmt.Sprintf("%s.golden", t.Name())) } -func TestPipelineRunDescribe_zero_timeout(t *testing.T) { +func TestPipelineRunDescribe_zero_timeout_v1beta1(t *testing.T) { prun := []*v1beta1.PipelineRun{ { ObjectMeta: metav1.ObjectMeta{ @@ -1978,7 +2066,7 @@ func TestPipelineRunDescribe_zero_timeout(t *testing.T) { t.Errorf("unable to create dynamic client: %v", err) } - cs, _ := test.SeedV1beta1TestData(t, pipelinev1beta1test.Data{Namespaces: namespaces, PipelineRuns: prun}) + cs, _ := test.SeedV1beta1TestData(t, pipelinetest.Data{Namespaces: namespaces, PipelineRuns: prun}) cs.Pipeline.Resources = cb.APIResourceList(version, []string{"pipelinerun", "taskrun"}) p := &test.Params{Tekton: cs.Pipeline, Kube: cs.Kube, Dynamic: dynamic} @@ -1991,7 +2079,7 @@ func TestPipelineRunDescribe_zero_timeout(t *testing.T) { golden.Assert(t, actual, fmt.Sprintf("%s.golden", t.Name())) } -func TestPipelineRunDescribe_v1beta1_with_workspaces(t *testing.T) { +func TestPipelineRunDescribe_with_workspaces_v1beta1(t *testing.T) { clock := clockwork.NewFakeClock() pipelinerunname := "pipeline-run" taskRuns := []*v1beta1.TaskRun{ @@ -2084,10 +2172,13 @@ func TestPipelineRunDescribe_v1beta1_with_workspaces(t *testing.T) { PipelineRunStatusFields: v1beta1.PipelineRunStatusFields{ StartTime: &metav1.Time{Time: clock.Now().Add(-10 * time.Minute)}, CompletionTime: &metav1.Time{Time: clock.Now().Add(10 * time.Minute)}, - TaskRuns: map[string]*v1beta1.PipelineRunTaskRunStatus{ - "tr-1": { + ChildReferences: []v1beta1.ChildStatusReference{ + { + Name: "tr-1", PipelineTaskName: "t-1", - Status: &taskRuns[0].Status, + TypeMeta: runtime.TypeMeta{ + Kind: "TaskRun", + }, }, }, PipelineResults: []v1beta1.PipelineRunResult{ @@ -2128,7 +2219,7 @@ func TestPipelineRunDescribe_v1beta1_with_workspaces(t *testing.T) { if err != nil { t.Errorf("unable to create dynamic client: %v", err) } - cs, _ := test.SeedV1beta1TestData(t, pipelinev1beta1test.Data{Namespaces: namespaces, PipelineRuns: prun, TaskRuns: taskRuns}) + cs, _ := test.SeedV1beta1TestData(t, pipelinetest.Data{Namespaces: namespaces, PipelineRuns: prun, TaskRuns: taskRuns}) cs.Pipeline.Resources = cb.APIResourceList(version, []string{"pipelinerun", "taskrun"}) p := &test.Params{Tekton: cs.Pipeline, Kube: cs.Kube, Dynamic: dynamic} @@ -2140,46 +2231,7 @@ func TestPipelineRunDescribe_v1beta1_with_workspaces(t *testing.T) { golden.Assert(t, got, fmt.Sprintf("%s.golden", t.Name())) } -func TestPipelineRunDescribeV1beta1_withoutNameOfOnlyOnePipelineRunPresent(t *testing.T) { - pipelinerunname := "pipeline-run" - prun := []*v1beta1.PipelineRun{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: pipelinerunname, - Namespace: "ns", - }, - }, - } - namespaces := []*corev1.Namespace{ - { - ObjectMeta: metav1.ObjectMeta{ - Name: "ns", - }, - }, - } - - version := "v1beta1" - tdc := testDynamic.Options{} - dynamic, err := tdc.Client( - cb.UnstructuredV1beta1PR(prun[0], version), - ) - if err != nil { - t.Errorf("unable to create dynamic client: %v", err) - } - cs, _ := test.SeedV1beta1TestData(t, pipelinev1beta1test.Data{Namespaces: namespaces, PipelineRuns: prun}) - cs.Pipeline.Resources = cb.APIResourceList(version, []string{"pipelinerun", "taskrun"}) - p := &test.Params{Tekton: cs.Pipeline, Kube: cs.Kube, Dynamic: dynamic} - p.SetNamespace("ns") - - pipelinerun := Command(p) - got, err := test.ExecuteCommand(pipelinerun, "desc") - if err != nil { - t.Errorf("Unexpected error: %v", err) - } - golden.Assert(t, got, fmt.Sprintf("%s.golden", t.Name())) -} - -func TestPipelineRunDescribeWithSkippedTasksV1beta1(t *testing.T) { +func TestPipelineRunDescribeWithSkippedTasks_v1beta1(t *testing.T) { clock := clockwork.NewFakeClock() pipelinerunname := "pipeline-run" taskRuns := []*v1beta1.TaskRun{ @@ -2291,14 +2343,20 @@ func TestPipelineRunDescribeWithSkippedTasksV1beta1(t *testing.T) { PipelineRunStatusFields: v1beta1.PipelineRunStatusFields{ StartTime: &metav1.Time{Time: clock.Now()}, CompletionTime: &metav1.Time{Time: clock.Now().Add(20 * time.Minute)}, - TaskRuns: map[string]*v1beta1.PipelineRunTaskRunStatus{ - "tr-1": { + ChildReferences: []v1beta1.ChildStatusReference{ + { + Name: "tr-1", PipelineTaskName: "t-1", - Status: &taskRuns[0].Status, + TypeMeta: runtime.TypeMeta{ + Kind: "TaskRun", + }, }, - "tr-2": { + { + Name: "tr-2", PipelineTaskName: "t-2", - Status: &taskRuns[1].Status, + TypeMeta: runtime.TypeMeta{ + Kind: "TaskRun", + }, }, }, SkippedTasks: []v1beta1.SkippedTask{ @@ -2356,7 +2414,7 @@ func TestPipelineRunDescribeWithSkippedTasksV1beta1(t *testing.T) { if err != nil { t.Errorf("unable to create dynamic client: %v", err) } - cs, _ := test.SeedV1beta1TestData(t, pipelinev1beta1test.Data{Namespaces: namespaces, PipelineRuns: prun, TaskRuns: taskRuns}) + cs, _ := test.SeedV1beta1TestData(t, pipelinetest.Data{Namespaces: namespaces, PipelineRuns: prun, TaskRuns: taskRuns}) cs.Pipeline.Resources = cb.APIResourceList(version, []string{"pipelinerun", "taskrun"}) p := &test.Params{Tekton: cs.Pipeline, Kube: cs.Kube, Dynamic: dynamic} @@ -2368,7 +2426,7 @@ func TestPipelineRunDescribeWithSkippedTasksV1beta1(t *testing.T) { golden.Assert(t, got, fmt.Sprintf("%s.golden", t.Name())) } -func TestPipelineRunDescribe_cancelled_pipelinerun_multiple_taskrun(t *testing.T) { +func TestPipelineRunDescribe_cancelled_pipelinerun_multiple_taskrun_v1beta1(t *testing.T) { clock := clockwork.NewFakeClock() trs := []*v1beta1.TaskRun{ @@ -2434,9 +2492,21 @@ func TestPipelineRunDescribe_cancelled_pipelinerun_multiple_taskrun(t *testing.T }, Status: v1beta1.PipelineRunStatus{ PipelineRunStatusFields: v1beta1.PipelineRunStatusFields{ - TaskRuns: map[string]*v1beta1.PipelineRunTaskRunStatus{ - "tr-1": {PipelineTaskName: "t-1", Status: &trs[0].Status}, - "tr-2": {PipelineTaskName: "t-2", Status: &trs[1].Status}, + ChildReferences: []v1beta1.ChildStatusReference{ + { + Name: "tr-1", + PipelineTaskName: "t-1", + TypeMeta: runtime.TypeMeta{ + Kind: "TaskRun", + }, + }, + { + Name: "tr-2", + PipelineTaskName: "t-2", + TypeMeta: runtime.TypeMeta{ + Kind: "TaskRun", + }, + }, }, StartTime: &metav1.Time{Time: clock.Now()}, CompletionTime: &metav1.Time{Time: clock.Now().Add(5 * time.Minute)}, @@ -2472,7 +2542,7 @@ func TestPipelineRunDescribe_cancelled_pipelinerun_multiple_taskrun(t *testing.T if err != nil { t.Errorf("unable to create dynamic client: %v", err) } - cs, _ := test.SeedV1beta1TestData(t, pipelinev1beta1test.Data{Namespaces: namespaces, PipelineRuns: pipelineRuns, + cs, _ := test.SeedV1beta1TestData(t, pipelinetest.Data{Namespaces: namespaces, PipelineRuns: pipelineRuns, TaskRuns: trs, }) cs.Pipeline.Resources = cb.APIResourceList(version, []string{"pipelinerun", "taskrun"}) @@ -2487,7 +2557,7 @@ func TestPipelineRunDescribe_cancelled_pipelinerun_multiple_taskrun(t *testing.T golden.Assert(t, actual, fmt.Sprintf("%s.golden", t.Name())) } -func TestPipelineRunDescribeWithTimeouts(t *testing.T) { +func TestPipelineRunDescribeWithTimeouts_v1beta1(t *testing.T) { clock := clockwork.NewFakeClock() pipelinerunname := "pipeline-run" taskRuns := []*v1beta1.TaskRun{ @@ -2603,14 +2673,20 @@ func TestPipelineRunDescribeWithTimeouts(t *testing.T) { PipelineRunStatusFields: v1beta1.PipelineRunStatusFields{ StartTime: &metav1.Time{Time: clock.Now()}, CompletionTime: &metav1.Time{Time: clock.Now().Add(20 * time.Minute)}, - TaskRuns: map[string]*v1beta1.PipelineRunTaskRunStatus{ - "tr-1": { + ChildReferences: []v1beta1.ChildStatusReference{ + { + Name: "tr-1", PipelineTaskName: "t-1", - Status: &taskRuns[0].Status, + TypeMeta: runtime.TypeMeta{ + Kind: "TaskRun", + }, }, - "tr-2": { + { + Name: "tr-2", PipelineTaskName: "t-2", - Status: &taskRuns[1].Status, + TypeMeta: runtime.TypeMeta{ + Kind: "TaskRun", + }, }, }, SkippedTasks: []v1beta1.SkippedTask{ @@ -2668,7 +2744,7 @@ func TestPipelineRunDescribeWithTimeouts(t *testing.T) { if err != nil { t.Errorf("unable to create dynamic client: %v", err) } - cs, _ := test.SeedV1beta1TestData(t, pipelinev1beta1test.Data{Namespaces: namespaces, PipelineRuns: prun, TaskRuns: taskRuns}) + cs, _ := test.SeedV1beta1TestData(t, pipelinetest.Data{Namespaces: namespaces, PipelineRuns: prun, TaskRuns: taskRuns}) cs.Pipeline.Resources = cb.APIResourceList(version, []string{"pipelinerun", "taskrun"}) p := &test.Params{Tekton: cs.Pipeline, Kube: cs.Kube, Dynamic: dynamic} @@ -2680,7 +2756,7 @@ func TestPipelineRunDescribeWithTimeouts(t *testing.T) { golden.Assert(t, got, fmt.Sprintf("%s.golden", t.Name())) } -func TestPipelineRunDescribe_with_annotations(t *testing.T) { +func TestPipelineRunDescribe_with_annotations_v1beta1(t *testing.T) { prun := []*v1beta1.PipelineRun{ { ObjectMeta: metav1.ObjectMeta{ @@ -2715,7 +2791,7 @@ func TestPipelineRunDescribe_with_annotations(t *testing.T) { if err != nil { t.Errorf("unable to create dynamic client: %v", err) } - cs, _ := test.SeedV1beta1TestData(t, pipelinev1beta1test.Data{Namespaces: namespaces, PipelineRuns: prun}) + cs, _ := test.SeedV1beta1TestData(t, pipelinetest.Data{Namespaces: namespaces, PipelineRuns: prun}) cs.Pipeline.Resources = cb.APIResourceList(version, []string{"pipelinerun", "taskrun"}) p := &test.Params{Tekton: cs.Pipeline, Kube: cs.Kube, Dynamic: dynamic} diff --git a/pkg/cmd/pipelinerun/describe_v1_test.go b/pkg/cmd/pipelinerun/describe_v1_test.go new file mode 100644 index 000000000..723b14992 --- /dev/null +++ b/pkg/cmd/pipelinerun/describe_v1_test.go @@ -0,0 +1,2745 @@ +// Copyright © 2023 The Tekton Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package pipelinerun + +import ( + "fmt" + "strings" + "testing" + "time" + + "github.com/jonboulle/clockwork" + "github.com/tektoncd/cli/pkg/test" + cb "github.com/tektoncd/cli/pkg/test/builder" + testDynamic "github.com/tektoncd/cli/pkg/test/dynamic" + v1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" + "gotest.tools/v3/golden" + corev1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/selection" + "knative.dev/pkg/apis" + duckv1 "knative.dev/pkg/apis/duck/v1" +) + +func TestPipelineRunDescribe_invalid_namespace(t *testing.T) { + ns := []*corev1.Namespace{ + { + ObjectMeta: metav1.ObjectMeta{ + Name: "ns", + }, + }, + } + + cs, _ := test.SeedTestData(t, test.Data{Namespaces: ns}) + p := &test.Params{Tekton: cs.Pipeline, Kube: cs.Kube} + + pipelinerun := Command(p) + out, err := test.ExecuteCommand(pipelinerun, "desc", "bar", "-n", "invalid") + if err == nil { + t.Errorf("Expected error for invalid namespace") + } + expected := "Error: failed to find pipelinerun \"bar\"\n" + test.AssertOutput(t, expected, out) +} + +func TestPipelineRunDescribe_not_found(t *testing.T) { + ns := []*corev1.Namespace{ + { + ObjectMeta: metav1.ObjectMeta{ + Name: "ns", + }, + }, + } + + cs, _ := test.SeedTestData(t, test.Data{Namespaces: ns}) + cs.Pipeline.Resources = cb.APIResourceList("v1", []string{"pipelinerun"}) + tdc := testDynamic.Options{} + dynamic, err := tdc.Client() + if err != nil { + fmt.Println(err) + } + p := &test.Params{Tekton: cs.Pipeline, Kube: cs.Kube, Dynamic: dynamic} + + pipelinerun := Command(p) + _, err = test.ExecuteCommand(pipelinerun, "desc", "bar", "-n", "ns") + if err == nil { + t.Errorf("Expected error, did not get any") + } + expected := "failed to find pipelinerun \"bar\"" + test.AssertOutput(t, expected, err.Error()) +} + +func TestPipelineRunDescribe_only_taskrun(t *testing.T) { + clock := clockwork.NewFakeClock() + + trs := []*v1.TaskRun{ + { + ObjectMeta: metav1.ObjectMeta{ + Name: "tr-1", + Namespace: "ns", + }, + Status: v1.TaskRunStatus{ + TaskRunStatusFields: v1.TaskRunStatusFields{ + StartTime: &metav1.Time{Time: clock.Now().Add(2 * time.Minute)}, + CompletionTime: &metav1.Time{Time: clock.Now().Add(5 * time.Minute)}, + }, + Status: duckv1.Status{ + Conditions: duckv1.Conditions{ + { + Status: corev1.ConditionTrue, + Type: apis.ConditionSucceeded, + }, + }, + }, + }, + }, + } + + pipelineRuns := []*v1.PipelineRun{ + { + ObjectMeta: metav1.ObjectMeta{ + Name: "pipeline-run", + Namespace: "ns", + CreationTimestamp: metav1.Time{Time: clock.Now()}, + Labels: map[string]string{"tekton.dev/pipeline": "pipeline"}, + }, + Spec: v1.PipelineRunSpec{ + PipelineRef: &v1.PipelineRef{ + Name: "pipeline", + }, + Timeouts: &v1.TimeoutFields{ + Pipeline: &metav1.Duration{Duration: 1 * time.Hour}, + }, + }, + Status: v1.PipelineRunStatus{ + PipelineRunStatusFields: v1.PipelineRunStatusFields{ + ChildReferences: []v1.ChildStatusReference{ + { + Name: "tr-1", + PipelineTaskName: "t-1", + TypeMeta: runtime.TypeMeta{ + Kind: "TaskRun", + }, + }, + }, + StartTime: &metav1.Time{Time: clock.Now()}, + CompletionTime: &metav1.Time{Time: clock.Now().Add(5 * time.Minute)}, + }, + Status: duckv1.Status{ + Conditions: duckv1.Conditions{ + { + Status: corev1.ConditionTrue, + Reason: v1.PipelineRunReasonSuccessful.String(), + }, + }, + }, + }, + }, + } + + namespaces := []*corev1.Namespace{ + { + ObjectMeta: metav1.ObjectMeta{ + Name: "ns", + }, + }, + } + + version := "v1" + tdc := testDynamic.Options{} + dynamic, err := tdc.Client( + cb.UnstructuredPR(pipelineRuns[0], version), + cb.UnstructuredTR(trs[0], version), + ) + if err != nil { + t.Errorf("unable to create dynamic client: %v", err) + } + cs, _ := test.SeedTestData(t, test.Data{Namespaces: namespaces, PipelineRuns: pipelineRuns, + TaskRuns: trs, + }) + cs.Pipeline.Resources = cb.APIResourceList(version, []string{"pipelinerun", "taskrun"}) + p := &test.Params{Tekton: cs.Pipeline, Kube: cs.Kube, Dynamic: dynamic, Clock: clock} + + pipelinerun := Command(p) + clock.Advance(10 * time.Minute) + actual, err := test.ExecuteCommand(pipelinerun, "desc", "pipeline-run", "-n", "ns") + if err != nil { + t.Errorf("Unexpected error: %v", err) + } + golden.Assert(t, actual, fmt.Sprintf("%s.golden", t.Name())) +} + +func TestPipelineRunDescribe_multiple_taskrun_ordering(t *testing.T) { + clock := clockwork.NewFakeClock() + + trs := []*v1.TaskRun{ + { + ObjectMeta: metav1.ObjectMeta{ + Name: "tr-1", + Namespace: "ns", + }, + Status: v1.TaskRunStatus{ + TaskRunStatusFields: v1.TaskRunStatusFields{ + StartTime: &metav1.Time{Time: clock.Now().Add(2 * time.Minute)}, + CompletionTime: &metav1.Time{Time: clock.Now().Add(5 * time.Minute)}, + }, + Status: duckv1.Status{ + Conditions: duckv1.Conditions{ + { + Status: corev1.ConditionTrue, + Type: apis.ConditionSucceeded, + }, + }, + }, + }, + }, + { + ObjectMeta: metav1.ObjectMeta{ + Name: "tr-2", + Namespace: "ns", + }, + Status: v1.TaskRunStatus{ + TaskRunStatusFields: v1.TaskRunStatusFields{ + StartTime: &metav1.Time{Time: clock.Now().Add(5 * time.Minute)}, + CompletionTime: &metav1.Time{Time: clock.Now().Add(9 * time.Minute)}, + }, + Status: duckv1.Status{ + Conditions: duckv1.Conditions{ + { + Status: corev1.ConditionTrue, + Type: apis.ConditionSucceeded, + }, + }, + }, + }, + }, + } + + pipelineRuns := []*v1.PipelineRun{ + { + ObjectMeta: metav1.ObjectMeta{ + Name: "pipeline-run", + Namespace: "ns", + CreationTimestamp: metav1.Time{Time: clock.Now()}, + Labels: map[string]string{"tekton.dev/pipeline": "pipeline"}, + }, + Spec: v1.PipelineRunSpec{ + PipelineRef: &v1.PipelineRef{ + Name: "pipeline", + }, + Timeouts: &v1.TimeoutFields{ + Pipeline: &metav1.Duration{Duration: 1 * time.Hour}, + }, + }, + Status: v1.PipelineRunStatus{ + PipelineRunStatusFields: v1.PipelineRunStatusFields{ + ChildReferences: []v1.ChildStatusReference{ + { + Name: "tr-1", + PipelineTaskName: "t-1", + TypeMeta: runtime.TypeMeta{ + Kind: "TaskRun", + }, + }, + { + Name: "tr-2", + PipelineTaskName: "t-2", + TypeMeta: runtime.TypeMeta{ + Kind: "TaskRun", + }, + }, + }, + StartTime: &metav1.Time{Time: clock.Now()}, + CompletionTime: &metav1.Time{Time: clock.Now().Add(15 * time.Minute)}, + }, + Status: duckv1.Status{ + Conditions: duckv1.Conditions{ + { + Status: corev1.ConditionTrue, + Reason: v1.PipelineRunReasonSuccessful.String(), + }, + }, + }, + }, + }, + } + + namespaces := []*corev1.Namespace{ + { + ObjectMeta: metav1.ObjectMeta{ + Name: "ns", + }, + }, + } + + version := "v1" + tdc := testDynamic.Options{} + dynamic, err := tdc.Client( + cb.UnstructuredPR(pipelineRuns[0], version), + cb.UnstructuredTR(trs[0], version), + cb.UnstructuredTR(trs[1], version), + ) + if err != nil { + t.Errorf("unable to create dynamic client: %v", err) + } + cs, _ := test.SeedTestData(t, test.Data{Namespaces: namespaces, PipelineRuns: pipelineRuns, + TaskRuns: trs, + }) + cs.Pipeline.Resources = cb.APIResourceList(version, []string{"pipelinerun", "taskrun"}) + p := &test.Params{Tekton: cs.Pipeline, Kube: cs.Kube, Dynamic: dynamic, Clock: clock} + + pipelinerun := Command(p) + clock.Advance(10 * time.Minute) + actual, err := test.ExecuteCommand(pipelinerun, "desc", "pipeline-run", "-n", "ns") + if err != nil { + t.Errorf("Unexpected error: %v", err) + } + golden.Assert(t, actual, fmt.Sprintf("%s.golden", t.Name())) + +} + +func TestPipelineRunDescribe_multiple_taskrun_without_status(t *testing.T) { + clock := clockwork.NewFakeClock() + + trs := []*v1.TaskRun{ + { + ObjectMeta: metav1.ObjectMeta{ + Name: "tr-1", + Namespace: "ns", + }, + Status: v1.TaskRunStatus{ + TaskRunStatusFields: v1.TaskRunStatusFields{ + StartTime: &metav1.Time{Time: clock.Now().Add(2 * time.Minute)}, + CompletionTime: &metav1.Time{Time: clock.Now().Add(5 * time.Minute)}, + }, + Status: duckv1.Status{ + Conditions: duckv1.Conditions{ + { + Status: corev1.ConditionTrue, + Type: apis.ConditionSucceeded, + }, + }, + }, + }, + }, + { + ObjectMeta: metav1.ObjectMeta{ + Name: "tr-0", + Namespace: "ns", + }, + Status: v1.TaskRunStatus{}, + }, + } + + pipelineRuns := []*v1.PipelineRun{ + { + ObjectMeta: metav1.ObjectMeta{ + Name: "pipeline-run", + Namespace: "ns", + CreationTimestamp: metav1.Time{Time: clock.Now()}, + Labels: map[string]string{"tekton.dev/pipeline": "pipeline"}, + }, + Spec: v1.PipelineRunSpec{ + Timeouts: &v1.TimeoutFields{ + Pipeline: &metav1.Duration{Duration: 1 * time.Hour}, + }, + PipelineRef: &v1.PipelineRef{ + Name: "pipeline", + }, + }, + Status: v1.PipelineRunStatus{ + PipelineRunStatusFields: v1.PipelineRunStatusFields{ + ChildReferences: []v1.ChildStatusReference{ + { + Name: "tr-1", + PipelineTaskName: "t-1", + TypeMeta: runtime.TypeMeta{ + Kind: "TaskRun", + }, + }, + { + Name: "tr-0", + PipelineTaskName: "t-0", + TypeMeta: runtime.TypeMeta{ + Kind: "TaskRun", + }, + }, + }, + StartTime: &metav1.Time{Time: clock.Now()}, + CompletionTime: &metav1.Time{Time: clock.Now().Add(5 * time.Minute)}, + }, + Status: duckv1.Status{ + Conditions: duckv1.Conditions{ + { + Status: corev1.ConditionFalse, + Reason: v1.PipelineRunReasonFailed.String(), + }, + }, + }, + }, + }, + } + + namespaces := []*corev1.Namespace{ + { + ObjectMeta: metav1.ObjectMeta{ + Name: "ns", + }, + }, + } + + version := "v1" + tdc := testDynamic.Options{} + dynamic, err := tdc.Client( + cb.UnstructuredPR(pipelineRuns[0], version), + cb.UnstructuredTR(trs[0], version), + cb.UnstructuredTR(trs[1], version), + ) + if err != nil { + t.Errorf("unable to create dynamic client: %v", err) + } + cs, _ := test.SeedTestData(t, test.Data{Namespaces: namespaces, PipelineRuns: pipelineRuns, + TaskRuns: trs, + }) + cs.Pipeline.Resources = cb.APIResourceList(version, []string{"pipelinerun", "taskrun"}) + p := &test.Params{Tekton: cs.Pipeline, Kube: cs.Kube, Dynamic: dynamic, Clock: clock} + + pipelinerun := Command(p) + clock.Advance(10 * time.Minute) + actual, err := test.ExecuteCommand(pipelinerun, "desc", "pipeline-run", "-n", "ns") + if err != nil { + t.Errorf("Unexpected error: %v", err) + } + golden.Assert(t, actual, fmt.Sprintf("%s.golden", t.Name())) +} + +func TestPipelineRunDescribe_failed(t *testing.T) { + clock := clockwork.NewFakeClock() + + trs := []*v1.TaskRun{ + { + ObjectMeta: metav1.ObjectMeta{ + Name: "tr-1", + Namespace: "ns", + }, + Status: v1.TaskRunStatus{ + TaskRunStatusFields: v1.TaskRunStatusFields{ + StartTime: &metav1.Time{Time: clock.Now().Add(2 * time.Minute)}, + CompletionTime: &metav1.Time{Time: clock.Now().Add(5 * time.Minute)}, + }, + Status: duckv1.Status{ + Conditions: duckv1.Conditions{ + { + Status: corev1.ConditionFalse, + Reason: v1.PipelineRunReasonFailed.String(), + Message: "Testing tr failed", + }, + }, + }, + }, + }, + } + + pipelineRuns := []*v1.PipelineRun{ + { + ObjectMeta: metav1.ObjectMeta{ + Name: "pipeline-run", + Namespace: "ns", + CreationTimestamp: metav1.Time{Time: clock.Now()}, + Labels: map[string]string{"tekton.dev/pipeline": "pipeline"}, + }, + Spec: v1.PipelineRunSpec{ + Timeouts: &v1.TimeoutFields{ + Pipeline: &metav1.Duration{Duration: 1 * time.Hour}, + }, + PipelineRef: &v1.PipelineRef{ + Name: "pipeline", + }, + TaskRunTemplate: v1.PipelineTaskRunTemplate{ + ServiceAccountName: "test-sa", + }, + }, + Status: v1.PipelineRunStatus{ + PipelineRunStatusFields: v1.PipelineRunStatusFields{ + ChildReferences: []v1.ChildStatusReference{ + { + Name: "tr-1", + PipelineTaskName: "t-1", + TypeMeta: runtime.TypeMeta{ + Kind: "TaskRun", + }, + }, + }, + StartTime: &metav1.Time{Time: clock.Now()}, + CompletionTime: &metav1.Time{Time: clock.Now().Add(5 * time.Minute)}, + }, + Status: duckv1.Status{ + Conditions: duckv1.Conditions{ + { + Status: corev1.ConditionFalse, + Reason: "Resource not found", + Message: "Resource test-resource not found in the pipelinerun", + }, + }, + }, + }, + }, + } + + namespaces := []*corev1.Namespace{ + { + ObjectMeta: metav1.ObjectMeta{ + Name: "ns", + }, + }, + } + + version := "v1" + tdc := testDynamic.Options{} + dynamic, err := tdc.Client( + cb.UnstructuredPR(pipelineRuns[0], version), + cb.UnstructuredTR(trs[0], version), + ) + if err != nil { + t.Errorf("unable to create dynamic client: %v", err) + } + cs, _ := test.SeedTestData(t, test.Data{Namespaces: namespaces, PipelineRuns: pipelineRuns, + TaskRuns: trs, + }) + cs.Pipeline.Resources = cb.APIResourceList(version, []string{"pipelinerun", "taskrun"}) + p := &test.Params{Tekton: cs.Pipeline, Kube: cs.Kube, Dynamic: dynamic, Clock: clock} + + pipelinerun := Command(p) + clock.Advance(10 * time.Minute) + actual, err := test.ExecuteCommand(pipelinerun, "desc", "pipeline-run", "-n", "ns") + if err != nil { + t.Errorf("Unexpected error: %v", err) + } + golden.Assert(t, actual, fmt.Sprintf("%s.golden", t.Name())) +} + +func TestPipelineRunDescribe_last_no_PipelineRun_present(t *testing.T) { + pipelineRuns := []*v1.PipelineRun{} + namespaces := []*corev1.Namespace{ + { + ObjectMeta: metav1.ObjectMeta{ + Name: "ns", + }, + }, + } + + version := "v1" + tdc := testDynamic.Options{} + dynamic, err := tdc.Client() + if err != nil { + t.Errorf("unable to create dynamic client: %v", err) + } + cs, _ := test.SeedTestData(t, test.Data{Namespaces: namespaces, PipelineRuns: pipelineRuns}) + + cs.Pipeline.Resources = cb.APIResourceList(version, []string{"pipelinerun"}) + p := &test.Params{Tekton: cs.Pipeline, Kube: cs.Kube, Dynamic: dynamic} + + pipelinerun := Command(p) + out, err := test.ExecuteCommand(pipelinerun, "desc", "--last", "-n", "ns") + if err != nil { + t.Errorf("Unexpected error: %v", err) + } + expected := "No PipelineRuns present in namespace ns\n" + test.AssertOutput(t, expected, out) +} + +func TestPipelineRunDescribe_failed_withoutTRCondition(t *testing.T) { + clock := clockwork.NewFakeClock() + + trs := []*v1.TaskRun{ + { + ObjectMeta: metav1.ObjectMeta{ + Name: "tr-1", + Namespace: "ns", + }, + Status: v1.TaskRunStatus{ + TaskRunStatusFields: v1.TaskRunStatusFields{ + StartTime: &metav1.Time{Time: clock.Now().Add(2 * time.Minute)}, + CompletionTime: &metav1.Time{Time: clock.Now().Add(5 * time.Minute)}, + }, + }, + }, + } + + pipelineRuns := []*v1.PipelineRun{ + { + ObjectMeta: metav1.ObjectMeta{ + Name: "pipeline-run", + Namespace: "ns", + CreationTimestamp: metav1.Time{Time: clock.Now()}, + Labels: map[string]string{"tekton.dev/pipeline": "pipeline"}, + }, + Spec: v1.PipelineRunSpec{ + Timeouts: &v1.TimeoutFields{ + Pipeline: &metav1.Duration{Duration: 1 * time.Hour}, + }, + PipelineRef: &v1.PipelineRef{ + Name: "pipeline", + }, + TaskRunTemplate: v1.PipelineTaskRunTemplate{ + ServiceAccountName: "test-sa", + }, + }, + Status: v1.PipelineRunStatus{ + PipelineRunStatusFields: v1.PipelineRunStatusFields{ + ChildReferences: []v1.ChildStatusReference{ + { + Name: "tr-1", + PipelineTaskName: "t-1", + TypeMeta: runtime.TypeMeta{ + Kind: "TaskRun", + }, + }, + }, + StartTime: &metav1.Time{Time: clock.Now()}, + CompletionTime: &metav1.Time{Time: clock.Now().Add(5 * time.Minute)}, + }, + Status: duckv1.Status{ + Conditions: duckv1.Conditions{ + { + Status: corev1.ConditionFalse, + Reason: "Resource not found", + Message: "Resource test-resource not found in the pipelinerun", + }, + }, + }, + }, + }, + } + + namespaces := []*corev1.Namespace{ + { + ObjectMeta: metav1.ObjectMeta{ + Name: "ns", + }, + }, + } + + version := "v1" + tdc := testDynamic.Options{} + dynamic, err := tdc.Client( + cb.UnstructuredPR(pipelineRuns[0], version), + cb.UnstructuredTR(trs[0], version), + ) + if err != nil { + t.Errorf("unable to create dynamic client: %v", err) + } + cs, _ := test.SeedTestData(t, test.Data{Namespaces: namespaces, PipelineRuns: pipelineRuns, + TaskRuns: trs, + }) + cs.Pipeline.Resources = cb.APIResourceList(version, []string{"pipelinerun", "taskrun"}) + p := &test.Params{Tekton: cs.Pipeline, Kube: cs.Kube, Dynamic: dynamic, Clock: clock} + + pipelinerun := Command(p) + clock.Advance(10 * time.Minute) + actual, err := test.ExecuteCommand(pipelinerun, "desc", "pipeline-run", "-n", "ns") + if err != nil { + t.Errorf("Unexpected error: %v", err) + } + golden.Assert(t, actual, fmt.Sprintf("%s.golden", t.Name())) +} + +func TestPipelineRunDescribe_failed_withoutPRCondition(t *testing.T) { + clock := clockwork.NewFakeClock() + + trs := []*v1.TaskRun{ + { + ObjectMeta: metav1.ObjectMeta{ + Name: "tr-1", + Namespace: "ns", + }, + Status: v1.TaskRunStatus{ + TaskRunStatusFields: v1.TaskRunStatusFields{ + StartTime: &metav1.Time{Time: clock.Now().Add(2 * time.Minute)}, + CompletionTime: &metav1.Time{Time: clock.Now().Add(5 * time.Minute)}, + }, + }, + }, + } + + pipelineRuns := []*v1.PipelineRun{ + { + ObjectMeta: metav1.ObjectMeta{ + Name: "pipeline-run", + Namespace: "ns", + CreationTimestamp: metav1.Time{Time: clock.Now()}, + Labels: map[string]string{"tekton.dev/pipeline": "pipeline"}, + }, + Spec: v1.PipelineRunSpec{ + Timeouts: &v1.TimeoutFields{ + Pipeline: &metav1.Duration{Duration: 1 * time.Hour}, + }, + PipelineRef: &v1.PipelineRef{ + Name: "pipeline", + }, + TaskRunTemplate: v1.PipelineTaskRunTemplate{ + ServiceAccountName: "test-sa", + }, + }, + Status: v1.PipelineRunStatus{ + PipelineRunStatusFields: v1.PipelineRunStatusFields{ + ChildReferences: []v1.ChildStatusReference{ + { + Name: "tr-1", + PipelineTaskName: "t-1", + TypeMeta: runtime.TypeMeta{ + Kind: "TaskRun", + }, + }, + }, + StartTime: &metav1.Time{Time: clock.Now()}, + CompletionTime: &metav1.Time{Time: clock.Now().Add(5 * time.Minute)}, + }, + }, + }, + } + + namespaces := []*corev1.Namespace{ + { + ObjectMeta: metav1.ObjectMeta{ + Name: "ns", + }, + }, + } + + version := "v1" + tdc := testDynamic.Options{} + dynamic, err := tdc.Client( + cb.UnstructuredPR(pipelineRuns[0], version), + cb.UnstructuredTR(trs[0], version), + ) + if err != nil { + t.Errorf("unable to create dynamic client: %v", err) + } + cs, _ := test.SeedTestData(t, test.Data{Namespaces: namespaces, PipelineRuns: pipelineRuns, + TaskRuns: trs, + }) + cs.Pipeline.Resources = cb.APIResourceList(version, []string{"pipelinerun", "taskrun"}) + p := &test.Params{Tekton: cs.Pipeline, Kube: cs.Kube, Dynamic: dynamic, Clock: clock} + + pipelinerun := Command(p) + clock.Advance(10 * time.Minute) + actual, err := test.ExecuteCommand(pipelinerun, "desc", "pipeline-run", "-n", "ns") + if err != nil { + t.Errorf("Unexpected error: %v", err) + } + golden.Assert(t, actual, fmt.Sprintf("%s.golden", t.Name())) +} + +func TestPipelineRunDescribe_with_resources_taskrun(t *testing.T) { + clock := clockwork.NewFakeClock() + + trs := []*v1.TaskRun{ + { + ObjectMeta: metav1.ObjectMeta{ + Name: "tr-1", + Namespace: "ns", + }, + Status: v1.TaskRunStatus{ + TaskRunStatusFields: v1.TaskRunStatusFields{ + StartTime: &metav1.Time{Time: clock.Now().Add(2 * time.Minute)}, + CompletionTime: &metav1.Time{Time: clock.Now().Add(5 * time.Minute)}, + }, + Status: duckv1.Status{ + Conditions: duckv1.Conditions{ + { + Status: corev1.ConditionTrue, + Type: apis.ConditionSucceeded, + }, + }, + }, + }, + }, + } + + pipelineRuns := []*v1.PipelineRun{ + { + ObjectMeta: metav1.ObjectMeta{ + Name: "pipeline-run", + Namespace: "ns", + CreationTimestamp: metav1.Time{Time: clock.Now()}, + Labels: map[string]string{"tekton.dev/pipeline": "pipeline"}, + }, + Spec: v1.PipelineRunSpec{ + Timeouts: &v1.TimeoutFields{ + Pipeline: &metav1.Duration{Duration: 1 * time.Hour}, + }, + PipelineRef: &v1.PipelineRef{ + Name: "pipeline", + }, + TaskRunTemplate: v1.PipelineTaskRunTemplate{ + ServiceAccountName: "test-sa", + }, + Params: []v1.Param{ + { + Name: "test-param", + Value: v1.ParamValue{ + Type: v1.ParamTypeString, + StringVal: "param-value", + }, + }, + }, + }, + Status: v1.PipelineRunStatus{ + PipelineRunStatusFields: v1.PipelineRunStatusFields{ + ChildReferences: []v1.ChildStatusReference{ + { + Name: "tr-1", + PipelineTaskName: "t-1", + TypeMeta: runtime.TypeMeta{ + Kind: "TaskRun", + }, + }, + }, + StartTime: &metav1.Time{Time: clock.Now()}, + CompletionTime: &metav1.Time{Time: clock.Now().Add(5 * time.Minute)}, + }, + Status: duckv1.Status{ + Conditions: duckv1.Conditions{ + { + Status: corev1.ConditionTrue, + Reason: v1.PipelineRunReasonSuccessful.String(), + }, + }, + }, + }, + }, + } + + namespaces := []*corev1.Namespace{ + { + ObjectMeta: metav1.ObjectMeta{ + Name: "ns", + }, + }, + } + + version := "v1" + tdc := testDynamic.Options{} + dynamic, err := tdc.Client( + cb.UnstructuredPR(pipelineRuns[0], version), + cb.UnstructuredTR(trs[0], version), + ) + if err != nil { + t.Errorf("unable to create dynamic client: %v", err) + } + cs, _ := test.SeedTestData(t, test.Data{Namespaces: namespaces, PipelineRuns: pipelineRuns, + TaskRuns: trs, + }) + cs.Pipeline.Resources = cb.APIResourceList(version, []string{"pipelinerun", "taskrun"}) + p := &test.Params{Tekton: cs.Pipeline, Kube: cs.Kube, Dynamic: dynamic, Clock: clock} + + pipelinerun := Command(p) + clock.Advance(10 * time.Minute) + actual, err := test.ExecuteCommand(pipelinerun, "desc", "pipeline-run", "-n", "ns") + if err != nil { + t.Errorf("Unexpected error: %v", err) + } + golden.Assert(t, actual, fmt.Sprintf("%s.golden", t.Name())) +} + +func TestPipelineRunDescribe_without_start_time(t *testing.T) { + clock := clockwork.NewFakeClock() + + pipelineRuns := []*v1.PipelineRun{ + { + ObjectMeta: metav1.ObjectMeta{ + Name: "pipeline-run", + Namespace: "ns", + CreationTimestamp: metav1.Time{Time: clock.Now()}, + Labels: map[string]string{"tekton.dev/pipeline": "pipeline"}, + }, + Spec: v1.PipelineRunSpec{ + Timeouts: &v1.TimeoutFields{ + Pipeline: &metav1.Duration{Duration: 1 * time.Hour}, + }, + PipelineRef: &v1.PipelineRef{ + Name: "pipeline", + }, + }, + }, + } + + namespaces := []*corev1.Namespace{ + { + ObjectMeta: metav1.ObjectMeta{ + Name: "ns", + }, + }, + } + + version := "v1" + tdc := testDynamic.Options{} + dynamic, err := tdc.Client( + cb.UnstructuredPR(pipelineRuns[0], version), + ) + if err != nil { + t.Errorf("unable to create dynamic client: %v", err) + } + cs, _ := test.SeedTestData(t, test.Data{Namespaces: namespaces, PipelineRuns: pipelineRuns}) + cs.Pipeline.Resources = cb.APIResourceList(version, []string{"pipelinerun", "taskrun"}) + p := &test.Params{Tekton: cs.Pipeline, Kube: cs.Kube, Dynamic: dynamic, Clock: clock} + + pipelinerun := Command(p) + clock.Advance(10 * time.Minute) + actual, err := test.ExecuteCommand(pipelinerun, "desc", "pipeline-run", "-n", "ns") + if err != nil { + t.Errorf("Unexpected error: %v", err) + } + golden.Assert(t, actual, fmt.Sprintf("%s.golden", t.Name())) +} + +func TestPipelineRunDescribe_without_pipelineref(t *testing.T) { + clock := clockwork.NewFakeClock() + + pipelineRuns := []*v1.PipelineRun{ + { + ObjectMeta: metav1.ObjectMeta{ + Name: "pipeline-run", + Namespace: "ns", + CreationTimestamp: metav1.Time{Time: clock.Now()}, + Labels: map[string]string{"tekton.dev/pipeline": "pipeline"}, + }, + }, + } + + namespaces := []*corev1.Namespace{ + { + ObjectMeta: metav1.ObjectMeta{ + Name: "ns", + }, + }, + } + + version := "v1" + tdc := testDynamic.Options{} + dynamic, err := tdc.Client( + cb.UnstructuredPR(pipelineRuns[0], version), + ) + if err != nil { + t.Errorf("unable to create dynamic client: %v", err) + } + cs, _ := test.SeedTestData(t, test.Data{Namespaces: namespaces, PipelineRuns: pipelineRuns}) + cs.Pipeline.Resources = cb.APIResourceList(version, []string{"pipelinerun", "taskrun"}) + p := &test.Params{Tekton: cs.Pipeline, Kube: cs.Kube, Dynamic: dynamic, Clock: clock} + + pipelinerun := Command(p) + clock.Advance(10 * time.Minute) + actual, err := test.ExecuteCommand(pipelinerun, "desc", "pipeline-run", "-n", "ns") + if err != nil { + t.Errorf("Unexpected error: %v", err) + } + golden.Assert(t, actual, fmt.Sprintf("%s.golden", t.Name())) +} + +func TestPipelineRunDescribe_withoutNameOfOnlyOnePipelineRunPresent(t *testing.T) { + clock := clockwork.NewFakeClock() + + pipelineRuns := []*v1.PipelineRun{ + { + ObjectMeta: metav1.ObjectMeta{ + Name: "pipeline-run", + Namespace: "ns", + CreationTimestamp: metav1.Time{Time: clock.Now()}, + Labels: map[string]string{"tekton.dev/pipeline": "pipeline"}, + }, + }, + } + + namespaces := []*corev1.Namespace{ + { + ObjectMeta: metav1.ObjectMeta{ + Name: "ns", + }, + }, + } + + version := "v1" + tdc := testDynamic.Options{} + dynamic, err := tdc.Client( + cb.UnstructuredPR(pipelineRuns[0], version), + ) + if err != nil { + t.Errorf("unable to create dynamic client: %v", err) + } + cs, _ := test.SeedTestData(t, test.Data{Namespaces: namespaces, PipelineRuns: pipelineRuns}) + cs.Pipeline.Resources = cb.APIResourceList(version, []string{"pipelinerun", "taskrun"}) + p := &test.Params{Tekton: cs.Pipeline, Kube: cs.Kube, Dynamic: dynamic, Clock: clock} + p.SetNamespace("ns") + pipelinerun := Command(p) + clock.Advance(10 * time.Minute) + actual, err := test.ExecuteCommand(pipelinerun, "desc") + if err != nil { + t.Errorf("Unexpected error: %v", err) + } + golden.Assert(t, actual, fmt.Sprintf("%s.golden", t.Name())) +} + +func TestPipelineRunDescribe_no_resourceref(t *testing.T) { + clock := clockwork.NewFakeClock() + + trs := []*v1.TaskRun{ + { + ObjectMeta: metav1.ObjectMeta{ + Name: "tr-1", + Namespace: "ns", + }, + Status: v1.TaskRunStatus{ + TaskRunStatusFields: v1.TaskRunStatusFields{ + StartTime: &metav1.Time{Time: clock.Now().Add(2 * time.Minute)}, + CompletionTime: &metav1.Time{Time: clock.Now().Add(5 * time.Minute)}, + }, + Status: duckv1.Status{ + Conditions: duckv1.Conditions{ + { + Status: corev1.ConditionTrue, + Type: apis.ConditionSucceeded, + }, + }, + }, + }, + }, + } + + pipelineRuns := []*v1.PipelineRun{ + { + ObjectMeta: metav1.ObjectMeta{ + Name: "pipeline-run", + Namespace: "ns", + CreationTimestamp: metav1.Time{Time: clock.Now()}, + Labels: map[string]string{"tekton.dev/pipeline": "pipeline"}, + }, + Spec: v1.PipelineRunSpec{ + Timeouts: &v1.TimeoutFields{ + Pipeline: &metav1.Duration{Duration: 1 * time.Hour}, + }, + PipelineRef: &v1.PipelineRef{ + Name: "pipeline", + }, + TaskRunTemplate: v1.PipelineTaskRunTemplate{ + ServiceAccountName: "test-sa", + }, + Params: []v1.Param{ + { + Name: "test-param", + Value: v1.ParamValue{ + Type: v1.ParamTypeString, + StringVal: "param-value", + }, + }, + }, + }, + Status: v1.PipelineRunStatus{ + PipelineRunStatusFields: v1.PipelineRunStatusFields{ + ChildReferences: []v1.ChildStatusReference{ + { + Name: "tr-1", + PipelineTaskName: "t-1", + TypeMeta: runtime.TypeMeta{ + Kind: "TaskRun", + }, + }, + }, + StartTime: &metav1.Time{Time: clock.Now()}, + CompletionTime: &metav1.Time{Time: clock.Now().Add(5 * time.Minute)}, + }, + Status: duckv1.Status{ + Conditions: duckv1.Conditions{ + { + Status: corev1.ConditionTrue, + Reason: v1.PipelineRunReasonSuccessful.String(), + }, + }, + }, + }, + }, + } + + namespaces := []*corev1.Namespace{ + { + ObjectMeta: metav1.ObjectMeta{ + Name: "ns", + }, + }, + } + + version := "v1" + tdc := testDynamic.Options{} + dynamic, err := tdc.Client( + cb.UnstructuredPR(pipelineRuns[0], version), + cb.UnstructuredTR(trs[0], version), + ) + if err != nil { + t.Errorf("unable to create dynamic client: %v", err) + } + cs, _ := test.SeedTestData(t, test.Data{Namespaces: namespaces, PipelineRuns: pipelineRuns, + TaskRuns: trs, + }) + cs.Pipeline.Resources = cb.APIResourceList(version, []string{"pipelinerun", "taskrun"}) + p := &test.Params{Tekton: cs.Pipeline, Kube: cs.Kube, Dynamic: dynamic, Clock: clock} + + pipelinerun := Command(p) + clock.Advance(10 * time.Minute) + actual, err := test.ExecuteCommand(pipelinerun, "desc", "pipeline-run", "-n", "ns") + if err != nil { + t.Errorf("Unexpected error: %v", err) + } + golden.Assert(t, actual, fmt.Sprintf("%s.golden", t.Name())) +} + +func TestPipelineRunDescribe_cancelled_pipelinerun(t *testing.T) { + clock := clockwork.NewFakeClock() + + trs := []*v1.TaskRun{ + { + ObjectMeta: metav1.ObjectMeta{ + Name: "tr-1", + Namespace: "ns", + }, + Status: v1.TaskRunStatus{ + TaskRunStatusFields: v1.TaskRunStatusFields{ + StartTime: &metav1.Time{Time: clock.Now().Add(2 * time.Minute)}, + CompletionTime: &metav1.Time{Time: clock.Now().Add(5 * time.Minute)}, + }, + Status: duckv1.Status{ + Conditions: duckv1.Conditions{ + { + Status: corev1.ConditionTrue, + Type: apis.ConditionSucceeded, + }, + }, + }, + }, + }, + } + + pipelineRuns := []*v1.PipelineRun{ + { + ObjectMeta: metav1.ObjectMeta{ + Name: "pipeline-run", + Namespace: "ns", + CreationTimestamp: metav1.Time{Time: clock.Now()}, + Labels: map[string]string{"tekton.dev/pipeline": "pipeline"}, + }, + Spec: v1.PipelineRunSpec{ + Timeouts: &v1.TimeoutFields{ + Pipeline: &metav1.Duration{Duration: 1 * time.Hour}, + }, + PipelineRef: &v1.PipelineRef{ + Name: "pipeline", + }, + }, + Status: v1.PipelineRunStatus{ + PipelineRunStatusFields: v1.PipelineRunStatusFields{ + ChildReferences: []v1.ChildStatusReference{ + { + Name: "tr-1", + PipelineTaskName: "t-1", + TypeMeta: runtime.TypeMeta{ + Kind: "TaskRun", + }, + }, + }, + StartTime: &metav1.Time{Time: clock.Now()}, + CompletionTime: &metav1.Time{Time: clock.Now().Add(5 * time.Minute)}, + }, + Status: duckv1.Status{ + Conditions: duckv1.Conditions{ + { + Status: corev1.ConditionFalse, + Reason: "PipelineRunCancelled", + Message: "PipelineRun \"pipeline-run\" was cancelled", + }, + }, + }, + }, + }, + } + + namespaces := []*corev1.Namespace{ + { + ObjectMeta: metav1.ObjectMeta{ + Name: "ns", + }, + }, + } + + version := "v1" + tdc := testDynamic.Options{} + dynamic, err := tdc.Client( + cb.UnstructuredPR(pipelineRuns[0], version), + cb.UnstructuredTR(trs[0], version), + ) + if err != nil { + t.Errorf("unable to create dynamic client: %v", err) + } + cs, _ := test.SeedTestData(t, test.Data{Namespaces: namespaces, PipelineRuns: pipelineRuns, + TaskRuns: trs, + }) + cs.Pipeline.Resources = cb.APIResourceList(version, []string{"pipelinerun", "taskrun"}) + p := &test.Params{Tekton: cs.Pipeline, Kube: cs.Kube, Dynamic: dynamic, Clock: clock} + + pipelinerun := Command(p) + clock.Advance(10 * time.Minute) + actual, err := test.ExecuteCommand(pipelinerun, "desc", "pipeline-run", "-n", "ns") + if err != nil { + t.Errorf("Unexpected error: %v", err) + } + golden.Assert(t, actual, fmt.Sprintf("%s.golden", t.Name())) +} + +func TestPipelineRunDescribe_without_tr_start_time(t *testing.T) { + clock := clockwork.NewFakeClock() + + trs := []*v1.TaskRun{ + { + ObjectMeta: metav1.ObjectMeta{ + Name: "tr-1", + Namespace: "ns", + }, + Status: v1.TaskRunStatus{ + Status: duckv1.Status{ + Conditions: duckv1.Conditions{ + { + Status: corev1.ConditionUnknown, + Type: apis.ConditionReady, + }, + }, + }, + }, + }, + } + + pipelineRuns := []*v1.PipelineRun{ + { + ObjectMeta: metav1.ObjectMeta{ + Name: "pipeline-run", + Namespace: "ns", + CreationTimestamp: metav1.Time{Time: clock.Now()}, + Labels: map[string]string{"tekton.dev/pipeline": "pipeline"}, + }, + Spec: v1.PipelineRunSpec{ + Timeouts: &v1.TimeoutFields{ + Pipeline: &metav1.Duration{Duration: 1 * time.Hour}, + }, + PipelineRef: &v1.PipelineRef{ + Name: "pipeline", + }, + }, + Status: v1.PipelineRunStatus{ + PipelineRunStatusFields: v1.PipelineRunStatusFields{ + ChildReferences: []v1.ChildStatusReference{ + { + Name: "tr-1", + PipelineTaskName: "t-1", + TypeMeta: runtime.TypeMeta{ + Kind: "TaskRun", + }, + }, + }, + StartTime: &metav1.Time{Time: clock.Now()}, + }, + Status: duckv1.Status{ + Conditions: duckv1.Conditions{ + { + Status: corev1.ConditionUnknown, + Reason: v1.PipelineRunReasonRunning.String(), + }, + }, + }, + }, + }, + } + + namespaces := []*corev1.Namespace{ + { + ObjectMeta: metav1.ObjectMeta{ + Name: "ns", + }, + }, + } + + version := "v1" + tdc := testDynamic.Options{} + dynamic, err := tdc.Client( + cb.UnstructuredPR(pipelineRuns[0], version), + cb.UnstructuredTR(trs[0], version), + ) + if err != nil { + t.Errorf("unable to create dynamic client: %v", err) + } + cs, _ := test.SeedTestData(t, test.Data{Namespaces: namespaces, PipelineRuns: pipelineRuns, + TaskRuns: trs, + }) + cs.Pipeline.Resources = cb.APIResourceList(version, []string{"pipelinerun", "taskrun"}) + p := &test.Params{Tekton: cs.Pipeline, Kube: cs.Kube, Dynamic: dynamic, Clock: clock} + + pipelinerun := Command(p) + clock.Advance(10 * time.Minute) + actual, err := test.ExecuteCommand(pipelinerun, "desc", "pipeline-run", "-n", "ns") + if err != nil { + t.Errorf("Unexpected error: %v", err) + } + golden.Assert(t, actual, fmt.Sprintf("%s.golden", t.Name())) +} + +func TestPipelineRunDescribe_custom_timeout(t *testing.T) { + prun := []*v1.PipelineRun{ + { + ObjectMeta: metav1.ObjectMeta{ + Name: "pr-custom-timeout", + Namespace: "ns", + }, + Spec: v1.PipelineRunSpec{ + PipelineRef: &v1.PipelineRef{ + Name: "pr-custom-timeout", + }, + Timeouts: &v1.TimeoutFields{ + Pipeline: &metav1.Duration{Duration: 1 * time.Minute}, + }, + }, + }, + } + + namespaces := []*corev1.Namespace{ + { + ObjectMeta: metav1.ObjectMeta{ + Name: "ns", + }, + }, + } + + version := "v1" + tdc := testDynamic.Options{} + dynamic, err := tdc.Client( + cb.UnstructuredPR(prun[0], version), + ) + if err != nil { + t.Errorf("unable to create dynamic client: %v", err) + } + cs, _ := test.SeedTestData(t, test.Data{Namespaces: namespaces, PipelineRuns: prun}) + cs.Pipeline.Resources = cb.APIResourceList(version, []string{"pipelinerun", "taskrun"}) + p := &test.Params{Tekton: cs.Pipeline, Kube: cs.Kube, Dynamic: dynamic} + + pipelinerun := Command(p) + actual, err := test.ExecuteCommand(pipelinerun, "desc", "pr-custom-timeout", "-n", "ns") + if err != nil { + t.Errorf("Unexpected error: %v", err) + } + golden.Assert(t, actual, fmt.Sprintf("%s.golden", t.Name())) +} + +func TestPipelineRunDescribe_custom_output(t *testing.T) { + pipelinerunname := "pipeline-run" + expected := "pipelinerun.tekton.dev/" + pipelinerunname + prun := []*v1.PipelineRun{ + { + ObjectMeta: metav1.ObjectMeta{ + Name: pipelinerunname, + Namespace: "ns", + }, + }, + } + namespaces := []*corev1.Namespace{ + { + ObjectMeta: metav1.ObjectMeta{ + Name: "ns", + }, + }, + } + + version := "v1" + tdc := testDynamic.Options{} + dynamic, err := tdc.Client( + cb.UnstructuredPR(prun[0], version), + ) + if err != nil { + t.Errorf("unable to create dynamic client: %v", err) + } + cs, _ := test.SeedTestData(t, test.Data{Namespaces: namespaces, PipelineRuns: prun}) + cs.Pipeline.Resources = cb.APIResourceList(version, []string{"pipelinerun", "taskrun"}) + p := &test.Params{Tekton: cs.Pipeline, Kube: cs.Kube, Dynamic: dynamic} + + pipelinerun := Command(p) + got, err := test.ExecuteCommand(pipelinerun, "desc", "-o", "name", "-n", "ns", pipelinerunname) + if err != nil { + t.Errorf("Unexpected error: %v", err) + } + got = strings.TrimSpace(got) + if got != expected { + t.Errorf("Result should be '%s' != '%s'", got, expected) + } +} + +func TestPipelineRunDescribe(t *testing.T) { + clock := clockwork.NewFakeClock() + pipelinerunname := "pipeline-run" + taskRuns := []*v1.TaskRun{ + { + ObjectMeta: metav1.ObjectMeta{ + Namespace: "ns", + Name: "tr-1", + Labels: map[string]string{"tekton.dev/task": "task-1"}, + }, + Spec: v1.TaskRunSpec{ + TaskRef: &v1.TaskRef{ + Name: "task-1", + }, + }, + Status: v1.TaskRunStatus{ + Status: duckv1.Status{ + Conditions: duckv1.Conditions{ + { + Status: corev1.ConditionFalse, + Reason: v1.PipelineRunReasonFailed.String(), + }, + }, + }, + TaskRunStatusFields: v1.TaskRunStatusFields{ + StartTime: &metav1.Time{Time: clock.Now()}, + CompletionTime: &metav1.Time{Time: clock.Now().Add(5 * time.Minute)}, + }, + }, + }, + { + ObjectMeta: metav1.ObjectMeta{ + Namespace: "ns", + Name: "tr-2", + Labels: map[string]string{"tekton.dev/task": "task-1"}, + }, + Spec: v1.TaskRunSpec{ + TaskRef: &v1.TaskRef{ + Name: "task-1", + }, + }, + Status: v1.TaskRunStatus{ + Status: duckv1.Status{ + Conditions: duckv1.Conditions{ + { + Status: corev1.ConditionTrue, + Reason: v1.PipelineRunReasonSuccessful.String(), + }, + }, + }, + TaskRunStatusFields: v1.TaskRunStatusFields{ + StartTime: &metav1.Time{Time: clock.Now().Add(10 * time.Minute)}, + CompletionTime: &metav1.Time{Time: clock.Now().Add(17 * time.Minute)}, + }, + }, + }, + } + + prun := []*v1.PipelineRun{ + { + ObjectMeta: metav1.ObjectMeta{ + Name: pipelinerunname, + Namespace: "ns", + }, + Spec: v1.PipelineRunSpec{ + PipelineRef: &v1.PipelineRef{ + Name: "pipeline", + }, + Params: []v1.Param{ + { + Name: "p-1", + Value: v1.ParamValue{ + Type: v1.ParamTypeString, + StringVal: "somethingdifferent", + }, + }, + { + Name: "p-2", + Value: v1.ParamValue{ + Type: v1.ParamTypeArray, + ArrayVal: []string{"booms", "booms", "booms"}, + }, + }, + }, + }, + Status: v1.PipelineRunStatus{ + Status: duckv1.Status{ + Conditions: duckv1.Conditions{ + { + Status: corev1.ConditionTrue, + Reason: v1.PipelineRunReasonSuccessful.String(), + Message: "Completed", + }, + }, + }, + PipelineRunStatusFields: v1.PipelineRunStatusFields{ + StartTime: &metav1.Time{Time: clock.Now()}, + CompletionTime: &metav1.Time{Time: clock.Now().Add(20 * time.Minute)}, + ChildReferences: []v1.ChildStatusReference{ + { + Name: "tr-1", + PipelineTaskName: "t-1", + TypeMeta: runtime.TypeMeta{ + Kind: "TaskRun", + }, + }, + { + Name: "tr-2", + PipelineTaskName: "t-2", + TypeMeta: runtime.TypeMeta{ + Kind: "TaskRun", + }, + }, + }, + }, + }, + }, + } + + namespaces := []*corev1.Namespace{ + { + ObjectMeta: metav1.ObjectMeta{ + Name: "ns", + }, + }, + } + + version := "v1" + tdc := testDynamic.Options{} + dynamic, err := tdc.Client( + cb.UnstructuredPR(prun[0], version), + cb.UnstructuredTR(taskRuns[0], version), + cb.UnstructuredTR(taskRuns[1], version), + ) + if err != nil { + t.Errorf("unable to create dynamic client: %v", err) + } + cs, _ := test.SeedTestData(t, test.Data{Namespaces: namespaces, PipelineRuns: prun, TaskRuns: taskRuns}) + cs.Pipeline.Resources = cb.APIResourceList(version, []string{"pipelinerun", "taskrun"}) + p := &test.Params{Tekton: cs.Pipeline, Kube: cs.Kube, Dynamic: dynamic} + + pipelinerun := Command(p) + got, err := test.ExecuteCommand(pipelinerun, "desc", "-n", "ns", pipelinerunname) + if err != nil { + t.Errorf("Unexpected error: %v", err) + } + golden.Assert(t, got, fmt.Sprintf("%s.golden", t.Name())) +} + +func TestPipelineRunDescribe_taskrun_with_no_status(t *testing.T) { + clock := clockwork.NewFakeClock() + pipelinerunname := "pipeline-run" + taskRuns := []*v1.TaskRun{ + { + ObjectMeta: metav1.ObjectMeta{ + Namespace: "ns", + Name: "tr-1", + Labels: map[string]string{"tekton.dev/task": "task-1"}, + }, + Spec: v1.TaskRunSpec{ + TaskRef: &v1.TaskRef{ + Name: "task-1", + }, + }, + Status: v1.TaskRunStatus{ + Status: duckv1.Status{ + Conditions: duckv1.Conditions{ + { + Status: corev1.ConditionFalse, + Reason: v1.PipelineRunReasonFailed.String(), + }, + }, + }, + TaskRunStatusFields: v1.TaskRunStatusFields{ + StartTime: &metav1.Time{Time: clock.Now()}, + CompletionTime: &metav1.Time{Time: clock.Now().Add(5 * time.Minute)}, + }, + }, + }, + { + ObjectMeta: metav1.ObjectMeta{ + Namespace: "ns", + Name: "tr-2", + Labels: map[string]string{"tekton.dev/task": "task-1"}, + }, + Spec: v1.TaskRunSpec{ + TaskRef: &v1.TaskRef{ + Name: "task-1", + }, + }, + }, + } + + prun := []*v1.PipelineRun{ + { + ObjectMeta: metav1.ObjectMeta{ + Name: pipelinerunname, + Namespace: "ns", + }, + Spec: v1.PipelineRunSpec{ + PipelineRef: &v1.PipelineRef{ + Name: "pipeline", + }, + Params: []v1.Param{ + { + Name: "p-1", + Value: v1.ParamValue{ + Type: v1.ParamTypeString, + StringVal: "somethingdifferent", + }, + }, + { + Name: "p-2", + Value: v1.ParamValue{ + Type: v1.ParamTypeArray, + ArrayVal: []string{"booms", "booms", "booms"}, + }, + }, + }, + }, + Status: v1.PipelineRunStatus{ + Status: duckv1.Status{ + Conditions: duckv1.Conditions{ + { + Status: corev1.ConditionTrue, + Reason: v1.PipelineRunReasonSuccessful.String(), + Message: "Completed", + }, + }, + }, + PipelineRunStatusFields: v1.PipelineRunStatusFields{ + StartTime: &metav1.Time{Time: clock.Now()}, + CompletionTime: &metav1.Time{Time: clock.Now().Add(20 * time.Minute)}, + ChildReferences: []v1.ChildStatusReference{ + { + Name: "tr-1", + PipelineTaskName: "t-1", + TypeMeta: runtime.TypeMeta{ + Kind: "TaskRun", + }, + }, + { + Name: "tr-2", + PipelineTaskName: "t-2", + TypeMeta: runtime.TypeMeta{ + Kind: "TaskRun", + }, + }, + }, + }, + }, + }, + } + + namespaces := []*corev1.Namespace{ + { + ObjectMeta: metav1.ObjectMeta{ + Name: "ns", + }, + }, + } + + version := "v1" + tdc := testDynamic.Options{} + dynamic, err := tdc.Client( + cb.UnstructuredPR(prun[0], version), + cb.UnstructuredTR(taskRuns[0], version), + cb.UnstructuredTR(taskRuns[1], version), + ) + if err != nil { + t.Errorf("unable to create dynamic client: %v", err) + } + cs, _ := test.SeedTestData(t, test.Data{Namespaces: namespaces, PipelineRuns: prun, TaskRuns: taskRuns}) + cs.Pipeline.Resources = cb.APIResourceList(version, []string{"pipelinerun", "taskrun"}) + p := &test.Params{Tekton: cs.Pipeline, Kube: cs.Kube, Dynamic: dynamic} + + pipelinerun := Command(p) + got, err := test.ExecuteCommand(pipelinerun, "desc", "-n", "ns", pipelinerunname) + if err != nil { + t.Errorf("Unexpected error: %v", err) + } + golden.Assert(t, got, fmt.Sprintf("%s.golden", t.Name())) +} + +func TestPipelineRunDescribe_last(t *testing.T) { + clock := clockwork.NewFakeClock() + pipelinerunname1 := "pipeline-run" + pipelinerunname2 := "pipeline-run2" + taskRuns := []*v1.TaskRun{ + { + ObjectMeta: metav1.ObjectMeta{ + Namespace: "ns", + Name: "tr-1", + Labels: map[string]string{"tekton.dev/task": "task-1"}, + }, + Spec: v1.TaskRunSpec{ + TaskRef: &v1.TaskRef{ + Name: "task-1", + }, + }, + Status: v1.TaskRunStatus{ + Status: duckv1.Status{ + Conditions: duckv1.Conditions{ + { + Status: corev1.ConditionFalse, + Reason: v1.PipelineRunReasonFailed.String(), + }, + }, + }, + TaskRunStatusFields: v1.TaskRunStatusFields{ + StartTime: &metav1.Time{Time: clock.Now()}, + CompletionTime: &metav1.Time{Time: clock.Now().Add(5 * time.Minute)}, + }, + }, + }, + { + ObjectMeta: metav1.ObjectMeta{ + Namespace: "ns", + Name: "tr-2", + Labels: map[string]string{"tekton.dev/task": "task-1"}, + }, + Spec: v1.TaskRunSpec{ + TaskRef: &v1.TaskRef{ + Name: "task-1", + }, + }, + Status: v1.TaskRunStatus{ + Status: duckv1.Status{ + Conditions: duckv1.Conditions{ + { + Status: corev1.ConditionTrue, + Reason: v1.PipelineRunReasonSuccessful.String(), + }, + }, + }, + TaskRunStatusFields: v1.TaskRunStatusFields{ + StartTime: &metav1.Time{Time: clock.Now().Add(-10 * time.Minute)}, + CompletionTime: &metav1.Time{Time: clock.Now().Add(-3 * time.Minute)}, + }, + }, + }, + } + + prun := []*v1.PipelineRun{ + { + ObjectMeta: metav1.ObjectMeta{ + Name: pipelinerunname1, + Namespace: "ns", + }, + Spec: v1.PipelineRunSpec{ + PipelineRef: &v1.PipelineRef{ + Name: "pipeline", + }, + Params: []v1.Param{ + { + Name: "p-1", + Value: v1.ParamValue{ + Type: v1.ParamTypeString, + StringVal: "somethingdifferent", + }, + }, + { + Name: "p-2", + Value: v1.ParamValue{ + Type: v1.ParamTypeArray, + ArrayVal: []string{"booms", "booms", "booms"}, + }, + }, + }, + }, + Status: v1.PipelineRunStatus{ + Status: duckv1.Status{ + Conditions: duckv1.Conditions{ + { + Status: corev1.ConditionTrue, + Reason: v1.PipelineRunReasonSuccessful.String(), + Message: "Completed", + }, + }, + }, + PipelineRunStatusFields: v1.PipelineRunStatusFields{ + StartTime: &metav1.Time{Time: clock.Now().Add(-10 * time.Minute)}, + CompletionTime: &metav1.Time{Time: clock.Now().Add(10 * time.Minute)}, + ChildReferences: []v1.ChildStatusReference{ + { + Name: "tr-1", + PipelineTaskName: "t-1", + TypeMeta: runtime.TypeMeta{ + Kind: "TaskRun", + }, + }, + { + Name: "tr-2", + PipelineTaskName: "t-2", + TypeMeta: runtime.TypeMeta{ + Kind: "TaskRun", + }, + }, + }, + }, + }, + }, + { + ObjectMeta: metav1.ObjectMeta{ + Name: pipelinerunname2, + Namespace: "ns", + }, + Spec: v1.PipelineRunSpec{ + PipelineRef: &v1.PipelineRef{ + Name: "pipeline2", + }, + Params: []v1.Param{ + { + Name: "p-1", + Value: v1.ParamValue{ + Type: v1.ParamTypeString, + StringVal: "somethingdifferent", + }, + }, + { + Name: "p-2", + Value: v1.ParamValue{ + Type: v1.ParamTypeArray, + ArrayVal: []string{"booms", "booms", "booms"}, + }, + }, + }, + }, + Status: v1.PipelineRunStatus{ + Status: duckv1.Status{ + Conditions: duckv1.Conditions{ + { + Status: corev1.ConditionTrue, + Reason: v1.PipelineRunReasonSuccessful.String(), + Message: "Completed", + }, + }, + }, + PipelineRunStatusFields: v1.PipelineRunStatusFields{ + StartTime: &metav1.Time{Time: clock.Now()}, + CompletionTime: &metav1.Time{Time: clock.Now().Add(20 * time.Minute)}, + ChildReferences: []v1.ChildStatusReference{ + { + Name: "tr-1", + PipelineTaskName: "t-1", + TypeMeta: runtime.TypeMeta{ + Kind: "TaskRun", + }, + }, + { + Name: "tr-2", + PipelineTaskName: "t-2", + TypeMeta: runtime.TypeMeta{ + Kind: "TaskRun", + }, + }, + }, + }, + }, + }, + } + + namespaces := []*corev1.Namespace{ + { + ObjectMeta: metav1.ObjectMeta{ + Name: "ns", + }, + }, + } + + version := "v1" + tdc := testDynamic.Options{} + dynamic, err := tdc.Client( + cb.UnstructuredPR(prun[0], version), + cb.UnstructuredPR(prun[1], version), + cb.UnstructuredTR(taskRuns[0], version), + cb.UnstructuredTR(taskRuns[1], version), + ) + if err != nil { + t.Errorf("unable to create dynamic client: %v", err) + } + cs, _ := test.SeedTestData(t, test.Data{Namespaces: namespaces, PipelineRuns: prun, TaskRuns: taskRuns}) + cs.Pipeline.Resources = cb.APIResourceList(version, []string{"pipelinerun", "taskrun"}) + p := &test.Params{Tekton: cs.Pipeline, Kube: cs.Kube, Dynamic: dynamic} + + pipelinerun := Command(p) + got, err := test.ExecuteCommand(pipelinerun, "desc", "-n", "ns", "--last") + if err != nil { + t.Errorf("Unexpected error: %v", err) + } + golden.Assert(t, got, fmt.Sprintf("%s.golden", t.Name())) +} + +func TestPipelineRunDescribe_with_results(t *testing.T) { + clock := clockwork.NewFakeClock() + pipelinerunname := "pipeline-run" + taskRuns := []*v1.TaskRun{ + { + ObjectMeta: metav1.ObjectMeta{ + Namespace: "ns", + Name: "tr-1", + Labels: map[string]string{"tekton.dev/task": "task-1"}, + }, + Spec: v1.TaskRunSpec{ + TaskRef: &v1.TaskRef{ + Name: "task-1", + }, + }, + Status: v1.TaskRunStatus{ + Status: duckv1.Status{ + Conditions: duckv1.Conditions{ + { + Status: corev1.ConditionFalse, + Reason: v1.PipelineRunReasonFailed.String(), + }, + }, + }, + TaskRunStatusFields: v1.TaskRunStatusFields{ + StartTime: &metav1.Time{Time: clock.Now()}, + CompletionTime: &metav1.Time{Time: clock.Now().Add(5 * time.Minute)}, + }, + }, + }, + } + + prun := []*v1.PipelineRun{ + { + ObjectMeta: metav1.ObjectMeta{ + Name: pipelinerunname, + Namespace: "ns", + }, + Spec: v1.PipelineRunSpec{ + PipelineRef: &v1.PipelineRef{ + Name: "pipeline", + }, + Params: []v1.Param{ + { + Name: "p-1", + Value: v1.ParamValue{ + Type: v1.ParamTypeString, + StringVal: "somethingdifferent", + }, + }, + }, + }, + Status: v1.PipelineRunStatus{ + Status: duckv1.Status{ + Conditions: duckv1.Conditions{ + { + Status: corev1.ConditionTrue, + Reason: v1.PipelineRunReasonSuccessful.String(), + Message: "Completed", + }, + }, + }, + PipelineRunStatusFields: v1.PipelineRunStatusFields{ + StartTime: &metav1.Time{Time: clock.Now().Add(-10 * time.Minute)}, + CompletionTime: &metav1.Time{Time: clock.Now().Add(10 * time.Minute)}, + ChildReferences: []v1.ChildStatusReference{ + { + Name: "tr-1", + PipelineTaskName: "t-1", + TypeMeta: runtime.TypeMeta{ + Kind: "TaskRun", + }, + }, + }, + Results: []v1.PipelineRunResult{ + { + Name: "result-1", + Value: v1.ParamValue{ + Type: v1.ParamTypeString, + StringVal: "value-1", + }, + }, + { + Name: "result-2", + Value: v1.ParamValue{ + Type: v1.ParamTypeString, + StringVal: "value-2", + }, + }, + }, + }, + }, + }, + } + + namespaces := []*corev1.Namespace{ + { + ObjectMeta: metav1.ObjectMeta{ + Name: "ns", + }, + }, + } + + version := "v1" + tdc := testDynamic.Options{} + dynamic, err := tdc.Client( + cb.UnstructuredPR(prun[0], version), + cb.UnstructuredTR(taskRuns[0], version), + ) + if err != nil { + t.Errorf("unable to create dynamic client: %v", err) + } + cs, _ := test.SeedTestData(t, test.Data{Namespaces: namespaces, PipelineRuns: prun, TaskRuns: taskRuns}) + cs.Pipeline.Resources = cb.APIResourceList(version, []string{"pipelinerun", "taskrun"}) + p := &test.Params{Tekton: cs.Pipeline, Kube: cs.Kube, Dynamic: dynamic} + + pipelinerun := Command(p) + got, err := test.ExecuteCommand(pipelinerun, "desc", "-n", "ns", "--last") + if err != nil { + t.Errorf("Unexpected error: %v", err) + } + golden.Assert(t, got, fmt.Sprintf("%s.golden", t.Name())) +} + +func TestPipelineRunDescribe_zero_timeout(t *testing.T) { + prun := []*v1.PipelineRun{ + { + ObjectMeta: metav1.ObjectMeta{ + Name: "pipeline-run-zero-timeout", + Namespace: "ns", + }, + Spec: v1.PipelineRunSpec{ + PipelineRef: &v1.PipelineRef{ + Name: "pipeline-zero-timeout", + }, + Timeouts: &v1.TimeoutFields{ + Pipeline: &metav1.Duration{Duration: 0}, + }, + }, + }, + } + + namespaces := []*corev1.Namespace{ + { + ObjectMeta: metav1.ObjectMeta{ + Name: "ns", + }, + }, + } + + version := "v1" + tdc := testDynamic.Options{} + dynamic, err := tdc.Client( + cb.UnstructuredPR(prun[0], version), + ) + if err != nil { + t.Errorf("unable to create dynamic client: %v", err) + } + + cs, _ := test.SeedTestData(t, test.Data{Namespaces: namespaces, PipelineRuns: prun}) + cs.Pipeline.Resources = cb.APIResourceList(version, []string{"pipelinerun", "taskrun"}) + p := &test.Params{Tekton: cs.Pipeline, Kube: cs.Kube, Dynamic: dynamic} + + pipelinerun := Command(p) + actual, err := test.ExecuteCommand(pipelinerun, "desc", "pipeline-run-zero-timeout", "-n", "ns") + if err != nil { + t.Errorf("Unexpected error: %v", err) + } + + golden.Assert(t, actual, fmt.Sprintf("%s.golden", t.Name())) +} + +func TestPipelineRunDescribe_with_workspaces(t *testing.T) { + clock := clockwork.NewFakeClock() + pipelinerunname := "pipeline-run" + taskRuns := []*v1.TaskRun{ + { + ObjectMeta: metav1.ObjectMeta{ + Namespace: "ns", + Name: "tr-1", + Labels: map[string]string{"tekton.dev/task": "task-1"}, + }, + Spec: v1.TaskRunSpec{ + TaskRef: &v1.TaskRef{ + Name: "task-1", + }, + }, + Status: v1.TaskRunStatus{ + Status: duckv1.Status{ + Conditions: duckv1.Conditions{ + { + Status: corev1.ConditionFalse, + Reason: v1.PipelineRunReasonFailed.String(), + }, + }, + }, + TaskRunStatusFields: v1.TaskRunStatusFields{ + StartTime: &metav1.Time{Time: clock.Now()}, + CompletionTime: &metav1.Time{Time: clock.Now().Add(5 * time.Minute)}, + }, + }, + }, + } + + prun := []*v1.PipelineRun{ + { + ObjectMeta: metav1.ObjectMeta{ + Name: pipelinerunname, + Namespace: "ns", + }, + Spec: v1.PipelineRunSpec{ + PipelineRef: &v1.PipelineRef{ + Name: "pipeline", + }, + Params: []v1.Param{ + { + Name: "p-1", + Value: v1.ParamValue{ + Type: v1.ParamTypeString, + StringVal: "somethingdifferent", + }, + }, + }, + Workspaces: []v1.WorkspaceBinding{ + { + Name: "test", + SubPath: "test", + EmptyDir: &corev1.EmptyDirVolumeSource{}, + }, + { + Name: "configmap", + ConfigMap: &corev1.ConfigMapVolumeSource{ + LocalObjectReference: corev1.LocalObjectReference{ + Name: "bar"}, + }, + }, + { + Name: "secret", + Secret: &corev1.SecretVolumeSource{ + SecretName: "foobar", + }, + }, + }, + }, + Status: v1.PipelineRunStatus{ + Status: duckv1.Status{ + Conditions: duckv1.Conditions{ + { + Status: corev1.ConditionTrue, + Reason: v1.PipelineRunReasonSuccessful.String(), + Message: "Completed", + }, + }, + }, + PipelineRunStatusFields: v1.PipelineRunStatusFields{ + StartTime: &metav1.Time{Time: clock.Now().Add(-10 * time.Minute)}, + CompletionTime: &metav1.Time{Time: clock.Now().Add(10 * time.Minute)}, + ChildReferences: []v1.ChildStatusReference{ + { + Name: "tr-1", + PipelineTaskName: "t-1", + TypeMeta: runtime.TypeMeta{ + Kind: "TaskRun", + }, + }, + }, + Results: []v1.PipelineRunResult{ + { + Name: "result-1", + Value: v1.ParamValue{ + Type: v1.ParamTypeString, + StringVal: "value-1", + }, + }, + { + Name: "result-2", + Value: v1.ParamValue{ + Type: v1.ParamTypeString, + StringVal: "value-2", + }, + }, + }, + }, + }, + }, + } + + namespaces := []*corev1.Namespace{ + { + ObjectMeta: metav1.ObjectMeta{ + Name: "ns", + }, + }, + } + + version := "v1" + tdc := testDynamic.Options{} + dynamic, err := tdc.Client( + cb.UnstructuredPR(prun[0], version), + cb.UnstructuredTR(taskRuns[0], version), + ) + if err != nil { + t.Errorf("unable to create dynamic client: %v", err) + } + cs, _ := test.SeedTestData(t, test.Data{Namespaces: namespaces, PipelineRuns: prun, TaskRuns: taskRuns}) + cs.Pipeline.Resources = cb.APIResourceList(version, []string{"pipelinerun", "taskrun"}) + p := &test.Params{Tekton: cs.Pipeline, Kube: cs.Kube, Dynamic: dynamic} + + pipelinerun := Command(p) + got, err := test.ExecuteCommand(pipelinerun, "desc", "-n", "ns", "--last") + if err != nil { + t.Errorf("Unexpected error: %v", err) + } + golden.Assert(t, got, fmt.Sprintf("%s.golden", t.Name())) +} + +func TestPipelineRunDescribeWithSkippedTasks(t *testing.T) { + clock := clockwork.NewFakeClock() + pipelinerunname := "pipeline-run" + taskRuns := []*v1.TaskRun{ + { + ObjectMeta: metav1.ObjectMeta{ + Namespace: "ns", + Name: "tr-1", + Labels: map[string]string{"tekton.dev/task": "task-1"}, + }, + Spec: v1.TaskRunSpec{ + TaskRef: &v1.TaskRef{ + Name: "task-1", + }, + }, + Status: v1.TaskRunStatus{ + Status: duckv1.Status{ + Conditions: duckv1.Conditions{ + { + Status: corev1.ConditionFalse, + Reason: v1.PipelineRunReasonFailed.String(), + }, + }, + }, + TaskRunStatusFields: v1.TaskRunStatusFields{ + StartTime: &metav1.Time{Time: clock.Now()}, + CompletionTime: &metav1.Time{Time: clock.Now().Add(5 * time.Minute)}, + }, + }, + }, + { + ObjectMeta: metav1.ObjectMeta{ + Namespace: "ns", + Name: "tr-2", + Labels: map[string]string{"tekton.dev/task": "task-1"}, + }, + Spec: v1.TaskRunSpec{ + TaskRef: &v1.TaskRef{ + Name: "task-1", + }, + }, + Status: v1.TaskRunStatus{ + Status: duckv1.Status{ + Conditions: duckv1.Conditions{ + { + Status: corev1.ConditionTrue, + Reason: v1.PipelineRunReasonSuccessful.String(), + }, + }, + }, + TaskRunStatusFields: v1.TaskRunStatusFields{ + StartTime: &metav1.Time{Time: clock.Now().Add(10 * time.Minute)}, + CompletionTime: &metav1.Time{Time: clock.Now().Add(17 * time.Minute)}, + }, + }, + }, + } + + prun := []*v1.PipelineRun{ + { + ObjectMeta: metav1.ObjectMeta{ + Name: pipelinerunname, + Namespace: "ns", + }, + Spec: v1.PipelineRunSpec{ + PipelineRef: &v1.PipelineRef{ + Name: "pipeline", + }, + Params: []v1.Param{ + { + Name: "p-1", + Value: v1.ParamValue{ + Type: v1.ParamTypeString, + StringVal: "somethingdifferent", + }, + }, + { + Name: "p-2", + Value: v1.ParamValue{ + Type: v1.ParamTypeArray, + ArrayVal: []string{"booms", "booms", "booms"}, + }, + }, + }, + }, + Status: v1.PipelineRunStatus{ + Status: duckv1.Status{ + Conditions: duckv1.Conditions{ + { + Status: corev1.ConditionTrue, + Reason: v1.PipelineRunReasonSuccessful.String(), + Message: "Completed", + }, + }, + }, + PipelineRunStatusFields: v1.PipelineRunStatusFields{ + StartTime: &metav1.Time{Time: clock.Now()}, + CompletionTime: &metav1.Time{Time: clock.Now().Add(20 * time.Minute)}, + ChildReferences: []v1.ChildStatusReference{ + { + Name: "tr-1", + PipelineTaskName: "t-1", + TypeMeta: runtime.TypeMeta{ + Kind: "TaskRun", + }, + }, + { + Name: "tr-2", + PipelineTaskName: "t-2", + TypeMeta: runtime.TypeMeta{ + Kind: "TaskRun", + }, + }, + }, + SkippedTasks: []v1.SkippedTask{ + { + Name: "task-should-be-skipped-1", + WhenExpressions: []v1.WhenExpression{ + { + Input: "yes", + Operator: selection.In, + Values: []string{"missing"}, + }, + }, + }, + { + Name: "task-should-be-skipped-2", + WhenExpressions: []v1.WhenExpression{ + { + Input: "README.md", + Operator: selection.NotIn, + Values: []string{"README.md"}, + }, + }, + }, + { + Name: "task-should-be-skipped-3", + WhenExpressions: []v1.WhenExpression{ + { + Input: "monday", + Operator: selection.NotIn, + Values: []string{"friday"}, + }, + }, + }, + }, + }, + }, + }, + } + + namespaces := []*corev1.Namespace{ + { + ObjectMeta: metav1.ObjectMeta{ + Name: "ns", + }, + }, + } + + version := "v1" + tdc := testDynamic.Options{} + dynamic, err := tdc.Client( + cb.UnstructuredPR(prun[0], version), + cb.UnstructuredTR(taskRuns[0], version), + cb.UnstructuredTR(taskRuns[1], version), + ) + if err != nil { + t.Errorf("unable to create dynamic client: %v", err) + } + cs, _ := test.SeedTestData(t, test.Data{Namespaces: namespaces, PipelineRuns: prun, TaskRuns: taskRuns}) + cs.Pipeline.Resources = cb.APIResourceList(version, []string{"pipelinerun", "taskrun"}) + p := &test.Params{Tekton: cs.Pipeline, Kube: cs.Kube, Dynamic: dynamic} + + pipelinerun := Command(p) + got, err := test.ExecuteCommand(pipelinerun, "desc", "-n", "ns", pipelinerunname) + if err != nil { + t.Errorf("Unexpected error: %v", err) + } + golden.Assert(t, got, fmt.Sprintf("%s.golden", t.Name())) +} + +func TestPipelineRunDescribe_cancelled_pipelinerun_multiple_taskrun(t *testing.T) { + clock := clockwork.NewFakeClock() + + trs := []*v1.TaskRun{ + { + ObjectMeta: metav1.ObjectMeta{ + Name: "tr-1", + Namespace: "ns", + }, + Status: v1.TaskRunStatus{ + TaskRunStatusFields: v1.TaskRunStatusFields{ + StartTime: &metav1.Time{Time: clock.Now().Add(1 * time.Minute)}, + CompletionTime: &metav1.Time{Time: clock.Now().Add(3 * time.Minute)}, + }, + Status: duckv1.Status{ + Conditions: duckv1.Conditions{ + { + Status: corev1.ConditionFalse, + Type: apis.ConditionSucceeded, + Reason: v1.TaskRunReasonCancelled.String(), + Message: "TaskRun \"tr-1\" was cancelled", + }, + }, + }, + }, + }, + { + ObjectMeta: metav1.ObjectMeta{ + Name: "tr-2", + Namespace: "ns", + }, + Status: v1.TaskRunStatus{ + TaskRunStatusFields: v1.TaskRunStatusFields{ + StartTime: &metav1.Time{Time: clock.Now().Add(2 * time.Minute)}, + CompletionTime: &metav1.Time{Time: clock.Now().Add(4 * time.Minute)}, + }, + Status: duckv1.Status{ + Conditions: duckv1.Conditions{ + { + Status: corev1.ConditionFalse, + Type: apis.ConditionSucceeded, + Reason: v1.TaskRunReasonCancelled.String(), + Message: "TaskRun \"tr-2\" was cancelled", + }, + }, + }, + }, + }, + } + + pipelineRuns := []*v1.PipelineRun{ + { + ObjectMeta: metav1.ObjectMeta{ + Name: "pipeline-run", + Namespace: "ns", + CreationTimestamp: metav1.Time{Time: clock.Now()}, + Labels: map[string]string{"tekton.dev/pipeline": "pipeline"}, + }, + Spec: v1.PipelineRunSpec{ + Timeouts: &v1.TimeoutFields{ + Pipeline: &metav1.Duration{Duration: 1 * time.Hour}, + }, + PipelineRef: &v1.PipelineRef{ + Name: "pipeline", + }, + }, + Status: v1.PipelineRunStatus{ + PipelineRunStatusFields: v1.PipelineRunStatusFields{ + ChildReferences: []v1.ChildStatusReference{ + { + Name: "tr-1", + PipelineTaskName: "t-1", + TypeMeta: runtime.TypeMeta{ + Kind: "TaskRun", + }, + }, + { + Name: "tr-2", + PipelineTaskName: "t-2", + TypeMeta: runtime.TypeMeta{ + Kind: "TaskRun", + }, + }, + }, + StartTime: &metav1.Time{Time: clock.Now()}, + CompletionTime: &metav1.Time{Time: clock.Now().Add(5 * time.Minute)}, + }, + Status: duckv1.Status{ + Conditions: duckv1.Conditions{ + { + Status: corev1.ConditionFalse, + Reason: "PipelineRunCancelled", + Message: "PipelineRun \"pipeline-run\" was cancelled", + }, + }, + }, + }, + }, + } + + namespaces := []*corev1.Namespace{ + { + ObjectMeta: metav1.ObjectMeta{ + Name: "ns", + }, + }, + } + + version := "v1" + tdc := testDynamic.Options{} + dynamic, err := tdc.Client( + cb.UnstructuredPR(pipelineRuns[0], version), + cb.UnstructuredTR(trs[0], version), + cb.UnstructuredTR(trs[1], version), + ) + if err != nil { + t.Errorf("unable to create dynamic client: %v", err) + } + cs, _ := test.SeedTestData(t, test.Data{Namespaces: namespaces, PipelineRuns: pipelineRuns, + TaskRuns: trs, + }) + cs.Pipeline.Resources = cb.APIResourceList(version, []string{"pipelinerun", "taskrun"}) + p := &test.Params{Tekton: cs.Pipeline, Kube: cs.Kube, Dynamic: dynamic, Clock: clock} + + pipelinerun := Command(p) + clock.Advance(10 * time.Minute) + actual, err := test.ExecuteCommand(pipelinerun, "desc", "pipeline-run", "-n", "ns") + if err != nil { + t.Errorf("Unexpected error: %v", err) + } + golden.Assert(t, actual, fmt.Sprintf("%s.golden", t.Name())) +} + +func TestPipelineRunDescribeWithTimeouts(t *testing.T) { + clock := clockwork.NewFakeClock() + pipelinerunname := "pipeline-run" + taskRuns := []*v1.TaskRun{ + { + ObjectMeta: metav1.ObjectMeta{ + Namespace: "ns", + Name: "tr-1", + Labels: map[string]string{"tekton.dev/task": "task-1"}, + }, + Spec: v1.TaskRunSpec{ + TaskRef: &v1.TaskRef{ + Name: "task-1", + }, + }, + Status: v1.TaskRunStatus{ + Status: duckv1.Status{ + Conditions: duckv1.Conditions{ + { + Status: corev1.ConditionFalse, + Reason: v1.PipelineRunReasonFailed.String(), + }, + }, + }, + TaskRunStatusFields: v1.TaskRunStatusFields{ + StartTime: &metav1.Time{Time: clock.Now()}, + CompletionTime: &metav1.Time{Time: clock.Now().Add(5 * time.Minute)}, + }, + }, + }, + { + ObjectMeta: metav1.ObjectMeta{ + Namespace: "ns", + Name: "tr-2", + Labels: map[string]string{"tekton.dev/task": "task-1"}, + }, + Spec: v1.TaskRunSpec{ + TaskRef: &v1.TaskRef{ + Name: "task-1", + }, + }, + Status: v1.TaskRunStatus{ + Status: duckv1.Status{ + Conditions: duckv1.Conditions{ + { + Status: corev1.ConditionTrue, + Reason: v1.PipelineRunReasonSuccessful.String(), + }, + }, + }, + TaskRunStatusFields: v1.TaskRunStatusFields{ + StartTime: &metav1.Time{Time: clock.Now().Add(10 * time.Minute)}, + CompletionTime: &metav1.Time{Time: clock.Now().Add(17 * time.Minute)}, + }, + }, + }, + } + + prun := []*v1.PipelineRun{ + { + ObjectMeta: metav1.ObjectMeta{ + Name: pipelinerunname, + Namespace: "ns", + }, + Spec: v1.PipelineRunSpec{ + PipelineRef: &v1.PipelineRef{ + Name: "pipeline", + }, + Timeouts: &v1.TimeoutFields{ + Tasks: &metav1.Duration{Duration: 50 * time.Minute}, + Pipeline: &metav1.Duration{Duration: 1 * time.Hour}, + }, + Params: []v1.Param{ + { + Name: "p-1", + Value: v1.ParamValue{ + Type: v1.ParamTypeString, + StringVal: "somethingdifferent", + }, + }, + { + Name: "p-2", + Value: v1.ParamValue{ + Type: v1.ParamTypeArray, + ArrayVal: []string{"booms", "booms", "booms"}, + }, + }, + }, + }, + Status: v1.PipelineRunStatus{ + Status: duckv1.Status{ + Conditions: duckv1.Conditions{ + { + Status: corev1.ConditionTrue, + Reason: v1.PipelineRunReasonSuccessful.String(), + Message: "Completed", + }, + }, + }, + PipelineRunStatusFields: v1.PipelineRunStatusFields{ + StartTime: &metav1.Time{Time: clock.Now()}, + CompletionTime: &metav1.Time{Time: clock.Now().Add(20 * time.Minute)}, + ChildReferences: []v1.ChildStatusReference{ + { + Name: "tr-1", + PipelineTaskName: "t-1", + TypeMeta: runtime.TypeMeta{ + Kind: "TaskRun", + }, + }, + { + Name: "tr-2", + PipelineTaskName: "t-2", + TypeMeta: runtime.TypeMeta{ + Kind: "TaskRun", + }, + }, + }, + SkippedTasks: []v1.SkippedTask{ + { + Name: "task-should-be-skipped-1", + WhenExpressions: []v1.WhenExpression{ + { + Input: "yes", + Operator: selection.In, + Values: []string{"missing"}, + }, + }, + }, + { + Name: "task-should-be-skipped-2", + WhenExpressions: []v1.WhenExpression{ + { + Input: "README.md", + Operator: selection.NotIn, + Values: []string{"README.md"}, + }, + }, + }, + { + Name: "task-should-be-skipped-3", + WhenExpressions: []v1.WhenExpression{ + { + Input: "monday", + Operator: selection.NotIn, + Values: []string{"friday"}, + }, + }, + }, + }, + }, + }, + }, + } + + namespaces := []*corev1.Namespace{ + { + ObjectMeta: metav1.ObjectMeta{ + Name: "ns", + }, + }, + } + + version := "v1" + tdc := testDynamic.Options{} + dynamic, err := tdc.Client( + cb.UnstructuredPR(prun[0], version), + cb.UnstructuredTR(taskRuns[0], version), + cb.UnstructuredTR(taskRuns[1], version), + ) + if err != nil { + t.Errorf("unable to create dynamic client: %v", err) + } + cs, _ := test.SeedTestData(t, test.Data{Namespaces: namespaces, PipelineRuns: prun, TaskRuns: taskRuns}) + cs.Pipeline.Resources = cb.APIResourceList(version, []string{"pipelinerun", "taskrun"}) + p := &test.Params{Tekton: cs.Pipeline, Kube: cs.Kube, Dynamic: dynamic} + + pipelinerun := Command(p) + got, err := test.ExecuteCommand(pipelinerun, "desc", "-n", "ns", pipelinerunname) + if err != nil { + t.Errorf("Unexpected error: %v", err) + } + golden.Assert(t, got, fmt.Sprintf("%s.golden", t.Name())) +} + +func TestPipelineRunDescribe_with_annotations(t *testing.T) { + prun := []*v1.PipelineRun{ + { + ObjectMeta: metav1.ObjectMeta{ + Name: "pr-with-annotations", + Namespace: "ns", + Annotations: map[string]string{ + corev1.LastAppliedConfigAnnotation: "LastAppliedConfig", + "tekton.dev/tags": "testing", + }, + }, + Spec: v1.PipelineRunSpec{ + PipelineRef: &v1.PipelineRef{ + Name: "pr-with-annotations", + }, + }, + }, + } + + namespaces := []*corev1.Namespace{ + { + ObjectMeta: metav1.ObjectMeta{ + Name: "ns", + }, + }, + } + + version := "v1" + tdc := testDynamic.Options{} + dynamic, err := tdc.Client( + cb.UnstructuredPR(prun[0], version), + ) + if err != nil { + t.Errorf("unable to create dynamic client: %v", err) + } + cs, _ := test.SeedTestData(t, test.Data{Namespaces: namespaces, PipelineRuns: prun}) + cs.Pipeline.Resources = cb.APIResourceList(version, []string{"pipelinerun", "taskrun"}) + p := &test.Params{Tekton: cs.Pipeline, Kube: cs.Kube, Dynamic: dynamic} + + pipelinerun := Command(p) + actual, err := test.ExecuteCommand(pipelinerun, "desc", "pr-with-annotations", "-n", "ns") + if err != nil { + t.Errorf("Unexpected error: %v", err) + } + golden.Assert(t, actual, fmt.Sprintf("%s.golden", t.Name())) +} diff --git a/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribeV1beta1.golden b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe.golden similarity index 85% rename from pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribeV1beta1.golden rename to pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe.golden index 64d6d5b80..1b58c97de 100644 --- a/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribeV1beta1.golden +++ b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe.golden @@ -7,12 +7,6 @@ Status STARTED DURATION STATUS 0 seconds ago 20m0s Succeeded -Resources - - NAME RESOURCE REF - res-1 test-res - res-2 test-res2 - Params NAME VALUE diff --git a/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribeWithSkippedTasksV1beta1.golden b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribeWithSkippedTasks.golden similarity index 87% rename from pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribeWithSkippedTasksV1beta1.golden rename to pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribeWithSkippedTasks.golden index 1c3224779..468b1bdb5 100644 --- a/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribeWithSkippedTasksV1beta1.golden +++ b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribeWithSkippedTasks.golden @@ -7,12 +7,6 @@ Status STARTED DURATION STATUS 0 seconds ago 20m0s Succeeded -Resources - - NAME RESOURCE REF - res-1 test-res - res-2 test-res2 - Params NAME VALUE diff --git a/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribeWithSkippedTasks_v1beta1.golden b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribeWithSkippedTasks_v1beta1.golden new file mode 100644 index 000000000..66999ff4d --- /dev/null +++ b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribeWithSkippedTasks_v1beta1.golden @@ -0,0 +1,29 @@ +Name: pipeline-run +Namespace: ns +Pipeline Ref: pipeline +Annotations: + tekton.dev/v1beta1Resources=[{"name":"res-1","resourceRef":{"name":"test-res"}},{"name":"res-2","resourceRef":{"name":"test-res2"}}] + +Status + +STARTED DURATION STATUS +0 seconds ago 20m0s Succeeded + +Params + + NAME VALUE + p-1 somethingdifferent + p-2 [booms booms booms] + +Taskruns + + NAME TASK NAME STARTED DURATION STATUS + tr-2 t-2 -10 minutes ago 7m0s Succeeded + tr-1 t-1 0 seconds ago 5m0s Failed + +Skipped Tasks + + NAME + task-should-be-skipped-1 + task-should-be-skipped-2 + task-should-be-skipped-3 diff --git a/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribeWithTimeouts.golden b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribeWithTimeouts.golden index dad74fb35..503d186e4 100644 --- a/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribeWithTimeouts.golden +++ b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribeWithTimeouts.golden @@ -11,12 +11,6 @@ Timeouts Pipeline: 1h0m0s Tasks: 50m0s -Resources - - NAME RESOURCE REF - res-1 test-res - res-2 test-res2 - Params NAME VALUE diff --git a/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribeWithTimeouts_v1beta1.golden b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribeWithTimeouts_v1beta1.golden new file mode 100644 index 000000000..c92d1ac49 --- /dev/null +++ b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribeWithTimeouts_v1beta1.golden @@ -0,0 +1,33 @@ +Name: pipeline-run +Namespace: ns +Pipeline Ref: pipeline +Annotations: + tekton.dev/v1beta1Resources=[{"name":"res-1","resourceRef":{"name":"test-res"}},{"name":"res-2","resourceRef":{"name":"test-res2"}}] + +Status + +STARTED DURATION STATUS +0 seconds ago 20m0s Succeeded + +Timeouts + Pipeline: 1h0m0s + Tasks: 50m0s + +Params + + NAME VALUE + p-1 somethingdifferent + p-2 [booms booms booms] + +Taskruns + + NAME TASK NAME STARTED DURATION STATUS + tr-2 t-2 -10 minutes ago 7m0s Succeeded + tr-1 t-1 0 seconds ago 5m0s Failed + +Skipped Tasks + + NAME + task-should-be-skipped-1 + task-should-be-skipped-2 + task-should-be-skipped-3 diff --git a/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_cancelled_pipelinerun.golden b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_cancelled_pipelinerun.golden index 36a5eacc2..7583e68b2 100644 --- a/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_cancelled_pipelinerun.golden +++ b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_cancelled_pipelinerun.golden @@ -1,7 +1,6 @@ -Name: pipeline-run -Namespace: ns -Pipeline Ref: pipeline -Timeout(Deprecated): 1h0m0s +Name: pipeline-run +Namespace: ns +Pipeline Ref: pipeline Labels: tekton.dev/pipeline=pipeline @@ -14,6 +13,9 @@ Message PipelineRun "pipeline-run" was cancelled +Timeouts + Pipeline: 1h0m0s + Taskruns NAME TASK NAME STARTED DURATION STATUS diff --git a/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_cancelled_pipelinerun_multiple_taskrun.golden b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_cancelled_pipelinerun_multiple_taskrun.golden index 8bff1a279..72aec4b96 100644 --- a/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_cancelled_pipelinerun_multiple_taskrun.golden +++ b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_cancelled_pipelinerun_multiple_taskrun.golden @@ -1,7 +1,6 @@ -Name: pipeline-run -Namespace: ns -Pipeline Ref: pipeline -Timeout(Deprecated): 1h0m0s +Name: pipeline-run +Namespace: ns +Pipeline Ref: pipeline Labels: tekton.dev/pipeline=pipeline @@ -15,6 +14,9 @@ Message PipelineRun "pipeline-run" was cancelled TaskRun(s) cancelled: tr-1, tr-2 +Timeouts + Pipeline: 1h0m0s + Taskruns NAME TASK NAME STARTED DURATION STATUS diff --git a/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_cancelled_pipelinerun_multiple_taskrun_v1beta1.golden b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_cancelled_pipelinerun_multiple_taskrun_v1beta1.golden new file mode 100644 index 000000000..72aec4b96 --- /dev/null +++ b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_cancelled_pipelinerun_multiple_taskrun_v1beta1.golden @@ -0,0 +1,24 @@ +Name: pipeline-run +Namespace: ns +Pipeline Ref: pipeline +Labels: + tekton.dev/pipeline=pipeline + +Status + +STARTED DURATION STATUS +10 minutes ago 5m0s Cancelled(PipelineRunCancelled) + +Message + +PipelineRun "pipeline-run" was cancelled +TaskRun(s) cancelled: tr-1, tr-2 + +Timeouts + Pipeline: 1h0m0s + +Taskruns + + NAME TASK NAME STARTED DURATION STATUS + tr-2 t-2 8 minutes ago 2m0s Cancelled(TaskRunCancelled) + tr-1 t-1 9 minutes ago 2m0s Cancelled(TaskRunCancelled) diff --git a/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_cancelled_pipelinerun_v1beta1.golden b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_cancelled_pipelinerun_v1beta1.golden new file mode 100644 index 000000000..7583e68b2 --- /dev/null +++ b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_cancelled_pipelinerun_v1beta1.golden @@ -0,0 +1,22 @@ +Name: pipeline-run +Namespace: ns +Pipeline Ref: pipeline +Labels: + tekton.dev/pipeline=pipeline + +Status + +STARTED DURATION STATUS +10 minutes ago 5m0s Cancelled(PipelineRunCancelled) + +Message + +PipelineRun "pipeline-run" was cancelled + +Timeouts + Pipeline: 1h0m0s + +Taskruns + + NAME TASK NAME STARTED DURATION STATUS + tr-1 t-1 8 minutes ago 3m0s Succeeded diff --git a/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_custom_timeout.golden b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_custom_timeout.golden index a3259a5b4..ddc240c29 100644 --- a/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_custom_timeout.golden +++ b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_custom_timeout.golden @@ -1,9 +1,11 @@ -Name: pr-custom-timeout -Namespace: ns -Pipeline Ref: pr-custom-timeout -Timeout(Deprecated): 1m0s +Name: pr-custom-timeout +Namespace: ns +Pipeline Ref: pr-custom-timeout Status STARTED DURATION STATUS --- --- --- + +Timeouts + Pipeline: 1m0s diff --git a/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_custom_timeout_v1beta1.golden b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_custom_timeout_v1beta1.golden new file mode 100644 index 000000000..ddc240c29 --- /dev/null +++ b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_custom_timeout_v1beta1.golden @@ -0,0 +1,11 @@ +Name: pr-custom-timeout +Namespace: ns +Pipeline Ref: pr-custom-timeout + +Status + +STARTED DURATION STATUS +--- --- --- + +Timeouts + Pipeline: 1m0s diff --git a/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_failed.golden b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_failed.golden index ad4124742..bcd84163d 100644 --- a/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_failed.golden +++ b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_failed.golden @@ -1,8 +1,7 @@ -Name: pipeline-run -Namespace: ns -Pipeline Ref: pipeline -Service Account: test-sa -Timeout(Deprecated): 1h0m0s +Name: pipeline-run +Namespace: ns +Pipeline Ref: pipeline +Service Account: test-sa Labels: tekton.dev/pipeline=pipeline @@ -16,6 +15,9 @@ Message Resource test-resource not found in the pipelinerun TaskRun(s) cancelled: tr-1 +Timeouts + Pipeline: 1h0m0s + Taskruns NAME TASK NAME STARTED DURATION STATUS diff --git a/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_failed_v1beta1.golden b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_failed_v1beta1.golden new file mode 100644 index 000000000..bcd84163d --- /dev/null +++ b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_failed_v1beta1.golden @@ -0,0 +1,24 @@ +Name: pipeline-run +Namespace: ns +Pipeline Ref: pipeline +Service Account: test-sa +Labels: + tekton.dev/pipeline=pipeline + +Status + +STARTED DURATION STATUS +10 minutes ago 5m0s Failed(Resource not found) + +Message + +Resource test-resource not found in the pipelinerun +TaskRun(s) cancelled: tr-1 + +Timeouts + Pipeline: 1h0m0s + +Taskruns + + NAME TASK NAME STARTED DURATION STATUS + tr-1 t-1 8 minutes ago 3m0s Failed diff --git a/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_failed_withoutPRCondition.golden b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_failed_withoutPRCondition.golden index b0b8d305d..f8e787648 100644 --- a/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_failed_withoutPRCondition.golden +++ b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_failed_withoutPRCondition.golden @@ -1,8 +1,7 @@ -Name: pipeline-run -Namespace: ns -Pipeline Ref: pipeline -Service Account: test-sa -Timeout(Deprecated): 1h0m0s +Name: pipeline-run +Namespace: ns +Pipeline Ref: pipeline +Service Account: test-sa Labels: tekton.dev/pipeline=pipeline @@ -11,6 +10,9 @@ Status STARTED DURATION STATUS 10 minutes ago 5m0s --- +Timeouts + Pipeline: 1h0m0s + Taskruns NAME TASK NAME STARTED DURATION STATUS diff --git a/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_failed_withoutPRCondition_v1beta1.golden b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_failed_withoutPRCondition_v1beta1.golden new file mode 100644 index 000000000..f8e787648 --- /dev/null +++ b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_failed_withoutPRCondition_v1beta1.golden @@ -0,0 +1,19 @@ +Name: pipeline-run +Namespace: ns +Pipeline Ref: pipeline +Service Account: test-sa +Labels: + tekton.dev/pipeline=pipeline + +Status + +STARTED DURATION STATUS +10 minutes ago 5m0s --- + +Timeouts + Pipeline: 1h0m0s + +Taskruns + + NAME TASK NAME STARTED DURATION STATUS + tr-1 t-1 8 minutes ago 3m0s --- diff --git a/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_failed_withoutTRCondition.golden b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_failed_withoutTRCondition.golden index f13bb6938..b86f7b76a 100644 --- a/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_failed_withoutTRCondition.golden +++ b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_failed_withoutTRCondition.golden @@ -1,8 +1,7 @@ -Name: pipeline-run -Namespace: ns -Pipeline Ref: pipeline -Service Account: test-sa -Timeout(Deprecated): 1h0m0s +Name: pipeline-run +Namespace: ns +Pipeline Ref: pipeline +Service Account: test-sa Labels: tekton.dev/pipeline=pipeline @@ -15,6 +14,9 @@ Message Resource test-resource not found in the pipelinerun +Timeouts + Pipeline: 1h0m0s + Taskruns NAME TASK NAME STARTED DURATION STATUS diff --git a/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_failed_withoutTRCondition_v1beta1.golden b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_failed_withoutTRCondition_v1beta1.golden new file mode 100644 index 000000000..b86f7b76a --- /dev/null +++ b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_failed_withoutTRCondition_v1beta1.golden @@ -0,0 +1,23 @@ +Name: pipeline-run +Namespace: ns +Pipeline Ref: pipeline +Service Account: test-sa +Labels: + tekton.dev/pipeline=pipeline + +Status + +STARTED DURATION STATUS +10 minutes ago 5m0s Failed(Resource not found) + +Message + +Resource test-resource not found in the pipelinerun + +Timeouts + Pipeline: 1h0m0s + +Taskruns + + NAME TASK NAME STARTED DURATION STATUS + tr-1 t-1 8 minutes ago 3m0s --- diff --git a/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_lastV1beta1.golden b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_last.golden similarity index 84% rename from pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_lastV1beta1.golden rename to pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_last.golden index abe42821e..8727211fb 100644 --- a/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_lastV1beta1.golden +++ b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_last.golden @@ -7,12 +7,6 @@ Status STARTED DURATION STATUS 0 seconds ago 20m0s Succeeded -Resources - - NAME RESOURCE REF - res-1x test-res - res-2x test-res2 - Params NAME VALUE diff --git a/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_last_v1beta1.golden b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_last_v1beta1.golden new file mode 100644 index 000000000..7dc1e7216 --- /dev/null +++ b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_last_v1beta1.golden @@ -0,0 +1,22 @@ +Name: pipeline-run2 +Namespace: ns +Pipeline Ref: pipeline2 +Annotations: + tekton.dev/v1beta1Resources=[{"name":"res-1x","resourceRef":{"name":"test-res"}},{"name":"res-2x","resourceRef":{"name":"test-res2"}}] + +Status + +STARTED DURATION STATUS +0 seconds ago 20m0s Succeeded + +Params + + NAME VALUE + p-1 somethingdifferent + p-2 [booms booms booms] + +Taskruns + + NAME TASK NAME STARTED DURATION STATUS + tr-1 t-1 0 seconds ago 5m0s Failed + tr-2 t-2 10 minutes ago 7m0s Succeeded diff --git a/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_multiple_taskrun_ordering.golden b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_multiple_taskrun_ordering.golden index 7401a4038..9891e0761 100644 --- a/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_multiple_taskrun_ordering.golden +++ b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_multiple_taskrun_ordering.golden @@ -1,7 +1,6 @@ -Name: pipeline-run -Namespace: ns -Pipeline Ref: pipeline -Timeout(Deprecated): 1h0m0s +Name: pipeline-run +Namespace: ns +Pipeline Ref: pipeline Labels: tekton.dev/pipeline=pipeline @@ -10,6 +9,9 @@ Status STARTED DURATION STATUS 10 minutes ago 15m0s Succeeded +Timeouts + Pipeline: 1h0m0s + Taskruns NAME TASK NAME STARTED DURATION STATUS diff --git a/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_multiple_taskrun_ordering_v1beta1.golden b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_multiple_taskrun_ordering_v1beta1.golden new file mode 100644 index 000000000..9891e0761 --- /dev/null +++ b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_multiple_taskrun_ordering_v1beta1.golden @@ -0,0 +1,19 @@ +Name: pipeline-run +Namespace: ns +Pipeline Ref: pipeline +Labels: + tekton.dev/pipeline=pipeline + +Status + +STARTED DURATION STATUS +10 minutes ago 15m0s Succeeded + +Timeouts + Pipeline: 1h0m0s + +Taskruns + + NAME TASK NAME STARTED DURATION STATUS + tr-2 t-2 5 minutes ago 4m0s Succeeded + tr-1 t-1 8 minutes ago 3m0s Succeeded diff --git a/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_multiple_taskrun_without_status.golden b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_multiple_taskrun_without_status.golden index e7f1a4f35..54f49aace 100644 --- a/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_multiple_taskrun_without_status.golden +++ b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_multiple_taskrun_without_status.golden @@ -1,7 +1,6 @@ -Name: pipeline-run -Namespace: ns -Pipeline Ref: pipeline -Timeout(Deprecated): 1h0m0s +Name: pipeline-run +Namespace: ns +Pipeline Ref: pipeline Labels: tekton.dev/pipeline=pipeline @@ -10,7 +9,11 @@ Status STARTED DURATION STATUS 10 minutes ago 5m0s Failed +Timeouts + Pipeline: 1h0m0s + Taskruns NAME TASK NAME STARTED DURATION STATUS + tr-0 t-0 --- --- --- tr-1 t-1 8 minutes ago 3m0s Succeeded diff --git a/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_multiple_taskrun_without_status_v1beta1.golden b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_multiple_taskrun_without_status_v1beta1.golden new file mode 100644 index 000000000..54f49aace --- /dev/null +++ b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_multiple_taskrun_without_status_v1beta1.golden @@ -0,0 +1,19 @@ +Name: pipeline-run +Namespace: ns +Pipeline Ref: pipeline +Labels: + tekton.dev/pipeline=pipeline + +Status + +STARTED DURATION STATUS +10 minutes ago 5m0s Failed + +Timeouts + Pipeline: 1h0m0s + +Taskruns + + NAME TASK NAME STARTED DURATION STATUS + tr-0 t-0 --- --- --- + tr-1 t-1 8 minutes ago 3m0s Succeeded diff --git a/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_no_resourceref.golden b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_no_resourceref.golden index e30903c2c..567936dee 100644 --- a/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_no_resourceref.golden +++ b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_no_resourceref.golden @@ -1,8 +1,7 @@ -Name: pipeline-run -Namespace: ns -Pipeline Ref: pipeline -Service Account: test-sa -Timeout(Deprecated): 1h0m0s +Name: pipeline-run +Namespace: ns +Pipeline Ref: pipeline +Service Account: test-sa Labels: tekton.dev/pipeline=pipeline @@ -11,10 +10,8 @@ Status STARTED DURATION STATUS 10 minutes ago 5m0s Succeeded -Resources - - NAME RESOURCE REF - test-resource +Timeouts + Pipeline: 1h0m0s Params diff --git a/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_no_resourceref_v1beta1.golden b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_no_resourceref_v1beta1.golden new file mode 100644 index 000000000..a77c67a06 --- /dev/null +++ b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_no_resourceref_v1beta1.golden @@ -0,0 +1,26 @@ +Name: pipeline-run +Namespace: ns +Pipeline Ref: pipeline +Service Account: test-sa +Labels: + tekton.dev/pipeline=pipeline +Annotations: + tekton.dev/v1beta1Resources=[{"name":"test-resource"}] + +Status + +STARTED DURATION STATUS +10 minutes ago 5m0s Succeeded + +Timeouts + Pipeline: 1h0m0s + +Params + + NAME VALUE + test-param param-value + +Taskruns + + NAME TASK NAME STARTED DURATION STATUS + tr-1 t-1 8 minutes ago 3m0s Succeeded diff --git a/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_only_taskrun.golden b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_only_taskrun.golden index 92bb0b51e..3d35daa80 100644 --- a/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_only_taskrun.golden +++ b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_only_taskrun.golden @@ -1,7 +1,6 @@ -Name: pipeline-run -Namespace: ns -Pipeline Ref: pipeline -Timeout(Deprecated): 1h0m0s +Name: pipeline-run +Namespace: ns +Pipeline Ref: pipeline Labels: tekton.dev/pipeline=pipeline @@ -10,6 +9,9 @@ Status STARTED DURATION STATUS 10 minutes ago 5m0s Succeeded +Timeouts + Pipeline: 1h0m0s + Taskruns NAME TASK NAME STARTED DURATION STATUS diff --git a/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_only_taskrun_v1beta1.golden b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_only_taskrun_v1beta1.golden new file mode 100644 index 000000000..3d35daa80 --- /dev/null +++ b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_only_taskrun_v1beta1.golden @@ -0,0 +1,18 @@ +Name: pipeline-run +Namespace: ns +Pipeline Ref: pipeline +Labels: + tekton.dev/pipeline=pipeline + +Status + +STARTED DURATION STATUS +10 minutes ago 5m0s Succeeded + +Timeouts + Pipeline: 1h0m0s + +Taskruns + + NAME TASK NAME STARTED DURATION STATUS + tr-1 t-1 8 minutes ago 3m0s Succeeded diff --git a/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribeV1beta1_taskrun_with_no_status.golden b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_taskrun_with_no_status.golden similarity index 83% rename from pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribeV1beta1_taskrun_with_no_status.golden rename to pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_taskrun_with_no_status.golden index 10c682e64..bfdc4fea2 100644 --- a/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribeV1beta1_taskrun_with_no_status.golden +++ b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_taskrun_with_no_status.golden @@ -7,12 +7,6 @@ Status STARTED DURATION STATUS 0 seconds ago 20m0s Succeeded -Resources - - NAME RESOURCE REF - res-1 test-res - res-2 test-res2 - Params NAME VALUE @@ -22,4 +16,5 @@ Params Taskruns NAME TASK NAME STARTED DURATION STATUS + tr-2 t-2 --- --- --- tr-1 t-1 0 seconds ago 5m0s Failed diff --git a/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_taskrun_with_no_status_v1beta1.golden b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_taskrun_with_no_status_v1beta1.golden new file mode 100644 index 000000000..c77e9d7a4 --- /dev/null +++ b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_taskrun_with_no_status_v1beta1.golden @@ -0,0 +1,22 @@ +Name: pipeline-run +Namespace: ns +Pipeline Ref: pipeline +Annotations: + tekton.dev/v1beta1Resources=[{"name":"res-1","resourceRef":{"name":"test-res"}},{"name":"res-2","resourceRef":{"name":"test-res2"}}] + +Status + +STARTED DURATION STATUS +0 seconds ago 20m0s Succeeded + +Params + + NAME VALUE + p-1 somethingdifferent + p-2 [booms booms booms] + +Taskruns + + NAME TASK NAME STARTED DURATION STATUS + tr-2 t-2 --- --- --- + tr-1 t-1 0 seconds ago 5m0s Failed diff --git a/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_v1beta1.golden b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_v1beta1.golden new file mode 100644 index 000000000..a209e5c8d --- /dev/null +++ b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_v1beta1.golden @@ -0,0 +1,22 @@ +Name: pipeline-run +Namespace: ns +Pipeline Ref: pipeline +Annotations: + tekton.dev/v1beta1Resources=[{"name":"res-1","resourceRef":{"name":"test-res"}},{"name":"res-2","resourceRef":{"name":"test-res2"}}] + +Status + +STARTED DURATION STATUS +0 seconds ago 20m0s Succeeded + +Params + + NAME VALUE + p-1 somethingdifferent + p-2 [booms booms booms] + +Taskruns + + NAME TASK NAME STARTED DURATION STATUS + tr-2 t-2 -10 minutes ago 7m0s Succeeded + tr-1 t-1 0 seconds ago 5m0s Failed diff --git a/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_with_annotations_v1beta1.golden b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_with_annotations_v1beta1.golden new file mode 100644 index 000000000..2d61b5ca3 --- /dev/null +++ b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_with_annotations_v1beta1.golden @@ -0,0 +1,10 @@ +Name: pr-with-annotations +Namespace: ns +Pipeline Ref: pr-with-annotations +Annotations: + tekton.dev/tags=testing + +Status + +STARTED DURATION STATUS +--- --- --- diff --git a/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_with_resources_taskrun.golden b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_with_resources_taskrun.golden index 9e756d3a5..567936dee 100644 --- a/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_with_resources_taskrun.golden +++ b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_with_resources_taskrun.golden @@ -1,8 +1,7 @@ -Name: pipeline-run -Namespace: ns -Pipeline Ref: pipeline -Service Account: test-sa -Timeout(Deprecated): 1h0m0s +Name: pipeline-run +Namespace: ns +Pipeline Ref: pipeline +Service Account: test-sa Labels: tekton.dev/pipeline=pipeline @@ -11,10 +10,8 @@ Status STARTED DURATION STATUS 10 minutes ago 5m0s Succeeded -Resources - - NAME RESOURCE REF - test-resource test-resource-ref +Timeouts + Pipeline: 1h0m0s Params diff --git a/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_with_resources_taskrun_v1beta1.golden b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_with_resources_taskrun_v1beta1.golden new file mode 100644 index 000000000..06bcb7ec8 --- /dev/null +++ b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_with_resources_taskrun_v1beta1.golden @@ -0,0 +1,26 @@ +Name: pipeline-run +Namespace: ns +Pipeline Ref: pipeline +Service Account: test-sa +Labels: + tekton.dev/pipeline=pipeline +Annotations: + tekton.dev/v1beta1Resources=[{"name":"test-resource","resourceRef":{"name":"test-resource-ref"}}] + +Status + +STARTED DURATION STATUS +10 minutes ago 5m0s Succeeded + +Timeouts + Pipeline: 1h0m0s + +Params + + NAME VALUE + test-param param-value + +Taskruns + + NAME TASK NAME STARTED DURATION STATUS + tr-1 t-1 8 minutes ago 3m0s Succeeded diff --git a/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_v1beta1_with_results.golden b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_with_results.golden similarity index 88% rename from pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_v1beta1_with_results.golden rename to pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_with_results.golden index 983a2155a..6bf409217 100644 --- a/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_v1beta1_with_results.golden +++ b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_with_results.golden @@ -7,11 +7,6 @@ Status STARTED DURATION STATUS 10 minutes ago 20m0s Succeeded -Resources - - NAME RESOURCE REF - res-1 test-res - Params NAME VALUE diff --git a/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_with_results_v1beta1.golden b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_with_results_v1beta1.golden new file mode 100644 index 000000000..a2bd8784b --- /dev/null +++ b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_with_results_v1beta1.golden @@ -0,0 +1,26 @@ +Name: pipeline-run +Namespace: ns +Pipeline Ref: pipeline +Annotations: + tekton.dev/v1beta1Resources=[{"name":"res-1","resourceRef":{"name":"test-res"}}] + +Status + +STARTED DURATION STATUS +10 minutes ago 20m0s Succeeded + +Params + + NAME VALUE + p-1 somethingdifferent + +Results + + NAME VALUE + result-1 value-1 + result-2 value-2 + +Taskruns + + NAME TASK NAME STARTED DURATION STATUS + tr-1 t-1 0 seconds ago 5m0s Failed diff --git a/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_v1beta1_with_workspaces.golden b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_with_workspaces.golden similarity index 91% rename from pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_v1beta1_with_workspaces.golden rename to pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_with_workspaces.golden index fc6eeec23..3615deffc 100644 --- a/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_v1beta1_with_workspaces.golden +++ b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_with_workspaces.golden @@ -7,11 +7,6 @@ Status STARTED DURATION STATUS 10 minutes ago 20m0s Succeeded -Resources - - NAME RESOURCE REF - res-1 test-res - Params NAME VALUE diff --git a/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_with_workspaces_v1beta1.golden b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_with_workspaces_v1beta1.golden new file mode 100644 index 000000000..125f9f1c1 --- /dev/null +++ b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_with_workspaces_v1beta1.golden @@ -0,0 +1,33 @@ +Name: pipeline-run +Namespace: ns +Pipeline Ref: pipeline +Annotations: + tekton.dev/v1beta1Resources=[{"name":"res-1","resourceRef":{"name":"test-res"}}] + +Status + +STARTED DURATION STATUS +10 minutes ago 20m0s Succeeded + +Params + + NAME VALUE + p-1 somethingdifferent + +Results + + NAME VALUE + result-1 value-1 + result-2 value-2 + +Workspaces + + NAME SUB PATH WORKSPACE BINDING + test test EmptyDir (emptyDir=) + configmap --- ConfigMap (config=bar) + secret --- Secret (secret=foobar) + +Taskruns + + NAME TASK NAME STARTED DURATION STATUS + tr-1 t-1 0 seconds ago 5m0s Failed diff --git a/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribeV1beta1_withoutNameOfOnlyOnePipelineRunPresent.golden b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_withoutNameOfOnlyOnePipelineRunPresent_v1beta1.golden similarity index 73% rename from pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribeV1beta1_withoutNameOfOnlyOnePipelineRunPresent.golden rename to pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_withoutNameOfOnlyOnePipelineRunPresent_v1beta1.golden index 4af6fa8cc..221f26db0 100644 --- a/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribeV1beta1_withoutNameOfOnlyOnePipelineRunPresent.golden +++ b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_withoutNameOfOnlyOnePipelineRunPresent_v1beta1.golden @@ -1,5 +1,7 @@ Name: pipeline-run Namespace: ns +Labels: + tekton.dev/pipeline=pipeline Status diff --git a/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_without_pipelineref_v1beta1.golden b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_without_pipelineref_v1beta1.golden new file mode 100644 index 000000000..221f26db0 --- /dev/null +++ b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_without_pipelineref_v1beta1.golden @@ -0,0 +1,9 @@ +Name: pipeline-run +Namespace: ns +Labels: + tekton.dev/pipeline=pipeline + +Status + +STARTED DURATION STATUS +--- --- --- diff --git a/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_without_start_time.golden b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_without_start_time.golden index 83ce62fc8..ed3402948 100644 --- a/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_without_start_time.golden +++ b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_without_start_time.golden @@ -1,7 +1,6 @@ -Name: pipeline-run -Namespace: ns -Pipeline Ref: pipeline -Timeout(Deprecated): 1h0m0s +Name: pipeline-run +Namespace: ns +Pipeline Ref: pipeline Labels: tekton.dev/pipeline=pipeline @@ -9,3 +8,6 @@ Status STARTED DURATION STATUS --- --- --- + +Timeouts + Pipeline: 1h0m0s diff --git a/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_without_start_time_v1beta1.golden b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_without_start_time_v1beta1.golden new file mode 100644 index 000000000..ed3402948 --- /dev/null +++ b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_without_start_time_v1beta1.golden @@ -0,0 +1,13 @@ +Name: pipeline-run +Namespace: ns +Pipeline Ref: pipeline +Labels: + tekton.dev/pipeline=pipeline + +Status + +STARTED DURATION STATUS +--- --- --- + +Timeouts + Pipeline: 1h0m0s diff --git a/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_without_tr_start_time.golden b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_without_tr_start_time.golden index af3825099..7005890d4 100644 --- a/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_without_tr_start_time.golden +++ b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_without_tr_start_time.golden @@ -1,7 +1,6 @@ -Name: pipeline-run -Namespace: ns -Pipeline Ref: pipeline -Timeout(Deprecated): 1h0m0s +Name: pipeline-run +Namespace: ns +Pipeline Ref: pipeline Labels: tekton.dev/pipeline=pipeline @@ -10,6 +9,9 @@ Status STARTED DURATION STATUS 10 minutes ago --- Running +Timeouts + Pipeline: 1h0m0s + Taskruns NAME TASK NAME STARTED DURATION STATUS diff --git a/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_without_tr_start_time_v1beta1.golden b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_without_tr_start_time_v1beta1.golden new file mode 100644 index 000000000..7005890d4 --- /dev/null +++ b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_without_tr_start_time_v1beta1.golden @@ -0,0 +1,18 @@ +Name: pipeline-run +Namespace: ns +Pipeline Ref: pipeline +Labels: + tekton.dev/pipeline=pipeline + +Status + +STARTED DURATION STATUS +10 minutes ago --- Running + +Timeouts + Pipeline: 1h0m0s + +Taskruns + + NAME TASK NAME STARTED DURATION STATUS + tr-1 t-1 --- --- Running diff --git a/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_zero_timeout.golden b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_zero_timeout.golden index 84ff9c284..d84e741fd 100644 --- a/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_zero_timeout.golden +++ b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_zero_timeout.golden @@ -6,3 +6,6 @@ Status STARTED DURATION STATUS --- --- --- + +Timeouts + Pipeline: 0s diff --git a/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_zero_timeout_v1beta1.golden b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_zero_timeout_v1beta1.golden new file mode 100644 index 000000000..d84e741fd --- /dev/null +++ b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_zero_timeout_v1beta1.golden @@ -0,0 +1,11 @@ +Name: pipeline-run-zero-timeout +Namespace: ns +Pipeline Ref: pipeline-zero-timeout + +Status + +STARTED DURATION STATUS +--- --- --- + +Timeouts + Pipeline: 0s diff --git a/pkg/cmd/taskrun/delete.go b/pkg/cmd/taskrun/delete.go index 781a3cdae..1b31d80e5 100644 --- a/pkg/cmd/taskrun/delete.go +++ b/pkg/cmd/taskrun/delete.go @@ -26,7 +26,6 @@ import ( "github.com/tektoncd/cli/pkg/deleter" "github.com/tektoncd/cli/pkg/formatted" "github.com/tektoncd/cli/pkg/options" - pipelinerunpkg "github.com/tektoncd/cli/pkg/pipelinerun" taskpkg "github.com/tektoncd/cli/pkg/task" "github.com/tektoncd/cli/pkg/taskrun" trsort "github.com/tektoncd/cli/pkg/taskrun/sort" @@ -401,7 +400,8 @@ func trsWithOwnerPrFinished(cs *cli.Clients, runs *v1.TaskRunList) *v1.TaskRunLi func ownerPrFinished(cs *cli.Clients, tr v1.TaskRun) bool { for _, ref := range tr.GetOwnerReferences() { if ref.Kind == pipeline.PipelineRunControllerName { - pr, err := pipelinerunpkg.Get(cs, ref.Name, metav1.GetOptions{}, tr.Namespace) + var pr *v1.PipelineRun + err := actions.GetV1(pipelineRunGroupResource, cs, tr.Namespace, ref.Name, metav1.GetOptions{}, &pr) if err != nil { return false } diff --git a/pkg/cmd/taskrun/taskrun.go b/pkg/cmd/taskrun/taskrun.go index b9ea5fc1c..66ae3a373 100644 --- a/pkg/cmd/taskrun/taskrun.go +++ b/pkg/cmd/taskrun/taskrun.go @@ -23,6 +23,7 @@ import ( ) var taskrunGroupResource = schema.GroupVersionResource{Group: "tekton.dev", Resource: "taskruns"} +var pipelineRunGroupResource = schema.GroupVersionResource{Group: "tekton.dev", Resource: "pipelineruns"} func Command(p cli.Params) *cobra.Command { cmd := &cobra.Command{ diff --git a/pkg/formatted/description.go b/pkg/formatted/description.go index 54b96f943..66bbee78c 100644 --- a/pkg/formatted/description.go +++ b/pkg/formatted/description.go @@ -15,6 +15,7 @@ package formatted import ( + v1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" corev1 "k8s.io/api/core/v1" ) @@ -36,3 +37,12 @@ func RemoveLastAppliedConfig(annotations map[string]string) map[string]string { } return removed } + +// Check if PipelineRef exists on a PipelineRunSpec. Returns empty string if not present. +func PipelineRefExists(spec v1.PipelineRunSpec) string { + if spec.PipelineRef == nil { + return "" + } + + return spec.PipelineRef.Name +} diff --git a/pkg/formatted/description_test.go b/pkg/formatted/description_test.go index b00557207..e86df4756 100644 --- a/pkg/formatted/description_test.go +++ b/pkg/formatted/description_test.go @@ -18,7 +18,8 @@ import ( "reflect" "testing" - v1 "k8s.io/api/core/v1" + v1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" + metav1 "k8s.io/api/core/v1" ) func TestFormatDesc(t *testing.T) { @@ -76,8 +77,8 @@ func TestRemoveLastAppliedConfig(t *testing.T) { { name: "Annotations with last-applied-configuration", input: map[string]string{ - v1.LastAppliedConfigAnnotation: "JSON String", - "tekton.dev/tags": "game", + metav1.LastAppliedConfigAnnotation: "JSON String", + "tekton.dev/tags": "game", }, want: map[string]string{ "tekton.dev/tags": "game", @@ -93,3 +94,27 @@ func TestRemoveLastAppliedConfig(t *testing.T) { }) } } + +func TestPipelineRefExists_Present(t *testing.T) { + spec := v1.PipelineRunSpec{ + PipelineRef: &v1.PipelineRef{ + Name: "Pipeline", + }, + } + + output := PipelineRefExists(spec) + if output != "Pipeline" { + t.Errorf("Input = %s, want %s", output, "Pipeline") + } +} + +func TestPipelineRefExists_Not_Present(t *testing.T) { + spec := v1.PipelineRunSpec{ + PipelineRef: nil, + } + + output := PipelineRefExists(spec) + if output != "" { + t.Errorf("Input = %s, want %s", output, "") + } +} diff --git a/pkg/formatted/results.go b/pkg/formatted/results.go index d99981768..2dac96019 100644 --- a/pkg/formatted/results.go +++ b/pkg/formatted/results.go @@ -36,12 +36,3 @@ func Result(value v1beta1.ArrayOrString) string { } return "" } - -// ResultString will format a given result value. -// This is a deprecated function, that should get removed once all results -// are using ArrayOrString. -// Deprecated -func ResultString(value string) string { - // remove trailing new-line from value - return strings.TrimSuffix(value, "\n") -} diff --git a/pkg/formatted/workspace.go b/pkg/formatted/workspace.go index 5da0d187e..8d407d796 100644 --- a/pkg/formatted/workspace.go +++ b/pkg/formatted/workspace.go @@ -17,11 +17,39 @@ package formatted import ( "fmt" + v1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" corev1 "k8s.io/api/core/v1" ) -func Workspace(ws v1beta1.WorkspaceBinding) string { +func Workspace(ws v1.WorkspaceBinding) string { + if ws.VolumeClaimTemplate != nil { + return "VolumeClaimTemplate" + } + if ws.PersistentVolumeClaim != nil { + claimName := ws.PersistentVolumeClaim.ClaimName + return fmt.Sprintf("PersistentVolumeClaim (claimName=%s)", claimName) + } + if ws.EmptyDir != nil { + dirType := getWorkspaceEmptyDir(ws.EmptyDir) + return fmt.Sprintf("EmptyDir (emptyDir=%s)", dirType) + } + if ws.ConfigMap != nil { + cm := getWorkspaceConfig(ws.ConfigMap) + return fmt.Sprintf("ConfigMap (%s)", cm) + } + if ws.Secret != nil { + secret := getWorkspaceSecret(ws.Secret) + return fmt.Sprintf("Secret (%s)", secret) + } + if ws.CSI != nil { + return fmt.Sprintf("CSI (Driver=%s)", ws.CSI.Driver) + } + return "" +} + +// TODO: remove as we move the taskrun describe +func WorkspaceV1beta1(ws v1beta1.WorkspaceBinding) string { if ws.VolumeClaimTemplate != nil { return "VolumeClaimTemplate" } diff --git a/pkg/formatted/workspace_test.go b/pkg/formatted/workspace_test.go index f3a769ef3..59d5531f8 100644 --- a/pkg/formatted/workspace_test.go +++ b/pkg/formatted/workspace_test.go @@ -17,13 +17,13 @@ package formatted import ( "testing" - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" + v1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" "gotest.tools/v3/assert" corev1 "k8s.io/api/core/v1" ) func TestWorkspace(t *testing.T) { - workspaceSpec := []v1beta1.WorkspaceBinding{ + workspaceSpec := []v1.WorkspaceBinding{ { Name: "emptydir-default", EmptyDir: &corev1.EmptyDirVolumeSource{}, diff --git a/pkg/options/describe.go b/pkg/options/describe.go index 936c17233..00ba580e9 100644 --- a/pkg/options/describe.go +++ b/pkg/options/describe.go @@ -25,7 +25,7 @@ import ( "github.com/fatih/color" "github.com/ktr0731/go-fuzzyfinder" "github.com/tektoncd/cli/pkg/cli" - prdesc "github.com/tektoncd/cli/pkg/pipelinerun/description" + pipelinerunpkg "github.com/tektoncd/cli/pkg/pipelinerun" trdesc "github.com/tektoncd/cli/pkg/taskrun/description" ) @@ -141,7 +141,11 @@ func (opts *DescribeOptions) FuzzyAsk(resource string, options []string) error { return fmt.Sprintf("Cannot get taskrun description for %s: %s", bname, err.Error()) } case ResourceNamePipelineRun: - err := prdesc.PrintPipelineRunDescription(&s, bname, opts.Params) + cs, err := opts.Params.Clients() + if err != nil { + return fmt.Sprintf("Cannot initialize client: %s", err.Error()) + } + err = pipelinerunpkg.PrintPipelineRunDescription(s.Out, cs, opts.Params.Namespace(), bname, opts.Params.Time()) if err != nil { return fmt.Sprintf("Cannot get pipelinerun description for %s: %s", bname, err.Error()) } diff --git a/pkg/options/logs.go b/pkg/options/logs.go index 8ff3d4cab..87ec2f952 100644 --- a/pkg/options/logs.go +++ b/pkg/options/logs.go @@ -26,7 +26,7 @@ import ( "github.com/fatih/color" "github.com/ktr0731/go-fuzzyfinder" "github.com/tektoncd/cli/pkg/cli" - prdesc "github.com/tektoncd/cli/pkg/pipelinerun/description" + pipelinerunpkg "github.com/tektoncd/cli/pkg/pipelinerun" "github.com/tektoncd/cli/pkg/pods/stream" trdesc "github.com/tektoncd/cli/pkg/taskrun/description" ) @@ -138,7 +138,11 @@ func (opts *LogOptions) FuzzyAsk(resource string, options []string) error { return fmt.Sprintf("Cannot get taskrun description for %s: %s", bname, err.Error()) } case ResourceNamePipelineRun: - err := prdesc.PrintPipelineRunDescription(&s, bname, opts.Params) + cs, err := opts.Params.Clients() + if err != nil { + return fmt.Sprintf("Cannot initialize client: %s", err.Error()) + } + err = pipelinerunpkg.PrintPipelineRunDescription(s.Out, cs, opts.Params.Namespace(), bname, opts.Params.Time()) if err != nil { return fmt.Sprintf("Cannot get pipelinerun description for %s: %s", bname, err.Error()) } diff --git a/pkg/pipelinerun/description/description.go b/pkg/pipelinerun/description.go similarity index 53% rename from pkg/pipelinerun/description/description.go rename to pkg/pipelinerun/description.go index 7180ff06f..ac50d8fb3 100644 --- a/pkg/pipelinerun/description/description.go +++ b/pkg/pipelinerun/description.go @@ -12,35 +12,35 @@ // See the License for the specific language governing permissions and // limitations under the License. -package description +package pipelinerun import ( + "context" "fmt" + "io" "sort" "strings" "text/tabwriter" "text/template" + "github.com/jonboulle/clockwork" + "github.com/tektoncd/cli/pkg/actions" "github.com/tektoncd/cli/pkg/cli" "github.com/tektoncd/cli/pkg/formatted" - "github.com/tektoncd/cli/pkg/pipelinerun" + v1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime/schema" ) -const templ = `{{decorate "bold" "Name"}}: {{ .PipelineRun.Name }} +const describeTemplate = `{{decorate "bold" "Name"}}: {{ .PipelineRun.Name }} {{decorate "bold" "Namespace"}}: {{ .PipelineRun.Namespace }} {{- $pRefName := pipelineRefExists .PipelineRun.Spec }}{{- if ne $pRefName "" }} {{decorate "bold" "Pipeline Ref"}}: {{ $pRefName }} {{- end }} -{{- if ne .PipelineRun.Spec.ServiceAccountName "" }} -{{decorate "bold" "Service Account"}}: {{ .PipelineRun.Spec.ServiceAccountName }} -{{- end }} - -{{- $timeout := getTimeout .PipelineRun -}} -{{- if and (ne $timeout "") (ne $timeout "0s") }} -{{decorate "bold" "Timeout(Deprecated)"}}: {{ .PipelineRun.Spec.Timeout.Duration.String }} +{{- if ne .PipelineRun.Spec.TaskRunTemplate.ServiceAccountName "" }} +{{decorate "bold" "Service Account"}}: {{ .PipelineRun.Spec.TaskRunTemplate.ServiceAccountName }} {{- end }} {{- $l := len .PipelineRun.Labels }}{{ if eq $l 0 }} @@ -60,8 +60,8 @@ const templ = `{{decorate "bold" "Name"}}: {{ .PipelineRun.Name }} {{decorate "status" ""}}{{decorate "underline bold" "Status\n"}} STARTED DURATION STATUS -{{ formatAge .PipelineRun.Status.StartTime .Params.Time }} {{ formatDuration .PipelineRun.Status.StartTime .PipelineRun.Status.CompletionTime }} {{ formatCondition .PipelineRun.Status.Conditions }} -{{- $msg := hasFailed .PipelineRun -}} +{{ formatAge .PipelineRun.Status.StartTime .Time }} {{ formatDuration .PipelineRun.Status.StartTime .PipelineRun.Status.CompletionTime }} {{ formatCondition .PipelineRun.Status.Conditions }} +{{- $msg := hasFailed .PipelineRun .TaskrunList -}} {{- if ne $msg "" }} {{decorate "message" ""}}{{decorate "underline bold" "Message\n"}} @@ -86,19 +86,6 @@ STARTED DURATION STATUS {{- end }} {{- end }} -{{- if ne (len .PipelineRun.Spec.Resources) 0 }} - -{{decorate "resources" ""}}{{decorate "underline bold" "Resources\n"}} - NAME RESOURCE REF -{{- range $i, $r := .PipelineRun.Spec.Resources }} -{{- $rRefName := pipelineResourceRefExists $r }}{{- if ne $rRefName "" }} - {{decorate "bullet" $r.Name }} {{ $r.ResourceRef.Name }} -{{- else }} - {{decorate "bullet" $r.Name }} {{ "" }} -{{- end }} -{{- end }} -{{- end }} - {{- if ne (len .PipelineRun.Spec.Params) 0 }} {{decorate "params" ""}}{{decorate "underline bold" "Params\n"}} @@ -106,17 +93,19 @@ STARTED DURATION STATUS {{- range $i, $p := .PipelineRun.Spec.Params }} {{- if eq $p.Value.Type "string" }} {{decorate "bullet" $p.Name }} {{ $p.Value.StringVal }} -{{- else }} +{{- else if eq $p.Value.Type "array" }} {{decorate "bullet" $p.Name }} {{ $p.Value.ArrayVal }} +{{- else }} + {{decorate "bullet" $p.Name }} {{ $p.Value.ObjectVal }} {{- end }} {{- end }} {{- end }} -{{- if ne (len .PipelineRun.Status.PipelineResults) 0 }} +{{- if ne (len .PipelineRun.Status.Results) 0 }} {{decorate "results" ""}}{{decorate "underline bold" "Results\n"}} NAME VALUE -{{- range $result := .PipelineRun.Status.PipelineResults }} +{{- range $result := .PipelineRun.Status.Results }} {{- if eq $result.Value.Type "string" }} {{decorate "bullet" $result.Name }} {{ $result.Value.StringVal }} {{- else }} @@ -143,7 +132,7 @@ STARTED DURATION STATUS {{decorate "taskruns" ""}}{{decorate "underline bold" "Taskruns\n"}} NAME TASK NAME STARTED DURATION STATUS {{- range $taskrun := .TaskrunList }}{{ if checkTRStatus $taskrun }} - {{decorate "bullet" $taskrun.TaskrunName }} {{ $taskrun.PipelineTaskName }} {{ formatAge $taskrun.Status.StartTime $.Params.Time }} {{ formatDuration $taskrun.Status.StartTime $taskrun.Status.CompletionTime }} {{ formatCondition $taskrun.Status.Conditions }} + {{decorate "bullet" $taskrun.TaskRunName }} {{ $taskrun.PipelineTaskName }} {{ formatAge $taskrun.Status.StartTime $.Time }} {{ formatDuration $taskrun.Status.StartTime $taskrun.Status.CompletionTime }} {{ formatCondition $taskrun.Status.Conditions }} {{- end }} {{- end }} {{- end }} @@ -158,16 +147,17 @@ STARTED DURATION STATUS {{- end }} ` -type tkr struct { - TaskrunName string - *v1beta1.PipelineRunTaskRunStatus +type TaskRunWithStatus struct { + TaskRunName string + PipelineTaskName string + Status *v1.TaskRunStatus } -type taskrunList []tkr +type TaskRunWithStatusList []TaskRunWithStatus -func (trs taskrunList) Len() int { return len(trs) } -func (trs taskrunList) Swap(i, j int) { trs[i], trs[j] = trs[j], trs[i] } -func (trs taskrunList) Less(i, j int) bool { +func (trs TaskRunWithStatusList) Len() int { return len(trs) } +func (trs TaskRunWithStatusList) Swap(i, j int) { trs[i], trs[j] = trs[j], trs[i] } +func (trs TaskRunWithStatusList) Less(i, j int) bool { if trs[j].Status == nil || trs[j].Status.StartTime == nil { return false } @@ -179,85 +169,108 @@ func (trs taskrunList) Less(i, j int) bool { return trs[j].Status.StartTime.Before(trs[i].Status.StartTime) } -func newTaskrunListFromMap(statusMap map[string]*v1beta1.PipelineRunTaskRunStatus) taskrunList { - var trl taskrunList - for taskrunName, taskrunStatus := range statusMap { - trl = append(trl, tkr{ - taskrunName, - taskrunStatus, - }) - } - return trl -} - -func PrintPipelineRunDescription(s *cli.Stream, prName string, p cli.Params) error { - cs, err := p.Clients() +func PrintPipelineRunDescription(out io.Writer, c *cli.Clients, ns string, prName string, time clockwork.Clock) error { + pr, err := getPipelineRun(pipelineRunGroupResource, c, prName, ns) if err != nil { - return fmt.Errorf("failed to create tekton client: %v", err) + return fmt.Errorf("failed to find pipelinerun %q", prName) } - pr, err := pipelinerun.Get(cs, prName, metav1.GetOptions{}, p.Namespace()) - if err != nil { - return fmt.Errorf("failed to find pipelinerun %q", prName) + var taskRunList TaskRunWithStatusList + for _, child := range pr.Status.ChildReferences { + if child.Kind == "TaskRun" { + var tr *v1.TaskRun + err = actions.GetV1(taskrunGroupResource, c, child.Name, ns, metav1.GetOptions{}, &tr) + if err != nil { + return fmt.Errorf("failed to find get taskruns of the pipelineruns") + } + taskRunList = append(taskRunList, TaskRunWithStatus{ + tr.Name, + child.PipelineTaskName, + &tr.Status, + }) + } } - var trl taskrunList - if len(pr.Status.TaskRuns) != 0 { - trl = newTaskrunListFromMap(pr.Status.TaskRuns) - sort.Sort(trl) + if len(taskRunList) != 0 { + sort.Sort(taskRunList) } var data = struct { - PipelineRun *v1beta1.PipelineRun - Params cli.Params - TaskrunList taskrunList + PipelineRun *v1.PipelineRun + Time clockwork.Clock + TaskrunList TaskRunWithStatusList }{ PipelineRun: pr, - Params: p, - TaskrunList: trl, + Time: time, + TaskrunList: taskRunList, } funcMap := template.FuncMap{ - "formatAge": formatted.Age, - "formatDuration": formatted.Duration, - "formatCondition": formatted.Condition, - "formatResult": formatted.ResultString, - "formatWorkspace": formatted.Workspace, - "hasFailed": hasFailed, - "pipelineRefExists": pipelineRefExists, - "pipelineResourceRefExists": pipelineResourceRefExists, - "decorate": formatted.DecorateAttr, - "getTimeout": getTimeoutValue, - "checkTRStatus": checkTaskRunStatus, - "removeLastAppliedConfig": formatted.RemoveLastAppliedConfig, + "formatAge": formatted.Age, + "formatDuration": formatted.Duration, + "formatCondition": formatted.Condition, + "formatResult": formatted.Result, + "formatWorkspace": formatted.Workspace, + "hasFailed": hasFailed, + "pipelineRefExists": formatted.PipelineRefExists, + "decorate": formatted.DecorateAttr, + "checkTRStatus": checkTaskRunStatus, + "removeLastAppliedConfig": formatted.RemoveLastAppliedConfig, } - w := tabwriter.NewWriter(s.Out, 0, 5, 3, ' ', tabwriter.TabIndent) - t := template.Must(template.New("Describe Pipelinerun").Funcs(funcMap).Parse(templ)) + w := tabwriter.NewWriter(out, 0, 5, 3, ' ', tabwriter.TabIndent) + t := template.Must(template.New("Describe Pipelinerun").Funcs(funcMap).Parse(describeTemplate)) if err = t.Execute(w, data); err != nil { - fmt.Fprintf(s.Err, "failed to execute template: ") return err } return w.Flush() } -func hasFailed(pr *v1beta1.PipelineRun) string { +func getPipelineRun(gr schema.GroupVersionResource, c *cli.Clients, prName, ns string) (*v1.PipelineRun, error) { + var pipelinerun v1.PipelineRun + gvr, err := actions.GetGroupVersionResource(gr, c.Tekton.Discovery()) + if err != nil { + return nil, err + } + + if gvr.Version == "v1" { + err := actions.GetV1(pipelineRunGroupResource, c, prName, ns, metav1.GetOptions{}, &pipelinerun) + if err != nil { + return nil, err + } + return &pipelinerun, nil + } + + var pipelinerunV1beta1 v1beta1.PipelineRun + err = actions.GetV1(pipelineRunGroupResource, c, prName, ns, metav1.GetOptions{}, &pipelinerunV1beta1) + if err != nil { + return nil, err + } + + err = pipelinerunV1beta1.ConvertTo(context.Background(), &pipelinerun) + if err != nil { + return nil, err + } + return &pipelinerun, nil +} + +func hasFailed(pr *v1.PipelineRun, taskruns TaskRunWithStatusList) string { if len(pr.Status.Conditions) == 0 { return "" } if pr.Status.Conditions[0].Status == corev1.ConditionFalse { - trNames := []string{} - for taskRunName, tr := range pr.Status.TaskRuns { - if tr.Status == nil { + var trNames []string + for _, taskrun := range taskruns { + if taskrun.Status == nil { continue } - if len(tr.Status.Conditions) == 0 { + if len(taskrun.Status.Conditions) == 0 { continue } - if tr.Status.Conditions[0].Status == corev1.ConditionFalse { - trNames = append(trNames, taskRunName) + if taskrun.Status.Conditions[0].Status == corev1.ConditionFalse { + trNames = append(trNames, taskrun.TaskRunName) } } message := pr.Status.Conditions[0].Message @@ -270,31 +283,6 @@ func hasFailed(pr *v1beta1.PipelineRun) string { return "" } -func getTimeoutValue(pr *v1beta1.PipelineRun) string { - if pr.Spec.Timeout != nil { - return pr.Spec.Timeout.Duration.String() - } - return "" -} - -func checkTaskRunStatus(taskRun tkr) bool { - return taskRun.PipelineRunTaskRunStatus.Status != nil -} - -// Check if PipelineRef exists on a PipelineRunSpec. Returns empty string if not present. -func pipelineRefExists(spec v1beta1.PipelineRunSpec) string { - if spec.PipelineRef == nil { - return "" - } - - return spec.PipelineRef.Name -} - -// Check if PipelineResourceRef exists on a PipelineResourceBinding. Returns empty string if not present. -func pipelineResourceRefExists(res v1beta1.PipelineResourceBinding) string { - if res.ResourceRef == nil { - return "" - } - - return res.ResourceRef.Name +func checkTaskRunStatus(taskRun TaskRunWithStatus) bool { + return taskRun.Status != nil } diff --git a/pkg/pipelinerun/description/description_test.go b/pkg/pipelinerun/description_test.go similarity index 52% rename from pkg/pipelinerun/description/description_test.go rename to pkg/pipelinerun/description_test.go index 65b5b6745..b5db8f6ce 100644 --- a/pkg/pipelinerun/description/description_test.go +++ b/pkg/pipelinerun/description_test.go @@ -12,74 +12,31 @@ // See the License for the specific language governing permissions and // limitations under the License. -package description +package pipelinerun import ( "testing" "github.com/tektoncd/cli/pkg/test" - "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" + v1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "knative.dev/pkg/apis" duckv1 "knative.dev/pkg/apis/duck/v1" ) -func TestPipelineRefExists_Present(t *testing.T) { - spec := v1beta1.PipelineRunSpec{ - PipelineRef: &v1beta1.PipelineRef{ - Name: "Pipeline", - }, - } - - output := pipelineRefExists(spec) - test.AssertOutput(t, "Pipeline", output) -} - -func TestPipelineRefExists_Not_Present(t *testing.T) { - spec := v1beta1.PipelineRunSpec{ - PipelineRef: nil, - } - - output := pipelineRefExists(spec) - test.AssertOutput(t, "", output) -} - -func TestPipelineResourceRefExists_Present(t *testing.T) { - spec := v1beta1.PipelineResourceBinding{ - ResourceRef: &v1beta1.PipelineResourceRef{ - Name: "Pipeline", - }, - } - - output := pipelineResourceRefExists(spec) - test.AssertOutput(t, "Pipeline", output) -} - -func TestPipelineResourceRefExists_Not_Present(t *testing.T) { - spec := v1beta1.PipelineResourceBinding{ - ResourceRef: nil, - } - - output := pipelineResourceRefExists(spec) - test.AssertOutput(t, "", output) -} - func TestHasFailed_PipelineAndTaskRunFailedMessage(t *testing.T) { - - trs := []*v1beta1.TaskRun{ + taskRunWithStatusList := TaskRunWithStatusList{ { - ObjectMeta: metav1.ObjectMeta{ - Name: "tr-1", - Namespace: "ns", - }, - Status: v1beta1.TaskRunStatus{ + TaskRunName: "tr-1", + PipelineTaskName: "task", + Status: &v1.TaskRunStatus{ Status: duckv1.Status{ Conditions: duckv1.Conditions{ { Status: corev1.ConditionFalse, Type: apis.ConditionSucceeded, - Reason: v1beta1.TaskRunReasonCancelled.String(), + Reason: v1.TaskRunReasonCancelled.String(), Message: "TaskRun \"tr-1\" was cancelled", }, }, @@ -88,15 +45,18 @@ func TestHasFailed_PipelineAndTaskRunFailedMessage(t *testing.T) { }, } - pipelineRuns := []*v1beta1.PipelineRun{ + pipelineRuns := []*v1.PipelineRun{ { ObjectMeta: metav1.ObjectMeta{ Name: "pipeline-run", }, - Status: v1beta1.PipelineRunStatus{ - PipelineRunStatusFields: v1beta1.PipelineRunStatusFields{ - TaskRuns: map[string]*v1beta1.PipelineRunTaskRunStatus{ - "tr-1": {PipelineTaskName: "t-1", Status: &trs[0].Status}, + Status: v1.PipelineRunStatus{ + PipelineRunStatusFields: v1.PipelineRunStatusFields{ + ChildReferences: []v1.ChildStatusReference{ + { + Name: "tr-1", + PipelineTaskName: "test", + }, }, }, Status: duckv1.Status{ @@ -112,25 +72,22 @@ func TestHasFailed_PipelineAndTaskRunFailedMessage(t *testing.T) { }, } - message := hasFailed(pipelineRuns[0]) + message := hasFailed(pipelineRuns[0], taskRunWithStatusList) test.AssertOutput(t, "PipelineRun \"pipeline-run\" was cancelled\nTaskRun(s) cancelled: tr-1", message) } func TestHasFailed_PipelineFailedMessage(t *testing.T) { - - trs := []*v1beta1.TaskRun{ + taskRunWithStatusList := TaskRunWithStatusList{ { - ObjectMeta: metav1.ObjectMeta{ - Name: "tr-1", - Namespace: "ns", - }, - Status: v1beta1.TaskRunStatus{ + TaskRunName: "tr-1", + PipelineTaskName: "t-1", + Status: &v1.TaskRunStatus{ Status: duckv1.Status{ Conditions: duckv1.Conditions{ { Status: corev1.ConditionTrue, Type: apis.ConditionSucceeded, - Reason: string(v1beta1.TaskRunReasonSuccessful), + Reason: v1.TaskRunReasonSuccessful.String(), }, }, }, @@ -138,15 +95,18 @@ func TestHasFailed_PipelineFailedMessage(t *testing.T) { }, } - pipelineRuns := []*v1beta1.PipelineRun{ + pipelineRuns := []*v1.PipelineRun{ { ObjectMeta: metav1.ObjectMeta{ Name: "pipeline-run", }, - Status: v1beta1.PipelineRunStatus{ - PipelineRunStatusFields: v1beta1.PipelineRunStatusFields{ - TaskRuns: map[string]*v1beta1.PipelineRunTaskRunStatus{ - "tr-1": {PipelineTaskName: "t-1", Status: &trs[0].Status}, + Status: v1.PipelineRunStatus{ + PipelineRunStatusFields: v1.PipelineRunStatusFields{ + ChildReferences: []v1.ChildStatusReference{ + { + Name: "tr-1", + PipelineTaskName: "t-1", + }, }, }, Status: duckv1.Status{ @@ -162,6 +122,6 @@ func TestHasFailed_PipelineFailedMessage(t *testing.T) { }, } - message := hasFailed(pipelineRuns[0]) + message := hasFailed(pipelineRuns[0], taskRunWithStatusList) test.AssertOutput(t, "PipelineRun \"pipeline-run\" was cancelled", message) } diff --git a/pkg/pipelinerun/pipelinerun.go b/pkg/pipelinerun/pipelinerun.go index 8c0aa3ac1..252c9bf1e 100644 --- a/pkg/pipelinerun/pipelinerun.go +++ b/pkg/pipelinerun/pipelinerun.go @@ -35,7 +35,8 @@ import ( "k8s.io/apimachinery/pkg/watch" ) -var prGroupResource = schema.GroupVersionResource{Group: "tekton.dev", Resource: "pipelineruns"} +var pipelineRunGroupResource = schema.GroupVersionResource{Group: "tekton.dev", Resource: "pipelineruns"} +var taskrunGroupResource = schema.GroupVersionResource{Group: "tekton.dev", Resource: "taskruns"} // GetAllPipelineRuns returns all pipelinesruns running in a namespace func GetAllPipelineRuns(gr schema.GroupVersionResource, opts metav1.ListOptions, c *cli.Clients, ns string, limit int, time clockwork.Clock) ([]string, error) { @@ -61,9 +62,10 @@ func GetAllPipelineRuns(gr schema.GroupVersionResource, opts metav1.ListOptions, return ret, nil } +// TODO: remove as all the function uses are moved to new func // It will fetch the resource in v1beta1 struct format func Get(c *cli.Clients, prname string, opts metav1.GetOptions, ns string) (*v1beta1.PipelineRun, error) { - unstructuredPR, err := actions.Get(prGroupResource, c.Dynamic, c.Tekton.Discovery(), prname, ns, opts) + unstructuredPR, err := actions.Get(pipelineRunGroupResource, c.Dynamic, c.Tekton.Discovery(), prname, ns, opts) if err != nil { return nil, err } @@ -83,7 +85,7 @@ func Get(c *cli.Clients, prname string, opts metav1.GetOptions, ns string) (*v1b } func Watch(c *cli.Clients, opts metav1.ListOptions, ns string) (watch.Interface, error) { - watch, err := actions.Watch(prGroupResource, c, ns, opts) + watch, err := actions.Watch(pipelineRunGroupResource, c, ns, opts) if err != nil { return nil, err } @@ -121,7 +123,7 @@ func Create(c *cli.Clients, pr *v1beta1.PipelineRun, opts metav1.CreateOptions, Object: object, } - newUnstructuredPR, err := actions.Create(prGroupResource, c, unstructuredPR, ns, opts) + newUnstructuredPR, err := actions.Create(pipelineRunGroupResource, c, unstructuredPR, ns, opts) if err != nil { return nil, err } diff --git a/pkg/pipelinerun/pipelinerun_test.go b/pkg/pipelinerun/pipelinerun_test.go index 7f4637202..e800f1e17 100644 --- a/pkg/pipelinerun/pipelinerun_test.go +++ b/pkg/pipelinerun/pipelinerun_test.go @@ -21,6 +21,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/jonboulle/clockwork" + "github.com/tektoncd/cli/pkg/actions" "github.com/tektoncd/cli/pkg/cli" "github.com/tektoncd/cli/pkg/test" cb "github.com/tektoncd/cli/pkg/test/builder" @@ -193,7 +194,7 @@ func TestPipelineRunsList_v1beta1(t *testing.T) { for _, tp := range testParams { t.Run(tp.name, func(t *testing.T) { - got, err := GetAllPipelineRuns(prGroupResource, tp.listOptions, tp.client, tp.namespace, 5, tp.time) + got, err := GetAllPipelineRuns(pipelineRunGroupResource, tp.listOptions, tp.client, tp.namespace, 5, tp.time) if err != nil { t.Errorf("unexpected Error") } @@ -358,7 +359,7 @@ func TestPipelineRunsList(t *testing.T) { for _, tp := range testParams { t.Run(tp.name, func(t *testing.T) { - got, err := GetAllPipelineRuns(prGroupResource, tp.listOptions, tp.client, tp.namespace, 5, tp.time) + got, err := GetAllPipelineRuns(pipelineRunGroupResource, tp.listOptions, tp.client, tp.namespace, 5, tp.time) if err != nil { t.Errorf("unexpected Error") } @@ -367,7 +368,7 @@ func TestPipelineRunsList(t *testing.T) { } } -func TestPipelineRunGet(t *testing.T) { +func TestPipelineRunGet_v1beta1(t *testing.T) { version := "v1beta1" clock := clockwork.NewFakeClock() pr1Started := clock.Now().Add(10 * time.Second) @@ -446,11 +447,99 @@ func TestPipelineRunGet(t *testing.T) { t.Errorf("unable to create client: %v", err) } - got, err := Get(c, "pipelinerun1", metav1.GetOptions{}, "ns") + var pipeline *v1beta1.PipelineRun + err = actions.GetV1(pipelineRunGroupResource, c, "pipelinerun1", "ns", metav1.GetOptions{}, &pipeline) if err != nil { t.Errorf("unexpected Error") } - test.AssertOutput(t, "pipelinerun1", got.Name) + test.AssertOutput(t, "pipelinerun1", pipeline.Name) +} + +func TestPipelineRunGet(t *testing.T) { + version := "v1" + clock := clockwork.NewFakeClock() + pr1Started := clock.Now().Add(10 * time.Second) + runDuration := 1 * time.Minute + + prdata := []*v1.PipelineRun{ + { + ObjectMeta: metav1.ObjectMeta{ + Name: "pipelinerun1", + Namespace: "ns", + Labels: map[string]string{"tekton.dev/pipeline": "pipeline"}, + }, + Spec: v1.PipelineRunSpec{ + PipelineRef: &v1.PipelineRef{ + Name: "pipeline", + }, + }, + Status: v1.PipelineRunStatus{ + Status: duckv1.Status{ + Conditions: duckv1.Conditions{ + { + Status: corev1.ConditionTrue, + Reason: v1.PipelineRunReasonSuccessful.String(), + }, + }, + }, + PipelineRunStatusFields: v1.PipelineRunStatusFields{ + StartTime: &metav1.Time{Time: pr1Started}, + CompletionTime: &metav1.Time{Time: pr1Started.Add(runDuration)}, + }, + }, + }, + { + ObjectMeta: metav1.ObjectMeta{ + Name: "pipelinerun2", + Namespace: "ns", + Labels: map[string]string{"tekton.dev/pipeline": "pipeline"}, + }, + Spec: v1.PipelineRunSpec{ + PipelineRef: &v1.PipelineRef{ + Name: "pipeline", + }, + }, + Status: v1.PipelineRunStatus{ + Status: duckv1.Status{ + Conditions: duckv1.Conditions{ + { + Status: corev1.ConditionTrue, + Reason: v1.PipelineRunReasonSuccessful.String(), + }, + }, + }, + PipelineRunStatusFields: v1.PipelineRunStatusFields{ + StartTime: &metav1.Time{Time: pr1Started}, + CompletionTime: &metav1.Time{Time: pr1Started.Add(runDuration)}, + }, + }, + }, + } + cs, _ := test.SeedTestData(t, test.Data{ + PipelineRuns: prdata, + }) + cs.Pipeline.Resources = cb.APIResourceList(version, []string{"pipelinerun"}) + tdc := testDynamic.Options{} + dc, err := tdc.Client( + cb.UnstructuredPR(prdata[0], version), + cb.UnstructuredPR(prdata[1], version), + ) + if err != nil { + t.Errorf("unable to create dynamic client: %v", err) + } + + p := &test.Params{Tekton: cs.Pipeline, Clock: clock, Kube: cs.Kube, Dynamic: dc} + c, err := p.Clients() + if err != nil { + t.Errorf("unable to create client: %v", err) + } + + var pipeline *v1.PipelineRun + err = actions.GetV1(pipelineRunGroupResource, c, "pipelinerun1", "ns", metav1.GetOptions{}, &pipeline) + if err != nil { + t.Errorf("unexpected Error") + } + test.AssertOutput(t, "pipelinerun1", pipeline.Name) } func TestPipelineRunGet_MinimalEmbeddedStatus(t *testing.T) { diff --git a/pkg/taskrun/description/description.go b/pkg/taskrun/description/description.go index c09217ca9..8e7adc183 100644 --- a/pkg/taskrun/description/description.go +++ b/pkg/taskrun/description/description.go @@ -228,7 +228,7 @@ func PrintTaskRunDescription(s *cli.Stream, trName string, p cli.Params) error { "formatDuration": formatted.Duration, "formatCondition": formatted.Condition, "formatResult": formatted.Result, - "formatWorkspace": formatted.Workspace, + "formatWorkspace": formatted.WorkspaceV1beta1, "hasFailed": hasFailed, "taskRefExists": taskRefExists, "taskResourceRefExists": taskResourceRefExists,