bcc5c4a8bd
Driver plugin framework to facilitate development of driver plugins. Implementing plugins only need to implement the DriverPlugin interface. The framework proxies this interface to the go-plugin GRPC interface generated from the driver.proto spec. A testing harness is provided to allow implementing drivers to test the full lifecycle of the driver plugin. An example use: func TestMyDriver(t *testing.T) { harness := NewDriverHarness(t, &MyDiverPlugin{}) // The harness implements the DriverPlugin interface and can be used as such taskHandle, err := harness.StartTask(...) }
42 lines
1,021 B
Go
42 lines
1,021 B
Go
package drivers
|
|
|
|
import (
|
|
"context"
|
|
|
|
hclog "github.com/hashicorp/go-hclog"
|
|
plugin "github.com/hashicorp/go-plugin"
|
|
"github.com/hashicorp/nomad/plugins/drivers/proto"
|
|
"google.golang.org/grpc"
|
|
)
|
|
|
|
// PluginDriver wraps a DriverPlugin and implements go-plugins GRPCPlugin
|
|
// interface to expose the the interface over gRPC
|
|
type PluginDriver struct {
|
|
plugin.NetRPCUnsupportedPlugin
|
|
impl DriverPlugin
|
|
logger hclog.Logger
|
|
}
|
|
|
|
func NewDriverPlugin(d DriverPlugin, logger hclog.Logger) plugin.GRPCPlugin {
|
|
return &PluginDriver{
|
|
impl: d,
|
|
logger: logger.Named("driver_plugin"),
|
|
}
|
|
}
|
|
|
|
func (p *PluginDriver) GRPCServer(broker *plugin.GRPCBroker, s *grpc.Server) error {
|
|
proto.RegisterDriverServer(s, &driverPluginServer{
|
|
impl: p.impl,
|
|
broker: broker,
|
|
logger: p.logger,
|
|
})
|
|
return nil
|
|
}
|
|
|
|
func (p *PluginDriver) GRPCClient(ctx context.Context, broker *plugin.GRPCBroker, c *grpc.ClientConn) (interface{}, error) {
|
|
return &driverPluginClient{
|
|
client: proto.NewDriverClient(c),
|
|
logger: p.logger,
|
|
}, nil
|
|
}
|