Skip to content

Commit 94cfce6

Browse files
authored
Merge pull request containerd#2434 from crosbymichael/shimv2
Runtime v2 (shim API)
2 parents 02579c8 + d53a96f commit 94cfce6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+10838
-653
lines changed

.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ addons:
2727
- socat
2828

2929
env:
30-
- TRAVIS_GOOS=linux TRAVIS_CGO_ENABLED=1
30+
- TRAVIS_GOOS=linux TEST_RUNTIME=io.containerd.runc.v1 TRAVIS_CGO_ENABLED=1
31+
- TRAVIS_GOOS=linux TEST_RUNTIME=io.containerd.runtime.v1.linux TRAVIS_CGO_ENABLED=1
3132
- TRAVIS_GOOS=darwin TRAVIS_CGO_ENABLED=0
3233

3334
before_install:

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,10 @@ bin/containerd-shim: cmd/containerd-shim FORCE # set !cgo and omit pie for a sta
172172
@echo "$(WHALE) bin/containerd-shim"
173173
@CGO_ENABLED=0 go build ${GO_BUILD_FLAGS} -o bin/containerd-shim ${SHIM_GO_LDFLAGS} ${GO_TAGS} ./cmd/containerd-shim
174174

175+
bin/containerd-shim-runc-v1: cmd/containerd-shim-runc-v1 FORCE # set !cgo and omit pie for a static shim build: https://github.com/golang/go/issues/17789#issuecomment-258542220
176+
@echo "$(WHALE) bin/containerd-shim-runc-v1"
177+
@CGO_ENABLED=0 go build ${GO_BUILD_FLAGS} -o bin/containerd-shim-runc-v1 ${SHIM_GO_LDFLAGS} ${GO_TAGS} ./cmd/containerd-shim-runc-v1
178+
175179
binaries: $(BINARIES) ## build binaries
176180
@echo "$(WHALE) $@"
177181

Makefile.linux

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515

1616
#linux specific settings
17-
COMMANDS += containerd-shim
17+
COMMANDS += containerd-shim containerd-shim-runc-v1
1818

1919
# check GOOS for cross compile builds
2020
ifeq ($(GOOS),linux)

Protobuild.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ plugins = ["fieldpath"] # disable grpc for this package
3737

3838
[[overrides]]
3939
# enable ttrpc and disable fieldpath and grpc for the shim
40-
prefixes = ["github.com/containerd/containerd/runtime/shim/v1"]
40+
prefixes = ["github.com/containerd/containerd/runtime/v1/shim/v1", "github.com/containerd/containerd/runtime/v2/task"]
4141
plugins = ["ttrpc"]
4242

4343
# Aggregrate the API descriptors to lock down API changes.

client.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,12 @@ func New(address string, opts ...ClientOpt) (*Client, error) {
7979
return nil, err
8080
}
8181
}
82+
rt := fmt.Sprintf("%s.%s", plugin.RuntimePlugin, runtime.GOOS)
83+
if copts.defaultRuntime != "" {
84+
rt = copts.defaultRuntime
85+
}
8286
c := &Client{
83-
runtime: fmt.Sprintf("%s.%s", plugin.RuntimePlugin, runtime.GOOS),
87+
runtime: rt,
8488
}
8589
if copts.services != nil {
8690
c.services = *copts.services

client_opts.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@ import (
2323
)
2424

2525
type clientOpts struct {
26-
defaultns string
27-
services *services
28-
dialOptions []grpc.DialOption
26+
defaultns string
27+
defaultRuntime string
28+
services *services
29+
dialOptions []grpc.DialOption
2930
}
3031

3132
// ClientOpt allows callers to set options on the containerd client
@@ -42,6 +43,14 @@ func WithDefaultNamespace(ns string) ClientOpt {
4243
}
4344
}
4445

