/
plugin.go
66 lines (51 loc) · 1.51 KB
/
plugin.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package runtime
import (
"os"
api "github.com/dodo-cli/dodo-core/api/v1alpha3"
dodo "github.com/dodo-cli/dodo-core/pkg/plugin"
"github.com/hashicorp/go-plugin"
"golang.org/x/net/context"
"google.golang.org/grpc"
)
const Type pluginType = "runtime"
type pluginType string
func (t pluginType) String() string {
return string(t)
}
func (t pluginType) GRPCClient() (plugin.Plugin, error) {
return &grpcPlugin{}, nil
}
func (t pluginType) GRPCServer(p dodo.Plugin) (plugin.Plugin, error) {
rt, ok := p.(ContainerRuntime)
if !ok {
return nil, dodo.ErrInvalidPlugin{
Plugin: p.PluginInfo().Name,
Message: "plugin does not implement ContainerRuntime API",
}
}
return &grpcPlugin{Impl: rt}, nil
}
type ContainerRuntime interface {
dodo.Plugin
ResolveImage(string) (string, error)
CreateContainer(*api.Backdrop, bool, bool) (string, error)
StartContainer(string) error
DeleteContainer(string) error
ResizeContainer(string, uint32, uint32) error
KillContainer(string, os.Signal) error
StreamContainer(string, *dodo.StreamConfig) (*Result, error)
}
type Result struct {
ExitCode int
}
type grpcPlugin struct {
plugin.NetRPCUnsupportedPlugin
Impl ContainerRuntime
}
func (p *grpcPlugin) GRPCClient(_ context.Context, _ *plugin.GRPCBroker, conn *grpc.ClientConn) (interface{}, error) {
return &client{runtimeClient: api.NewRuntimePluginClient(conn)}, nil
}
func (p *grpcPlugin) GRPCServer(_ *plugin.GRPCBroker, s *grpc.Server) error {
api.RegisterRuntimePluginServer(s, &server{impl: p.Impl})
return nil
}