driver: allow attaching additional metadata to the client
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
||||
"github.com/moby/buildkit/client"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/backoff"
|
||||
"google.golang.org/grpc/metadata"
|
||||
)
|
||||
|
||||
type Driver struct {
|
||||
@@ -63,8 +64,13 @@ func (d *Driver) Rm(ctx context.Context, force, rmVolume, rmDaemon bool) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *Driver) Client(ctx context.Context) (*client.Client, error) {
|
||||
opts := []client.ClientOpt{}
|
||||
func (d *Driver) Client(ctx context.Context, copts ...driver.ClientOption) (*client.Client, error) {
|
||||
co := driver.ClientOptions{}
|
||||
for _, opt := range copts {
|
||||
opt(&co)
|
||||
}
|
||||
|
||||
var opts []client.ClientOpt
|
||||
|
||||
backoffConfig := backoff.DefaultConfig
|
||||
backoffConfig.MaxDelay = 1 * time.Second
|
||||
@@ -79,6 +85,14 @@ func (d *Driver) Client(ctx context.Context) (*client.Client, error) {
|
||||
}...)
|
||||
}
|
||||
|
||||
if len(co.Meta) > 0 {
|
||||
opts = append(opts, client.WithGRPCDialOption(grpc.WithChainUnaryInterceptor(func(ctx context.Context, method string, req, reply interface{}, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error {
|
||||
// merge the existing context with new metadata.
|
||||
ctx = metadata.NewOutgoingContext(ctx, co.Meta)
|
||||
return invoker(ctx, method, req, reply, cc, opts...)
|
||||
})))
|
||||
}
|
||||
|
||||
return client.New(ctx, d.InitConfig.EndpointAddr, opts...)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user