Runtime v2

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
Michael Crosby
2018-07-09 13:27:52 -04:00
parent 6de11ab973
commit da1b5470cd
78 changed files with 9836 additions and 652 deletions

View File

@@ -0,0 +1,36 @@
// +build linux
/*
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 main
import (
"fmt"
"os"
"github.com/containerd/containerd/runtime/v2/runc"
"github.com/containerd/containerd/runtime/v2/shim"
"github.com/sirupsen/logrus"
)
func main() {
if err := shim.Run(runc.New); err != nil {
logrus.WithError(err).Error("shim run")
fmt.Fprintf(os.Stderr, "containerd-shim-run-v1: %s\n", err)
os.Exit(1)
}
}

View File

@@ -36,9 +36,9 @@ import (
"github.com/containerd/containerd/events"
"github.com/containerd/containerd/namespaces"
"github.com/containerd/containerd/runtime/linux/proc"
"github.com/containerd/containerd/runtime/shim"
shimapi "github.com/containerd/containerd/runtime/shim/v1"
"github.com/containerd/containerd/runtime/v1/linux/proc"
"github.com/containerd/containerd/runtime/v1/shim"
shimapi "github.com/containerd/containerd/runtime/v1/shim/v1"
"github.com/containerd/ttrpc"
"github.com/containerd/typeurl"
ptypes "github.com/gogo/protobuf/types"
@@ -134,7 +134,7 @@ func executeShim() error {
shimapi.RegisterShimService(server, sv)
socket := socketFlag
if err := serve(server, socket); err != nil {
if err := serve(context.Background(), server, socket); err != nil {
return err
}
logger := logrus.WithFields(logrus.Fields{
@@ -152,7 +152,7 @@ func executeShim() error {
// serve serves the ttrpc API over a unix socket at the provided path
// this function does not block
func serve(server *ttrpc.Server, path string) error {
func serve(ctx context.Context, server *ttrpc.Server, path string) error {
var (
l net.Listener
err error
@@ -172,7 +172,7 @@ func serve(server *ttrpc.Server, path string) error {
logrus.WithField("socket", path).Debug("serving api on unix socket")
go func() {
defer l.Close()
if err := server.Serve(context.Background(), l); err != nil &&
if err := server.Serve(ctx, l); err != nil &&
!strings.Contains(err.Error(), "use of closed network connection") {
logrus.WithError(err).Fatal("containerd-shim: ttrpc server failure")
}

View File

@@ -22,7 +22,7 @@ import (
"os"
"os/signal"
"github.com/containerd/containerd/runtime/shim"
"github.com/containerd/containerd/runtime/v1/shim"
runc "github.com/containerd/go-runc"
"github.com/containerd/ttrpc"
)

View File

@@ -20,7 +20,7 @@ import (
"os"
"os/signal"
"github.com/containerd/containerd/runtime/shim"
"github.com/containerd/containerd/runtime/v1/shim"
runc "github.com/containerd/go-runc"
"github.com/containerd/ttrpc"
"github.com/opencontainers/runc/libcontainer/system"

View File

@@ -22,7 +22,7 @@ import (
"os"
"os/signal"
"github.com/containerd/containerd/runtime/shim"
"github.com/containerd/containerd/runtime/v1/shim"
runc "github.com/containerd/go-runc"
"github.com/containerd/ttrpc"
)

View File

@@ -19,7 +19,8 @@ package main
import (
_ "github.com/containerd/aufs"
_ "github.com/containerd/containerd/metrics/cgroups"
_ "github.com/containerd/containerd/runtime/linux"
_ "github.com/containerd/containerd/runtime/v1/linux"
_ "github.com/containerd/containerd/runtime/v2"
_ "github.com/containerd/containerd/snapshots/native"
_ "github.com/containerd/containerd/snapshots/overlay"
_ "github.com/containerd/zfs"

View File

@@ -105,7 +105,7 @@ var (
},
cli.StringFlag{
Name: "runtime",
Usage: "runtime name (io.containerd.runtime.v1.linux, io.containerd.runtime.v1.windows, io.containerd.runtime.v1.com.vmware.linux)",
Usage: "runtime name",
Value: fmt.Sprintf("io.containerd.runtime.v1.%s", runtime.GOOS),
},
cli.BoolFlag{

View File

@@ -26,7 +26,7 @@ import (
"github.com/containerd/console"
"github.com/containerd/containerd/cmd/ctr/commands"
shim "github.com/containerd/containerd/runtime/shim/v1"
"github.com/containerd/containerd/runtime/v2/task"
"github.com/containerd/ttrpc"
"github.com/containerd/typeurl"
ptypes "github.com/gogo/protobuf/types"
@@ -36,8 +36,6 @@ import (
"github.com/urfave/cli"
)
var empty = &ptypes.Empty{}
var fifoFlags = []cli.Flag{
cli.StringFlag{
Name: "stdin",
@@ -57,7 +55,7 @@ var fifoFlags = []cli.Flag{
},
}
// Command is the cli command for interacting with a shim
// Command is the cli command for interacting with a task
var Command = cli.Command{
Name: "shim",
Usage: "interact with a shim directly",
@@ -77,13 +75,13 @@ var Command = cli.Command{
var startCommand = cli.Command{
Name: "start",
Usage: "start a container with a shim",
Usage: "start a container with a task",
Action: func(context *cli.Context) error {
service, err := getShimService(context)
service, err := getTaskService(context)
if err != nil {
return err
}
_, err = service.Start(gocontext.Background(), &shim.StartRequest{
_, err = service.Start(gocontext.Background(), &task.StartRequest{
ID: context.Args().First(),
})
return err
@@ -92,13 +90,15 @@ var startCommand = cli.Command{
var deleteCommand = cli.Command{
Name: "delete",
Usage: "delete a container with a shim",
Usage: "delete a container with a task",
Action: func(context *cli.Context) error {
service, err := getShimService(context)
service, err := getTaskService(context)
if err != nil {
return err
}
r, err := service.Delete(gocontext.Background(), empty)
r, err := service.Delete(gocontext.Background(), &task.DeleteRequest{
ID: context.Args().First(),
})
if err != nil {
return err
}
@@ -109,13 +109,13 @@ var deleteCommand = cli.Command{
var stateCommand = cli.Command{
Name: "state",
Usage: "get the state of all the processes of the shim",
Usage: "get the state of all the processes of the task",
Action: func(context *cli.Context) error {
service, err := getShimService(context)
service, err := getTaskService(context)
if err != nil {
return err
}
r, err := service.State(gocontext.Background(), &shim.StateRequest{
r, err := service.State(gocontext.Background(), &task.StateRequest{
ID: context.Args().First(),
})
if err != nil {
@@ -128,7 +128,7 @@ var stateCommand = cli.Command{
var execCommand = cli.Command{
Name: "exec",
Usage: "exec a new process in the shim's container",
Usage: "exec a new process in the task's container",
Flags: append(fifoFlags,
cli.BoolFlag{
Name: "attach,a",
@@ -149,7 +149,7 @@ var execCommand = cli.Command{
},
),
Action: func(context *cli.Context) error {
service, err := getShimService(context)
service, err := getTaskService(context)
if err != nil {
return err
}
@@ -178,7 +178,7 @@ var execCommand = cli.Command{
return err
}
rq := &shim.ExecProcessRequest{
rq := &task.ExecProcessRequest{
ID: id,
Spec: &ptypes.Any{
TypeUrl: url,
@@ -192,7 +192,7 @@ var execCommand = cli.Command{
if _, err := service.Exec(ctx, rq); err != nil {
return err
}
r, err := service.Start(ctx, &shim.StartRequest{
r, err := service.Start(ctx, &task.StartRequest{
ID: id,
})
if err != nil {
@@ -211,7 +211,7 @@ var execCommand = cli.Command{
if err != nil {
return err
}
if _, err := service.ResizePty(ctx, &shim.ResizePtyRequest{
if _, err := service.ResizePty(ctx, &task.ResizePtyRequest{
ID: id,
Width: uint32(size.Width),
Height: uint32(size.Height),
@@ -225,7 +225,7 @@ var execCommand = cli.Command{
},
}
func getShimService(context *cli.Context) (shim.ShimService, error) {
func getTaskService(context *cli.Context) (task.TaskService, error) {
bindSocket := context.GlobalString("socket")
if bindSocket == "" {
return nil, errors.New("socket path must be specified")
@@ -241,5 +241,5 @@ func getShimService(context *cli.Context) (shim.ShimService, error) {
// TODO(stevvooe): This actually leaks the connection. We were leaking it
// before, so may not be a huge deal.
return shim.NewShimClient(client), nil
return task.NewTaskClient(client), nil
}

View File

@@ -18,9 +18,12 @@ package tasks
import (
"fmt"
"runtime"
"github.com/containerd/containerd"
"github.com/containerd/containerd/cmd/ctr/commands"
"github.com/containerd/containerd/runtime/linux/runctypes"
"github.com/containerd/containerd/runtime/v2/runc/options"
"github.com/pkg/errors"
"github.com/urfave/cli"
)
@@ -34,6 +37,11 @@ var checkpointCommand = cli.Command{
Name: "exit",
Usage: "stop the container after the checkpoint",
},
cli.StringFlag{
Name: "runtime",
Usage: "runtime name",
Value: fmt.Sprintf("io.containerd.runtime.v1.%s", runtime.GOOS),
},
},
Action: func(context *cli.Context) error {
id := context.Args().First()
@@ -55,7 +63,7 @@ var checkpointCommand = cli.Command{
}
var opts []containerd.CheckpointTaskOpts
if context.Bool("exit") {
opts = append(opts, containerd.WithExit)
opts = append(opts, withExit(context.String("runtime")))
}
checkpoint, err := task.Checkpoint(ctx, opts...)
if err != nil {
@@ -65,3 +73,19 @@ var checkpointCommand = cli.Command{
return nil
},
}
func withExit(rt string) containerd.CheckpointTaskOpts {
return func(r *containerd.CheckpointTaskInfo) error {
switch rt {
case "io.containerd.runc.v1":
r.Options = &options.CheckpointOptions{
Exit: true,
}
default:
r.Options = &runctypes.CheckpointOptions{
Exit: true,
}
}
return nil
}
}