Skip to content

Commit 58094bf

Browse files
committed
feat(shim): add urunc task service wrapper
Signed-off-by: sidneychang <2190206983@qq.com>
1 parent 11e894a commit 58094bf

5 files changed

Lines changed: 102 additions & 3 deletions

File tree

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ URUNC_SRC += $(wildcard $(CURDIR)/pkg/unikontainers/types/*.go)
7272
URUNC_SRC += $(wildcard $(CURDIR)/pkg/unikontainers/initrd/*.go)
7373
URUNC_SRC += $(wildcard $(CURDIR)/pkg/network/*.go)
7474
SHIM_SRC := $(wildcard $(CURDIR)/cmd/containerd-shim-urunc-v2/*.go)
75+
SHIM_SRC += $(wildcard $(CURDIR)/pkg/containerd-shim/*.go)
7576

7677
#? CNTR_TOOL Tool to run the linter container (default: docker)
7778
CNTR_TOOL ?= docker

cmd/containerd-shim-urunc-v2/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ import (
1818
"context"
1919

2020
"github.com/containerd/containerd/runtime/v2/runc/manager"
21-
_ "github.com/containerd/containerd/runtime/v2/runc/task/plugin"
2221
"github.com/containerd/containerd/runtime/v2/shim"
22+
_ "github.com/urunc-dev/urunc/pkg/containerd-shim"
2323
)
2424

2525
func main() {

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ require (
77
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2
88
github.com/cavaliergopher/cpio v1.0.1
99
github.com/containerd/containerd v1.7.30
10+
github.com/containerd/containerd/api v1.10.0
11+
github.com/containerd/ttrpc v1.2.7
1012
github.com/creack/pty v1.1.24
1113
github.com/elastic/go-seccomp-bpf v1.6.0
1214
github.com/hashicorp/go-version v1.9.0
@@ -36,15 +38,13 @@ require (
3638
github.com/cilium/ebpf v0.20.0 // indirect
3739
github.com/containerd/cgroups/v3 v3.1.0 // indirect
3840
github.com/containerd/console v1.0.5 // indirect
39-
github.com/containerd/containerd/api v1.10.0 // indirect
4041
github.com/containerd/continuity v0.4.5 // indirect
4142
github.com/containerd/errdefs v1.0.0 // indirect
4243
github.com/containerd/errdefs/pkg v0.3.0 // indirect
4344
github.com/containerd/fifo v1.1.0 // indirect
4445
github.com/containerd/go-runc v1.0.0 // indirect
4546
github.com/containerd/log v0.1.0 // indirect
4647
github.com/containerd/platforms v0.2.1 // indirect
47-
github.com/containerd/ttrpc v1.2.7 // indirect
4848
github.com/containerd/typeurl/v2 v2.2.3 // indirect
4949
github.com/coreos/go-systemd/v22 v22.7.0 // indirect
5050
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect

pkg/containerd-shim/task_plugin.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// Copyright (c) 2023-2026, Nubificus LTD
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package containerdshim
16+
17+
import (
18+
"github.com/containerd/containerd/pkg/shutdown"
19+
"github.com/containerd/containerd/plugin"
20+
runcTask "github.com/containerd/containerd/runtime/v2/runc/task"
21+
"github.com/containerd/containerd/runtime/v2/shim"
22+
)
23+
24+
func init() {
25+
plugin.Register(&plugin.Registration{
26+
Type: plugin.TTRPCPlugin,
27+
ID: "task",
28+
Requires: []plugin.Type{
29+
plugin.EventPlugin,
30+
plugin.InternalPlugin,
31+
},
32+
InitFn: func(ic *plugin.InitContext) (interface{}, error) {
33+
pp, err := ic.GetByID(plugin.EventPlugin, "publisher")
34+
if err != nil {
35+
return nil, err
36+
}
37+
38+
ss, err := ic.GetByID(plugin.InternalPlugin, "shutdown")
39+
if err != nil {
40+
return nil, err
41+
}
42+
43+
inner, err := runcTask.NewTaskService(ic.Context, pp.(shim.Publisher), ss.(shutdown.Service))
44+
if err != nil {
45+
return nil, err
46+
}
47+
48+
return &taskService{
49+
TaskService: inner,
50+
containerdAddress: ic.Address,
51+
}, nil
52+
},
53+
})
54+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Copyright (c) 2023-2026, Nubificus LTD
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package containerdshim
16+
17+
import (
18+
"context"
19+
20+
taskAPI "github.com/containerd/containerd/api/runtime/task/v2"
21+
"github.com/containerd/ttrpc"
22+
)
23+
24+
// taskService is urunc's shim-side wrapper around containerd's runc task
25+
// service. It is intentionally behavior-preserving for now; feature-specific
26+
// helpers can hook into Create/Delete here without replacing the plugin again.
27+
type taskService struct {
28+
taskAPI.TaskService
29+
30+
containerdAddress string
31+
}
32+
33+
func (s *taskService) Create(ctx context.Context, r *taskAPI.CreateTaskRequest) (*taskAPI.CreateTaskResponse, error) {
34+
return s.TaskService.Create(ctx, r)
35+
}
36+
37+
func (s *taskService) Delete(ctx context.Context, r *taskAPI.DeleteRequest) (*taskAPI.DeleteResponse, error) {
38+
return s.TaskService.Delete(ctx, r)
39+
}
40+
41+
func (s *taskService) RegisterTTRPC(server *ttrpc.Server) error {
42+
taskAPI.RegisterTaskService(server, s)
43+
return nil
44+
}

0 commit comments

Comments
 (0)