Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade github.com/urfave/cli to v2 #6628

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 10 additions & 10 deletions cmd/containerd-stress/density.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,29 +33,29 @@ import (
"github.com/containerd/containerd/namespaces"
"github.com/containerd/containerd/oci"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
cli "github.com/urfave/cli/v2"
)

var densityCommand = cli.Command{
Name: "density",
Usage: "stress tests density of containers running on a system",
Flags: []cli.Flag{
cli.IntFlag{
&cli.IntFlag{
Name: "count",
Usage: "number of containers to run",
Value: 10,
},
},
Action: func(cliContext *cli.Context) error {
config := config{
Address: cliContext.GlobalString("address"),
Duration: cliContext.GlobalDuration("duration"),
Concurrency: cliContext.GlobalInt("concurrent"),
Exec: cliContext.GlobalBool("exec"),
Image: cliContext.GlobalString("image"),
JSON: cliContext.GlobalBool("json"),
Metrics: cliContext.GlobalString("metrics"),
Snapshotter: cliContext.GlobalString("snapshotter"),
Address: cliContext.String("address"),
Duration: cliContext.Duration("duration"),
Concurrency: cliContext.Int("concurrent"),
Exec: cliContext.Bool("exec"),
Image: cliContext.String("image"),
JSON: cliContext.Bool("json"),
Metrics: cliContext.String("metrics"),
Snapshotter: cliContext.String("snapshotter"),
}
client, err := config.newClient()
if err != nil {
Expand Down
86 changes: 46 additions & 40 deletions cmd/containerd-stress/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (
"github.com/containerd/containerd/plugin"
metrics "github.com/docker/go-metrics"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
cli "github.com/urfave/cli/v2"
)

var (
Expand Down Expand Up @@ -111,76 +111,82 @@ func main() {
app.Name = "containerd-stress"
app.Description = "stress test a containerd daemon"
app.Flags = []cli.Flag{
cli.BoolFlag{
&cli.BoolFlag{
Name: "debug",
Usage: "set debug output in the logs",
},
cli.StringFlag{
Name: "address,a",
Value: "/run/containerd/containerd.sock",
Usage: "path to the containerd socket",
&cli.StringFlag{
Name: "address",
Aliases: []string{"a"},
Value: "/run/containerd/containerd.sock",
Usage: "path to the containerd socket",
},
cli.IntFlag{
Name: "concurrent,c",
Value: 1,
Usage: "set the concurrency of the stress test",
&cli.IntFlag{
Name: "concurrent",
Aliases: []string{"c"},
Value: 1,
Usage: "set the concurrency of the stress test",
},
cli.DurationFlag{
Name: "duration,d",
Value: 1 * time.Minute,
Usage: "set the duration of the stress test",
&cli.DurationFlag{
Name: "duration",
Aliases: []string{"d"},
Value: 1 * time.Minute,
Usage: "set the duration of the stress test",
},
cli.BoolFlag{
&cli.BoolFlag{
Name: "exec",
Usage: "add execs to the stress tests",
},
cli.StringFlag{
Name: "image,i",
Value: "docker.io/library/alpine:latest",
Usage: "image to be utilized for testing",
&cli.StringFlag{
Name: "image",
Aliases: []string{"i"},
Value: "docker.io/library/alpine:latest",
Usage: "image to be utilized for testing",
},
cli.BoolFlag{
Name: "json,j",
Usage: "output results in json format",
&cli.BoolFlag{
Name: "json",
Aliases: []string{"j"},
Usage: "output results in json format",
},
cli.StringFlag{
Name: "metrics,m",
Usage: "address to serve the metrics API",
&cli.StringFlag{
Name: "metrics",
Aliases: []string{"m"},
Usage: "address to serve the metrics API",
},
cli.StringFlag{
&cli.StringFlag{
Name: "runtime",
Usage: "set the runtime to stress test",
Value: plugin.RuntimeRuncV2,
},
cli.StringFlag{
&cli.StringFlag{
Name: "snapshotter",
Usage: "set the snapshotter to use",
Value: "overlayfs",
},
}
app.Before = func(context *cli.Context) error {
if context.GlobalBool("json") {
if context.Bool("json") {
logrus.SetLevel(logrus.WarnLevel)
}
if context.GlobalBool("debug") {
if context.Bool("debug") {
logrus.SetLevel(logrus.DebugLevel)
}
return nil
}
app.Commands = []cli.Command{
densityCommand,
app.Commands = []*cli.Command{
&densityCommand,
}
app.Action = func(context *cli.Context) error {
config := config{
Address: context.GlobalString("address"),
Duration: context.GlobalDuration("duration"),
Concurrency: context.GlobalInt("concurrent"),
Exec: context.GlobalBool("exec"),
Image: context.GlobalString("image"),
JSON: context.GlobalBool("json"),
Metrics: context.GlobalString("metrics"),
Runtime: context.GlobalString("runtime"),
Snapshotter: context.GlobalString("snapshotter"),
Address: context.String("address"),
Duration: context.Duration("duration"),
Concurrency: context.Int("concurrent"),
Exec: context.Bool("exec"),
Image: context.String("image"),
JSON: context.Bool("json"),
Metrics: context.String("metrics"),
Runtime: context.String("runtime"),
Snapshotter: context.String("snapshotter"),
}
if config.Metrics != "" {
return serve(config)
Expand Down
6 changes: 3 additions & 3 deletions cmd/containerd/command/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
srvconfig "github.com/containerd/containerd/services/server/config"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/pelletier/go-toml"
"github.com/urfave/cli"
cli "github.com/urfave/cli/v2"
)

// Config is a wrapper of server config for printing out.
Expand Down Expand Up @@ -95,7 +95,7 @@ func outputConfig(cfg *srvconfig.Config) error {
var configCommand = cli.Command{
Name: "config",
Usage: "information on the containerd config",
Subcommands: []cli.Command{
Subcommands: []*cli.Command{
{
Name: "default",
Usage: "see the output of the default config",
Expand All @@ -108,7 +108,7 @@ var configCommand = cli.Command{
Usage: "see the output of the final main config with imported in subconfig files",
Action: func(context *cli.Context) error {
config := defaultConfig()
if err := srvconfig.LoadConfig(context.GlobalString("config"), config); err != nil && !os.IsNotExist(err) {
if err := srvconfig.LoadConfig(context.String("config"), config); err != nil && !os.IsNotExist(err) {
return err
}

Expand Down
45 changes: 24 additions & 21 deletions cmd/containerd/command/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import (
"github.com/containerd/containerd/tracing"
"github.com/containerd/containerd/version"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
cli "github.com/urfave/cli/v2"
"google.golang.org/grpc/grpclog"
)

Expand Down Expand Up @@ -79,33 +79,36 @@ at the default file location. The *containerd config* command can be used to
generate the default configuration for containerd. The output of that command
can be used and modified as necessary as a custom configuration.`
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "config,c",
Usage: "path to the configuration file",
Value: filepath.Join(defaults.DefaultConfigDir, "config.toml"),
&cli.StringFlag{
Name: "config",
Aliases: []string{"c"},
Usage: "path to the configuration file",
Value: filepath.Join(defaults.DefaultConfigDir, "config.toml"),
},
cli.StringFlag{
Name: "log-level,l",
Usage: "set the logging level [trace, debug, info, warn, error, fatal, panic]",
&cli.StringFlag{
Name: "log-level",
Aliases: []string{"l"},
Usage: "set the logging level [trace, debug, info, warn, error, fatal, panic]",
},
cli.StringFlag{
Name: "address,a",
Usage: "address for containerd's GRPC server",
&cli.StringFlag{
Name: "address",
Aliases: []string{"a"},
Usage: "address for containerd's GRPC server",
},
cli.StringFlag{
&cli.StringFlag{
Name: "root",
Usage: "containerd root directory",
},
cli.StringFlag{
&cli.StringFlag{
Name: "state",
Usage: "containerd state directory",
},
}
app.Flags = append(app.Flags, serviceFlags()...)
app.Commands = []cli.Command{
configCommand,
publishCommand,
ociHook,
app.Commands = []*cli.Command{
&configCommand,
&publishCommand,
&ociHook,
}
app.Action = func(context *cli.Context) error {
var (
Expand All @@ -120,9 +123,9 @@ can be used and modified as necessary as a custom configuration.`

// Only try to load the config if it either exists, or the user explicitly
// told us to load this path.
configPath := context.GlobalString("config")
configPath := context.String("config")
_, err := os.Stat(configPath)
if !os.IsNotExist(err) || context.GlobalIsSet("config") {
if !os.IsNotExist(err) || context.IsSet("config") {
if err := srvconfig.LoadConfig(configPath, config); err != nil {
return err
}
Expand Down Expand Up @@ -321,7 +324,7 @@ func applyFlags(context *cli.Context, config *srvconfig.Config) error {
d: &config.GRPC.Address,
},
} {
if s := context.GlobalString(v.name); s != "" {
if s := context.String(v.name); s != "" {
*v.d = s
}
}
Expand All @@ -332,7 +335,7 @@ func applyFlags(context *cli.Context, config *srvconfig.Config) error {
}

func setLogLevel(context *cli.Context, config *srvconfig.Config) error {
l := context.GlobalString("log-level")
l := context.String("log-level")
if l == "" {
l = config.Debug.Level
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/containerd/command/oci-hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"text/template"

specs "github.com/opencontainers/runtime-spec/specs-go"
"github.com/urfave/cli"
cli "github.com/urfave/cli/v2"
)

var ociHook = cli.Command{
Expand All @@ -43,7 +43,7 @@ var ociHook = cli.Command{
}
var (
ctx = newTemplateContext(state, spec)
args = []string(context.Args())
args = context.Args().Slice()
env = os.Environ()
)
if err := newList(&args).render(ctx); err != nil {
Expand Down
8 changes: 4 additions & 4 deletions cmd/containerd/command/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
"github.com/containerd/containerd/namespaces"
"github.com/containerd/containerd/pkg/dialer"
"github.com/gogo/protobuf/types"
"github.com/urfave/cli"
cli "github.com/urfave/cli/v2"
"google.golang.org/grpc"
"google.golang.org/grpc/backoff"
"google.golang.org/grpc/credentials/insecure"
Expand All @@ -39,11 +39,11 @@ var publishCommand = cli.Command{
Name: "publish",
Usage: "binary to publish events to containerd",
Flags: []cli.Flag{
cli.StringFlag{
&cli.StringFlag{
Name: "namespace",
Usage: "namespace to publish to",
},
cli.StringFlag{
&cli.StringFlag{
Name: "topic",
Usage: "topic of the event",
},
Expand All @@ -58,7 +58,7 @@ var publishCommand = cli.Command{
if err != nil {
return err
}
client, err := connectEvents(context.GlobalString("address"))
client, err := connectEvents(context.String("address"))
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/containerd/command/service_unsupported.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ package command

import (
"github.com/containerd/containerd/services/server"
"github.com/urfave/cli"
cli "github.com/urfave/cli/v2"
)

// serviceFlags returns an array of flags for configuring containerd to run
Expand Down