Remove urfave cli dep from shim
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
parent
a70b95b202
commit
13c7c3ef10
@ -4,6 +4,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
@ -20,12 +21,10 @@ import (
|
|||||||
"github.com/containerd/containerd/linux/shim"
|
"github.com/containerd/containerd/linux/shim"
|
||||||
shimapi "github.com/containerd/containerd/linux/shim/v1"
|
shimapi "github.com/containerd/containerd/linux/shim/v1"
|
||||||
"github.com/containerd/containerd/reaper"
|
"github.com/containerd/containerd/reaper"
|
||||||
"github.com/containerd/containerd/version"
|
|
||||||
"github.com/containerd/typeurl"
|
"github.com/containerd/typeurl"
|
||||||
google_protobuf "github.com/golang/protobuf/ptypes/empty"
|
google_protobuf "github.com/golang/protobuf/ptypes/empty"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
"github.com/urfave/cli"
|
|
||||||
"golang.org/x/sys/unix"
|
"golang.org/x/sys/unix"
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
)
|
)
|
||||||
@ -40,53 +39,40 @@ const usage = `
|
|||||||
shim for container lifecycle and reconnection
|
shim for container lifecycle and reconnection
|
||||||
`
|
`
|
||||||
|
|
||||||
func main() {
|
var (
|
||||||
app := cli.NewApp()
|
debugFlag bool
|
||||||
app.Name = "containerd-shim"
|
namespaceFlag string
|
||||||
app.Version = version.Version
|
socketFlag string
|
||||||
app.Usage = usage
|
addressFlag string
|
||||||
app.Flags = []cli.Flag{
|
workdirFlag string
|
||||||
cli.BoolFlag{
|
runtimeRootFlag string
|
||||||
Name: "debug",
|
criuFlag string
|
||||||
Usage: "enable debug output in logs",
|
systemdCgroupFlag bool
|
||||||
},
|
)
|
||||||
cli.StringFlag{
|
|
||||||
Name: "namespace,n",
|
func init() {
|
||||||
Usage: "namespace that owns the task",
|
flag.BoolVar(&debugFlag, "debug", false, "enable debug output in logs")
|
||||||
},
|
flag.StringVar(&namespaceFlag, "namespace", "", "namespace that owns the shim")
|
||||||
cli.StringFlag{
|
flag.StringVar(&socketFlag, "socket", "", "abstract socket path to serve")
|
||||||
Name: "socket,s",
|
flag.StringVar(&addressFlag, "address", "", "grpc address back to main containerd")
|
||||||
Usage: "abstract socket path to serve on",
|
flag.StringVar(&workdirFlag, "workdir", "", "path used to storge large temporary data")
|
||||||
},
|
flag.StringVar(&runtimeRootFlag, "runtime-root", shim.RuncRoot, "root directory for the runtime")
|
||||||
cli.StringFlag{
|
flag.StringVar(&criuFlag, "criu", "", "path to criu binary")
|
||||||
Name: "address,a",
|
flag.BoolVar(&systemdCgroupFlag, "systemd-cgroup", false, "set runtime to use systemd-cgroup")
|
||||||
Usage: "grpc address back to containerd",
|
flag.Parse()
|
||||||
},
|
|
||||||
cli.StringFlag{
|
|
||||||
Name: "workdir,w",
|
|
||||||
Usage: "path used to store large temporary data",
|
|
||||||
},
|
|
||||||
cli.StringFlag{
|
|
||||||
Name: "runtime-root",
|
|
||||||
Usage: "root directory for the runtime",
|
|
||||||
Value: shim.RuncRoot,
|
|
||||||
},
|
|
||||||
cli.StringFlag{
|
|
||||||
Name: "criu,c",
|
|
||||||
Usage: "path to criu",
|
|
||||||
},
|
|
||||||
cli.BoolFlag{
|
|
||||||
Name: "systemd-cgroup",
|
|
||||||
Usage: "set runtime to use systemd-cgroup",
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
app.Before = func(context *cli.Context) error {
|
|
||||||
if context.GlobalBool("debug") {
|
func main() {
|
||||||
|
if debugFlag {
|
||||||
logrus.SetLevel(logrus.DebugLevel)
|
logrus.SetLevel(logrus.DebugLevel)
|
||||||
}
|
}
|
||||||
return nil
|
if err := executeShim(); err != nil {
|
||||||
|
fmt.Fprintf(os.Stderr, "containerd-shim: %s\n", err)
|
||||||
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
app.Action = func(context *cli.Context) error {
|
}
|
||||||
|
|
||||||
|
func executeShim() error {
|
||||||
// start handling signals as soon as possible so that things are properly reaped
|
// start handling signals as soon as possible so that things are properly reaped
|
||||||
// or if runtime exits before we hit the handler
|
// or if runtime exits before we hit the handler
|
||||||
signals, err := setupSignals()
|
signals, err := setupSignals()
|
||||||
@ -98,18 +84,18 @@ func main() {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
server := newServer()
|
server := newServer()
|
||||||
e, err := connectEvents(context.GlobalString("address"))
|
e, err := connectEvents(addressFlag)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
sv, err := shim.NewService(
|
sv, err := shim.NewService(
|
||||||
shim.Config{
|
shim.Config{
|
||||||
Path: path,
|
Path: path,
|
||||||
Namespace: context.GlobalString("namespace"),
|
Namespace: namespaceFlag,
|
||||||
WorkDir: context.GlobalString("workdir"),
|
WorkDir: workdirFlag,
|
||||||
Criu: context.GlobalString("criu"),
|
Criu: criuFlag,
|
||||||
SystemdCgroup: context.GlobalBool("systemd-cgroup"),
|
SystemdCgroup: systemdCgroupFlag,
|
||||||
RuntimeRoot: context.GlobalString("runtime-root"),
|
RuntimeRoot: runtimeRootFlag,
|
||||||
},
|
},
|
||||||
&remoteEventsPublisher{client: e},
|
&remoteEventsPublisher{client: e},
|
||||||
)
|
)
|
||||||
@ -118,22 +104,17 @@ func main() {
|
|||||||
}
|
}
|
||||||
logrus.Debug("registering grpc server")
|
logrus.Debug("registering grpc server")
|
||||||
shimapi.RegisterShimServer(server, sv)
|
shimapi.RegisterShimServer(server, sv)
|
||||||
socket := context.GlobalString("socket")
|
socket := socketFlag
|
||||||
if err := serve(server, socket); err != nil {
|
if err := serve(server, socket); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
logger := logrus.WithFields(logrus.Fields{
|
logger := logrus.WithFields(logrus.Fields{
|
||||||
"pid": os.Getpid(),
|
"pid": os.Getpid(),
|
||||||
"path": path,
|
"path": path,
|
||||||
"namespace": context.GlobalString("namespace"),
|
"namespace": namespaceFlag,
|
||||||
})
|
})
|
||||||
return handleSignals(logger, signals, server, sv)
|
return handleSignals(logger, signals, server, sv)
|
||||||
}
|
}
|
||||||
if err := app.Run(os.Args); err != nil {
|
|
||||||
fmt.Fprintf(os.Stderr, "containerd-shim: %s\n", err)
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// serve serves the grpc API over a unix socket at the provided path
|
// serve serves the grpc API over a unix socket at the provided path
|
||||||
// this function does not block
|
// this function does not block
|
||||||
|
@ -86,22 +86,22 @@ func WithStart(binary, address, daemonAddress, cgroup string, nonewns, debug boo
|
|||||||
|
|
||||||
func newCommand(binary, daemonAddress string, nonewns, debug bool, config Config, socket *os.File) *exec.Cmd {
|
func newCommand(binary, daemonAddress string, nonewns, debug bool, config Config, socket *os.File) *exec.Cmd {
|
||||||
args := []string{
|
args := []string{
|
||||||
"--namespace", config.Namespace,
|
"-namespace", config.Namespace,
|
||||||
"--workdir", config.WorkDir,
|
"-workdir", config.WorkDir,
|
||||||
"--address", daemonAddress,
|
"-address", daemonAddress,
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.Criu != "" {
|
if config.Criu != "" {
|
||||||
args = append(args, "--criu-path", config.Criu)
|
args = append(args, "-criu-path", config.Criu)
|
||||||
}
|
}
|
||||||
if config.RuntimeRoot != "" {
|
if config.RuntimeRoot != "" {
|
||||||
args = append(args, "--runtime-root", config.RuntimeRoot)
|
args = append(args, "-runtime-root", config.RuntimeRoot)
|
||||||
}
|
}
|
||||||
if config.SystemdCgroup {
|
if config.SystemdCgroup {
|
||||||
args = append(args, "--systemd-cgroup")
|
args = append(args, "-systemd-cgroup")
|
||||||
}
|
}
|
||||||
if debug {
|
if debug {
|
||||||
args = append(args, "--debug")
|
args = append(args, "-debug")
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd := exec.Command(binary, args...)
|
cmd := exec.Command(binary, args...)
|
||||||
|
Loading…
Reference in New Issue
Block a user