-
Notifications
You must be signed in to change notification settings - Fork 4
/
logs.go
44 lines (35 loc) · 929 Bytes
/
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
package aws
import (
"bufio"
"math"
"strconv"
"time"
log "github.com/Sirupsen/logrus"
pb "github.com/dinesh/datacol/api/models"
sched "github.com/dinesh/datacol/cloud/kube"
)
func (a *AwsCloud) LogStream(app string, opts pb.LogStreamOptions) (*bufio.Reader, func() error, error) {
ns := a.DeploymentName
c := a.kubeClient()
pod, err := sched.RunningPods(ns, app, c)
if err != nil {
return nil, nil, err
}
log.Debugf("Getting logs from pod %s", pod)
req := c.Core().RESTClient().Get().
Namespace(ns).
Name(pod).
Resource("pods").
SubResource("log").
Param("container", app).
Param("follow", strconv.FormatBool(opts.Follow))
if opts.Since > 0 {
sec := int64(math.Ceil(float64(opts.Since) / float64(time.Second)))
req = req.Param("sinceSeconds", strconv.FormatInt(sec, 10))
}
rc, err := req.Stream()
if err != nil {
return nil, nil, err
}
return bufio.NewReader(rc), rc.Close, nil
}