Skip to content

Commit 5421f08

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 5421f08

File tree

124 files changed

+8284
-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

+8284
-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(ctx 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: 17 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>
@@ -24,43 +25,44 @@ 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.`,
2627
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`,
28+
&cli.StringFlag{
29+
Name: "bundle",
30+
Aliases: []string{"b"},
31+
Value: "",
32+
Usage: `path to the root of the bundle directory, defaults to the current directory`,
3133
},
32-
cli.StringFlag{
34+
&cli.StringFlag{
3335
Name: "console-socket",
3436
Value: "",
3537
Usage: "path to an AF_UNIX socket which will receive a file descriptor referencing the master end of the console's pseudoterminal",
3638
},
37-
cli.StringFlag{
39+
&cli.StringFlag{
3840
Name: "pidfd-socket",
3941
Usage: "path to an AF_UNIX socket which will receive a file descriptor referencing the init process",
4042
},
41-
cli.StringFlag{
43+
&cli.StringFlag{
4244
Name: "pid-file",
4345
Value: "",
4446
Usage: "specify the file to write the process id to",
4547
},
46-
cli.BoolFlag{
48+
&cli.BoolFlag{
4749
Name: "no-pivot",
4850
Usage: "do not use pivot root to jail process inside rootfs. This should be used whenever the rootfs is on top of a ramdisk",
4951
},
50-
cli.BoolFlag{
52+
&cli.BoolFlag{
5153
Name: "no-new-keyring",
5254
Usage: "do not create a new session keyring for the container. This will cause the container to inherit the calling processes session key",
5355
},
54-
cli.IntFlag{
56+
&cli.IntFlag{
5557
Name: "preserve-fds",
5658
Usage: "Pass N additional file descriptors to the container (stdio + $LISTEN_FDS + N in total)",
5759
},
5860
},
59-
Action: func(context *cli.Context) error {
60-
if err := checkArgs(context, 1, exactArgs); err != nil {
61+
Action: func(ctx context.Context, cmd *cli.Command) error {
62+
if err := checkArgs(cmd, 1, exactArgs); err != nil {
6163
return err
6264
}
63-
status, err := startContainer(context, CT_ACT_CREATE, nil)
65+
status, err := startContainer(cmd, CT_ACT_CREATE, nil)
6466
if err == nil {
6567
// exit with the container's exit status so any external supervisor
6668
// is notified of the exit with the correct exit status.

delete.go

Lines changed: 13 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>
@@ -38,24 +39,25 @@ status of "ubuntu01" as "stopped" the following will delete resources held for
3839
3940
# runc delete ubuntu01`,
4041
Flags: []cli.Flag{
41-
cli.BoolFlag{
42-
Name: "force, f",
43-
Usage: "Forcibly deletes the container if it is still running (uses SIGKILL)",
42+
&cli.BoolFlag{
43+
Name: "force",
44+
Aliases: []string{"f"},
45+
Usage: "Forcibly deletes the container if it is still running (uses SIGKILL)",
4446
},
4547
},
46-
Action: func(context *cli.Context) error {
47-
if err := checkArgs(context, 1, exactArgs); err != nil {
48+
Action: func(ctx context.Context, cmd *cli.Command) error {
49+
if err := checkArgs(cmd, 1, exactArgs); err != nil {
4850
return err
4951
}
5052

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

events.go

Lines changed: 11 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,10 +15,10 @@ 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>
@@ -26,18 +27,18 @@ 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.`,
2829
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"},
30+
&cli.DurationFlag{Name: "interval", Value: 5 * time.Second, Usage: "set the stats collection interval"},
31+
&cli.BoolFlag{Name: "stats", Usage: "display the container's stats then exit"},
3132
},
32-
Action: func(context *cli.Context) error {
33-
if err := checkArgs(context, 1, exactArgs); err != nil {
33+
Action: func(ctx context.Context, cmd *cli.Command) error {
34+
if err := checkArgs(cmd, 1, exactArgs); err != nil {
3435
return err
3536
}
36-
container, err := getContainer(context)
37+
container, err := getContainer(cmd)
3738
if err != nil {
3839
return err
3940
}
40-
duration := context.Duration("interval")
41+
duration := cmd.Duration("interval")
4142
if duration <= 0 {
4243
return errors.New("duration interval must be greater than 0")
4344
}
@@ -63,7 +64,7 @@ information is displayed once every 5 seconds.`,
6364
}
6465
}
6566
}()
66-
if context.Bool("stats") {
67+
if cmd.Bool("stats") {
6768
s, err := container.Stats()
6869
if err != nil {
6970
return err
@@ -74,7 +75,7 @@ information is displayed once every 5 seconds.`,
7475
return nil
7576
}
7677
go func() {
77-
for range time.Tick(context.Duration("interval")) {
78+
for range time.Tick(cmd.Duration("interval")) {
7879
s, err := container.Stats()
7980
if err != nil {
8081
logrus.Error(err)

0 commit comments

Comments
 (0)