mirror of
https://github.com/opencontainers/runc.git
synced 2026-07-10 21:53:57 +08:00
chore(deps): upgrade urfave/cli from v1 to v3
Migrate from urfave/cli v1 (maintenance mode) to v3 to benefit from active development, improved features, and long-term support. Signed-off-by: lifubang <lifubang@acmcoder.com>
This commit is contained in:
+49
-46
@@ -1,6 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
@@ -11,13 +12,13 @@ import (
|
||||
"github.com/moby/sys/userns"
|
||||
"github.com/opencontainers/runtime-spec/specs-go"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/urfave/cli"
|
||||
"github.com/urfave/cli/v3"
|
||||
"golang.org/x/sys/unix"
|
||||
|
||||
"github.com/opencontainers/runc/libcontainer"
|
||||
)
|
||||
|
||||
var checkpointCommand = cli.Command{
|
||||
var checkpointCommand = &cli.Command{
|
||||
Name: "checkpoint",
|
||||
Usage: "checkpoint a running container",
|
||||
ArgsUsage: `<container-id>
|
||||
@@ -25,27 +26,29 @@ var checkpointCommand = cli.Command{
|
||||
Where "<container-id>" is the name for the instance of the container to be
|
||||
checkpointed.`,
|
||||
Description: `The checkpoint command saves the state of the container instance.`,
|
||||
// Disable comma as separator for slice flags.
|
||||
DisableSliceFlagSeparator: true,
|
||||
Flags: []cli.Flag{
|
||||
cli.StringFlag{Name: "image-path", Value: "", Usage: "path for saving criu image files"},
|
||||
cli.StringFlag{Name: "work-path", Value: "", Usage: "path for saving work files and logs"},
|
||||
cli.StringFlag{Name: "parent-path", Value: "", Usage: "path for previous criu image files in pre-dump"},
|
||||
cli.BoolFlag{Name: "leave-running", Usage: "leave the process running after checkpointing"},
|
||||
cli.BoolFlag{Name: "tcp-established", Usage: "allow open tcp connections"},
|
||||
cli.BoolFlag{Name: "tcp-skip-in-flight", Usage: "skip in-flight tcp connections"},
|
||||
cli.BoolFlag{Name: "link-remap", Usage: "allow one to link unlinked files back when possible"},
|
||||
cli.BoolFlag{Name: "ext-unix-sk", Usage: "allow external unix sockets"},
|
||||
cli.BoolFlag{Name: "shell-job", Usage: "allow shell jobs"},
|
||||
cli.BoolFlag{Name: "lazy-pages", Usage: "use userfaultfd to lazily restore memory pages"},
|
||||
cli.IntFlag{Name: "status-fd", Value: -1, Usage: "criu writes \\0 to this FD once lazy-pages is ready"},
|
||||
cli.StringFlag{Name: "page-server", Value: "", Usage: "ADDRESS:PORT of the page server"},
|
||||
cli.BoolFlag{Name: "file-locks", Usage: "handle file locks, for safety"},
|
||||
cli.BoolFlag{Name: "pre-dump", Usage: "dump container's memory information only, leave the container running after this"},
|
||||
cli.StringFlag{Name: "manage-cgroups-mode", Value: "", Usage: "cgroups mode: soft|full|strict|ignore (default: soft)"},
|
||||
cli.StringSliceFlag{Name: "empty-ns", Usage: "create a namespace, but don't restore its properties"},
|
||||
cli.BoolFlag{Name: "auto-dedup", Usage: "enable auto deduplication of memory images"},
|
||||
&cli.StringFlag{Name: "image-path", Value: "", Usage: "path for saving criu image files"},
|
||||
&cli.StringFlag{Name: "work-path", Value: "", Usage: "path for saving work files and logs"},
|
||||
&cli.StringFlag{Name: "parent-path", Value: "", Usage: "path for previous criu image files in pre-dump"},
|
||||
&cli.BoolFlag{Name: "leave-running", Usage: "leave the process running after checkpointing"},
|
||||
&cli.BoolFlag{Name: "tcp-established", Usage: "allow open tcp connections"},
|
||||
&cli.BoolFlag{Name: "tcp-skip-in-flight", Usage: "skip in-flight tcp connections"},
|
||||
&cli.BoolFlag{Name: "link-remap", Usage: "allow one to link unlinked files back when possible"},
|
||||
&cli.BoolFlag{Name: "ext-unix-sk", Usage: "allow external unix sockets"},
|
||||
&cli.BoolFlag{Name: "shell-job", Usage: "allow shell jobs"},
|
||||
&cli.BoolFlag{Name: "lazy-pages", Usage: "use userfaultfd to lazily restore memory pages"},
|
||||
&cli.IntFlag{Name: "status-fd", Value: -1, Usage: "criu writes \\0 to this FD once lazy-pages is ready"},
|
||||
&cli.StringFlag{Name: "page-server", Value: "", Usage: "ADDRESS:PORT of the page server"},
|
||||
&cli.BoolFlag{Name: "file-locks", Usage: "handle file locks, for safety"},
|
||||
&cli.BoolFlag{Name: "pre-dump", Usage: "dump container's memory information only, leave the container running after this"},
|
||||
&cli.StringFlag{Name: "manage-cgroups-mode", Value: "", Usage: "cgroups mode: soft|full|strict|ignore (default: soft)"},
|
||||
&cli.StringSliceFlag{Name: "empty-ns", Usage: "create a namespace, but don't restore its properties"},
|
||||
&cli.BoolFlag{Name: "auto-dedup", Usage: "enable auto deduplication of memory images"},
|
||||
},
|
||||
Action: func(context *cli.Context) error {
|
||||
if err := checkArgs(context, 1, exactArgs); err != nil {
|
||||
Action: func(_ context.Context, cmd *cli.Command) error {
|
||||
if err := checkArgs(cmd, 1, exactArgs); err != nil {
|
||||
return err
|
||||
}
|
||||
// XXX: Currently this is untested with rootless containers.
|
||||
@@ -53,7 +56,7 @@ checkpointed.`,
|
||||
logrus.Warn("runc checkpoint is untested with rootless containers")
|
||||
}
|
||||
|
||||
container, err := getContainer(context)
|
||||
container, err := getContainer(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -64,7 +67,7 @@ checkpointed.`,
|
||||
if status == libcontainer.Created || status == libcontainer.Stopped {
|
||||
return fmt.Errorf("Container cannot be checkpointed in %s state", status.String())
|
||||
}
|
||||
options, err := criuOptions(context)
|
||||
options, err := criuOptions(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -80,8 +83,8 @@ checkpointed.`,
|
||||
},
|
||||
}
|
||||
|
||||
func prepareImagePaths(context *cli.Context) (string, string, error) {
|
||||
imagePath := context.String("image-path")
|
||||
func prepareImagePaths(cmd *cli.Command) (string, string, error) {
|
||||
imagePath := cmd.String("image-path")
|
||||
if imagePath == "" {
|
||||
imagePath = getDefaultImagePath()
|
||||
}
|
||||
@@ -90,7 +93,7 @@ func prepareImagePaths(context *cli.Context) (string, string, error) {
|
||||
return "", "", err
|
||||
}
|
||||
|
||||
parentPath := context.String("parent-path")
|
||||
parentPath := cmd.String("parent-path")
|
||||
if parentPath == "" {
|
||||
return imagePath, parentPath, nil
|
||||
}
|
||||
@@ -112,35 +115,35 @@ func prepareImagePaths(context *cli.Context) (string, string, error) {
|
||||
return imagePath, parentPath, nil
|
||||
}
|
||||
|
||||
func criuOptions(context *cli.Context) (*libcontainer.CriuOpts, error) {
|
||||
imagePath, parentPath, err := prepareImagePaths(context)
|
||||
func criuOptions(cmd *cli.Command) (*libcontainer.CriuOpts, error) {
|
||||
imagePath, parentPath, err := prepareImagePaths(cmd)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
opts := &libcontainer.CriuOpts{
|
||||
ImagesDirectory: imagePath,
|
||||
WorkDirectory: context.String("work-path"),
|
||||
WorkDirectory: cmd.String("work-path"),
|
||||
ParentImage: parentPath,
|
||||
LeaveRunning: context.Bool("leave-running"),
|
||||
TcpEstablished: context.Bool("tcp-established"),
|
||||
TcpSkipInFlight: context.Bool("tcp-skip-in-flight"),
|
||||
LinkRemap: context.Bool("link-remap"),
|
||||
ExternalUnixConnections: context.Bool("ext-unix-sk"),
|
||||
ShellJob: context.Bool("shell-job"),
|
||||
FileLocks: context.Bool("file-locks"),
|
||||
PreDump: context.Bool("pre-dump"),
|
||||
AutoDedup: context.Bool("auto-dedup"),
|
||||
LazyPages: context.Bool("lazy-pages"),
|
||||
StatusFd: context.Int("status-fd"),
|
||||
LsmProfile: context.String("lsm-profile"),
|
||||
LsmMountContext: context.String("lsm-mount-context"),
|
||||
ManageCgroupsMode: context.String("manage-cgroups-mode"),
|
||||
LeaveRunning: cmd.Bool("leave-running"),
|
||||
TcpEstablished: cmd.Bool("tcp-established"),
|
||||
TcpSkipInFlight: cmd.Bool("tcp-skip-in-flight"),
|
||||
LinkRemap: cmd.Bool("link-remap"),
|
||||
ExternalUnixConnections: cmd.Bool("ext-unix-sk"),
|
||||
ShellJob: cmd.Bool("shell-job"),
|
||||
FileLocks: cmd.Bool("file-locks"),
|
||||
PreDump: cmd.Bool("pre-dump"),
|
||||
AutoDedup: cmd.Bool("auto-dedup"),
|
||||
LazyPages: cmd.Bool("lazy-pages"),
|
||||
StatusFd: cmd.Int("status-fd"),
|
||||
LsmProfile: cmd.String("lsm-profile"),
|
||||
LsmMountContext: cmd.String("lsm-mount-context"),
|
||||
ManageCgroupsMode: cmd.String("manage-cgroups-mode"),
|
||||
}
|
||||
|
||||
// CRIU options below may or may not be set.
|
||||
|
||||
if psOpt := context.String("page-server"); psOpt != "" {
|
||||
if psOpt := cmd.String("page-server"); psOpt != "" {
|
||||
address, port, err := net.SplitHostPort(psOpt)
|
||||
|
||||
if err != nil || address == "" || port == "" {
|
||||
@@ -159,12 +162,12 @@ func criuOptions(context *cli.Context) (*libcontainer.CriuOpts, error) {
|
||||
// runc doesn't manage network devices and their configuration.
|
||||
nsmask := unix.CLONE_NEWNET
|
||||
|
||||
if context.IsSet("empty-ns") {
|
||||
if cmd.IsSet("empty-ns") {
|
||||
namespaceMapping := map[specs.LinuxNamespaceType]int{
|
||||
specs.NetworkNamespace: unix.CLONE_NEWNET,
|
||||
}
|
||||
|
||||
for _, ns := range context.StringSlice("empty-ns") {
|
||||
for _, ns := range cmd.StringSlice("empty-ns") {
|
||||
f, exists := namespaceMapping[specs.LinuxNamespaceType(ns)]
|
||||
if !exists {
|
||||
return nil, fmt.Errorf("namespace %q is not supported", ns)
|
||||
|
||||
Reference in New Issue
Block a user