Skip to content

Commit 4de0ed8

Browse files
committed
api,adaptation: protocol translation for v1alpha1.
Add protocol translation for plugins that talk v1alpha1. Signed-off-by: Krisztian Litkey <[email protected]>
1 parent 6f9ecde commit 4de0ed8

File tree

7 files changed

+3163
-0
lines changed

7 files changed

+3163
-0
lines changed

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module github.com/containerd/nri
33
go 1.24.0
44

55
require (
6+
github.com/brianvoe/gofakeit/v7 v7.7.3
67
github.com/containerd/ttrpc v1.2.7
78
github.com/google/go-cmp v0.7.0
89
github.com/knqyf263/go-plugin v0.9.0

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
github.com/blang/semver/v4 v4.0.0 h1:1PFHFE6yCCTv8C1TeyNNarDzntLi7wMI5i/pzqYIsAM=
22
github.com/blang/semver/v4 v4.0.0/go.mod h1:IbckMUScFkM3pff0VJDNKRiT6TG/YpiHIM2yvyW5YoQ=
3+
github.com/brianvoe/gofakeit/v7 v7.7.3 h1:RWOATEGpJ5EVg2nN8nlaEyaV/aB4d6c3GqYrbqQekss=
4+
github.com/brianvoe/gofakeit/v7 v7.7.3/go.mod h1:QXuPeBw164PJCzCUZVmgpgHJ3Llj49jSLVkKPMtxtxA=
35
github.com/containerd/log v0.1.0 h1:TCJt7ioM2cr/tfR8GPbGf9/VRAX8D2B4PjzCpfX540I=
46
github.com/containerd/log v0.1.0/go.mod h1:VRRf09a7mHDIRezVKTRCrOq78v577GXq3bSa3EhrzVo=
57
github.com/containerd/ttrpc v1.2.7 h1:qIrroQvuOL9HQ1X6KHe2ohc7p+HP/0VE6XPU7elJRqQ=

pkg/adaptation/plugin.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@ func (p *plugin) connect(conn stdnet.Conn) (retErr error) {
305305
}
306306

307307
api.RegisterRuntimeService(p.rpcs, p)
308+
p.RegisterV1Alpha1Bridge()
308309

309310
return nil
310311
}

pkg/adaptation/v1alpha1-bridge.go

