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

Fix logs command not showing logs #2251

Merged
merged 1 commit into from
Feb 27, 2024
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
4 changes: 2 additions & 2 deletions pkg/cmd/taskrun/logs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2844,7 +2844,7 @@ func TestLog_taskrun_follow_mode_update_timeout_v1beta1(t *testing.T) {
t.Errorf("Unexpected error: %v", err)
}

expectedOut := "task output-task create has not started yet or pod for task not yet available\n"
expectedOut := "task output-task has not started yet or pod for task not yet available\n"
test.AssertOutput(t, expectedOut, output)
}

Expand Down Expand Up @@ -2992,7 +2992,7 @@ func TestLog_taskrun_follow_mode_update_timeout(t *testing.T) {
t.Errorf("Unexpected error: %v", err)
}

expectedOut := "task output-task create has not started yet or pod for task not yet available\n"
expectedOut := "task output-task has not started yet or pod for task not yet available\n"
test.AssertOutput(t, expectedOut, output)
}

Expand Down
29 changes: 14 additions & 15 deletions pkg/log/task_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (r *Reader) readTaskLog() (<-chan Log, <-chan error, error) {

r.formTaskName(tr)

if !isDone(tr, r.retries) && r.follow {
if !tr.IsDone() && r.follow {
return r.readLiveTaskLogs(tr)
}
return r.readAvailableTaskLogs(tr)
Expand Down Expand Up @@ -91,7 +91,7 @@ func (r *Reader) readAvailableTaskLogs(tr *v1.TaskRun) (<-chan Log, <-chan error
}

// Check if taskrun failed on start up
if err := hasTaskRunFailed(tr, r.task, r.retries); err != nil {
if err := hasTaskRunFailed(tr, r.task); err != nil {
if r.stream != nil {
fmt.Fprintf(r.stream.Err, "%s\n", err.Error())
} else {
Expand Down Expand Up @@ -262,24 +262,24 @@ func (r *Reader) getTaskRunPodNames(run *v1.TaskRun) (<-chan string, <-chan erro
}
if run.Status.PodName != "" {
addPod(run.Status.PodName)
if areRetriesScheduled(run, r.retries) {
if !areRetriesScheduled(run, r.retries) {
return
}
}
case <-timeout:
// Check if taskrun failed on start up
if err := hasTaskRunFailed(run, r.task, r.retries); err != nil {
if err := hasTaskRunFailed(run, r.task); err != nil {
errC <- err
return
}
// check if pod has been started and has a name
if run.HasStarted() && run.Status.PodName != "" {
if !areRetriesScheduled(run, r.retries) {
if areRetriesScheduled(run, r.retries) {
continue
}
return
}
errC <- fmt.Errorf("task %s create has not started yet or pod for task not yet available", r.task)
errC <- fmt.Errorf("task %s has not started yet or pod for task not yet available", r.task)
return
}
}
Expand Down Expand Up @@ -351,8 +351,8 @@ func getSteps(pod *corev1.Pod) []*step {
return steps
}

func hasTaskRunFailed(tr *v1.TaskRun, taskName string, retries int) error {
if isFailure(tr, retries) {
func hasTaskRunFailed(tr *v1.TaskRun, taskName string) error {
if isFailure(tr) {
return fmt.Errorf("task %s has failed: %s", taskName, tr.Status.Conditions[0].Message)
}
return nil
Expand All @@ -370,16 +370,15 @@ func cast2taskrun(obj runtime.Object) (*v1.TaskRun, error) {
return run, nil
}

func isDone(tr *v1.TaskRun, retries int) bool {
return tr.IsDone() || !areRetriesScheduled(tr, retries)
}

func isFailure(tr *v1.TaskRun, retries int) bool {
func isFailure(tr *v1.TaskRun) bool {
conditions := tr.Status.Conditions
return len(conditions) != 0 && conditions[0].Status == corev1.ConditionFalse && areRetriesScheduled(tr, retries)
return len(conditions) != 0 && conditions[0].Status == corev1.ConditionFalse
}

func areRetriesScheduled(tr *v1.TaskRun, retries int) bool {
if tr.IsDone() {
return false
}
retriesDone := len(tr.Status.RetriesStatus)
return retriesDone >= retries
return retriesDone < retries
}
6 changes: 6 additions & 0 deletions test/e2e/pipeline/start_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ func TestPipelineInteractiveStartE2E(t *testing.T) {
})
})

t.Run("Validate pipeline logs, with follow mode (-f) and --last ", func(t *testing.T) {
res := tkn.Run(t, "pipeline", "logs", "--last", "-f")
expected := "\n\ntest-e2e\n\n"
helper.AssertOutput(t, expected, res.Stdout())
})

t.Run("Start PipelineRun using pipeline start interactively using --use-param-defaults and some of the params not having default ", func(t *testing.T) {
tkn.RunInteractiveTests(t, &cli.Prompt{
CmdArgs: []string{
Expand Down
2 changes: 1 addition & 1 deletion test/resources/pipeline.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ spec:
steps:
- name: create-new-file
image: ubuntu
script: touch $(workspaces.shared-data.path)/$(params.filename)
script: sleep 30s;touch $(workspaces.shared-data.path)/$(params.filename)
- name: write-new-stuff
image: ubuntu
script: echo $(params.message) > $(workspaces.shared-data.path)/$(params.filename)
Expand Down
Loading