Skip to content

Commit 6106733

Browse files
committed
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>
1 parent 348c766 commit 6106733

File tree

124 files changed

+8317
-13735
lines changed

Some content is hidden

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

124 files changed

+8317
-13735
lines changed

checkpoint.go

Lines changed: 47 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package main
22

33
import (
4+
"context"
45
"errors"
56
"fmt"
67
"net"
@@ -11,13 +12,13 @@ import (
1112
"github.com/moby/sys/userns"
1213
"github.com/opencontainers/runtime-spec/specs-go"
1314
"github.com/sirupsen/logrus"
14-
"github.com/urfave/cli"
15+
"github.com/urfave/cli/v3"
1516
"golang.org/x/sys/unix"
1617

1718
"github.com/opencontainers/runc/libcontainer"
1819
)
1920

20-
var checkpointCommand = cli.Command{
21+
var checkpointCommand = &cli.Command{
2122
Name: "checkpoint",
2223
Usage: "checkpoint a running container",
2324
ArgsUsage: `<container-id>
@@ -26,34 +27,34 @@ Where "<container-id>" is the name for the instance of the container to be
2627
checkpointed.`,
2728
Description: `The checkpoint command saves the state of the container instance.`,
2829
Flags: []cli.Flag{
29-
cli.StringFlag{Name: "image-path", Value: "", Usage: "path for saving criu image files"},
30-
cli.StringFlag{Name: "work-path", Value: "", Usage: "path for saving work files and logs"},
31-
cli.StringFlag{Name: "parent-path", Value: "", Usage: "path for previous criu image files in pre-dump"},
32-
cli.BoolFlag{Name: "leave-running", Usage: "leave the process running after checkpointing"},
33-
cli.BoolFlag{Name: "tcp-established", Usage: "allow open tcp connections"},
34-
cli.BoolFlag{Name: "tcp-skip-in-flight", Usage: "skip in-flight tcp connections"},
35-
cli.BoolFlag{Name: "link-remap", Usage: "allow one to link unlinked files back when possible"},
36-
cli.BoolFlag{Name: "ext-unix-sk", Usage: "allow external unix sockets"},
37-
cli.BoolFlag{Name: "shell-job", Usage: "allow shell jobs"},
38-
cli.BoolFlag{Name: "lazy-pages", Usage: "use userfaultfd to lazily restore memory pages"},
39-
cli.IntFlag{Name: "status-fd", Value: -1, Usage: "criu writes \\0 to this FD once lazy-pages is ready"},
40-
cli.StringFlag{Name: "page-server", Value: "", Usage: "ADDRESS:PORT of the page server"},
41-
cli.BoolFlag{Name: "file-locks", Usage: "handle file locks, for safety"},
42-
cli.BoolFlag{Name: "pre-dump", Usage: "dump container's memory information only, leave the container running after this"},
43-
cli.StringFlag{Name: "manage-cgroups-mode", Value: "", Usage: "cgroups mode: soft|full|strict|ignore (default: soft)"},
44-
cli.StringSliceFlag{Name: "empty-ns", Usage: "create a namespace, but don't restore its properties"},
45-
cli.BoolFlag{Name: "auto-dedup", Usage: "enable auto deduplication of memory images"},
30+
&cli.StringFlag{Name: "image-path", Value: "", Usage: "path for saving criu image files"},
31+
&cli.StringFlag{Name: "work-path", Value: "", Usage: "path for saving work files and logs"},
32+
&cli.StringFlag{Name: "parent-path", Value: "", Usage: "path for previous criu image files in pre-dump"},
33+
&cli.BoolFlag{Name: "leave-running", Usage: "leave the process running after checkpointing"},
34+
&cli.BoolFlag{Name: "tcp-established", Usage: "allow open tcp connections"},
35+
&cli.BoolFlag{Name: "tcp-skip-in-flight", Usage: "skip in-flight tcp connections"},
36+
&cli.BoolFlag{Name: "link-remap", Usage: "allow one to link unlinked files back when possible"},
37+
&cli.BoolFlag{Name: "ext-unix-sk", Usage: "allow external unix sockets"},
38+
&cli.BoolFlag{Name: "shell-job", Usage: "allow shell jobs"},
39+
&cli.BoolFlag{Name: "lazy-pages", Usage: "use userfaultfd to lazily restore memory pages"},
40+
&cli.IntFlag{Name: "status-fd", Value: -1, Usage: "criu writes \\0 to this FD once lazy-pages is ready"},
41+
&cli.StringFlag{Name: "page-server", Value: "", Usage: "ADDRESS:PORT of the page server"},
42+
&cli.BoolFlag{Name: "file-locks", Usage: "handle file locks, for safety"},
43+
&cli.BoolFlag{Name: "pre-dump", Usage: "dump container's memory information only, leave the container running after this"},
44+
&cli.StringFlag{Name: "manage-cgroups-mode", Value: "", Usage: "cgroups mode: soft|full|strict|ignore (default: soft)"},
45+
&cli.StringSliceFlag{Name: "empty-ns", Usage: "create a namespace, but don't restore its properties"},
46+
&cli.BoolFlag{Name: "auto-dedup", Usage: "enable auto deduplication of memory images"},
4647
},
47-
Action: func(context *cli.Context) error {
48-
if err := checkArgs(context, 1, exactArgs); err != nil {
48+
Action: func(_ context.Context, cmd *cli.Command) error {
49+
if err := checkArgs(cmd, 1, exactArgs); err != nil {
4950
return err
5051
}
5152
// XXX: Currently this is untested with rootless containers.
5253
if os.Geteuid() != 0 || userns.RunningInUserNS() {
5354
logrus.Warn("runc checkpoint is untested with rootless containers")
5455
}
5556

56-
container, err := getContainer(context)
57+
container, err := getContainer(cmd)
5758
if err != nil {
5859
return err
5960
}
@@ -64,7 +65,7 @@ checkpointed.`,
6465
if status == libcontainer.Created || status == libcontainer.Stopped {
6566
return fmt.Errorf("Container cannot be checkpointed in %s state", status.String())
6667
}
67-
options, err := criuOptions(context)
68+
options, err := criuOptions(cmd)
6869
if err != nil {
6970
return err
7071
}
@@ -80,8 +81,8 @@ checkpointed.`,
8081
},
8182
}
8283

83-
func prepareImagePaths(context *cli.Context) (string, string, error) {
84-
imagePath := context.String("image-path")
84+
func prepareImagePaths(cmd *cli.Command) (string, string, error) {
85+
imagePath := cmd.String("image-path")
8586
if imagePath == "" {
8687
imagePath = getDefaultImagePath()
8788
}
@@ -90,7 +91,7 @@ func prepareImagePaths(context *cli.Context) (string, string, error) {
9091
return "", "", err
9192
}
9293

93-
parentPath := context.String("parent-path")
94+
parentPath := cmd.String("parent-path")
9495
if parentPath == "" {
9596
return imagePath, parentPath, nil
9697
}
@@ -112,35 +113,35 @@ func prepareImagePaths(context *cli.Context) (string, string, error) {
112113
return imagePath, parentPath, nil
113114
}
114115

115-
func criuOptions(context *cli.Context) (*libcontainer.CriuOpts, error) {
116-
imagePath, parentPath, err := prepareImagePaths(context)
116+
func criuOptions(cmd *cli.Command) (*libcontainer.CriuOpts, error) {
117+
imagePath, parentPath, err := prepareImagePaths(cmd)
117118
if err != nil {
118119
return nil, err
119120
}
120121

121122
opts := &libcontainer.CriuOpts{
122123
ImagesDirectory: imagePath,
123-
WorkDirectory: context.String("work-path"),
124+
WorkDirectory: cmd.String("work-path"),
124125
ParentImage: parentPath,
125-
LeaveRunning: context.Bool("leave-running"),
126-
TcpEstablished: context.Bool("tcp-established"),
127-
TcpSkipInFlight: context.Bool("tcp-skip-in-flight"),
128-
LinkRemap: context.Bool("link-remap"),
129-
ExternalUnixConnections: context.Bool("ext-unix-sk"),
130-
ShellJob: context.Bool("shell-job"),
131-
FileLocks: context.Bool("file-locks"),
132-
PreDump: context.Bool("pre-dump"),
133-
AutoDedup: context.Bool("auto-dedup"),
134-
LazyPages: context.Bool("lazy-pages"),
135-
StatusFd: context.Int("status-fd"),
136-
LsmProfile: context.String("lsm-profile"),
137-
LsmMountContext: context.String("lsm-mount-context"),
138-
ManageCgroupsMode: context.String("manage-cgroups-mode"),
126+
LeaveRunning: cmd.Bool("leave-running"),
127+
TcpEstablished: cmd.Bool("tcp-established"),
128+
TcpSkipInFlight: cmd.Bool("tcp-skip-in-flight"),
129+
LinkRemap: cmd.Bool("link-remap"),
130+
ExternalUnixConnections: cmd.Bool("ext-unix-sk"),
131+
ShellJob: cmd.Bool("shell-job"),
132+
FileLocks: cmd.Bool("file-locks"),
133+
PreDump: cmd.Bool("pre-dump"),
134+
AutoDedup: cmd.Bool("auto-dedup"),
135+
LazyPages: cmd.Bool("lazy-pages"),
136+
StatusFd: cmd.Int("status-fd"),
137+
LsmProfile: cmd.String("lsm-profile"),
138+
LsmMountContext: cmd.String("lsm-mount-context"),
139+
ManageCgroupsMode: cmd.String("manage-cgroups-mode"),
139140
}
140141

141142
// CRIU options below may or may not be set.
142143

143-
if psOpt := context.String("page-server"); psOpt != "" {
144+
if psOpt := cmd.String("page-server"); psOpt != "" {
144145
address, port, err := net.SplitHostPort(psOpt)
145146

146147
if err != nil || address == "" || port == "" {
@@ -159,12 +160,12 @@ func criuOptions(context *cli.Context) (*libcontainer.CriuOpts, error) {
159160
// runc doesn't manage network devices and their configuration.
160161
nsmask := unix.CLONE_NEWNET
161162

162-
if context.IsSet("empty-ns") {
163+
if cmd.IsSet("empty-ns") {
163164
namespaceMapping := map[specs.LinuxNamespaceType]int{
164165
specs.NetworkNamespace: unix.CLONE_NEWNET,
165166
}
166167

167-
for _, ns := range context.StringSlice("empty-ns") {
168+
for _, ns := range cmd.StringSlice("empty-ns") {
168169
f, exists := namespaceMapping[specs.LinuxNamespaceType(ns)]
169170
if !exists {
170171
return nil, fmt.Errorf("namespace %q is not supported", ns)

create.go

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
package main
22

33
import (
4+
"context"
45
"fmt"
56
"os"
67

7-
"github.com/urfave/cli"
8+
"github.com/urfave/cli/v3"
89
)
910

10-
var createCommand = cli.Command{
11+
var createCommand = &cli.Command{
1112
Name: "create",
1213
Usage: "create a container",
1314
ArgsUsage: `<container-id>
@@ -23,44 +24,47 @@ The specification file includes an args parameter. The args parameter is used
2324
to specify command(s) that get run when the container is started. To change the
2425
command(s) that get executed on start, edit the args parameter of the spec. See
2526
"runc spec --help" for more explanation.`,
27+
// Disable comma as separator for slice flags.
28+
DisableSliceFlagSeparator: true,
2629
Flags: []cli.Flag{
27-
cli.StringFlag{
28-
Name: "bundle, b",
29-
Value: "",
30-
Usage: `path to the root of the bundle directory, defaults to the current directory`,
30+
&cli.StringFlag{
31+
Name: "bundle",
32+
Aliases: []string{"b"},
33+
Value: "",
34+
Usage: `path to the root of the bundle directory, defaults to the current directory`,
3135
},
32-
cli.StringFlag{
36+
&cli.StringFlag{
3337
Name: "console-socket",
3438
Value: "",
3539
Usage: "path to an AF_UNIX socket which will receive a file descriptor referencing the master end of the console's pseudoterminal",
3640
},
37-
cli.StringFlag{
41+
&cli.StringFlag{
3842
Name: "pidfd-socket",
3943
Usage: "path to an AF_UNIX socket which will receive a file descriptor referencing the init process",
4044
},
41-
cli.StringFlag{
45+
&cli.StringFlag{
4246
Name: "pid-file",
4347
Value: "",
4448
Usage: "specify the file to write the process id to",
4549
},
46-
cli.BoolFlag{
50+
&cli.BoolFlag{
4751
Name: "no-pivot",
4852
Usage: "do not use pivot root to jail process inside rootfs. This should be used whenever the rootfs is on top of a ramdisk",
4953
},
50-
cli.BoolFlag{
54+
&cli.BoolFlag{
5155
Name: "no-new-keyring",
5256
Usage: "do not create a new session keyring for the container. This will cause the container to inherit the calling processes session key",
5357
},
54-
cli.IntFlag{
58+
&cli.IntFlag{
5559
Name: "preserve-fds",
5660
Usage: "Pass N additional file descriptors to the container (stdio + $LISTEN_FDS + N in total)",
5761
},
5862
},
59-
Action: func(context *cli.Context) error {
60-
if err := checkArgs(context, 1, exactArgs); err != nil {
63+
Action: func(_ context.Context, cmd *cli.Command) error {
64+
if err := checkArgs(cmd, 1, exactArgs); err != nil {
6165
return err
6266
}
63-
status, err := startContainer(context, CT_ACT_CREATE, nil)
67+
status, err := startContainer(cmd, CT_ACT_CREATE, nil)
6468
if err == nil {
6569
// exit with the container's exit status so any external supervisor
6670
// is notified of the exit with the correct exit status.

delete.go

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
package main
22

33
import (
4+
"context"
45
"errors"
56
"fmt"
67
"os"
78
"path/filepath"
89
"time"
910

1011
"github.com/opencontainers/runc/libcontainer"
11-
"github.com/urfave/cli"
12+
"github.com/urfave/cli/v3"
1213

1314
"golang.org/x/sys/unix"
1415
)
@@ -24,7 +25,7 @@ func killContainer(container *libcontainer.Container) error {
2425
return errors.New("container init still running")
2526
}
2627

27-
var deleteCommand = cli.Command{
28+
var deleteCommand = &cli.Command{
2829
Name: "delete",
2930
Usage: "delete any resources held by the container often used with detached container",
3031
ArgsUsage: `<container-id>
@@ -37,25 +38,28 @@ status of "ubuntu01" as "stopped" the following will delete resources held for
3738
"ubuntu01" removing "ubuntu01" from the runc list of containers:
3839
3940
# runc delete ubuntu01`,
41+
// Disable comma as separator for slice flags.
42+
DisableSliceFlagSeparator: true,
4043
Flags: []cli.Flag{
41-
cli.BoolFlag{
42-
Name: "force, f",
43-
Usage: "Forcibly deletes the container if it is still running (uses SIGKILL)",
44+
&cli.BoolFlag{
45+
Name: "force",
46+
Aliases: []string{"f"},
47+
Usage: "Forcibly deletes the container if it is still running (uses SIGKILL)",
4448
},
4549
},
46-
Action: func(context *cli.Context) error {
47-
if err := checkArgs(context, 1, exactArgs); err != nil {
50+
Action: func(_ context.Context, cmd *cli.Command) error {
51+
if err := checkArgs(cmd, 1, exactArgs); err != nil {
4852
return err
4953
}
5054

51-
id := context.Args().First()
52-
force := context.Bool("force")
53-
container, err := getContainer(context)
55+
id := cmd.Args().First()
56+
force := cmd.Bool("force")
57+
container, err := getContainer(cmd)
5458
if err != nil {
5559
if errors.Is(err, libcontainer.ErrNotExist) {
5660
// if there was an aborted start or something of the sort then the container's directory could exist but
5761
// libcontainer does not see it because the state.json file inside that directory was never created.
58-
path := filepath.Join(context.GlobalString("root"), id)
62+
path := filepath.Join(cmd.String("root"), id)
5963
if e := os.RemoveAll(path); e != nil {
6064
fmt.Fprintf(os.Stderr, "remove %s: %v\n", path, e)
6165
}

events.go

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package main
22

33
import (
4+
"context"
45
"encoding/json"
56
"errors"
67
"fmt"
@@ -14,30 +15,32 @@ import (
1415
"github.com/opencontainers/runc/types"
1516

1617
"github.com/sirupsen/logrus"
17-
"github.com/urfave/cli"
18+
"github.com/urfave/cli/v3"
1819
)
1920

20-
var eventsCommand = cli.Command{
21+
var eventsCommand = &cli.Command{
2122
Name: "events",
2223
Usage: "display container events such as OOM notifications, cpu, memory, and IO usage statistics",
2324
ArgsUsage: `<container-id>
2425
2526
Where "<container-id>" is the name for the instance of the container.`,
2627
Description: `The events command displays information about the container. By default the
2728
information is displayed once every 5 seconds.`,
29+
// Disable comma as separator for slice flags.
30+
DisableSliceFlagSeparator: true,
2831
Flags: []cli.Flag{
29-
cli.DurationFlag{Name: "interval", Value: 5 * time.Second, Usage: "set the stats collection interval"},
30-
cli.BoolFlag{Name: "stats", Usage: "display the container's stats then exit"},
32+
&cli.DurationFlag{Name: "interval", Value: 5 * time.Second, Usage: "set the stats collection interval"},
33+
&cli.BoolFlag{Name: "stats", Usage: "display the container's stats then exit"},
3134
},
32-
Action: func(context *cli.Context) error {
33-
if err := checkArgs(context, 1, exactArgs); err != nil {
35+
Action: func(_ context.Context, cmd *cli.Command) error {
36+
if err := checkArgs(cmd, 1, exactArgs); err != nil {
3437
return err
3538
}
36-
container, err := getContainer(context)
39+
container, err := getContainer(cmd)
3740
if err != nil {
3841
return err
3942
}
40-
duration := context.Duration("interval")
43+
duration := cmd.Duration("interval")
4144
if duration <= 0 {
4245
return errors.New("duration interval must be greater than 0")
4346
}
@@ -63,7 +66,7 @@ information is displayed once every 5 seconds.`,
6366
}
6467
}
6568
}()
66-
if context.Bool("stats") {
69+
if cmd.Bool("stats") {
6770
s, err := container.Stats()
6871
if err != nil {
6972
return err
@@ -74,7 +77,7 @@ information is displayed once every 5 seconds.`,
7477
return nil
7578
}
7679
go func() {
77-
for range time.Tick(context.Duration("interval")) {
80+
for range time.Tick(cmd.Duration("interval")) {
7881
s, err := container.Stats()
7982
if err != nil {
8083
logrus.Error(err)

0 commit comments

Comments
 (0)