forked from openshift/osde2e
-
Notifications
You must be signed in to change notification settings - Fork 0
/
logs.go
63 lines (52 loc) · 1.44 KB
/
logs.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
package osd
import (
"fmt"
"math"
v1 "github.com/openshift-online/ocm-sdk-go/clustersmgmt/v1"
)
// Logs provides all logs available for clusterID, ids can be optionally provided for only specific logs.
func (u *OSD) Logs(clusterID string, length int, ids ...string) (logs map[string][]byte, err error) {
if len(ids) == 0 {
if ids, err = u.getLogList(clusterID); err != nil {
return logs, fmt.Errorf("couldn't get log list: %v", err)
}
}
logs = make(map[string][]byte, len(ids))
for _, logID := range ids {
resp, err := u.cluster(clusterID).
Logs().
Log(logID).
Get().Parameter("tail", length).
Send()
if resp != nil {
err = errResp(resp.Error())
}
if err != nil {
return logs, fmt.Errorf("the contents of log '%s' couldn't be retrieved: %v", logID, err)
}
logs[logID] = []byte(resp.Body().Content())
}
return
}
// FullLogs returns as much Logs as it can.
func (u *OSD) FullLogs(clusterID string, ids ...string) (map[string][]byte, error) {
return u.Logs(clusterID, math.MaxInt32-1, ids...)
}
func (u *OSD) getLogList(clusterID string) ([]string, error) {
resp, err := u.cluster(clusterID).
Logs().
List().
Send()
if resp != nil {
err = errResp(resp.Error())
}
if err != nil {
return nil, fmt.Errorf("couldn't retrieve log list for cluster '%s': %v", clusterID, err)
}
var logs []string
resp.Items().Each(func(l *v1.Log) bool {
logs = append(logs, l.ID())
return true
})
return logs, nil
}