-
Notifications
You must be signed in to change notification settings - Fork 1
/
taskrunLogs.go
79 lines (63 loc) · 1.5 KB
/
taskrunLogs.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package taskrun
import (
"context"
"fmt"
"io"
"strconv"
"github.com/clintjedwards/gofer/internal/cli/cl"
proto "github.com/clintjedwards/gofer/proto/go"
"github.com/spf13/cobra"
)
var cmdTaskRunLogs = &cobra.Command{
Use: "logs <pipeline> <run> <id>",
Short: "Examine logs for a particular taskrun/container",
Example: `$ gofer taskrun logs simple_test_pipeline 23 example_task`,
RunE: taskrunLogs,
Args: cobra.ExactArgs(3),
}
func init() {
CmdTaskRun.AddCommand(cmdTaskRunLogs)
}
func taskrunLogs(_ *cobra.Command, args []string) error {
// We don't use the formatter here because we may want to redirect logs we get into
// a file or such.
cl.State.Fmt.Finish()
pipeline := args[0]
runIDRaw := args[1]
runID, err := strconv.Atoi(runIDRaw)
if err != nil {
return err
}
id := args[2]
conn, err := cl.State.Connect()
if err != nil {
fmt.Println(err)
return err
}
defer conn.Close()
client := proto.NewGoferClient(conn)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
stream, err := client.GetTaskRunLogs(ctx, &proto.GetTaskRunLogsRequest{
NamespaceId: cl.State.Config.Namespace,
RunId: int64(runID),
PipelineId: pipeline,
Id: id,
})
if err != nil {
fmt.Printf("could not get logs for task run: %v\n", err)
return err
}
for {
resp, err := stream.Recv()
if err != nil {
if err == io.EOF {
break
}
fmt.Printf("could not get logs: %v\n", err)
return nil
}
fmt.Println(resp.LogLine)
}
return nil
}