From 963e62c014e0ec2a255d6fdb7f4d53b46e119ced Mon Sep 17 00:00:00 2001 From: Piyush Garg Date: Tue, 20 Oct 2020 11:30:51 +0530 Subject: [PATCH] tkn pr describe failing in pr with conditions This will fix the issue of tkn pr desc failing in case of pipelinerun with conditions and condition is not executed Add test Fix #1204 --- pkg/cmd/pipelinerun/describe_test.go | 73 +++++++++++++++++++ ...ibe_multiple_taskrun_without_status.golden | 32 ++++++++ pkg/pipelinerun/description/description.go | 3 + 3 files changed, 108 insertions(+) create mode 100644 pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_multiple_taskrun_without_status.golden diff --git a/pkg/cmd/pipelinerun/describe_test.go b/pkg/cmd/pipelinerun/describe_test.go index b45c3a3e30..84e8684ad0 100644 --- a/pkg/cmd/pipelinerun/describe_test.go +++ b/pkg/cmd/pipelinerun/describe_test.go @@ -241,6 +241,79 @@ func TestPipelineRunDescribe_multiple_taskrun_ordering(t *testing.T) { } +func TestPipelineRunDescribe_multiple_taskrun_without_status(t *testing.T) { + clock := clockwork.NewFakeClock() + + trs := []*v1alpha1.TaskRun{ + tb.TaskRun("tr-1", + tb.TaskRunNamespace("ns"), + tb.TaskRunStatus( + tb.TaskRunStartTime(clock.Now().Add(2*time.Minute)), + cb.TaskRunCompletionTime(clock.Now().Add(5*time.Minute)), + tb.StatusCondition(apis.Condition{ + Type: apis.ConditionSucceeded, + Status: corev1.ConditionTrue, + }), + ), + ), + } + + pipelineRuns := []*v1alpha1.PipelineRun{ + tb.PipelineRun("pipeline-run", + tb.PipelineRunNamespace("ns"), + cb.PipelineRunCreationTimestamp(clock.Now()), + tb.PipelineRunLabel("tekton.dev/pipeline", "pipeline"), + tb.PipelineRunSpec("pipeline"), + tb.PipelineRunStatus( + tb.PipelineRunTaskRunsStatus("tr-0", &v1alpha1.PipelineRunTaskRunStatus{ + PipelineTaskName: "t-0", + }), + tb.PipelineRunTaskRunsStatus("tr-1", &v1alpha1.PipelineRunTaskRunStatus{ + PipelineTaskName: "t-1", + Status: &trs[0].Status, + }), + tb.PipelineRunStatusCondition(apis.Condition{ + Status: corev1.ConditionFalse, + Reason: v1beta1.PipelineRunReasonFailed.String(), + }), + tb.PipelineRunStartTime(clock.Now()), + cb.PipelineRunCompletionTime(clock.Now().Add(5*time.Minute)), + ), + ), + } + + namespaces := []*corev1.Namespace{ + { + ObjectMeta: metav1.ObjectMeta{ + Name: "ns", + }, + }, + } + + version := "v1alpha1" + 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, pipelinetest.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() diff --git a/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_multiple_taskrun_without_status.golden b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_multiple_taskrun_without_status.golden new file mode 100644 index 0000000000..620c91a0ad --- /dev/null +++ b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_multiple_taskrun_without_status.golden @@ -0,0 +1,32 @@ +Name: pipeline-run +Namespace: ns +Pipeline Ref: pipeline +Timeout: 1h0m0s +Labels: + tekton.dev/pipeline=pipeline + +Status + +STARTED DURATION STATUS +10 minutes ago 5 minutes Failed + +Resources + + No resources + +Params + + No params + +Results + + No results + +Workspaces + + No workspaces + +Taskruns + + NAME TASK NAME STARTED DURATION STATUS + tr-1 t-1 8 minutes ago 3 minutes Succeeded diff --git a/pkg/pipelinerun/description/description.go b/pkg/pipelinerun/description/description.go index 74330d9fac..6e88cbffe4 100644 --- a/pkg/pipelinerun/description/description.go +++ b/pkg/pipelinerun/description/description.go @@ -214,6 +214,9 @@ func hasFailed(pr *v1beta1.PipelineRun) string { if pr.Status.Conditions[0].Status == corev1.ConditionFalse { for _, tr := range pr.Status.TaskRuns { + if tr.Status == nil { + continue + } if len(tr.Status.Conditions) == 0 { continue }