46+
// WithDefaultRuntime sets the default runtime on the client
47+
func WithDefaultRuntime(rt string) ClientOpt {
48+
return func(c *clientOpts) error {
49+
c.defaultRuntime = rt
50+
return nil
51+
}
52+
}
53+
4554
// WithDialOpts allows grpc.DialOptions to be set on the connection
4655
func WithDialOpts(opts []grpc.DialOption) ClientOpt {
4756
return func(c *clientOpts) error {

client_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,9 @@ func newClient(t testing.TB, address string, opts ...ClientOpt) (*Client, error)
153153
if testing.Short() {
154154
t.Skip()
155155
}
156+
if rt := os.Getenv("TEST_RUNTIME"); rt != "" {
157+
opts = append(opts, WithDefaultRuntime(rt))
158+
}
156159
// testutil.RequiresRoot(t) is not needed here (already called in TestMain)
157160
return New(address, opts...)
158161
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// +build linux
2+
3+
/*
4+
Copyright The containerd Authors.
5+
6+
Licensed under the Apache License, Version 2.0 (the "License");
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
*/
18+
19+
package main
20+
21+
import (
22+
"fmt"
23+
"os"
24+
25+
"github.com/containerd/containerd/runtime/v2/runc"
26+
"github.com/containerd/containerd/runtime/v2/shim"
27+
"github.com/sirupsen/logrus"
28+
)
29+
30+
func main() {
31+
if err := shim.Run(runc.New); err != nil {
32+
logrus.WithError(err).Error("shim run")
33+
fmt.Fprintf(os.Stderr, "containerd-shim-run-v1: %s\n", err)
34+
os.Exit(1)
35+
}
36+
}

cmd/containerd-shim/main_unix.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ import (
3636

3737
"github.com/containerd/containerd/events"
3838
"github.com/containerd/containerd/namespaces"
39-
"github.com/containerd/containerd/runtime/linux/proc"
40-
"github.com/containerd/containerd/runtime/shim"
41-
shimapi "github.com/containerd/containerd/runtime/shim/v1"
39+
"github.com/containerd/containerd/runtime/v1/linux/proc"
40+
"github.com/containerd/containerd/runtime/v1/shim"
41+
shimapi "github.com/containerd/containerd/runtime/v1/shim/v1"
4242
"github.com/containerd/ttrpc"
4343
"github.com/containerd/typeurl"
4444
ptypes "github.com/gogo/protobuf/types"
@@ -134,7 +134,7 @@ func executeShim() error {
134134
shimapi.RegisterShimService(server, sv)
135135

136136
socket := socketFlag
137-
if err := serve(server, socket); err != nil {
137+
if err := serve(context.Background(), server, socket); err != nil {
138138
return err
139139
}
140140
logger := logrus.WithFields(logrus.Fields{
@@ -152,7 +152,7 @@ func executeShim() error {
152152

153153
// serve serves the ttrpc API over a unix socket at the provided path
154154
// this function does not block
155-
func serve(server *ttrpc.Server, path string) error {
155+
func serve(ctx context.Context, server *ttrpc.Server, path string) error {
156156
var (
157157
l net.Listener
158158
err error
@@ -172,7 +172,7 @@ func serve(server *ttrpc.Server, path string) error {
172172
logrus.WithField("socket", path).Debug("serving api on unix socket")
173173
go func() {
174174
defer l.Close()
175-
if err := server.Serve(context.Background(), l); err != nil &&
175+
if err := server.Serve(ctx, l); err != nil &&
176176
!strings.Contains(err.Error(), "use of closed network connection") {
177177
logrus.WithError(err).Fatal("containerd-shim: ttrpc server failure")
178178
}

cmd/containerd-shim/shim_darwin.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
"os"
2323
"os/signal"
2424

25-
"github.com/containerd/containerd/runtime/shim"
25+
"github.com/containerd/containerd/runtime/v1/shim"
2626
runc "github.com/containerd/go-runc"
2727
"github.com/containerd/ttrpc"
2828
)

0 commit comments

Comments
 (0)