Lines changed: 228 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,228 @@
1+
/*
2+
Copyright The containerd Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package adaptation
18+
19+
import (
20+
"context"
21+
22+
old "github.com/containerd/nri/pkg/api"
23+
"github.com/containerd/nri/pkg/api/convert"
24+
api "github.com/containerd/nri/pkg/api/v1beta1"
25+
)
26+
27+
type v1alpha1Bridge struct {
28+
new *plugin
29+
old *v1alpha1Plugin
30+
}
31+
32+
type v1alpha1Plugin struct {
33+
p old.PluginService
34+
}
35+
36+
func (p *plugin) RegisterV1Alpha1Bridge() {
37+
b := &v1alpha1Bridge{new: p}
38+
old.RegisterRuntimeService(p.rpcs, b)
39+
}
40+
41+
func (b *v1alpha1Bridge) RegisterPlugin(ctx context.Context, req *old.RegisterPluginRequest) (*old.Empty, error) {
42+
b.old = &v1alpha1Plugin{
43+
p: old.NewPluginClient(b.new.rpcc),
44+
}
45+
b.new.impl.ttrpcImpl = b.old
46+
47+
nreq := convert.RegisterPluginRequest(req)
48+
nrpl, err := b.new.RegisterPlugin(ctx, nreq)
49+
if err != nil {
50+
return nil, err
51+
}
52+
53+
return convert.RegisterPluginResponse(nrpl), nil
54+
}
55+
56+
func (b *v1alpha1Bridge) UpdateContainers(ctx context.Context, req *old.UpdateContainersRequest) (*old.UpdateContainersResponse, error) {
57+
nreq := convert.UpdateContainersRequest(req)
58+
nrpl, err := b.new.UpdateContainers(ctx, nreq)
59+
if err != nil {
60+
return nil, err
61+
}
62+
63+
return convert.UpdateContainersResponse(nrpl), nil
64+
}
65+
66+
func (p *v1alpha1Plugin) Configure(ctx context.Context, req *api.ConfigureRequest) (*api.ConfigureResponse, error) {
67+
oreq := convert.ConfigureRequest(req)
68+
orpl, err := p.p.Configure(ctx, oreq)
69+
if err != nil {
70+
return nil, err
71+
}
72+
73+
return convert.ConfigureResponse(orpl), nil
74+
}
75+
76+
func (p *v1alpha1Plugin) Synchronize(ctx context.Context, req *api.SynchronizeRequest) (*api.SynchronizeResponse, error) {
77+
oreq := convert.SynchronizeRequest(req)
78+
orpl, err := p.p.Synchronize(ctx, oreq)
79+
if err != nil {
80+
return nil, err
81+
}
82+
83+
return convert.SynchronizeResponse(orpl), nil
84+
}
85+
86+
func (p *v1alpha1Plugin) Shutdown(_ context.Context, _ *api.ShutdownRequest) (*api.ShutdownResponse, error) {
87+
return &api.ShutdownResponse{}, nil
88+
}
89+
90+
func (p *v1alpha1Plugin) RunPodSandbox(ctx context.Context, req *api.RunPodSandboxRequest) (*api.RunPodSandboxResponse, error) {
91+
oreq := convert.RunPodSandboxRequest(req)
92+
orpl, err := p.p.StateChange(ctx, oreq)
93+
if err != nil {
94+
return nil, err
95+
}
96+
97+
return convert.RunPodSandboxResponse(orpl), nil
98+
}
99+
100+
func (p *v1alpha1Plugin) UpdatePodSandbox(ctx context.Context, req *api.UpdatePodSandboxRequest) (*api.UpdatePodSandboxResponse, error) {
101+
oreq := convert.UpdatePodSandboxRequest(req)
102+
orpl, err := p.p.UpdatePodSandbox(ctx, oreq)
103+
if err != nil {
104+
return nil, err
105+
}
106+
107+
return convert.UpdatePodSandboxResponse(orpl), nil
108+
}
109+
110+
func (p *v1alpha1Plugin) PostUpdatePodSandbox(ctx context.Context, req *api.PostUpdatePodSandboxRequest) (*api.PostUpdatePodSandboxResponse, error) {
111+
oreq := convert.PostUpdatePodSandboxRequest(req)
112+
orpl, err := p.p.StateChange(ctx, oreq)
113+
if err != nil {
114+
return nil, err
115+
}
116+
117+
return convert.PostUpdatePodSandboxResponse(orpl), nil
118+
}
119+
120+
func (p *v1alpha1Plugin) StopPodSandbox(ctx context.Context, req *api.StopPodSandboxRequest) (*api.StopPodSandboxResponse, error) {
121+
oreq := convert.StopPodSandboxRequest(req)
122+
orpl, err := p.p.StateChange(ctx, oreq)
123+
if err != nil {
124+
return nil, err
125+
}
126+
127+
return convert.StopPodSandboxResponse(orpl), nil
128+
}
129+
130+
func (p *v1alpha1Plugin) RemovePodSandbox(ctx context.Context, req *api.RemovePodSandboxRequest) (*api.RemovePodSandboxResponse, error) {
131+
oreq := convert.RemovePodSandboxRequest(req)
132+
orpl, err := p.p.StateChange(ctx, oreq)
133+
if err != nil {
134+
return nil, err
135+
}
136+
137+
return convert.RemovePodSandboxResponse(orpl), nil
138+
}
139+
140+
func (p *v1alpha1Plugin) CreateContainer(ctx context.Context, req *api.CreateContainerRequest) (*api.CreateContainerResponse, error) {
141+
oreq := convert.CreateContainerRequest(req)
142+
orpl, err := p.p.CreateContainer(ctx, oreq)
143+
if err != nil {
144+
return nil, err
145+
}
146+
147+
return convert.CreateContainerResponse(orpl), nil
148+
}
149+
150+
func (p *v1alpha1Plugin) PostCreateContainer(ctx context.Context, req *api.PostCreateContainerRequest) (*api.PostCreateContainerResponse, error) {
151+
oreq := convert.PostCreateContainerRequest(req)
152+
orpl, err := p.p.StateChange(ctx, oreq)
153+
if err != nil {
154+
return nil, err
155+
}
156+
157+
return convert.PostCreateContainerResponse(orpl), nil
158+
}
159+
160+
func (p *v1alpha1Plugin) StartContainer(ctx context.Context, req *api.StartContainerRequest) (*api.StartContainerResponse, error) {
161+
oreq := convert.StartContainerRequest(req)
162+
orpl, err := p.p.StateChange(ctx, oreq)
163+
if err != nil {
164+
return nil, err
165+
}
166+
167+
return convert.StartContainerResponse(orpl), nil
168+
}
169+
170+
func (p *v1alpha1Plugin) PostStartContainer(ctx context.Context, req *api.PostStartContainerRequest) (*api.PostStartContainerResponse, error) {
171+
oreq := convert.PostStartContainerRequest(req)
172+
orpl, err := p.p.StateChange(ctx, oreq)
173+
if err != nil {
174+
return nil, err
175+
}
176+
177+
return convert.PostStartContainerResponse(orpl), nil
178+
}
179+
180+
func (p *v1alpha1Plugin) UpdateContainer(ctx context.Context, req *api.UpdateContainerRequest) (*api.UpdateContainerResponse, error) {
181+
oreq := convert.UpdateContainerRequest(req)
182+
orpl, err := p.p.UpdateContainer(ctx, oreq)
183+
if err != nil {
184+
return nil, err
185+
}
186+
187+
return convert.UpdateContainerResponse(orpl), nil
188+
}
189+
190+
func (p *v1alpha1Plugin) PostUpdateContainer(ctx context.Context, req *api.PostUpdateContainerRequest) (*api.PostUpdateContainerResponse, error) {
191+
oreq := convert.PostUpdateContainerRequest(req)
192+
orpl, err := p.p.StateChange(ctx, oreq)
193+
if err != nil {
194+
return nil, err
195+
}
196+
197+
return convert.PostUpdateContainerResponse(orpl), nil
198+
}
199+
200+
func (p *v1alpha1Plugin) StopContainer(ctx context.Context, req *api.StopContainerRequest) (*api.StopContainerResponse, error) {
201+
oreq := convert.StopContainerRequest(req)
202+
orpl, err := p.p.StopContainer(ctx, oreq)
203+
if err != nil {
204+
return nil, err
205+
}
206+
207+
return convert.StopContainerResponse(orpl), nil
208+
}
209+
210+
func (p *v1alpha1Plugin) RemoveContainer(ctx context.Context, req *api.RemoveContainerRequest) (*api.RemoveContainerResponse, error) {
211+
oreq := convert.RemoveContainerRequest(req)
212+
orpl, err := p.p.StateChange(ctx, oreq)
213+
if err != nil {
214+
return nil, err
215+
}
216+
217+
return convert.RemoveContainerResponse(orpl), nil
218+
}
219+
220+
func (p *v1alpha1Plugin) ValidateContainerAdjustment(ctx context.Context, req *api.ValidateContainerAdjustmentRequest) (*api.ValidateContainerAdjustmentResponse, error) {
221+
oreq := convert.ValidateContainerAdjustmentRequest(req)
222+
orpl, err := p.p.ValidateContainerAdjustment(ctx, oreq)
223+
if err != nil {
224+
return nil, err
225+
}
226+
227+
return convert.ValidateContainerAdjustmentResponse(orpl), nil
228+
}

0 commit comments

Comments
 (0)