refact logs
parent
d3478d9c63
commit
2c2de7b269
|
|
@ -19,7 +19,7 @@ type (
|
||||||
// Loggable represents a K8s resource that has containers and can be logged.
|
// Loggable represents a K8s resource that has containers and can be logged.
|
||||||
Loggable interface {
|
Loggable interface {
|
||||||
Containers(ns, n string, includeInit bool) ([]string, error)
|
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.
|
// 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)
|
pod, err := j.assocPod(ns, n)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return NewPod(j).Logs(ns, pod, co, lines, prev)
|
|
||||||
|
return NewPod(j).Logs(ns, pod, opts)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Events retrieved jobs events.
|
// Events retrieved jobs events.
|
||||||
|
|
|
||||||
|
|
@ -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.
|
// Logs fetch container logs for a given pod and container.
|
||||||
func (p *Pod) Logs(ns, n, co string, lines int64, prev bool) *restclient.Request {
|
func (p *Pod) Logs(ns, n string, opts *v1.PodLogOptions) *restclient.Request {
|
||||||
return p.DialOrDie().CoreV1().Pods(ns).GetLogs(n, &v1.PodLogOptions{
|
return p.DialOrDie().CoreV1().Pods(ns).GetLogs(n, opts)
|
||||||
Container: co,
|
|
||||||
Follow: true,
|
|
||||||
TailLines: &lines,
|
|
||||||
Timestamps: false,
|
|
||||||
Previous: prev,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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 {
|
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)
|
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)
|
req.Context(ctx)
|
||||||
|
|
||||||
var blocked int32 = 1
|
var blocked int32 = 1
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue