-
Notifications
You must be signed in to change notification settings - Fork 3.3k
/
bridge.go
77 lines (59 loc) · 2.58 KB
/
bridge.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
67
68
69
70
71
72
73
74
75
76
77
/*
Copyright The containerd Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package sandbox
import (
"context"
"fmt"
"github.com/containerd/ttrpc"
"google.golang.org/grpc"
api "github.com/containerd/containerd/api/runtime/sandbox/v1"
)
// NewClient returns a new sandbox client that handles both GRPC and TTRPC clients.
func NewClient(client interface{}) (api.TTRPCSandboxService, error) {
switch c := client.(type) {
case *ttrpc.Client:
return api.NewTTRPCSandboxClient(c), nil
case grpc.ClientConnInterface:
return &grpcBridge{api.NewSandboxClient(c)}, nil
default:
return nil, fmt.Errorf("unsupported client type %T", client)
}
}
type grpcBridge struct {
client api.SandboxClient
}
var _ api.TTRPCSandboxService = (*grpcBridge)(nil)
func (g *grpcBridge) CreateSandbox(ctx context.Context, request *api.CreateSandboxRequest) (*api.CreateSandboxResponse, error) {
return g.client.CreateSandbox(ctx, request)
}
func (g *grpcBridge) StartSandbox(ctx context.Context, request *api.StartSandboxRequest) (*api.StartSandboxResponse, error) {
return g.client.StartSandbox(ctx, request)
}
func (g *grpcBridge) Platform(ctx context.Context, request *api.PlatformRequest) (*api.PlatformResponse, error) {
return g.client.Platform(ctx, request)
}
func (g *grpcBridge) StopSandbox(ctx context.Context, request *api.StopSandboxRequest) (*api.StopSandboxResponse, error) {
return g.client.StopSandbox(ctx, request)
}
func (g *grpcBridge) WaitSandbox(ctx context.Context, request *api.WaitSandboxRequest) (*api.WaitSandboxResponse, error) {
return g.client.WaitSandbox(ctx, request)
}
func (g *grpcBridge) SandboxStatus(ctx context.Context, request *api.SandboxStatusRequest) (*api.SandboxStatusResponse, error) {
return g.client.SandboxStatus(ctx, request)
}
func (g *grpcBridge) PingSandbox(ctx context.Context, request *api.PingRequest) (*api.PingResponse, error) {
return g.client.PingSandbox(ctx, request)
}
func (g *grpcBridge) ShutdownSandbox(ctx context.Context, request *api.ShutdownSandboxRequest) (*api.ShutdownSandboxResponse, error) {
return g.client.ShutdownSandbox(ctx, request)
}