Skip to content

Commit

Permalink
Fix to provide error in case of no pr logs
Browse files Browse the repository at this point in the history
Signed-off-by: vinamra28 <vinjain@redhat.com>
  • Loading branch information
vinamra28 authored and tekton-robot committed May 26, 2020
1 parent d95320f commit 028088b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
12 changes: 6 additions & 6 deletions pkg/cmd/pipelinerun/logs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -876,10 +876,10 @@ func TestLogs_nologs(t *testing.T) {
}
prlo := logOpts(prName, ns, cs, dc, fake.Streamer([]fake.Log{}), false, false)
output, err := fetchLogs(prlo)
if err != nil {
t.Errorf("Unexpected error: %v", err)
if err == nil {
t.Errorf("Unexpected output: %v", output)
}
test.AssertOutput(t, "No logs found\n", output)
test.AssertOutput(t, "pipelinerun has not started yet", err.Error())
}

func TestLog_run_failed_with_and_without_follow(t *testing.T) {
Expand Down Expand Up @@ -1727,10 +1727,10 @@ func TestLogs_nologs_v1beta1(t *testing.T) {
}
prlo := logOpts(prName, ns, cs, dc, fake.Streamer([]fake.Log{}), false, false)
output, err := fetchLogs(prlo)
if err != nil {
t.Errorf("Unexpected error: %v", err)
if err == nil {
t.Errorf("Unexpected output: %v", output)
}
test.AssertOutput(t, "No logs found\n", output)
test.AssertOutput(t, "pipelinerun has not started yet", err.Error())
}

func TestLog_run_failed_with_and_without_follow_v1beta1(t *testing.T) {
Expand Down
14 changes: 12 additions & 2 deletions pkg/log/pipeline_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/fields"
"k8s.io/apimachinery/pkg/runtime"
duckv1beta1 "knative.dev/pkg/apis/duck/v1beta1"
)

func (r *Reader) readPipelineLog() (<-chan Log, <-chan error, error) {
Expand Down Expand Up @@ -157,8 +158,10 @@ func (r *Reader) waitUntilAvailable(timeout time.Duration) error {
}
case <-time.After(timeout * time.Second):
watchRun.Stop()
fmt.Fprintln(r.stream.Err, "No logs found")
return nil
if err = hasPipelineRunFailed(run.Status.Conditions); err != nil {
return fmt.Errorf("pipelinerun %s has failed", run.Name)
}
return fmt.Errorf("pipelinerun has not started yet")
}
}
}
Expand Down Expand Up @@ -224,6 +227,13 @@ func empty(status v1beta1.PipelineRunStatus) bool {
return len(status.Conditions) == 0
}

func hasPipelineRunFailed(prConditions duckv1beta1.Conditions) error {
if len(prConditions) != 0 && prConditions[0].Status == corev1.ConditionFalse {
return fmt.Errorf("pipelinerun has failed: %s", prConditions[0].Message)
}
return nil
}

func cast2pipelinerun(obj runtime.Object) (*v1beta1.PipelineRun, error) {
var run *v1beta1.PipelineRun
unstruct, err := runtime.DefaultUnstructuredConverter.ToUnstructured(obj)
Expand Down

0 comments on commit 028088b

Please sign in to comment.