2017-12-19 09:34:34 +00:00
|
|
|
package client
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
controlapi "github.com/moby/buildkit/api/services/control"
|
2018-06-22 02:06:12 +00:00
|
|
|
"github.com/moby/buildkit/solver/pb"
|
|
|
|
specs "github.com/opencontainers/image-spec/specs-go/v1"
|
2017-12-19 09:34:34 +00:00
|
|
|
"github.com/pkg/errors"
|
|
|
|
)
|
|
|
|
|
|
|
|
type WorkerInfo struct {
|
2018-06-22 02:06:12 +00:00
|
|
|
ID string
|
|
|
|
Labels map[string]string
|
|
|
|
Platforms []specs.Platform
|
2017-12-19 09:34:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Client) ListWorkers(ctx context.Context, opts ...ListWorkersOption) ([]*WorkerInfo, error) {
|
|
|
|
info := &ListWorkersInfo{}
|
|
|
|
for _, o := range opts {
|
2018-07-26 00:20:03 +00:00
|
|
|
o.SetListWorkersOption(info)
|
2017-12-19 09:34:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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{
|
2018-06-22 02:06:12 +00:00
|
|
|
ID: w.ID,
|
|
|
|
Labels: w.Labels,
|
2018-06-30 01:35:39 +00:00
|
|
|
Platforms: pb.ToSpecPlatforms(w.Platforms),
|
2017-12-19 09:34:34 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
return wi, nil
|
|
|
|
}
|
|
|
|
|
2018-07-26 00:20:03 +00:00
|
|
|
type ListWorkersOption interface {
|
|
|
|
SetListWorkersOption(*ListWorkersInfo)
|
|
|
|
}
|
2017-12-19 09:34:34 +00:00
|
|
|
|
|
|
|
type ListWorkersInfo struct {
|
|
|
|
Filter []string
|
|
|
|
}
|