From a77f5ffcf46aafeb75e8aaccc639b53799dc6e27 Mon Sep 17 00:00:00 2001 From: vinamra28 Date: Wed, 26 Aug 2020 09:17:23 +0530 Subject: [PATCH] Display Workspaces in the output of PipelineRun describe command The workspaces declared in the PipelineRun will be displayed in the output of pipelinerun describe command. When we will do `tkn pipelinerun desc ` workspace name, subpath and workspace binding will be displayed in the output. Signed-off-by: vinamra28 --- pkg/cmd/pipelinerun/describe_test.go | 143 ++++++++++++++++++ .../TestPipelineRunDescribeV1beta1.golden | 4 + ...cribeV1beta1_taskrun_with_no_status.golden | 4 + ...neRunDescribe_cancelled_pipelinerun.golden | 4 + ...tPipelineRunDescribe_custom_timeout.golden | 4 + .../TestPipelineRunDescribe_failed.golden | 4 + ...nDescribe_failed_withoutPRCondition.golden | 4 + ...nDescribe_failed_withoutTRCondition.golden | 4 + .../TestPipelineRunDescribe_last.golden | 4 + ...TestPipelineRunDescribe_lastV1beta1.golden | 4 + ...nDescribe_multiple_taskrun_ordering.golden | 4 + ...tPipelineRunDescribe_no_resourceref.golden | 4 + ...estPipelineRunDescribe_only_taskrun.golden | 4 + ...ineRunDescribe_v1beta1_with_results.golden | 4 + ...RunDescribe_v1beta1_with_workspaces.golden | 36 +++++ ...eRunDescribe_with_resources_taskrun.golden | 4 + ...lineRunDescribe_without_pipelineref.golden | 4 + ...elineRunDescribe_without_start_time.golden | 4 + ...neRunDescribe_without_tr_start_time.golden | 4 + ...estPipelineRunDescribe_zero_timeout.golden | 4 + pkg/pipelinerun/description/description.go | 16 ++ 21 files changed, 267 insertions(+) create mode 100644 pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_v1beta1_with_workspaces.golden diff --git a/pkg/cmd/pipelinerun/describe_test.go b/pkg/cmd/pipelinerun/describe_test.go index 56e0656fc..b56020281 100644 --- a/pkg/cmd/pipelinerun/describe_test.go +++ b/pkg/cmd/pipelinerun/describe_test.go @@ -1773,3 +1773,146 @@ 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) { + clock := clockwork.NewFakeClock() + pipelinerunname := "pipeline-run" + taskRuns := []*v1beta1.TaskRun{ + { + ObjectMeta: metav1.ObjectMeta{ + Namespace: "ns", + Name: "tr-1", + Labels: map[string]string{"tekton.dev/task": "task-1"}, + }, + Spec: v1beta1.TaskRunSpec{ + TaskRef: &v1beta1.TaskRef{ + Name: "task-1", + }, + }, + Status: v1beta1.TaskRunStatus{ + Status: duckv1beta1.Status{ + Conditions: duckv1beta1.Conditions{ + { + Status: corev1.ConditionFalse, + Reason: v1beta1.PipelineRunReasonFailed.String(), + }, + }, + }, + TaskRunStatusFields: v1beta1.TaskRunStatusFields{ + StartTime: &metav1.Time{Time: clock.Now()}, + CompletionTime: &metav1.Time{Time: clock.Now().Add(5 * time.Minute)}, + }, + }, + }, + } + + prun := []*v1beta1.PipelineRun{ + { + ObjectMeta: metav1.ObjectMeta{ + Name: pipelinerunname, + Namespace: "ns", + }, + Spec: v1beta1.PipelineRunSpec{ + PipelineRef: &v1beta1.PipelineRef{ + Name: "pipeline", + }, + Resources: []v1beta1.PipelineResourceBinding{ + { + Name: "res-1", + ResourceRef: &v1beta1.PipelineResourceRef{ + Name: "test-res", + }, + }, + }, + Params: []v1beta1.Param{ + { + Name: "p-1", + Value: v1beta1.ArrayOrString{ + Type: v1beta1.ParamTypeString, + StringVal: "somethingdifferent", + }, + }, + }, + Workspaces: []v1beta1.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: v1beta1.PipelineRunStatus{ + Status: duckv1beta1.Status{ + Conditions: duckv1beta1.Conditions{ + { + Status: corev1.ConditionTrue, + Reason: v1beta1.PipelineRunReasonSuccessful.String(), + Message: "Completed", + }, + }, + }, + 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": { + PipelineTaskName: "t-1", + Status: &taskRuns[0].Status, + }, + }, + PipelineResults: []v1beta1.PipelineRunResult{ + { + Name: "result-1", + Value: "value-1", + }, + { + Name: "result-2", + Value: "value-2", + }, + }, + }, + }, + }, + } + + namespaces := []*corev1.Namespace{ + { + ObjectMeta: metav1.ObjectMeta{ + Name: "ns", + }, + }, + } + + version := "v1beta1" + tdc := testDynamic.Options{} + dynamic, err := tdc.Client( + cb.UnstructuredV1beta1PR(prun[0], version), + cb.UnstructuredV1beta1TR(taskRuns[0], version), + ) + 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.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())) +} diff --git a/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribeV1beta1.golden b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribeV1beta1.golden index 5d58add4f..fe1ba5eb1 100644 --- a/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribeV1beta1.golden +++ b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribeV1beta1.golden @@ -23,6 +23,10 @@ Results No results +Workspaces + + No workspaces + Taskruns NAME TASK NAME STARTED DURATION STATUS diff --git a/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribeV1beta1_taskrun_with_no_status.golden b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribeV1beta1_taskrun_with_no_status.golden index 37a869e67..da32fe703 100644 --- a/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribeV1beta1_taskrun_with_no_status.golden +++ b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribeV1beta1_taskrun_with_no_status.golden @@ -23,6 +23,10 @@ Results No results +Workspaces + + No workspaces + Taskruns NAME TASK NAME STARTED DURATION STATUS diff --git a/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_cancelled_pipelinerun.golden b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_cancelled_pipelinerun.golden index c29bd96ad..1c4488a5f 100644 --- a/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_cancelled_pipelinerun.golden +++ b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_cancelled_pipelinerun.golden @@ -26,6 +26,10 @@ Results No results +Workspaces + + No workspaces + Taskruns NAME TASK NAME STARTED DURATION STATUS diff --git a/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_custom_timeout.golden b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_custom_timeout.golden index 6b92788fc..21456eb66 100644 --- a/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_custom_timeout.golden +++ b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_custom_timeout.golden @@ -20,6 +20,10 @@ Results No results +Workspaces + + No workspaces + Taskruns No taskruns diff --git a/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_failed.golden b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_failed.golden index d6bbd7d5c..60af74529 100644 --- a/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_failed.golden +++ b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_failed.golden @@ -27,6 +27,10 @@ Results No results +Workspaces + + No workspaces + Taskruns NAME TASK NAME STARTED DURATION STATUS diff --git a/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_failed_withoutPRCondition.golden b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_failed_withoutPRCondition.golden index 3ede0a0e4..08fabb1f2 100644 --- a/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_failed_withoutPRCondition.golden +++ b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_failed_withoutPRCondition.golden @@ -23,6 +23,10 @@ Results No results +Workspaces + + No workspaces + Taskruns NAME TASK NAME STARTED DURATION STATUS diff --git a/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_failed_withoutTRCondition.golden b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_failed_withoutTRCondition.golden index 9c836ef3a..0ee4f4ec5 100644 --- a/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_failed_withoutTRCondition.golden +++ b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_failed_withoutTRCondition.golden @@ -27,6 +27,10 @@ Results No results +Workspaces + + No workspaces + Taskruns NAME TASK NAME STARTED DURATION STATUS diff --git a/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_last.golden b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_last.golden index 019ef67d2..ad6a55e43 100644 --- a/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_last.golden +++ b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_last.golden @@ -22,6 +22,10 @@ Results No results +Workspaces + + No workspaces + Taskruns NAME TASK NAME STARTED DURATION STATUS diff --git a/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_lastV1beta1.golden b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_lastV1beta1.golden index 0e38a9302..a45bbc9cf 100644 --- a/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_lastV1beta1.golden +++ b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_lastV1beta1.golden @@ -23,6 +23,10 @@ Results No results +Workspaces + + No workspaces + Taskruns NAME TASK NAME STARTED DURATION STATUS diff --git a/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_multiple_taskrun_ordering.golden b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_multiple_taskrun_ordering.golden index edada9fe5..33f97f800 100644 --- a/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_multiple_taskrun_ordering.golden +++ b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_multiple_taskrun_ordering.golden @@ -22,6 +22,10 @@ Results No results +Workspaces + + No workspaces + Taskruns NAME TASK NAME STARTED DURATION STATUS diff --git a/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_no_resourceref.golden b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_no_resourceref.golden index 37fb6caf3..0125ded27 100644 --- a/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_no_resourceref.golden +++ b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_no_resourceref.golden @@ -25,6 +25,10 @@ Results No results +Workspaces + + No workspaces + Taskruns NAME TASK NAME STARTED DURATION STATUS diff --git a/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_only_taskrun.golden b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_only_taskrun.golden index 478572fa1..5fe484120 100644 --- a/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_only_taskrun.golden +++ b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_only_taskrun.golden @@ -22,6 +22,10 @@ Results No results +Workspaces + + No workspaces + Taskruns NAME TASK NAME STARTED DURATION STATUS diff --git a/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_v1beta1_with_results.golden b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_v1beta1_with_results.golden index debe54a67..5fa45eed4 100644 --- a/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_v1beta1_with_results.golden +++ b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_v1beta1_with_results.golden @@ -23,6 +23,10 @@ Results result-1 value-1 result-2 value-2 +Workspaces + + No workspaces + Taskruns NAME TASK NAME STARTED DURATION STATUS diff --git a/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_v1beta1_with_workspaces.golden b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_v1beta1_with_workspaces.golden new file mode 100644 index 000000000..38bcf7793 --- /dev/null +++ b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_v1beta1_with_workspaces.golden @@ -0,0 +1,36 @@ +Name: pipeline-run +Namespace: ns +Pipeline Ref: pipeline + +Status + +STARTED DURATION STATUS +10 minutes ago 20 minutes Succeeded + +Resources + + NAME RESOURCE REF + res-1 test-res + +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 5 minutes Failed diff --git a/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_with_resources_taskrun.golden b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_with_resources_taskrun.golden index bab0d05b5..4b89b95bc 100644 --- a/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_with_resources_taskrun.golden +++ b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_with_resources_taskrun.golden @@ -25,6 +25,10 @@ Results No results +Workspaces + + No workspaces + Taskruns NAME TASK NAME STARTED DURATION STATUS diff --git a/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_without_pipelineref.golden b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_without_pipelineref.golden index 6614cf062..1a2dada53 100644 --- a/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_without_pipelineref.golden +++ b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_without_pipelineref.golden @@ -20,6 +20,10 @@ Results No results +Workspaces + + No workspaces + Taskruns No taskruns diff --git a/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_without_start_time.golden b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_without_start_time.golden index ca4a0611b..2682c3668 100644 --- a/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_without_start_time.golden +++ b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_without_start_time.golden @@ -22,6 +22,10 @@ Results No results +Workspaces + + No workspaces + Taskruns No taskruns 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 4618687ba..583ed07ee 100644 --- a/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_without_tr_start_time.golden +++ b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_without_tr_start_time.golden @@ -22,6 +22,10 @@ Results No results +Workspaces + + No workspaces + Taskruns NAME TASK NAME STARTED DURATION STATUS diff --git a/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_zero_timeout.golden b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_zero_timeout.golden index 51505f3dc..ad51d3931 100644 --- a/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_zero_timeout.golden +++ b/pkg/cmd/pipelinerun/testdata/TestPipelineRunDescribe_zero_timeout.golden @@ -19,6 +19,10 @@ Results No results +Workspaces + + No workspaces + Taskruns No taskruns diff --git a/pkg/pipelinerun/description/description.go b/pkg/pipelinerun/description/description.go index 07ee233d6..74330d9fa 100644 --- a/pkg/pipelinerun/description/description.go +++ b/pkg/pipelinerun/description/description.go @@ -97,6 +97,21 @@ STARTED DURATION STATUS {{- end }} {{- end }} +{{decorate "workspaces" ""}}{{decorate "underline bold" "Workspaces\n"}} + +{{- if eq (len .PipelineRun.Spec.Workspaces) 0 }} + No workspaces +{{- else }} + NAME SUB PATH WORKSPACE BINDING +{{- range $workspace := .PipelineRun.Spec.Workspaces }} +{{- if not $workspace.SubPath }} + {{ decorate "bullet" $workspace.Name }} {{ "---" }} {{ formatWorkspace $workspace }} +{{- else }} + {{ decorate "bullet" $workspace.Name }} {{ $workspace.SubPath }} {{ formatWorkspace $workspace }} +{{- end }} +{{- end }} +{{- end }} + {{decorate "taskruns" ""}}{{decorate "underline bold" "Taskruns\n"}} {{- $l := len .TaskrunList }}{{ if eq $l 0 }} No taskruns @@ -173,6 +188,7 @@ func PrintPipelineRunDescription(s *cli.Stream, prName string, p cli.Params) err "formatDuration": formatted.Duration, "formatCondition": formatted.Condition, "formatResult": formatted.Result, + "formatWorkspace": formatted.Workspace, "hasFailed": hasFailed, "pipelineRefExists": pipelineRefExists, "pipelineResourceRefExists": pipelineResourceRefExists,