Skip to content

Commit caa29a7

Browse files
willmyrsk8s-infra-cherrypick-robot
authored andcommitted
sandbox: forward Create fields, fix event topics
The gRPC sandbox controller service only forwarded the `options` field when calling the local controller. The `netns_path`, `rootfs`, and `annotations` fields were silently dropped, causing clients using the gRPC proxy path to receive incomplete sandbox configurations. Event topics were missing the leading `/` prefix ("sandboxes/create" instead of "/sandboxes/create"), causing the event exchange to reject the publish and return an error to the caller. Add unit tests for the controller service that exercise all RPC methods. Signed-off-by: William Myers <willmyrs@amazon.com>
1 parent dc432e1 commit caa29a7

2 files changed

Lines changed: 411 additions & 5 deletions

File tree

plugins/services/sandbox/controller_service.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import (
3434
"github.com/containerd/plugin/registry"
3535

3636
"github.com/containerd/containerd/v2/core/events"
37+
"github.com/containerd/containerd/v2/core/mount"
3738
"github.com/containerd/containerd/v2/core/sandbox"
3839
"github.com/containerd/containerd/v2/pkg/protobuf"
3940
"github.com/containerd/containerd/v2/plugins"
@@ -117,7 +118,6 @@ func (s *controllerService) Create(ctx context.Context, req *api.ControllerCreat
117118

118119
log.G(ctx).Debug("create sandbox")
119120

120-
// TODO: Rootfs
121121
ctrl, err := s.getController(req.Sandboxer)
122122
if err != nil {
123123
return nil, errgrpc.ToGRPC(err)
@@ -128,12 +128,17 @@ func (s *controllerService) Create(ctx context.Context, req *api.ControllerCreat
128128
} else {
129129
sb = sandbox.Sandbox{ID: req.GetSandboxID()}
130130
}
131-
err = ctrl.Create(ctx, sb, sandbox.WithOptions(req.GetOptions()))
131+
err = ctrl.Create(ctx, sb,
132+
sandbox.WithOptions(req.GetOptions()),
133+
sandbox.WithNetNSPath(req.GetNetnsPath()),
134+
sandbox.WithRootFS(mount.FromProto(req.GetRootfs())),
135+
sandbox.WithAnnotations(req.GetAnnotations()),
136+
)
132137
if err != nil {
133138
return &api.ControllerCreateResponse{}, errgrpc.ToGRPC(err)
134139
}
135140

136-
if err := s.publisher.Publish(ctx, "sandboxes/create", &eventtypes.SandboxCreate{
141+
if err := s.publisher.Publish(ctx, "/sandboxes/create", &eventtypes.SandboxCreate{
137142
SandboxID: req.GetSandboxID(),
138143
}); err != nil {
139144
return &api.ControllerCreateResponse{}, errgrpc.ToGRPC(err)
@@ -160,7 +165,7 @@ func (s *controllerService) Start(ctx context.Context, req *api.ControllerStartR
160165
return &api.ControllerStartResponse{}, errgrpc.ToGRPCf(err, "failed to start sandbox %q", req.GetSandboxID())
161166
}
162167

163-
if err := s.publisher.Publish(ctx, "sandboxes/start", &eventtypes.SandboxStart{
168+
if err := s.publisher.Publish(ctx, "/sandboxes/start", &eventtypes.SandboxStart{
164169
SandboxID: req.GetSandboxID(),
165170
}); err != nil {
166171
return &api.ControllerStartResponse{}, errgrpc.ToGRPC(err)
@@ -194,7 +199,7 @@ func (s *controllerService) Wait(ctx context.Context, req *api.ControllerWaitReq
194199
return &api.ControllerWaitResponse{}, errgrpc.ToGRPC(err)
195200
}
196201

197-
if err := s.publisher.Publish(ctx, "sandboxes/exit", &eventtypes.SandboxExit{
202+
if err := s.publisher.Publish(ctx, "/sandboxes/exit", &eventtypes.SandboxExit{
198203
SandboxID: req.GetSandboxID(),
199204
ExitStatus: exitStatus.ExitStatus,
200205
ExitedAt: protobuf.ToTimestamp(exitStatus.ExitedAt),

0 commit comments

Comments
 (0)