refact logs

mine
derailed 2019-06-20 19:40:57 -06:00
parent d3478d9c63
commit 2c2de7b269
3 changed files with 12 additions and 12 deletions

View File

@ -19,7 +19,7 @@ type (
// Loggable represents a K8s resource that has containers and can be logged.
Loggable interface {
Containers(ns, n string, includeInit bool) ([]string, error)
Logs(ns, n, co string, lines int64, previous bool) *restclient.Request
Logs(ns, n string, opts *v1.PodLogOptions) *restclient.Request
}
)
@ -66,12 +66,13 @@ func (j *Job) Containers(ns, n string, includeInit bool) ([]string, error) {
}
// Logs fetch container logs for a given job and container.
func (j *Job) Logs(ns, n, co string, lines int64, prev bool) *restclient.Request {
func (j *Job) Logs(ns, n string, opts *v1.PodLogOptions) *restclient.Request {
pod, err := j.assocPod(ns, n)
if err != nil {
return nil
}
return NewPod(j).Logs(ns, pod, co, lines, prev)
return NewPod(j).Logs(ns, pod, opts)
}
// Events retrieved jobs events.

View File

@ -78,12 +78,6 @@ func (p *Pod) Containers(ns, n string, includeInit bool) ([]string, error) {
}
// Logs fetch container logs for a given pod and container.
func (p *Pod) Logs(ns, n, co string, lines int64, prev bool) *restclient.Request {
return p.DialOrDie().CoreV1().Pods(ns).GetLogs(n, &v1.PodLogOptions{
Container: co,
Follow: true,
TailLines: &lines,
Timestamps: false,
Previous: prev,
})
func (p *Pod) Logs(ns, n string, opts *v1.PodLogOptions) *restclient.Request {
return p.DialOrDie().CoreV1().Pods(ns).GetLogs(n, opts)
}

View File

@ -170,7 +170,12 @@ func (r *Pod) Logs(ctx context.Context, c chan<- string, opts LogOptions) error
func tailLogs(ctx context.Context, res k8s.Loggable, c chan<- string, opts LogOptions) error {
log.Debug().Msgf("Tailing logs for %q/%q:%q", opts.Namespace, opts.Name, opts.Container)
req := res.Logs(opts.Namespace, opts.Name, opts.Container, opts.Lines, opts.Previous)
o := v1.PodLogOptions{
Container: opts.Container,
TailLines: &opts.Lines,
Previous: opts.Previous,
}
req := res.Logs(opts.Namespace, opts.Name, &o)
req.Context(ctx)
var blocked int32 = 1