Skip to content

Commit 1641c75

Browse files
authored
Merge pull request containerd#9809 from dereknola/urfave_v2
Migrate Urfave CLI from v1 to v2
2 parents 0f5586e + 132485a commit 1641c75

File tree

149 files changed

+11040
-4692
lines changed

Some content is hidden

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

149 files changed

+11040
-4692
lines changed

cmd/containerd-stress/density.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,14 @@ import (
3434
"github.com/containerd/containerd/v2/pkg/namespaces"
3535
"github.com/containerd/containerd/v2/pkg/oci"
3636
"github.com/containerd/log"
37-
"github.com/urfave/cli"
37+
"github.com/urfave/cli/v2"
3838
)
3939

40-
var densityCommand = cli.Command{
40+
var densityCommand = &cli.Command{
4141
Name: "density",
4242
Usage: "Stress tests density of containers running on a system",
4343
Flags: []cli.Flag{
44-
cli.IntFlag{
44+
&cli.IntFlag{
4545
Name: "count",
4646
Usage: "Number of containers to run",
4747
Value: 10,
@@ -58,14 +58,14 @@ var densityCommand = cli.Command{
5858
}
5959

6060
config := config{
61-
Address: cliContext.GlobalString("address"),
62-
Duration: cliContext.GlobalDuration("duration"),
63-
Concurrency: cliContext.GlobalInt("concurrent"),
64-
Exec: cliContext.GlobalBool("exec"),
65-
Image: cliContext.GlobalString("image"),
66-
JSON: cliContext.GlobalBool("json"),
67-
Metrics: cliContext.GlobalString("metrics"),
68-
Snapshotter: cliContext.GlobalString("snapshotter"),
61+
Address: cliContext.String("address"),
62+
Duration: cliContext.Duration("duration"),
63+
Concurrency: cliContext.Int("concurrent"),
64+
Exec: cliContext.Bool("exec"),
65+
Image: cliContext.String("image"),
66+
JSON: cliContext.Bool("json"),
67+
Metrics: cliContext.String("metrics"),
68+
Snapshotter: cliContext.String("snapshotter"),
6969
}
7070
client, err := config.newClient()
7171
if err != nil {

cmd/containerd-stress/main.go

Lines changed: 51 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import (
3434
"github.com/containerd/containerd/v2/plugins"
3535
"github.com/containerd/log"
3636
metrics "github.com/docker/go-metrics"
37-
"github.com/urfave/cli"
37+
"github.com/urfave/cli/v2"
3838
)
3939

4040
var (
@@ -63,9 +63,10 @@ func init() {
6363
panic(err)
6464
}
6565

66-
cli.HelpFlag = cli.BoolFlag{
67-
Name: "help, h",
68-
Usage: "Show help",
66+
cli.HelpFlag = &cli.BoolFlag{
67+
Name: "help",
68+
Aliases: []string{"h"},
69+
Usage: "Show help",
6970
}
7071
}
7172

@@ -129,85 +130,91 @@ func main() {
129130
app.Name = "containerd-stress"
130131
app.Description = "stress test a containerd daemon"
131132
app.Flags = []cli.Flag{
132-
cli.BoolFlag{
133+
&cli.BoolFlag{
133134
Name: "debug",
134135
Usage: "Set debug output in the logs",
135136
},
136-
cli.StringFlag{
137-
Name: "address,a",
138-
Value: "/run/containerd/containerd.sock",
139-
Usage: "Path to the containerd socket",
137+
&cli.StringFlag{
138+
Name: "address",
139+
Aliases: []string{"a"},
140+
Value: "/run/containerd/containerd.sock",
141+
Usage: "Path to the containerd socket",
140142
},
141-
cli.IntFlag{
142-
Name: "concurrent,c",
143-
Value: 1,
144-
Usage: "Set the concurrency of the stress test",
143+
&cli.IntFlag{
144+
Name: "concurrent",
145+
Aliases: []string{"c"},
146+
Value: 1,
147+
Usage: "Set the concurrency of the stress test",
145148
},
146-
cli.BoolFlag{
149+
&cli.BoolFlag{
147150
Name: "cri",
148151
Usage: "Utilize CRI to create pods for the stress test. This requires a runtime that matches CRI runtime handler. Example: --runtime runc",
149152
},
150-
cli.DurationFlag{
151-
Name: "duration,d",
152-
Value: 1 * time.Minute,
153-
Usage: "Set the duration of the stress test",
153+
&cli.DurationFlag{
154+
Name: "duration",
155+
Aliases: []string{"d"},
156+
Value: 1 * time.Minute,
157+
Usage: "Set the duration of the stress test",
154158
},
155-
cli.BoolFlag{
159+
&cli.BoolFlag{
156160
Name: "exec",
157161
Usage: "Add execs to the stress tests (non-CRI only)",
158162
},
159-
cli.StringFlag{
160-
Name: "image,i",
161-
Value: "docker.io/library/alpine:latest",
162-
Usage: "Image to be utilized for testing",
163+
&cli.StringFlag{
164+
Name: "image",
165+
Aliases: []string{"i"},
166+
Value: "docker.io/library/alpine:latest",
167+
Usage: "Image to be utilized for testing",
163168
},
164-
cli.BoolFlag{
165-
Name: "json,j",
166-
Usage: "Output results in json format",
169+
&cli.BoolFlag{
170+
Name: "json",
171+
Aliases: []string{"j"},
172+
Usage: "Output results in json format",
167173
},
168-
cli.StringFlag{
169-
Name: "metrics,m",
170-
Usage: "Address to serve the metrics API",
174+
&cli.StringFlag{
175+
Name: "metrics",
176+
Aliases: []string{"m"},
177+
Usage: "Address to serve the metrics API",
171178
},
172-
cli.StringFlag{
179+
&cli.StringFlag{
173180
Name: "runtime",
174181
Usage: "Set the runtime to stress test",
175182
Value: plugins.RuntimeRuncV2,
176183
},
177-
cli.StringFlag{
184+
&cli.StringFlag{
178185
Name: "snapshotter",
179186
Usage: "Set the snapshotter to use",
180187
Value: "overlayfs",
181188
},
182189
}
183190
app.Before = func(context *cli.Context) error {
184-
if context.GlobalBool("json") {
191+
if context.Bool("json") {
185192
if err := log.SetLevel("warn"); err != nil {
186193
return err
187194
}
188195
}
189-
if context.GlobalBool("debug") {
196+
if context.Bool("debug") {
190197
if err := log.SetLevel("debug"); err != nil {
191198
return err
192199
}
193200
}
194201
return nil
195202
}
196-
app.Commands = []cli.Command{
203+
app.Commands = []*cli.Command{
197204
densityCommand,
198205
}
199206
app.Action = func(context *cli.Context) error {
200207
config := config{
201-
Address: context.GlobalString("address"),
202-
Duration: context.GlobalDuration("duration"),
203-
Concurrency: context.GlobalInt("concurrent"),
204-
CRI: context.GlobalBool("cri"),
205-
Exec: context.GlobalBool("exec"),
206-
Image: context.GlobalString("image"),
207-
JSON: context.GlobalBool("json"),
208-
Metrics: context.GlobalString("metrics"),
209-
Runtime: context.GlobalString("runtime"),
210-
Snapshotter: context.GlobalString("snapshotter"),
208+
Address: context.String("address"),
209+
Duration: context.Duration("duration"),
210+
Concurrency: context.Int("concurrent"),
211+
CRI: context.Bool("cri"),
212+
Exec: context.Bool("exec"),
213+
Image: context.String("image"),
214+
JSON: context.Bool("json"),
215+
Metrics: context.String("metrics"),
216+
Runtime: context.String("runtime"),
217+
Snapshotter: context.String("snapshotter"),
211218
}
212219
if config.Metrics != "" {
213220
return serve(config)

cmd/containerd/command/config.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import (
3030
"github.com/containerd/plugin/registry"
3131
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
3232
"github.com/pelletier/go-toml/v2"
33-
"github.com/urfave/cli"
33+
"github.com/urfave/cli/v2"
3434
)
3535

3636
func outputConfig(ctx gocontext.Context, config *srvconfig.Config) error {
@@ -79,10 +79,10 @@ func defaultConfig() *srvconfig.Config {
7979
return platformAgnosticDefaultConfig()
8080
}
8181

82-
var configCommand = cli.Command{
82+
var configCommand = &cli.Command{
8383
Name: "config",
8484
Usage: "Information on the containerd config",
85-
Subcommands: []cli.Command{
85+
Subcommands: []*cli.Command{
8686
{
8787
Name: "default",
8888
Usage: "See the output of the default config",
@@ -96,7 +96,7 @@ var configCommand = cli.Command{
9696
Action: func(context *cli.Context) error {
9797
config := defaultConfig()
9898
ctx := gocontext.Background()
99-
if err := srvconfig.LoadConfig(ctx, context.GlobalString("config"), config); err != nil && !os.IsNotExist(err) {
99+
if err := srvconfig.LoadConfig(ctx, context.String("config"), config); err != nil && !os.IsNotExist(err) {
100100
return err
101101
}
102102

@@ -109,7 +109,7 @@ var configCommand = cli.Command{
109109
Action: func(context *cli.Context) error {
110110
config := defaultConfig()
111111
ctx := gocontext.Background()
112-
if err := srvconfig.LoadConfig(ctx, context.GlobalString("config"), config); err != nil && !os.IsNotExist(err) {
112+
if err := srvconfig.LoadConfig(ctx, context.String("config"), config); err != nil && !os.IsNotExist(err) {
113113
return err
114114
}
115115

cmd/containerd/command/main.go

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import (
3636
"github.com/containerd/containerd/v2/version"
3737
"github.com/containerd/errdefs"
3838
"github.com/containerd/log"
39-
"github.com/urfave/cli"
39+
"github.com/urfave/cli/v2"
4040
"google.golang.org/grpc/grpclog"
4141
)
4242

@@ -57,13 +57,15 @@ func init() {
5757
cli.VersionPrinter = func(c *cli.Context) {
5858
fmt.Println(c.App.Name, version.Package, c.App.Version, version.Revision)
5959
}
60-
cli.VersionFlag = cli.BoolFlag{
61-
Name: "version, v",
62-
Usage: "Print the version",
60+
cli.VersionFlag = &cli.BoolFlag{
61+
Name: "version",
62+
Aliases: []string{"v"},
63+
Usage: "Print the version",
6364
}
64-
cli.HelpFlag = cli.BoolFlag{
65-
Name: "help, h",
66-
Usage: "Show help",
65+
cli.HelpFlag = &cli.BoolFlag{
66+
Name: "help",
67+
Aliases: []string{"h"},
68+
Usage: "Show help",
6769
}
6870
}
6971

@@ -85,30 +87,33 @@ at the default file location. The *containerd config* command can be used to
8587
generate the default configuration for containerd. The output of that command
8688
can be used and modified as necessary as a custom configuration.`
8789
app.Flags = []cli.Flag{
88-
cli.StringFlag{
89-
Name: "config,c",
90-
Usage: "Path to the configuration file",
91-
Value: filepath.Join(defaults.DefaultConfigDir, "config.toml"),
90+
&cli.StringFlag{
91+
Name: "config",
92+
Aliases: []string{"c"},
93+
Usage: "Path to the configuration file",
94+
Value: filepath.Join(defaults.DefaultConfigDir, "config.toml"),
9295
},
93-
cli.StringFlag{
94-
Name: "log-level,l",
95-
Usage: "Set the logging level [trace, debug, info, warn, error, fatal, panic]",
96+
&cli.StringFlag{
97+
Name: "log-level",
98+
Aliases: []string{"l"},
99+
Usage: "Set the logging level [trace, debug, info, warn, error, fatal, panic]",
96100
},
97-
cli.StringFlag{
98-
Name: "address,a",
99-
Usage: "Address for containerd's GRPC server",
101+
&cli.StringFlag{
102+
Name: "address",
103+
Aliases: []string{"a"},
104+
Usage: "Address for containerd's GRPC server",
100105
},
101-
cli.StringFlag{
106+
&cli.StringFlag{
102107
Name: "root",
103108
Usage: "containerd root directory",
104109
},
105-
cli.StringFlag{
110+
&cli.StringFlag{
106111
Name: "state",
107112
Usage: "containerd state directory",
108113
},
109114
}
110115
app.Flags = append(app.Flags, serviceFlags()...)
111-
app.Commands = []cli.Command{
116+
app.Commands = []*cli.Command{
112117
configCommand,
113118
publishCommand,
114119
ociHook,
@@ -126,9 +131,9 @@ can be used and modified as necessary as a custom configuration.`
126131

127132
// Only try to load the config if it either exists, or the user explicitly
128133
// told us to load this path.
129-
configPath := context.GlobalString("config")
134+
configPath := context.String("config")
130135
_, err := os.Stat(configPath)
131-
if !os.IsNotExist(err) || context.GlobalIsSet("config") {
136+
if !os.IsNotExist(err) || context.IsSet("config") {
132137
if err := srvconfig.LoadConfig(ctx, configPath, config); err != nil {
133138
return err
134139
}
@@ -336,7 +341,7 @@ func applyFlags(context *cli.Context, config *srvconfig.Config) error {
336341
d: &config.GRPC.Address,
337342
},
338343
} {
339-
if s := context.GlobalString(v.name); s != "" {
344+
if s := context.String(v.name); s != "" {
340345
*v.d = s
341346
if v.name == "root" || v.name == "state" {
342347
absPath, err := filepath.Abs(s)
@@ -354,7 +359,7 @@ func applyFlags(context *cli.Context, config *srvconfig.Config) error {
354359
}
355360

356361
func setLogLevel(context *cli.Context, config *srvconfig.Config) error {
357-
l := context.GlobalString("log-level")
362+
l := context.String("log-level")
358363
if l == "" {
359364
l = config.Debug.Level
360365
}

cmd/containerd/command/oci-hook.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ import (
2727

2828
"github.com/containerd/containerd/v2/pkg/oci"
2929
"github.com/opencontainers/runtime-spec/specs-go"
30-
"github.com/urfave/cli"
30+
"github.com/urfave/cli/v2"
3131
)
3232

33-
var ociHook = cli.Command{
33+
var ociHook = &cli.Command{
3434
Name: "oci-hook",
3535
Usage: "Provides a base for OCI runtime hooks to allow arguments to be injected.",
3636
Action: func(context *cli.Context) error {
@@ -45,7 +45,7 @@ var ociHook = cli.Command{
4545
}
4646
var (
4747
ctx = newTemplateContext(state, spec)
48-
args = []string(context.Args())
48+
args = context.Args().Slice()
4949
env = os.Environ()
5050
)
5151
if err := newList(&args).render(ctx); err != nil {

0 commit comments

Comments
 (0)