1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00
moby--moby/vendor/github.com/moby/buildkit/client/workers.go
Andrew Hsu 67da8c84b6 vndr buildkit to e57eed4 and fsutil to b19464c
Signed-off-by: Andrew Hsu <andrewhsu@docker.com>
2018-08-02 18:19:13 +00:00

49 lines
1 KiB
Go

package client
import (
"context"
controlapi "github.com/moby/buildkit/api/services/control"
"github.com/moby/buildkit/solver/pb"
specs "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/pkg/errors"
)
type WorkerInfo struct {
ID string
Labels map[string]string
Platforms []specs.Platform
}
func (c *Client) ListWorkers(ctx context.Context, opts ...ListWorkersOption) ([]*WorkerInfo, error) {
info := &ListWorkersInfo{}
for _, o := range opts {
o.SetListWorkersOption(info)
}
req := &controlapi.ListWorkersRequest{Filter: info.Filter}
resp, err := c.controlClient().ListWorkers(ctx, req)
if err != nil {
return nil, errors.Wrap(err, "failed to list workers")
}
var wi []*WorkerInfo
for _, w := range resp.Record {
wi = append(wi, &WorkerInfo{
ID: w.ID,
Labels: w.Labels,
Platforms: pb.ToSpecPlatforms(w.Platforms),
})
}
return wi, nil
}
type ListWorkersOption interface {
SetListWorkersOption(*ListWorkersInfo)
}
type ListWorkersInfo struct {
Filter []string
}