diff --git a/cmd/containerd-stress/density.go b/cmd/containerd-stress/density.go index 6fe70f21c..a48928fe9 100644 --- a/cmd/containerd-stress/density.go +++ b/cmd/containerd-stress/density.go @@ -34,14 +34,14 @@ import ( "github.com/containerd/containerd/v2/pkg/namespaces" "github.com/containerd/containerd/v2/pkg/oci" "github.com/containerd/log" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) -var densityCommand = cli.Command{ +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, @@ -58,14 +58,14 @@ var densityCommand = cli.Command{ } 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 { diff --git a/cmd/containerd-stress/main.go b/cmd/containerd-stress/main.go index 98ba07590..e115f6b08 100644 --- a/cmd/containerd-stress/main.go +++ b/cmd/containerd-stress/main.go @@ -34,7 +34,7 @@ import ( "github.com/containerd/containerd/v2/plugins" "github.com/containerd/log" metrics "github.com/docker/go-metrics" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) var ( @@ -63,9 +63,10 @@ func init() { panic(err) } - cli.HelpFlag = cli.BoolFlag{ - Name: "help, h", - Usage: "Show help", + cli.HelpFlag = &cli.BoolFlag{ + Name: "help", + Aliases: []string{"h"}, + Usage: "Show help", } } @@ -129,85 +130,91 @@ 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.BoolFlag{ + &cli.BoolFlag{ Name: "cri", Usage: "Utilize CRI to create pods for the stress test. This requires a runtime that matches CRI runtime handler. Example: --runtime runc", }, - 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 (non-CRI only)", }, - 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: plugins.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") { if err := log.SetLevel("warn"); err != nil { return err } } - if context.GlobalBool("debug") { + if context.Bool("debug") { if err := log.SetLevel("debug"); err != nil { return err } } return nil } - app.Commands = []cli.Command{ + 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"), - CRI: context.GlobalBool("cri"), - 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"), + CRI: context.Bool("cri"), + 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) diff --git a/cmd/containerd/command/config.go b/cmd/containerd/command/config.go index 84e418e95..7fa1a09f0 100644 --- a/cmd/containerd/command/config.go +++ b/cmd/containerd/command/config.go @@ -29,7 +29,7 @@ import ( "github.com/containerd/plugin/registry" ocispec "github.com/opencontainers/image-spec/specs-go/v1" "github.com/pelletier/go-toml/v2" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) func outputConfig(ctx gocontext.Context, config *srvconfig.Config) error { @@ -78,10 +78,10 @@ func defaultConfig() *srvconfig.Config { return platformAgnosticDefaultConfig() } -var configCommand = cli.Command{ +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", @@ -95,7 +95,7 @@ var configCommand = cli.Command{ Action: func(context *cli.Context) error { config := defaultConfig() ctx := gocontext.Background() - if err := srvconfig.LoadConfig(ctx, context.GlobalString("config"), config); err != nil && !os.IsNotExist(err) { + if err := srvconfig.LoadConfig(ctx, context.String("config"), config); err != nil && !os.IsNotExist(err) { return err } @@ -108,7 +108,7 @@ var configCommand = cli.Command{ Action: func(context *cli.Context) error { config := defaultConfig() ctx := gocontext.Background() - if err := srvconfig.LoadConfig(ctx, context.GlobalString("config"), config); err != nil && !os.IsNotExist(err) { + if err := srvconfig.LoadConfig(ctx, context.String("config"), config); err != nil && !os.IsNotExist(err) { return err } diff --git a/cmd/containerd/command/main.go b/cmd/containerd/command/main.go index c11057e1b..cc6260e67 100644 --- a/cmd/containerd/command/main.go +++ b/cmd/containerd/command/main.go @@ -36,7 +36,7 @@ import ( "github.com/containerd/containerd/v2/version" "github.com/containerd/errdefs" "github.com/containerd/log" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" "google.golang.org/grpc/grpclog" ) @@ -57,13 +57,15 @@ func init() { cli.VersionPrinter = func(c *cli.Context) { fmt.Println(c.App.Name, version.Package, c.App.Version, version.Revision) } - cli.VersionFlag = cli.BoolFlag{ - Name: "version, v", - Usage: "Print the version", + cli.VersionFlag = &cli.BoolFlag{ + Name: "version", + Aliases: []string{"v"}, + Usage: "Print the version", } - cli.HelpFlag = cli.BoolFlag{ - Name: "help, h", - Usage: "Show help", + cli.HelpFlag = &cli.BoolFlag{ + Name: "help", + Aliases: []string{"h"}, + Usage: "Show help", } } @@ -85,30 +87,33 @@ 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{ + app.Commands = []*cli.Command{ configCommand, publishCommand, ociHook, @@ -126,9 +131,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(ctx, configPath, config); err != nil { return err } @@ -336,7 +341,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 if v.name == "root" || v.name == "state" { absPath, err := filepath.Abs(s) @@ -354,7 +359,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 } diff --git a/cmd/containerd/command/oci-hook.go b/cmd/containerd/command/oci-hook.go index 1dceaef63..dc37464c4 100644 --- a/cmd/containerd/command/oci-hook.go +++ b/cmd/containerd/command/oci-hook.go @@ -27,10 +27,10 @@ import ( "github.com/containerd/containerd/v2/pkg/oci" "github.com/opencontainers/runtime-spec/specs-go" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) -var ociHook = cli.Command{ +var ociHook = &cli.Command{ Name: "oci-hook", Usage: "Provides a base for OCI runtime hooks to allow arguments to be injected.", Action: func(context *cli.Context) error { @@ -45,7 +45,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 { diff --git a/cmd/containerd/command/publish.go b/cmd/containerd/command/publish.go index 4afce093d..3c85930fb 100644 --- a/cmd/containerd/command/publish.go +++ b/cmd/containerd/command/publish.go @@ -30,21 +30,21 @@ import ( "github.com/containerd/containerd/v2/protobuf/proto" "github.com/containerd/containerd/v2/protobuf/types" "github.com/containerd/errdefs" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" "google.golang.org/grpc" "google.golang.org/grpc/backoff" "google.golang.org/grpc/credentials/insecure" ) -var publishCommand = cli.Command{ +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", }, @@ -59,7 +59,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 } diff --git a/cmd/containerd/command/service_unsupported.go b/cmd/containerd/command/service_unsupported.go index 27943b497..96865688f 100644 --- a/cmd/containerd/command/service_unsupported.go +++ b/cmd/containerd/command/service_unsupported.go @@ -20,7 +20,7 @@ package command import ( "github.com/containerd/containerd/v2/cmd/containerd/server" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) // serviceFlags returns an array of flags for configuring containerd to run diff --git a/cmd/containerd/command/service_windows.go b/cmd/containerd/command/service_windows.go index f31bef1e7..0b8724dae 100644 --- a/cmd/containerd/command/service_windows.go +++ b/cmd/containerd/command/service_windows.go @@ -27,7 +27,7 @@ import ( "github.com/containerd/containerd/v2/cmd/containerd/server" "github.com/containerd/errdefs" "github.com/sirupsen/logrus" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" "golang.org/x/sys/windows" "golang.org/x/sys/windows/svc" "golang.org/x/sys/windows/svc/debug" @@ -53,25 +53,25 @@ const defaultServiceName = "containerd" // as a Windows service under control of SCM. func serviceFlags() []cli.Flag { return []cli.Flag{ - cli.StringFlag{ + &cli.StringFlag{ Name: "service-name", Usage: "Set the Windows service name", Value: defaultServiceName, }, - cli.BoolFlag{ + &cli.BoolFlag{ Name: "register-service", Usage: "Register the service and exit", }, - cli.BoolFlag{ + &cli.BoolFlag{ Name: "unregister-service", Usage: "Unregister the service and exit", }, - cli.BoolFlag{ + &cli.BoolFlag{ Name: "run-service", Usage: "", Hidden: true, }, - cli.StringFlag{ + &cli.StringFlag{ Name: "log-file", Usage: "Path to the containerd log file", }, @@ -80,7 +80,7 @@ func serviceFlags() []cli.Flag { // applyPlatformFlags applies platform-specific flags. func applyPlatformFlags(context *cli.Context) { - serviceNameFlag = context.GlobalString("service-name") + serviceNameFlag = context.String("service-name") if serviceNameFlag == "" { serviceNameFlag = defaultServiceName } @@ -101,9 +101,9 @@ func applyPlatformFlags(context *cli.Context) { d: &runServiceFlag, }, } { - *v.d = context.GlobalBool(v.name) + *v.d = context.Bool(v.name) } - logFileFlag = context.GlobalString("log-file") + logFileFlag = context.String("log-file") } type handler struct { diff --git a/cmd/ctr/app/main.go b/cmd/ctr/app/main.go index 115aa3c5c..31f8584cc 100644 --- a/cmd/ctr/app/main.go +++ b/cmd/ctr/app/main.go @@ -21,7 +21,7 @@ import ( "io" "github.com/containerd/log" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" "google.golang.org/grpc/grpclog" "github.com/containerd/containerd/v2/cmd/ctr/commands/containers" @@ -46,7 +46,7 @@ import ( "github.com/containerd/containerd/v2/version" ) -var extraCmds = []cli.Command{} +var extraCmds = []*cli.Command{} func init() { // Discard grpc logs so that they don't mess with our stdio @@ -55,13 +55,15 @@ func init() { cli.VersionPrinter = func(c *cli.Context) { fmt.Println(c.App.Name, version.Package, c.App.Version) } - cli.VersionFlag = cli.BoolFlag{ - Name: "version, v", - Usage: "Print the version", + cli.VersionFlag = &cli.BoolFlag{ + Name: "version", + Aliases: []string{"v"}, + Usage: "Print the version", } - cli.HelpFlag = cli.BoolFlag{ - Name: "help, h", - Usage: "Show help", + cli.HelpFlag = &cli.BoolFlag{ + Name: "help", + Aliases: []string{"h"}, + Usage: "Show help", } } @@ -86,32 +88,34 @@ containerd CLI ` app.EnableBashCompletion = true app.Flags = []cli.Flag{ - cli.BoolFlag{ + &cli.BoolFlag{ Name: "debug", Usage: "Enable debug output in logs", }, - cli.StringFlag{ - Name: "address, a", - Usage: "Address for containerd's GRPC server", - Value: defaults.DefaultAddress, - EnvVar: "CONTAINERD_ADDRESS", + &cli.StringFlag{ + Name: "address", + Aliases: []string{"a"}, + Usage: "Address for containerd's GRPC server", + Value: defaults.DefaultAddress, + EnvVars: []string{"CONTAINERD_ADDRESS"}, }, - cli.DurationFlag{ + &cli.DurationFlag{ Name: "timeout", Usage: "Total timeout for ctr commands", }, - cli.DurationFlag{ + &cli.DurationFlag{ Name: "connect-timeout", Usage: "Timeout for connecting to containerd", }, - cli.StringFlag{ - Name: "namespace, n", - Usage: "Namespace to use with commands", - Value: namespaces.Default, - EnvVar: namespaces.NamespaceEnvVar, + &cli.StringFlag{ + Name: "namespace", + Aliases: []string{"n"}, + Usage: "Namespace to use with commands", + Value: namespaces.Default, + EnvVars: []string{namespaces.NamespaceEnvVar}, }, } - app.Commands = append([]cli.Command{ + app.Commands = append([]*cli.Command{ plugins.Command, versionCmd.Command, containers.Command, @@ -131,7 +135,7 @@ containerd CLI deprecations.Command, }, extraCmds...) app.Before = func(context *cli.Context) error { - if context.GlobalBool("debug") { + if context.Bool("debug") { return log.SetLevel("debug") } return nil diff --git a/cmd/ctr/commands/client.go b/cmd/ctr/commands/client.go index b78efab0e..181bcbc6b 100644 --- a/cmd/ctr/commands/client.go +++ b/cmd/ctr/commands/client.go @@ -23,7 +23,7 @@ import ( "github.com/containerd/containerd/v2/pkg/epoch" "github.com/containerd/containerd/v2/pkg/namespaces" "github.com/containerd/log" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) // AppContext returns the context for a command. Should only be called once per @@ -34,8 +34,8 @@ import ( func AppContext(context *cli.Context) (gocontext.Context, gocontext.CancelFunc) { var ( ctx = gocontext.Background() - timeout = context.GlobalDuration("timeout") - namespace = context.GlobalString("namespace") + timeout = context.Duration("timeout") + namespace = context.String("namespace") cancel gocontext.CancelFunc ) ctx = namespaces.WithNamespace(ctx, namespace) @@ -55,9 +55,9 @@ func AppContext(context *cli.Context) (gocontext.Context, gocontext.CancelFunc) // NewClient returns a new containerd client func NewClient(context *cli.Context, opts ...containerd.Opt) (*containerd.Client, gocontext.Context, gocontext.CancelFunc, error) { - timeoutOpt := containerd.WithTimeout(context.GlobalDuration("connect-timeout")) + timeoutOpt := containerd.WithTimeout(context.Duration("connect-timeout")) opts = append(opts, timeoutOpt) - client, err := containerd.New(context.GlobalString("address"), opts...) + client, err := containerd.New(context.String("address"), opts...) if err != nil { return nil, nil, nil, err } diff --git a/cmd/ctr/commands/commands.go b/cmd/ctr/commands/commands.go index 9a870fbb9..4007b2d07 100644 --- a/cmd/ctr/commands/commands.go +++ b/cmd/ctr/commands/commands.go @@ -26,71 +26,73 @@ import ( "github.com/containerd/containerd/v2/defaults" "github.com/containerd/containerd/v2/pkg/atomicfile" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) var ( // SnapshotterFlags are cli flags specifying snapshotter names SnapshotterFlags = []cli.Flag{ - cli.StringFlag{ - Name: "snapshotter", - Usage: "Snapshotter name. Empty value stands for the default value.", - EnvVar: "CONTAINERD_SNAPSHOTTER", + &cli.StringFlag{ + Name: "snapshotter", + Usage: "Snapshotter name. Empty value stands for the default value.", + EnvVars: []string{"CONTAINERD_SNAPSHOTTER"}, }, } // SnapshotterLabels are cli flags specifying labels which will be added to the new snapshot for container. - SnapshotterLabels = cli.StringSliceFlag{ + SnapshotterLabels = &cli.StringSliceFlag{ Name: "snapshotter-label", Usage: "Labels added to the new snapshot for this container.", } // LabelFlag is a cli flag specifying labels - LabelFlag = cli.StringSliceFlag{ + LabelFlag = &cli.StringSliceFlag{ Name: "label", Usage: "Labels to attach to the image", } // RegistryFlags are cli flags specifying registry options RegistryFlags = []cli.Flag{ - cli.BoolFlag{ - Name: "skip-verify,k", - Usage: "Skip SSL certificate validation", + &cli.BoolFlag{ + Name: "skip-verify", + Aliases: []string{"k"}, + Usage: "Skip SSL certificate validation", }, - cli.BoolFlag{ + &cli.BoolFlag{ Name: "plain-http", Usage: "Allow connections using plain HTTP", }, - cli.StringFlag{ - Name: "user,u", - Usage: "User[:password] Registry user and password", + &cli.StringFlag{ + Name: "user", + Aliases: []string{"u"}, + Usage: "User[:password] Registry user and password", }, - cli.StringFlag{ + &cli.StringFlag{ Name: "refresh", Usage: "Refresh token for authorization server", }, - cli.StringFlag{ + &cli.StringFlag{ Name: "hosts-dir", // compatible with "/etc/docker/certs.d" Usage: "Custom hosts configuration directory", }, - cli.StringFlag{ + &cli.StringFlag{ Name: "tlscacert", Usage: "Path to TLS root CA", }, - cli.StringFlag{ + &cli.StringFlag{ Name: "tlscert", Usage: "Path to TLS client certificate", }, - cli.StringFlag{ + &cli.StringFlag{ Name: "tlskey", Usage: "Path to TLS client key", }, - cli.BoolFlag{ + &cli.BoolFlag{ Name: "http-dump", Usage: "Dump all HTTP request/responses when interacting with container registry", }, - cli.BoolFlag{ + &cli.BoolFlag{ Name: "http-trace", Usage: "Enable HTTP tracing for registry interactions", }, @@ -98,12 +100,12 @@ var ( // RuntimeFlags are cli flags specifying runtime RuntimeFlags = []cli.Flag{ - cli.StringFlag{ + &cli.StringFlag{ Name: "runtime", Usage: "Runtime name or absolute path to runtime binary", Value: defaults.DefaultRuntime, }, - cli.StringFlag{ + &cli.StringFlag{ Name: "runtime-config-path", Usage: "Optional runtime config path", }, @@ -111,117 +113,120 @@ var ( // ContainerFlags are cli flags specifying container options ContainerFlags = []cli.Flag{ - cli.StringFlag{ - Name: "config,c", - Usage: "Path to the runtime-specific spec config file", + &cli.StringFlag{ + Name: "config", + Aliases: []string{"c"}, + Usage: "Path to the runtime-specific spec config file", }, - cli.StringFlag{ + &cli.StringFlag{ Name: "cwd", Usage: "Specify the working directory of the process", }, - cli.StringSliceFlag{ + &cli.StringSliceFlag{ Name: "env", Usage: "Specify additional container environment variables (e.g. FOO=bar)", }, - cli.StringFlag{ + &cli.StringFlag{ Name: "env-file", Usage: "Specify additional container environment variables in a file(e.g. FOO=bar, one per line)", }, - cli.StringSliceFlag{ + &cli.StringSliceFlag{ Name: "label", Usage: "Specify additional labels (e.g. foo=bar)", }, - cli.StringSliceFlag{ + &cli.StringSliceFlag{ Name: "annotation", Usage: "Specify additional OCI annotations (e.g. foo=bar)", }, - cli.StringSliceFlag{ + &cli.StringSliceFlag{ Name: "mount", Usage: "Specify additional container mount (e.g. type=bind,src=/tmp,dst=/host,options=rbind:ro)", }, - cli.BoolFlag{ + &cli.BoolFlag{ Name: "net-host", Usage: "Enable host networking for the container", }, - cli.BoolFlag{ + &cli.BoolFlag{ Name: "privileged", Usage: "Run privileged container", }, - cli.BoolFlag{ + &cli.BoolFlag{ Name: "read-only", Usage: "Set the containers filesystem as readonly", }, - cli.StringFlag{ + &cli.StringFlag{ Name: "sandbox", Usage: "Create the container in the given sandbox", }, - cli.BoolFlag{ - Name: "tty,t", - Usage: "Allocate a TTY for the container", + &cli.BoolFlag{ + Name: "tty", + Aliases: []string{"t"}, + Usage: "Allocate a TTY for the container", }, - cli.StringSliceFlag{ + &cli.StringSliceFlag{ Name: "with-ns", Usage: "Specify existing Linux namespaces to join at container runtime (format ':')", }, - cli.StringFlag{ + &cli.StringFlag{ Name: "pid-file", Usage: "File path to write the task's pid", }, - cli.IntSliceFlag{ + &cli.IntSliceFlag{ Name: "gpus", Usage: "Add gpus to the container", }, - cli.BoolFlag{ + &cli.BoolFlag{ Name: "allow-new-privs", Usage: "Turn off OCI spec's NoNewPrivileges feature flag", }, - cli.Uint64Flag{ + &cli.Uint64Flag{ Name: "memory-limit", Usage: "Memory limit (in bytes) for the container", }, - cli.StringSliceFlag{ + &cli.StringSliceFlag{ Name: "cap-add", Usage: "Add Linux capabilities (Set capabilities with 'CAP_' prefix)", }, - cli.StringSliceFlag{ + &cli.StringSliceFlag{ Name: "cap-drop", Usage: "Drop Linux capabilities (Set capabilities with 'CAP_' prefix)", }, - cli.BoolFlag{ + &cli.BoolFlag{ Name: "seccomp", Usage: "Enable the default seccomp profile", }, - cli.StringFlag{ + &cli.StringFlag{ Name: "seccomp-profile", Usage: "File path to custom seccomp profile. seccomp must be set to true, before using seccomp-profile", }, - cli.StringFlag{ + &cli.StringFlag{ Name: "apparmor-default-profile", Usage: "Enable AppArmor with the default profile with the specified name, e.g. \"cri-containerd.apparmor.d\"", }, - cli.StringFlag{ + &cli.StringFlag{ Name: "apparmor-profile", Usage: "Enable AppArmor with an existing custom profile", }, - cli.StringFlag{ + &cli.StringFlag{ Name: "blockio-config-file", Usage: "File path to blockio class definitions. By default class definitions are not loaded.", }, - cli.StringFlag{ + &cli.StringFlag{ Name: "blockio-class", Usage: "Name of the blockio class to associate the container with", }, - cli.StringFlag{ + &cli.StringFlag{ Name: "rdt-class", Usage: "Name of the RDT class to associate the container with. Specifies a Class of Service (CLOS) for cache and memory bandwidth management.", }, - cli.StringFlag{ + &cli.StringFlag{ Name: "hostname", Usage: "Set the container's host name", }, - cli.StringFlag{ - Name: "user,u", - Usage: "Username or user id, group optional (format: [:])", + &cli.StringFlag{ + Name: "user", + Aliases: []string{"u"}, + Usage: "Username or user id, group optional (format: [:])", }, } ) diff --git a/cmd/ctr/commands/commands_unix.go b/cmd/ctr/commands/commands_unix.go index c328c29eb..cf15f7315 100644 --- a/cmd/ctr/commands/commands_unix.go +++ b/cmd/ctr/commands/commands_unix.go @@ -23,37 +23,37 @@ import ( "github.com/containerd/containerd/v2/core/runtime/v2/runc/options" runtimeoptions "github.com/containerd/containerd/v2/pkg/runtimeoptions/v1" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) func init() { - RuntimeFlags = append(RuntimeFlags, cli.StringFlag{ + RuntimeFlags = append(RuntimeFlags, &cli.StringFlag{ Name: "runc-binary", Usage: "Specify runc-compatible binary", - }, cli.StringFlag{ + }, &cli.StringFlag{ Name: "runc-root", Usage: "Specify runc-compatible root", - }, cli.BoolFlag{ + }, &cli.BoolFlag{ Name: "runc-systemd-cgroup", Usage: "Start runc with systemd cgroup manager", }) - ContainerFlags = append(ContainerFlags, cli.BoolFlag{ + ContainerFlags = append(ContainerFlags, &cli.BoolFlag{ Name: "rootfs", Usage: "Use custom rootfs that is not managed by containerd snapshotter", - }, cli.BoolFlag{ + }, &cli.BoolFlag{ Name: "no-pivot", Usage: "Disable use of pivot-root (linux only)", - }, cli.Int64Flag{ + }, &cli.Int64Flag{ Name: "cpu-quota", Usage: "Limit CPU CFS quota", Value: -1, - }, cli.Uint64Flag{ + }, &cli.Uint64Flag{ Name: "cpu-period", Usage: "Limit CPU CFS period", - }, cli.StringFlag{ + }, &cli.StringFlag{ Name: "rootfs-propagation", Usage: "Set the propagation of the container rootfs", - }, cli.StringSliceFlag{ + }, &cli.StringSliceFlag{ Name: "device", Usage: "File path to a device to add to the container; or a path to a directory tree of devices to add to the container", }) diff --git a/cmd/ctr/commands/commands_windows.go b/cmd/ctr/commands/commands_windows.go index 5e8ed328c..3a3280936 100644 --- a/cmd/ctr/commands/commands_windows.go +++ b/cmd/ctr/commands/commands_windows.go @@ -17,23 +17,21 @@ package commands import ( - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) func init() { ContainerFlags = append(ContainerFlags, - cli.Uint64Flag{ + &cli.Uint64Flag{ Name: "cpu-count", Usage: "Number of CPUs available to the container", - }, - cli.Uint64Flag{ + }, &cli.Uint64Flag{ Name: "cpu-shares", Usage: "The relative number of CPU shares given to the container relative to other workloads. Between 0 and 10,000.", - }, - cli.Uint64Flag{ + }, &cli.Uint64Flag{ Name: "cpu-max", Usage: "The number of processor cycles threads in a container can use per 10,000 cycles. Set to a percentage times 100. Between 1 and 10,000", - }, cli.StringSliceFlag{ + }, &cli.StringSliceFlag{ Name: "device", Usage: "Identifier of a device to add to the container (e.g. class://5B45201D-F2F2-4F3B-85BB-30FF1F953599)", }) diff --git a/cmd/ctr/commands/containers/checkpoint.go b/cmd/ctr/commands/containers/checkpoint.go index 4fef5c291..fbcb38941 100644 --- a/cmd/ctr/commands/containers/checkpoint.go +++ b/cmd/ctr/commands/containers/checkpoint.go @@ -23,23 +23,23 @@ import ( containerd "github.com/containerd/containerd/v2/client" "github.com/containerd/containerd/v2/cmd/ctr/commands" "github.com/containerd/errdefs" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) -var checkpointCommand = cli.Command{ +var checkpointCommand = &cli.Command{ Name: "checkpoint", Usage: "Checkpoint a container", ArgsUsage: "CONTAINER REF", Flags: []cli.Flag{ - cli.BoolFlag{ + &cli.BoolFlag{ Name: "rw", Usage: "Include the rw layer in the checkpoint", }, - cli.BoolFlag{ + &cli.BoolFlag{ Name: "image", Usage: "Include the image in the checkpoint", }, - cli.BoolFlag{ + &cli.BoolFlag{ Name: "task", Usage: "Checkpoint container task", }, diff --git a/cmd/ctr/commands/containers/containers.go b/cmd/ctr/commands/containers/containers.go index 86c6699fb..146e7f857 100644 --- a/cmd/ctr/commands/containers/containers.go +++ b/cmd/ctr/commands/containers/containers.go @@ -31,15 +31,15 @@ import ( "github.com/containerd/errdefs" "github.com/containerd/log" "github.com/containerd/typeurl/v2" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) // Command is the cli command for managing containers -var Command = cli.Command{ +var Command = &cli.Command{ Name: "containers", Usage: "Manage containers", Aliases: []string{"c", "container"}, - Subcommands: []cli.Command{ + Subcommands: []*cli.Command{ createCommand, deleteCommand, infoCommand, @@ -50,12 +50,11 @@ var Command = cli.Command{ }, } -var createCommand = cli.Command{ - Name: "create", - Usage: "Create container", - ArgsUsage: "[flags] Image|RootFS CONTAINER [COMMAND] [ARG...]", - SkipArgReorder: true, - Flags: append(commands.RuntimeFlags, append(append(commands.SnapshotterFlags, []cli.Flag{commands.SnapshotterLabels}...), commands.ContainerFlags...)...), +var createCommand = &cli.Command{ + Name: "create", + Usage: "Create container", + ArgsUsage: "[flags] Image|RootFS CONTAINER [COMMAND] [ARG...]", + Flags: append(commands.RuntimeFlags, append(append(commands.SnapshotterFlags, []cli.Flag{commands.SnapshotterLabels}...), commands.ContainerFlags...)...), Action: func(context *cli.Context) error { var ( id string @@ -91,20 +90,21 @@ var createCommand = cli.Command{ }, } -var listCommand = cli.Command{ +var listCommand = &cli.Command{ Name: "list", Aliases: []string{"ls"}, Usage: "List containers", ArgsUsage: "[flags] [, ...]", Flags: []cli.Flag{ - cli.BoolFlag{ - Name: "quiet, q", - Usage: "Print only the container id", + &cli.BoolFlag{ + Name: "quiet", + Aliases: []string{"q"}, + Usage: "Print only the container id", }, }, Action: func(context *cli.Context) error { var ( - filters = context.Args() + filters = context.Args().Slice() quiet = context.Bool("quiet") ) client, ctx, cancel, err := commands.NewClient(context) @@ -145,13 +145,13 @@ var listCommand = cli.Command{ }, } -var deleteCommand = cli.Command{ +var deleteCommand = &cli.Command{ Name: "delete", Usage: "Delete one or more existing containers", ArgsUsage: "[flags] CONTAINER [CONTAINER, ...]", Aliases: []string{"del", "remove", "rm"}, Flags: []cli.Flag{ - cli.BoolFlag{ + &cli.BoolFlag{ Name: "keep-snapshot", Usage: "Do not clean up snapshot with container", }, @@ -171,7 +171,7 @@ var deleteCommand = cli.Command{ if context.NArg() == 0 { return fmt.Errorf("must specify at least one container to delete: %w", errdefs.ErrInvalidArgument) } - for _, arg := range context.Args() { + for _, arg := range context.Args().Slice() { if err := deleteContainer(ctx, client, arg, deleteOpts...); err != nil { if exitErr == nil { exitErr = err @@ -206,7 +206,7 @@ func deleteContainer(ctx context.Context, client *containerd.Client, id string, } -var setLabelsCommand = cli.Command{ +var setLabelsCommand = &cli.Command{ Name: "label", Usage: "Set and clear labels for a container", ArgsUsage: "[flags] CONTAINER [=, ...]", @@ -244,12 +244,12 @@ var setLabelsCommand = cli.Command{ }, } -var infoCommand = cli.Command{ +var infoCommand = &cli.Command{ Name: "info", Usage: "Get info about a container", ArgsUsage: "CONTAINER", Flags: []cli.Flag{ - cli.BoolFlag{ + &cli.BoolFlag{ Name: "spec", Usage: "Only display the spec", }, diff --git a/cmd/ctr/commands/containers/restore.go b/cmd/ctr/commands/containers/restore.go index cdc5d26d8..1d1859dbc 100644 --- a/cmd/ctr/commands/containers/restore.go +++ b/cmd/ctr/commands/containers/restore.go @@ -26,19 +26,19 @@ import ( "github.com/containerd/containerd/v2/pkg/cio" "github.com/containerd/errdefs" "github.com/containerd/log" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) -var restoreCommand = cli.Command{ +var restoreCommand = &cli.Command{ Name: "restore", Usage: "Restore a container from checkpoint", ArgsUsage: "CONTAINER REF", Flags: []cli.Flag{ - cli.BoolFlag{ + &cli.BoolFlag{ Name: "rw", Usage: "Restore the rw layer from the checkpoint", }, - cli.BoolFlag{ + &cli.BoolFlag{ Name: "live", Usage: "Restore the runtime and memory data from the checkpoint", }, @@ -136,7 +136,7 @@ var restoreCommand = cli.Command{ return err } if code != 0 { - return cli.NewExitError("", int(code)) + return cli.Exit("", int(code)) } return nil }, diff --git a/cmd/ctr/commands/content/content.go b/cmd/ctr/commands/content/content.go index e19bc701f..38d1a4b4c 100644 --- a/cmd/ctr/commands/content/content.go +++ b/cmd/ctr/commands/content/content.go @@ -35,12 +35,12 @@ import ( units "github.com/docker/go-units" digest "github.com/opencontainers/go-digest" ocispec "github.com/opencontainers/image-spec/specs-go/v1" - "github.com/urfave/cli" + "github.com/urfave/cli/v2" ) var ( // Command is the cli command for managing content - Command = cli.Command{ + Command = &cli.Command{ Name: "content", Usage: "Manage content", Subcommands: cli.Commands{ @@ -59,7 +59,7 @@ var ( }, } - getCommand = cli.Command{ + getCommand = &cli.Command{ Name: "get", Usage: "Get the data for an object", ArgsUsage: "[, ...]", @@ -88,17 +88,17 @@ var ( }, } - ingestCommand = cli.Command{ + ingestCommand = &cli.Command{ Name: "ingest", Usage: "Accept content into the store", ArgsUsage: "[flags] ", Description: "ingest objects into the local content store", Flags: []cli.Flag{ - cli.Int64Flag{ + &cli.Int64Flag{ Name: "expected-size", Usage: "Validate against provided size", }, - cli.StringFlag{ + &cli.StringFlag{ Name: "expected-digest", Usage: "Verify content against expected digest", }, @@ -130,18 +130,19 @@ var ( }, } - activeIngestCommand = cli.Command{ + activeIngestCommand = &cli.Command{ Name: "active", Usage: "Display active transfers", ArgsUsage: "[flags] []", Description: "display the ongoing transfers", Flags: []cli.Flag{ - cli.DurationFlag{ - Name: "timeout, t", - Usage: "Total timeout for fetch", - EnvVar: "CONTAINERD_FETCH_TIMEOUT", + &cli.DurationFlag{ + Name: "timeout", + Aliases: []string{"t"}, + Usage: "Total timeout for fetch", + EnvVars: []string{"CONTAINERD_FETCH_TIMEOUT"}, }, - cli.StringFlag{ + &cli.StringFlag{ Name: "root", Usage: "Path to content store root", Value: "/tmp/content", // TODO(stevvooe): for now, just use the PWD/.content @@ -172,22 +173,23 @@ var ( }, } - listCommand = cli.Command{ + listCommand = &cli.Command{ Name: "list", Aliases: []string{"ls"}, Usage: "List all blobs in the store", ArgsUsage: "[flags]", Description: "list blobs in the content store", Flags: []cli.Flag{ - cli.BoolFlag{ - Name: "quiet, q", - Usage: "Print only the blob digest", + &cli.BoolFlag{ + Name: "quiet", + Aliases: []string{"q"}, + Usage: "Print only the blob digest", }, }, Action: func(context *cli.Context) error { var ( quiet = context.Bool("quiet") - args = []string(context.Args()) + args = context.Args().Slice() ) client, ctx, cancel, err := commands.NewClient(context) if err != nil { @@ -232,7 +234,7 @@ var ( }, } - setLabelsCommand = cli.Command{ + setLabelsCommand = &cli.Command{ Name: "label", Usage: "Add labels to content", ArgsUsage: " [