Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display Workspaces in the output of pipeline/pipelinerun describe command #1142

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions pkg/cmd/pipeline/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,16 @@ const describeTemplate = `{{decorate "bold" "Name"}}: {{ .PipelineName }}
{{- end }}
{{- end }}

{{decorate "workspaces" ""}}{{decorate "underline bold" "Workspaces\n"}}
{{- if eq (len .Pipeline.Spec.Workspaces) 0 }}
No workspaces
{{- else }}
NAME DESCRIPTION
{{- range $workspace := .Pipeline.Spec.Workspaces }}
{{ decorate "bullet" $workspace.Name }} {{ formatDesc $workspace.Description }}
{{- end }}
{{- end }}

{{decorate "tasks" ""}}{{decorate "underline bold" "Tasks\n"}}
{{- $tl := len .Pipeline.Spec.Tasks }}{{ if eq $tl 0 }}
No tasks
Expand Down
79 changes: 79 additions & 0 deletions pkg/cmd/pipeline/describe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -881,3 +881,82 @@ func TestPipelineDescribeV1beta1_with_results(t *testing.T) {
}
golden.Assert(t, got, fmt.Sprintf("%s.golden", t.Name()))
}

func TestPipelineDescribeV1beta1_with_workspaces(t *testing.T) {
clock := clockwork.NewFakeClock()
pipelines := []*v1beta1.Pipeline{
{
ObjectMeta: metav1.ObjectMeta{
Name: "pipeline",
Namespace: "ns",
},
Spec: v1beta1.PipelineSpec{
Resources: []v1beta1.PipelineDeclaredResource{
{
Name: "name",
Type: v1alpha1.PipelineResourceTypeGit,
},
},
Tasks: []v1beta1.PipelineTask{
{
Name: "task-1",
TaskRef: &v1beta1.TaskRef{
Name: "task-1",
},
},
{
Name: "task-2",
TaskRef: &v1beta1.TaskRef{
Name: "task-2",
},
},
},
Results: []v1beta1.PipelineResult{
{
Name: "result-1",
Description: "This is a description for result 1",
},
{
Name: "result-2",
Description: "This is a description for result 2",
},
{
Name: "result-3",
},
},
Workspaces: []v1beta1.PipelineWorkspaceDeclaration{
{
Name: "test",
Description: "test workspace",
},
},
},
},
}
namespaces := []*corev1.Namespace{
{
ObjectMeta: metav1.ObjectMeta{
Name: "ns",
},
},
}

version := "v1beta1"
tdc := testDynamic.Options{}
dynamic, err := tdc.Client(
cb.UnstructuredV1beta1P(pipelines[0], version),
)
if err != nil {
t.Errorf("unable to create dynamic client: %v", err)
}
cs, _ := test.SeedV1beta1TestData(t, pipelinev1beta1test.Data{Namespaces: namespaces, Pipelines: pipelines})
cs.Pipeline.Resources = cb.APIResourceList(version, []string{"pipeline", "pipelinerun"})
p := &test.Params{Tekton: cs.Pipeline, Clock: clock, Kube: cs.Kube, Dynamic: dynamic}
pipeline := Command(p)

got, err := test.ExecuteCommand(pipeline, "desc", "-n", "ns", "pipeline")
if err != nil {
t.Errorf("Unexpected error: %v", err)
}
golden.Assert(t, got, fmt.Sprintf("%s.golden", t.Name()))
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ Results

No results

Workspaces

No workspaces

Tasks

NAME TASKREF RUNAFTER TIMEOUT CONDITIONS PARAMS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ Results
result-2 This is a descripti...
result-3

Workspaces

No workspaces

Tasks

NAME TASKREF RUNAFTER TIMEOUT CONDITIONS PARAMS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ Results

No results

Workspaces

No workspaces

Tasks

NAME TASKREF RUNAFTER TIMEOUT CONDITIONS PARAMS
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
Name: pipeline
Namespace: ns

Resources

NAME TYPE
name git

Params

No params

Results

NAME DESCRIPTION
result-1 This is a descripti...
result-2 This is a descripti...
result-3

Workspaces

NAME DESCRIPTION
test test workspace

Tasks

NAME TASKREF RUNAFTER TIMEOUT CONDITIONS PARAMS
task-1 task-1 --- --- ---
task-2 task-2 --- --- ---

PipelineRuns

No pipelineruns
4 changes: 4 additions & 0 deletions pkg/cmd/pipeline/testdata/TestPipelineDescribe_empty.golden
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ Results

No results

Workspaces

No workspaces

Tasks

No tasks
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ Results

No results

Workspaces

No workspaces

Tasks

NAME TASKREF RUNAFTER TIMEOUT CONDITIONS PARAMS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ Results

No results

Workspaces

No workspaces

Tasks

No tasks
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ Results

No results

Workspaces

No workspaces

Tasks

NAME TASKREF RUNAFTER TIMEOUT CONDITIONS PARAMS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ Results

No results

Workspaces

No workspaces

Tasks

NAME TASKREF RUNAFTER TIMEOUT CONDITIONS PARAMS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ Results

No results

Workspaces

No workspaces

Tasks

NAME TASKREF RUNAFTER TIMEOUT CONDITIONS PARAMS
Expand Down
143 changes: 143 additions & 0 deletions pkg/cmd/pipelinerun/describe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ Results

No results

Workspaces

No workspaces

Taskruns

NAME TASK NAME STARTED DURATION STATUS
Expand Down
Loading