fix(osd): Use correct context in stats endpoint (#644)

Without this we never set the namespace for the context which prevents it from functioning at all

Signed-off-by: Brad Beam <brad.beam@talos-systems.com>
This commit is contained in:
Brad Beam 2019-05-11 14:26:23 -05:00 committed by GitHub
parent 967e547d87
commit a6989db1d1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -98,14 +98,14 @@ func (r *Registrator) Processes(ctx context.Context, in *proto.ProcessesRequest)
// Stats implements the proto.OSDServer interface.
// nolint: gocyclo
func (r *Registrator) Stats(ctx context.Context, in *proto.StatsRequest) (reply *proto.StatsReply, err error) {
client, _, err := connect(in.Namespace)
client, nsctx, err := connect(in.Namespace)
if err != nil {
return nil, err
}
// nolint: errcheck
defer client.Close()
containers, err := client.Containers(ctx)
containers, err := client.Containers(nsctx)
if err != nil {
return nil, err
}
@ -113,20 +113,20 @@ func (r *Registrator) Stats(ctx context.Context, in *proto.StatsRequest) (reply
stats := []*proto.Stat{}
for _, container := range containers {
task, err := container.Task(ctx, nil)
task, err := container.Task(nsctx, nil)
if err != nil {
log.Println(err)
continue
}
status, err := task.Status(ctx)
status, err := task.Status(nsctx)
if err != nil {
log.Println(err)
continue
}
if status.Status == containerd.Running {
metrics, err := task.Metrics(ctx)
metrics, err := task.Metrics(nsctx)
if err != nil {
log.Println(err)
continue