Skip to content

Commit 3bd40a3

Browse files
committed
Add long flag --display-name to display the log of pipelinerun
1 parent de8e888 commit 3bd40a3

File tree

10 files changed

+19
-39
lines changed

10 files changed

+19
-39
lines changed

docs/cmd/tkn_pipelinerun_logs.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ Show the logs of PipelineRun named 'microservice-1' for all Tasks and steps (inc
3131

3232
```
3333
-a, --all show all logs including init steps injected by tekton
34-
--display-name show logs with task display name (display name and step name)
3534
-E, --exit-with-pipelinerun-error exit with pipelinerun to the unix shell, 0 if success, 1 if error, 2 on unknown status
3635
-f, --follow stream live logs
3736
-F, --fzf use fzf to select a PipelineRun

docs/man/man1/tkn-pipelinerun-logs.1

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@ Show the logs of a PipelineRun
2323
\fB\-a\fP, \fB\-\-all\fP[=false]
2424
show all logs including init steps injected by tekton
2525

26-
.PP
27-
\fB\-\-display\-name\fP[=false]
28-
show logs with task display name (display name and step name)
29-
3026
.PP
3127
\fB\-E\fP, \fB\-\-exit\-with\-pipelinerun\-error\fP[=false]
3228
exit with pipelinerun to the unix shell, 0 if success, 1 if error, 2 on unknown status

pkg/cmd/pipelinerun/logs.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ Show the logs of PipelineRun named 'microservice-1' for all Tasks and steps (inc
8484
c.Flags().BoolVarP(&opts.Follow, "follow", "f", false, "stream live logs")
8585
c.Flags().BoolVarP(&opts.Timestamps, "timestamps", "", false, "show logs with timestamp")
8686
c.Flags().BoolVarP(&opts.Prefixing, "prefix", "", true, "prefix each log line with the log source (task name and step name)")
87-
c.Flags().BoolVarP(&opts.DisplayName, "display-name", "", false, "show logs with task display name (display name and step name)")
8887
c.Flags().BoolVarP(&opts.ExitWithPrError, "exit-with-pipelinerun-error", "E", false, "exit with pipelinerun to the unix shell, 0 if success, 1 if error, 2 on unknown status")
8988
c.Flags().StringSliceVarP(&opts.Tasks, "task", "t", []string{}, "show logs for mentioned Tasks only")
9089
c.Flags().IntVarP(&opts.Limit, "limit", "", defaultLimit, "lists number of PipelineRuns")
@@ -111,7 +110,7 @@ func Run(opts *options.LogOptions) error {
111110
return err
112111
}
113112

114-
log.NewWriter(log.LogTypePipeline, opts.Prefixing).WithDisplayName(opts.DisplayName).Write(opts.Stream, logC, errC)
113+
log.NewWriter(log.LogTypePipeline, opts.Prefixing).Write(opts.Stream, logC, errC)
115114

116115
// get pipelinerun status
117116
if opts.ExitWithPrError {

pkg/log/log.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,8 @@ var pipelineGroupResource = schema.GroupVersionResource{Group: "tekton.dev", Res
2727

2828
// Log represents data to write on log channel
2929
type Log struct {
30-
Pipeline string
31-
Task string
32-
TaskDisplayName string
33-
Step string
34-
Log string
30+
Pipeline string
31+
Task string
32+
Step string
33+
Log string
3534
}

pkg/log/pipeline_reader.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ func (r *Reader) pipeLogs(logC chan<- Log, errC chan<- error) {
192192
tlogC = nil
193193
continue
194194
}
195-
logC <- Log{Task: l.Task, TaskDisplayName: l.TaskDisplayName, Step: l.Step, Log: l.Log}
195+
logC <- Log{Task: l.Task, Step: l.Step, Log: l.Log}
196196

197197
case e, ok := <-terrC:
198198
if !ok {
@@ -208,7 +208,6 @@ func (r *Reader) setUpTask(taskNumber int, tr taskrunpkg.Run) {
208208
r.setNumber(taskNumber)
209209
r.setRun(tr.Name)
210210
r.setTask(tr.Task)
211-
r.setDisplayName(tr.DisplayName)
212211
r.setRetries(tr.Retries)
213212
}
214213

pkg/log/reader.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ type Reader struct {
3737
steps []string
3838
logType string
3939
task string
40-
displayName string
4140
number int
4241
activityTimeout time.Duration
4342
retries int
@@ -109,10 +108,6 @@ func (r *Reader) setTask(task string) {
109108
r.task = task
110109
}
111110

112-
func (r *Reader) setDisplayName(displayName string) {
113-
r.displayName = displayName
114-
}
115-
116111
func (r *Reader) clone() *Reader {
117112
c := *r
118113
return &c

pkg/log/task_reader.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,10 @@ func (r *Reader) readStepsLogs(logC chan<- Log, errC chan<- error, steps []*step
138138
case l, ok := <-containerLogC:
139139
if !ok {
140140
containerLogC = nil
141-
logC <- Log{Task: r.task, TaskDisplayName: r.displayName, Step: step.name, Log: "EOFLOG"}
141+
logC <- Log{Task: r.task, Step: step.name, Log: "EOFLOG"}
142142
continue
143143
}
144-
logC <- Log{Task: r.task, TaskDisplayName: r.displayName, Step: step.name, Log: l.Log}
144+
logC <- Log{Task: r.task, Step: step.name, Log: l.Log}
145145

146146
case e, ok := <-containerLogErrC:
147147
if !ok {

pkg/log/writer.go

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,9 @@ import (
2323

2424
// Writer helps logging pod"s log
2525
type Writer struct {
26-
fmt *formatted.Color
27-
logType string
28-
prefixing bool
29-
displayName bool
26+
fmt *formatted.Color
27+
logType string
28+
prefixing bool
3029
}
3130

3231
// NewWriter returns the new instance of LogWriter
@@ -38,12 +37,6 @@ func NewWriter(logType string, prefixing bool) *Writer {
3837
}
3938
}
4039

41-
// WithDisplayName sets the display name
42-
func (lw *Writer) WithDisplayName(displayName bool) *Writer {
43-
lw.displayName = displayName
44-
return lw
45-
}
46-
4740
// Write formatted pod's logs
4841
func (lw *Writer) Write(s *cli.Stream, logC <-chan Log, errC <-chan error) {
4942
for logC != nil || errC != nil {
@@ -59,10 +52,6 @@ func (lw *Writer) Write(s *cli.Stream, logC <-chan Log, errC <-chan error) {
5952
continue
6053
}
6154

62-
if lw.displayName && l.TaskDisplayName != "" {
63-
l.Task = l.TaskDisplayName
64-
}
65-
6655
if lw.prefixing {
6756
switch lw.logType {
6857
case LogTypePipeline:

pkg/options/logs.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ type LogOptions struct {
5151
Tail int64
5252
Timestamps bool
5353
Prefixing bool
54-
DisplayName bool
5554
ExitWithPrError bool
5655
// ActivityTimeout is the amount of time to wait for some activity
5756
// (e.g. Pod ready) before giving up.

pkg/taskrun/taskrun.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323

2424
type Run struct {
2525
Name string
26-
DisplayName string
2726
Task string
2827
Retries int
2928
StartTime *metav1.Time
@@ -91,9 +90,8 @@ func SortTasksBySpecOrder(pipelineTasks []v1.PipelineTask, pipelinesTaskRuns map
9190
if n, ok := trNames[ts.Name]; ok {
9291
trStatusFields := pipelinesTaskRuns[n].Status.TaskRunStatusFields
9392
trs = append(trs, Run{
94-
Task: ts.Name,
93+
Task: taskName(ts),
9594
Name: n,
96-
DisplayName: ts.DisplayName,
9795
Retries: ts.Retries,
9896
StartTime: trStatusFields.StartTime,
9997
CompletionTime: trStatusFields.CompletionTime,
@@ -103,3 +101,10 @@ func SortTasksBySpecOrder(pipelineTasks []v1.PipelineTask, pipelinesTaskRuns map
103101
sort.Sort(trs)
104102
return trs
105103
}
104+
105+
func taskName(task v1.PipelineTask) string {
106+
if task.DisplayName != "" {
107+
return task.DisplayName
108+
}
109+
return task.Name
110+
}

0 commit comments

Comments
 (0)