2018-04-19 13:07:27 -04:00
|
|
|
package client
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
controlapi "github.com/moby/buildkit/api/services/control"
|
2018-06-29 11:17:00 -04:00
|
|
|
"github.com/moby/buildkit/solver/pb"
|
|
|
|
specs "github.com/opencontainers/image-spec/specs-go/v1"
|
2018-04-19 13:07:27 -04:00
|
|
|
"github.com/pkg/errors"
|
|
|
|
)
|
|
|
|
|
|
|
|
type WorkerInfo struct {
|
2018-06-29 11:17:00 -04:00
|
|
|
ID string
|
|
|
|
Labels map[string]string
|
|
|
|
Platforms []specs.Platform
|
2018-04-19 13:07:27 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Client) ListWorkers(ctx context.Context, opts ...ListWorkersOption) ([]*WorkerInfo, error) {
|
|
|
|
info := &ListWorkersInfo{}
|
|
|
|
for _, o := range opts {
|
2018-08-11 15:04:13 -04:00
|
|
|
o.SetListWorkersOption(info)
|
2018-04-19 13:07:27 -04: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-29 11:17:00 -04:00
|
|
|
ID: w.ID,
|
|
|
|
Labels: w.Labels,
|
2018-08-11 15:04:13 -04:00
|
|
|
Platforms: pb.ToSpecPlatforms(w.Platforms),
|
2018-04-19 13:07:27 -04:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
return wi, nil
|
|
|
|
}
|
|
|
|
|
2018-08-11 15:04:13 -04:00
|
|
|
type ListWorkersOption interface {
|
|
|
|
SetListWorkersOption(*ListWorkersInfo)
|
|
|
|
}
|
2018-04-19 13:07:27 -04:00
|
|
|
|
|
|
|
type ListWorkersInfo struct {
|
|
|
|
Filter []string
|
|
|
|
}
|