-
Notifications
You must be signed in to change notification settings - Fork 0
/
logs_strategy.go
41 lines (33 loc) · 878 Bytes
/
logs_strategy.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
package executor
import (
"bytes"
"io"
"github.com/dhenkel92/pod-helper/pkg/config"
"github.com/dhenkel92/pod-helper/pkg/types"
v1 "k8s.io/api/core/v1"
)
func LogsStrategy(c chan bool, podExec *PodExecutor, conf *config.Config, result *types.Result) {
options := v1.PodLogOptions{
Container: result.Container.Name,
}
if conf.LogsConfig.Tail >= 0 {
options.TailLines = &conf.LogsConfig.Tail
}
req := podExec.Clientset.CoreV1().Pods(result.Pod.Namespace).GetLogs(result.Pod.Name, &options)
podLogs, err := req.Stream()
if err != nil {
result.ExecResult = types.ExecResult{Error: err}
c <- true
return
}
defer podLogs.Close()
buf := new(bytes.Buffer)
_, err = io.Copy(buf, podLogs)
if err != nil {
result.ExecResult = types.ExecResult{Error: err}
c <- true
return
}
result.ExecResult = types.ExecResult{StdOut: buf.String()}
c <- true
}