From e58f45f51cb31487acbf3411cd304f80351784b9 Mon Sep 17 00:00:00 2001 From: Sunghoon Kang Date: Thu, 12 Nov 2020 12:40:34 +0900 Subject: [PATCH] Ignore --follow flag when TaskRun or PipelineRun is done Currently, when --follow flag is given, reader tries to read live logs instead of available logs. This may confuses user to debug since live logs are not sorted in task order. --- pkg/cmd/taskrun/logs_test.go | 24 ++++++++++++++---------- pkg/log/pipeline_reader.go | 2 +- pkg/log/task_reader.go | 2 +- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/pkg/cmd/taskrun/logs_test.go b/pkg/cmd/taskrun/logs_test.go index 633248ccaf..9ea3e22142 100644 --- a/pkg/cmd/taskrun/logs_test.go +++ b/pkg/cmd/taskrun/logs_test.go @@ -1584,7 +1584,7 @@ func TestLog_taskrun_follow_mode_no_pod_name(t *testing.T) { t.Error("Expecting an error but it's empty") } - expected := "task output-task create has not started yet or pod for task not yet available" + expected := "pod for taskrun output-task-run not available yet" test.AssertOutput(t, expected, err.Error()) } @@ -1697,7 +1697,7 @@ func TestLog_taskrun_follow_mode_no_pod_name_v1beta1(t *testing.T) { t.Error("Expecting an error but it's empty") } - expected := "task output-task create has not started yet or pod for task not yet available" + expected := "pod for taskrun output-task-run not available yet" test.AssertOutput(t, expected, err.Error()) } @@ -1720,8 +1720,9 @@ func TestLog_taskrun_follow_mode_update_pod_name(t *testing.T) { tb.TaskRunStatus( tb.TaskRunStartTime(trStartTime), tb.StatusCondition(apis.Condition{ - Type: apis.ConditionSucceeded, - Status: corev1.ConditionTrue, + Type: apis.ConditionSucceeded, + Status: corev1.ConditionUnknown, + Message: "Running", }), tb.StepState( cb.StepName(trStep1Name), @@ -1832,8 +1833,9 @@ func TestLog_taskrun_follow_mode_update_pod_name_v1beta1(t *testing.T) { Status: duckv1beta1.Status{ Conditions: duckv1beta1.Conditions{ { - Type: apis.ConditionSucceeded, - Status: corev1.ConditionTrue, + Type: apis.ConditionSucceeded, + Status: corev1.ConditionUnknown, + Message: v1beta1.TaskRunReasonRunning.String(), }, }, }, @@ -1946,8 +1948,9 @@ func TestLog_taskrun_follow_mode_update_timeout(t *testing.T) { tb.TaskRunStatus( tb.TaskRunStartTime(trStartTime), tb.StatusCondition(apis.Condition{ - Type: apis.ConditionSucceeded, - Status: corev1.ConditionTrue, + Type: apis.ConditionSucceeded, + Status: corev1.ConditionUnknown, + Message: "Running", }), tb.StepState( cb.StepName(trStep1Name), @@ -2056,8 +2059,9 @@ func TestLog_taskrun_follow_mode_update_timeout_v1beta1(t *testing.T) { Status: duckv1beta1.Status{ Conditions: duckv1beta1.Conditions{ { - Type: apis.ConditionSucceeded, - Status: corev1.ConditionTrue, + Type: apis.ConditionSucceeded, + Status: corev1.ConditionUnknown, + Message: v1beta1.TaskRunReasonRunning.String(), }, }, }, diff --git a/pkg/log/pipeline_reader.go b/pkg/log/pipeline_reader.go index b81d2cfbb8..da1f515888 100644 --- a/pkg/log/pipeline_reader.go +++ b/pkg/log/pipeline_reader.go @@ -36,7 +36,7 @@ func (r *Reader) readPipelineLog() (<-chan Log, <-chan error, error) { return nil, nil, err } - if r.follow { + if !pr.IsDone() && r.follow { return r.readLivePipelineLogs(pr) } return r.readAvailablePipelineLogs(pr) diff --git a/pkg/log/task_reader.go b/pkg/log/task_reader.go index b1b14916a8..1f8491408e 100644 --- a/pkg/log/task_reader.go +++ b/pkg/log/task_reader.go @@ -52,7 +52,7 @@ func (r *Reader) readTaskLog() (<-chan Log, <-chan error, error) { r.formTaskName(tr) - if r.follow { + if !tr.IsDone() && r.follow { return r.readLiveTaskLogs() } return r.readAvailableTaskLogs(tr)