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

Show Sidecar Names with tkn tr desc #747

Merged
merged 1 commit into from
Feb 24, 2020
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
24 changes: 22 additions & 2 deletions pkg/cmd/taskrun/describe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,20 @@ var (
reasonRunning = corev1.ContainerStateRunning{StartedAt: metav1.Time{Time: time.Now()}}
)

// Pass one or more names for sidecar containers for testing with tkn tr describe.
// Replace with test builder option once https://github.com/tektoncd/pipeline/issues/2078
// is closed.
func sidecarState(names ...string) tb.TaskRunStatusOp {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's merged now, should we wait for a pipeline release to remove this?

return func(s *v1alpha1.TaskRunStatus) {
for _, name := range names {
sidecar := &v1alpha1.SidecarState{
Name: name,
}
s.Sidecars = append(s.Sidecars, *sidecar)
}
}
}

func TestTaskRunDescribe_invalid_namespace(t *testing.T) {
cs, _ := test.SeedTestData(t, pipelinetest.Data{
Namespaces: []*corev1.Namespace{
Expand Down Expand Up @@ -362,9 +376,11 @@ func TestTaskRunDescribe_step_status_default(t *testing.T) {
golden.Assert(t, actual, fmt.Sprintf("%s.golden", t.Name()))
}

func TestTaskRunDescribe_step_status_pending(t *testing.T) {
func TestTaskRunDescribe_step_status_pending_one_sidecar(t *testing.T) {
clock := clockwork.NewFakeClock()

sidecarState := sidecarState("sidecar1")

trs := []*v1alpha1.TaskRun{
tb.TaskRun("tr-1", "ns",
tb.TaskRunStatus(
Expand All @@ -382,6 +398,7 @@ func TestTaskRunDescribe_step_status_pending(t *testing.T) {
cb.StepName("step2"),
tb.SetStepStateWaiting(reasonWaiting),
),
sidecarState,
),
tb.TaskRunSpec(
tb.TaskRunTaskRef("t1"),
Expand Down Expand Up @@ -417,9 +434,11 @@ func TestTaskRunDescribe_step_status_pending(t *testing.T) {
golden.Assert(t, actual, fmt.Sprintf("%s.golden", t.Name()))
}

func TestTaskRunDescribe_step_status_running(t *testing.T) {
func TestTaskRunDescribe_step_status_running_multiple_sidecars(t *testing.T) {
clock := clockwork.NewFakeClock()

sidecarState := sidecarState("sidecar1", "sidecar2")

trs := []*v1alpha1.TaskRun{
tb.TaskRun("tr-1", "ns",
tb.TaskRunStatus(
Expand All @@ -437,6 +456,7 @@ func TestTaskRunDescribe_step_status_running(t *testing.T) {
cb.StepName("step2"),
tb.SetStepStateRunning(reasonRunning),
),
sidecarState,
),
tb.TaskRunSpec(
tb.TaskRunTaskRef("t1"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,7 @@ No params
Steps

No steps

Sidecars

No sidecars
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,7 @@ No params
Steps

No steps

Sidecars

No sidecars
4 changes: 4 additions & 0 deletions pkg/cmd/taskrun/testdata/TestTaskRunDescribe_failed.golden
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,7 @@ No params
Steps

No steps

Sidecars

No sidecars
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,7 @@ Steps
NAME STATUS
step1 Completed
step2 Completed

Sidecars

No sidecars
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,7 @@ No params
Steps

No steps

Sidecars

No sidecars
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,7 @@ Steps
NAME STATUS
step1 Completed
step2 Completed

Sidecars

No sidecars
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,7 @@ Steps
NAME STATUS
step1 Error
step2 ---

Sidecars

No sidecars
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,8 @@ Steps
NAME STATUS
step1 PodInitializing
step2 PodInitializing

Sidecars

NAME
sidecar1
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,9 @@ Steps
NAME STATUS
step1 Running
step2 Running

Sidecars

NAME
sidecar1
sidecar2
2 changes: 2 additions & 0 deletions pkg/formatted/color.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ func DecorateAttr(attrString, message string) string {
return fmt.Sprintf("💌 ")
case "taskruns":
return fmt.Sprintf("🗂 ")
case "sidecars":
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's gotta be a car, right? 🤷‍♂

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hahah it has to ! 🚗 🚗 🚗

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or mothercycle :D but the tiny red car is cutter imho!!

return fmt.Sprintf("🚗 ")
}

attr := color.Reset
Expand Down
4 changes: 2 additions & 2 deletions pkg/formatted/color_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,13 @@ func TestDecoration(t *testing.T) {
funcMap := template.FuncMap{
"decorate": DecorateAttr,
}
aTemplate := `{{decorate "bullet" "Foo"}} {{decorate "resources" ""}}{{decorate "params" ""}}{{decorate "tasks" ""}}{{decorate "pipelineruns" ""}}{{decorate "status" ""}}{{decorate "inputresources" ""}}{{decorate "outputresources" ""}}{{decorate "steps" ""}}{{decorate "message" ""}}{{decorate "taskruns" ""}}{{decorate "red" "Red"}} {{decorate "underline" "Foo"}}`
aTemplate := `{{decorate "bullet" "Foo"}} {{decorate "resources" ""}}{{decorate "params" ""}}{{decorate "tasks" ""}}{{decorate "pipelineruns" ""}}{{decorate "status" ""}}{{decorate "inputresources" ""}}{{decorate "outputresources" ""}}{{decorate "steps" ""}}{{decorate "message" ""}}{{decorate "taskruns" ""}}{{decorate "sidecars" ""}}{{decorate "red" "Red"}} {{decorate "underline" "Foo"}}`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one day we should clean this up and make the emojis template generation and testing a bit smarter !

processed := template.Must(template.New("Describe Pipeline").Funcs(funcMap).Parse(aTemplate))
buf := new(bytes.Buffer)

if err := processed.Execute(buf, nil); err != nil {
t.Error("Could not process the template.")
}
test.AssertOutput(t, "∙ Foo 📦 ⚓ 🗒 ⛩ 🌡️ 📨 📡 🦶 💌 🗂 \x1b[91mRed\x1b[0m \x1b[4mFoo\x1b[0m", buf.String())
test.AssertOutput(t, "∙ Foo 📦 ⚓ 🗒 ⛩ 🌡️ 📨 📡 🦶 💌 🗂 🚗 \x1b[91mRed\x1b[0m \x1b[4mFoo\x1b[0m", buf.String())

}
11 changes: 11 additions & 0 deletions pkg/helper/taskrun/description/taskrun_description.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,17 @@ No steps
{{decorate "bullet" $step.Name }} {{ $reason }}
{{- end }}
{{- end }}

{{decorate "sidecars" ""}}{{decorate "underline bold" "Sidecars"}}
{{$sidecars := .TaskRun.Status.Sidecars }}
{{- $l := len $sidecars }}{{ if eq $l 0 }}
No sidecars
{{- else }}
NAME
{{- range $sidecar := $sidecars }}
{{decorate "bullet" $sidecar.Name }}
{{- end }}
{{- end }}
`

func sortStepStatesByStartTime(steps []v1alpha1.StepState) []v1alpha1.StepState {
Expand Down