From dd0542f7c1e213873f78781a1253068e65b71bf9 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Thu, 20 Jun 2024 02:15:13 +0200 Subject: [PATCH] cmd: don't alias context package, and use cliContext for cli.Context Unfortunately, this is a rather large diff, but perhaps worth a one-time "rip off the bandaid" for v2. This patch removes the use of "gocontext" as alias for stdLib's "context", and uses "cliContext" for uses of cli.context. Signed-off-by: Sebastiaan van Stijn --- cmd/containerd-stress/main.go | 28 ++-- cmd/containerd/command/config.go | 20 +-- cmd/containerd/command/main.go | 30 ++-- cmd/containerd/command/oci-hook.go | 4 +- cmd/containerd/command/publish.go | 14 +- cmd/containerd/command/service_unsupported.go | 2 +- cmd/containerd/command/service_windows.go | 8 +- cmd/ctr/app/main.go | 8 +- cmd/ctr/commands/client.go | 24 +-- cmd/ctr/commands/commands.go | 6 +- cmd/ctr/commands/commands_unix.go | 22 +-- cmd/ctr/commands/commands_windows.go | 2 +- cmd/ctr/commands/containers/checkpoint.go | 14 +- cmd/ctr/commands/containers/containers.go | 48 +++--- cmd/ctr/commands/containers/restore.go | 12 +- cmd/ctr/commands/content/content.go | 88 +++++----- cmd/ctr/commands/content/fetch.go | 34 ++-- cmd/ctr/commands/content/prune.go | 8 +- cmd/ctr/commands/deprecations/deprecations.go | 6 +- cmd/ctr/commands/events/events.go | 6 +- cmd/ctr/commands/images/convert.go | 18 +- cmd/ctr/commands/images/export.go | 26 +-- cmd/ctr/commands/images/images.go | 40 ++--- cmd/ctr/commands/images/import.go | 56 +++---- cmd/ctr/commands/images/inspect.go | 8 +- cmd/ctr/commands/images/mount.go | 18 +- cmd/ctr/commands/images/pull.go | 38 ++--- cmd/ctr/commands/images/push.go | 44 ++--- cmd/ctr/commands/images/tag.go | 20 +-- cmd/ctr/commands/images/unmount.go | 12 +- cmd/ctr/commands/images/usage.go | 8 +- cmd/ctr/commands/info/info.go | 4 +- cmd/ctr/commands/install/install.go | 12 +- cmd/ctr/commands/leases/leases.go | 28 ++-- cmd/ctr/commands/namespaces/namespaces.go | 26 +-- .../commands/namespaces/namespaces_linux.go | 4 +- .../commands/namespaces/namespaces_other.go | 2 +- cmd/ctr/commands/oci/oci.go | 6 +- cmd/ctr/commands/plugins/plugins.go | 20 +-- cmd/ctr/commands/pprof/pprof.go | 44 ++--- cmd/ctr/commands/resolver.go | 50 +++--- cmd/ctr/commands/run/run.go | 42 ++--- cmd/ctr/commands/run/run_unix.go | 130 +++++++-------- cmd/ctr/commands/run/run_windows.go | 62 +++---- cmd/ctr/commands/sandboxes/sandboxes.go | 28 ++-- cmd/ctr/commands/shim/io_unix.go | 4 +- cmd/ctr/commands/shim/shim.go | 58 +++---- cmd/ctr/commands/signals.go | 6 +- cmd/ctr/commands/snapshots/snapshots.go | 154 +++++++++--------- cmd/ctr/commands/tasks/attach.go | 6 +- cmd/ctr/commands/tasks/checkpoint.go | 18 +- cmd/ctr/commands/tasks/delete.go | 16 +- cmd/ctr/commands/tasks/exec.go | 22 +-- cmd/ctr/commands/tasks/kill.go | 14 +- cmd/ctr/commands/tasks/list.go | 6 +- cmd/ctr/commands/tasks/metrics.go | 8 +- cmd/ctr/commands/tasks/pause.go | 6 +- cmd/ctr/commands/tasks/ps.go | 6 +- cmd/ctr/commands/tasks/resume.go | 6 +- cmd/ctr/commands/tasks/start.go | 18 +- cmd/ctr/commands/tasks/tasks.go | 4 +- cmd/ctr/commands/tasks/tasks_unix.go | 10 +- cmd/ctr/commands/tasks/tasks_windows.go | 6 +- cmd/ctr/commands/version/version.go | 8 +- .../cri/server/container_update_resources.go | 3 +- 65 files changed, 754 insertions(+), 755 deletions(-) diff --git a/cmd/containerd-stress/main.go b/cmd/containerd-stress/main.go index e115f6b08..e75017ff2 100644 --- a/cmd/containerd-stress/main.go +++ b/cmd/containerd-stress/main.go @@ -187,13 +187,13 @@ func main() { Value: "overlayfs", }, } - app.Before = func(context *cli.Context) error { - if context.Bool("json") { + app.Before = func(cliContext *cli.Context) error { + if cliContext.Bool("json") { if err := log.SetLevel("warn"); err != nil { return err } } - if context.Bool("debug") { + if cliContext.Bool("debug") { if err := log.SetLevel("debug"); err != nil { return err } @@ -203,18 +203,18 @@ func main() { app.Commands = []*cli.Command{ densityCommand, } - app.Action = func(context *cli.Context) error { + app.Action = func(cliContext *cli.Context) error { config := config{ - 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"), + Address: cliContext.String("address"), + Duration: cliContext.Duration("duration"), + Concurrency: cliContext.Int("concurrent"), + CRI: cliContext.Bool("cri"), + Exec: cliContext.Bool("exec"), + Image: cliContext.String("image"), + JSON: cliContext.Bool("json"), + Metrics: cliContext.String("metrics"), + Runtime: cliContext.String("runtime"), + Snapshotter: cliContext.String("snapshotter"), } if config.Metrics != "" { return serve(config) diff --git a/cmd/containerd/command/config.go b/cmd/containerd/command/config.go index da87c5550..b2456db9b 100644 --- a/cmd/containerd/command/config.go +++ b/cmd/containerd/command/config.go @@ -17,7 +17,7 @@ package command import ( - gocontext "context" + "context" "os" "path/filepath" @@ -33,7 +33,7 @@ import ( "github.com/urfave/cli/v2" ) -func outputConfig(ctx gocontext.Context, config *srvconfig.Config) error { +func outputConfig(ctx context.Context, config *srvconfig.Config) error { plugins, err := server.LoadPlugins(ctx, config) if err != nil { return err @@ -86,17 +86,17 @@ var configCommand = &cli.Command{ { Name: "default", Usage: "See the output of the default config", - Action: func(context *cli.Context) error { - return outputConfig(gocontext.Background(), defaultConfig()) + Action: func(cliContext *cli.Context) error { + return outputConfig(context.Background(), defaultConfig()) }, }, { Name: "dump", Usage: "See the output of the final main config with imported in subconfig files", - Action: func(context *cli.Context) error { + Action: func(cliContext *cli.Context) error { config := defaultConfig() - ctx := gocontext.Background() - if err := srvconfig.LoadConfig(ctx, context.String("config"), config); err != nil && !os.IsNotExist(err) { + ctx := context.Background() + if err := srvconfig.LoadConfig(ctx, cliContext.String("config"), config); err != nil && !os.IsNotExist(err) { return err } @@ -106,10 +106,10 @@ var configCommand = &cli.Command{ { Name: "migrate", Usage: "Migrate the current configuration file to the latest version (does not migrate subconfig files)", - Action: func(context *cli.Context) error { + Action: func(cliContext *cli.Context) error { config := defaultConfig() - ctx := gocontext.Background() - if err := srvconfig.LoadConfig(ctx, context.String("config"), config); err != nil && !os.IsNotExist(err) { + ctx := context.Background() + if err := srvconfig.LoadConfig(ctx, cliContext.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 cc6260e67..6f23e3dbb 100644 --- a/cmd/containerd/command/main.go +++ b/cmd/containerd/command/main.go @@ -17,7 +17,7 @@ package command import ( - gocontext "context" + "context" "fmt" "io" "net" @@ -54,8 +54,8 @@ func init() { // Discard grpc logs so that they don't mess with our stdio grpclog.SetLoggerV2(grpclog.NewLoggerV2(io.Discard, io.Discard, io.Discard)) - cli.VersionPrinter = func(c *cli.Context) { - fmt.Println(c.App.Name, version.Package, c.App.Version, version.Revision) + cli.VersionPrinter = func(cliContext *cli.Context) { + fmt.Println(cliContext.App.Name, version.Package, cliContext.App.Version, version.Revision) } cli.VersionFlag = &cli.BoolFlag{ Name: "version", @@ -118,12 +118,12 @@ can be used and modified as necessary as a custom configuration.` publishCommand, ociHook, } - app.Action = func(context *cli.Context) error { + app.Action = func(cliContext *cli.Context) error { var ( start = time.Now() signals = make(chan os.Signal, 2048) serverC = make(chan *server.Server, 1) - ctx, cancel = gocontext.WithCancel(gocontext.Background()) + ctx, cancel = context.WithCancel(context.Background()) config = defaultConfig() ) @@ -131,16 +131,16 @@ 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.String("config") + configPath := cliContext.String("config") _, err := os.Stat(configPath) - if !os.IsNotExist(err) || context.IsSet("config") { + if !os.IsNotExist(err) || cliContext.IsSet("config") { if err := srvconfig.LoadConfig(ctx, configPath, config); err != nil { return err } } // Apply flags to the config - if err := applyFlags(context, config); err != nil { + if err := applyFlags(cliContext, config); err != nil { return err } @@ -303,7 +303,7 @@ can be used and modified as necessary as a custom configuration.` return app } -func serve(ctx gocontext.Context, l net.Listener, serveFunc func(net.Listener) error) { +func serve(ctx context.Context, l net.Listener, serveFunc func(net.Listener) error) { path := l.Addr().String() log.G(ctx).WithField("address", path).Info("serving...") go func() { @@ -314,10 +314,10 @@ func serve(ctx gocontext.Context, l net.Listener, serveFunc func(net.Listener) e }() } -func applyFlags(context *cli.Context, config *srvconfig.Config) error { +func applyFlags(cliContext *cli.Context, config *srvconfig.Config) error { // the order for config vs flag values is that flags will always override // the config values if they are set - if err := setLogLevel(context, config); err != nil { + if err := setLogLevel(cliContext, config); err != nil { return err } if err := setLogFormat(config); err != nil { @@ -341,7 +341,7 @@ func applyFlags(context *cli.Context, config *srvconfig.Config) error { d: &config.GRPC.Address, }, } { - if s := context.String(v.name); s != "" { + if s := cliContext.String(v.name); s != "" { *v.d = s if v.name == "root" || v.name == "state" { absPath, err := filepath.Abs(s) @@ -353,13 +353,13 @@ func applyFlags(context *cli.Context, config *srvconfig.Config) error { } } - applyPlatformFlags(context) + applyPlatformFlags(cliContext) return nil } -func setLogLevel(context *cli.Context, config *srvconfig.Config) error { - l := context.String("log-level") +func setLogLevel(cliContext *cli.Context, config *srvconfig.Config) error { + l := cliContext.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 dc37464c4..6863356cc 100644 --- a/cmd/containerd/command/oci-hook.go +++ b/cmd/containerd/command/oci-hook.go @@ -33,7 +33,7 @@ import ( 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 { + Action: func(cliContext *cli.Context) error { state, err := loadHookState(os.Stdin) if err != nil { return err @@ -45,7 +45,7 @@ var ociHook = &cli.Command{ } var ( ctx = newTemplateContext(state, spec) - args = context.Args().Slice() + args = cliContext.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 ac084da66..81e569303 100644 --- a/cmd/containerd/command/publish.go +++ b/cmd/containerd/command/publish.go @@ -17,7 +17,7 @@ package command import ( - gocontext "context" + "context" "fmt" "io" "net" @@ -49,9 +49,9 @@ var publishCommand = &cli.Command{ Usage: "Topic of the event", }, }, - Action: func(context *cli.Context) error { - ctx := namespaces.WithNamespace(gocontext.Background(), context.String("namespace")) - topic := context.String("topic") + Action: func(cliContext *cli.Context) error { + ctx := namespaces.WithNamespace(context.Background(), cliContext.String("namespace")) + topic := cliContext.String("topic") if topic == "" { return fmt.Errorf("topic required to publish event: %w", errdefs.ErrInvalidArgument) } @@ -59,7 +59,7 @@ var publishCommand = &cli.Command{ if err != nil { return err } - client, err := connectEvents(context.String("address")) + client, err := connectEvents(cliContext.String("address")) if err != nil { return err } @@ -93,7 +93,7 @@ func connectEvents(address string) (eventsapi.EventsClient, error) { return eventsapi.NewEventsClient(conn), nil } -func connect(address string, d func(gocontext.Context, string) (net.Conn, error)) (*grpc.ClientConn, error) { +func connect(address string, d func(context.Context, string) (net.Conn, error)) (*grpc.ClientConn, error) { backoffConfig := backoff.DefaultConfig backoffConfig.MaxDelay = 3 * time.Second connParams := grpc.ConnectParams{ @@ -106,7 +106,7 @@ func connect(address string, d func(gocontext.Context, string) (net.Conn, error) grpc.FailOnNonTempDialError(true), grpc.WithConnectParams(connParams), } - ctx, cancel := gocontext.WithTimeout(gocontext.Background(), 2*time.Second) + ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second) defer cancel() conn, err := grpc.DialContext(ctx, dialer.DialAddress(address), gopts...) if err != nil { diff --git a/cmd/containerd/command/service_unsupported.go b/cmd/containerd/command/service_unsupported.go index 96865688f..e275132dd 100644 --- a/cmd/containerd/command/service_unsupported.go +++ b/cmd/containerd/command/service_unsupported.go @@ -30,7 +30,7 @@ func serviceFlags() []cli.Flag { } // applyPlatformFlags applies platform-specific flags. -func applyPlatformFlags(context *cli.Context) { +func applyPlatformFlags(cliContext *cli.Context) { } // registerUnregisterService is only relevant on Windows. diff --git a/cmd/containerd/command/service_windows.go b/cmd/containerd/command/service_windows.go index 0b8724dae..6243e9379 100644 --- a/cmd/containerd/command/service_windows.go +++ b/cmd/containerd/command/service_windows.go @@ -79,8 +79,8 @@ func serviceFlags() []cli.Flag { } // applyPlatformFlags applies platform-specific flags. -func applyPlatformFlags(context *cli.Context) { - serviceNameFlag = context.String("service-name") +func applyPlatformFlags(cliContext *cli.Context) { + serviceNameFlag = cliContext.String("service-name") if serviceNameFlag == "" { serviceNameFlag = defaultServiceName } @@ -101,9 +101,9 @@ func applyPlatformFlags(context *cli.Context) { d: &runServiceFlag, }, } { - *v.d = context.Bool(v.name) + *v.d = cliContext.Bool(v.name) } - logFileFlag = context.String("log-file") + logFileFlag = cliContext.String("log-file") } type handler struct { diff --git a/cmd/ctr/app/main.go b/cmd/ctr/app/main.go index 61ed1a425..13ec27635 100644 --- a/cmd/ctr/app/main.go +++ b/cmd/ctr/app/main.go @@ -52,8 +52,8 @@ func init() { // Discard grpc logs so that they don't mess with our stdio grpclog.SetLoggerV2(grpclog.NewLoggerV2(io.Discard, io.Discard, io.Discard)) - cli.VersionPrinter = func(c *cli.Context) { - fmt.Println(c.App.Name, version.Package, c.App.Version) + cli.VersionPrinter = func(cliContext *cli.Context) { + fmt.Println(cliContext.App.Name, version.Package, cliContext.App.Version) } cli.VersionFlag = &cli.BoolFlag{ Name: "version", @@ -135,8 +135,8 @@ containerd CLI info.Command, deprecations.Command, }, extraCmds...) - app.Before = func(context *cli.Context) error { - if context.Bool("debug") { + app.Before = func(cliContext *cli.Context) error { + if cliContext.Bool("debug") { return log.SetLevel("debug") } return nil diff --git a/cmd/ctr/commands/client.go b/cmd/ctr/commands/client.go index 80de87bb1..5354f5787 100644 --- a/cmd/ctr/commands/client.go +++ b/cmd/ctr/commands/client.go @@ -17,7 +17,7 @@ package commands import ( - gocontext "context" + "context" "os" "strconv" @@ -33,18 +33,18 @@ import ( // // This will ensure the namespace is picked up and set the timeout, if one is // defined. -func AppContext(context *cli.Context) (gocontext.Context, gocontext.CancelFunc) { +func AppContext(cliContext *cli.Context) (context.Context, context.CancelFunc) { var ( - ctx = gocontext.Background() - timeout = context.Duration("timeout") - namespace = context.String("namespace") - cancel gocontext.CancelFunc + ctx = context.Background() + timeout = cliContext.Duration("timeout") + namespace = cliContext.String("namespace") + cancel context.CancelFunc ) ctx = namespaces.WithNamespace(ctx, namespace) if timeout > 0 { - ctx, cancel = gocontext.WithTimeout(ctx, timeout) + ctx, cancel = context.WithTimeout(ctx, timeout) } else { - ctx, cancel = gocontext.WithCancel(ctx) + ctx, cancel = context.WithCancel(ctx) } if tm, err := epoch.SourceDateEpoch(); err != nil { log.L.WithError(err).Warn("Failed to read SOURCE_DATE_EPOCH") @@ -56,14 +56,14 @@ 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.Duration("connect-timeout")) +func NewClient(cliContext *cli.Context, opts ...containerd.Opt) (*containerd.Client, context.Context, context.CancelFunc, error) { + timeoutOpt := containerd.WithTimeout(cliContext.Duration("connect-timeout")) opts = append(opts, timeoutOpt) - client, err := containerd.New(context.String("address"), opts...) + client, err := containerd.New(cliContext.String("address"), opts...) if err != nil { return nil, nil, nil, err } - ctx, cancel := AppContext(context) + ctx, cancel := AppContext(cliContext) var suppressDeprecationWarnings bool if s := os.Getenv("CONTAINERD_SUPPRESS_DEPRECATION_WARNINGS"); s != "" { suppressDeprecationWarnings, err = strconv.ParseBool(s) diff --git a/cmd/ctr/commands/commands.go b/cmd/ctr/commands/commands.go index 4007b2d07..946da78ed 100644 --- a/cmd/ctr/commands/commands.go +++ b/cmd/ctr/commands/commands.go @@ -232,10 +232,10 @@ var ( ) // ObjectWithLabelArgs returns the first arg and a LabelArgs object -func ObjectWithLabelArgs(clicontext *cli.Context) (string, map[string]string) { +func ObjectWithLabelArgs(cliContext *cli.Context) (string, map[string]string) { var ( - first = clicontext.Args().First() - labelStrings = clicontext.Args().Tail() + first = cliContext.Args().First() + labelStrings = cliContext.Args().Tail() ) return first, LabelArgs(labelStrings) diff --git a/cmd/ctr/commands/commands_unix.go b/cmd/ctr/commands/commands_unix.go index 51740b37c..b17e789f4 100644 --- a/cmd/ctr/commands/commands_unix.go +++ b/cmd/ctr/commands/commands_unix.go @@ -59,37 +59,37 @@ func init() { }) } -func getRuncOptions(context *cli.Context) (*options.Options, error) { +func getRuncOptions(cliContext *cli.Context) (*options.Options, error) { runtimeOpts := &options.Options{} - if runcBinary := context.String("runc-binary"); runcBinary != "" { + if runcBinary := cliContext.String("runc-binary"); runcBinary != "" { runtimeOpts.BinaryName = runcBinary } - if context.Bool("runc-systemd-cgroup") { - if context.String("cgroup") == "" { + if cliContext.Bool("runc-systemd-cgroup") { + if cliContext.String("cgroup") == "" { // runc maps "machine.slice:foo:deadbeef" to "/machine.slice/foo-deadbeef.scope" return nil, errors.New("option --runc-systemd-cgroup requires --cgroup to be set, e.g. \"machine.slice:foo:deadbeef\"") } runtimeOpts.SystemdCgroup = true } - if root := context.String("runc-root"); root != "" { + if root := cliContext.String("runc-root"); root != "" { runtimeOpts.Root = root } return runtimeOpts, nil } -func RuntimeOptions(context *cli.Context) (interface{}, error) { +func RuntimeOptions(cliContext *cli.Context) (interface{}, error) { // validate first - if (context.String("runc-binary") != "" || context.Bool("runc-systemd-cgroup")) && - context.String("runtime") != "io.containerd.runc.v2" { + if (cliContext.String("runc-binary") != "" || cliContext.Bool("runc-systemd-cgroup")) && + cliContext.String("runtime") != "io.containerd.runc.v2" { return nil, errors.New("specifying runc-binary and runc-systemd-cgroup is only supported for \"io.containerd.runc.v2\" runtime") } - if context.String("runtime") == "io.containerd.runc.v2" { - return getRuncOptions(context) + if cliContext.String("runtime") == "io.containerd.runc.v2" { + return getRuncOptions(cliContext) } - if configPath := context.String("runtime-config-path"); configPath != "" { + if configPath := cliContext.String("runtime-config-path"); configPath != "" { return &runtimeoptions.Options{ ConfigPath: configPath, }, nil diff --git a/cmd/ctr/commands/commands_windows.go b/cmd/ctr/commands/commands_windows.go index 3a3280936..15bc3951c 100644 --- a/cmd/ctr/commands/commands_windows.go +++ b/cmd/ctr/commands/commands_windows.go @@ -37,6 +37,6 @@ func init() { }) } -func RuntimeOptions(context *cli.Context) (interface{}, error) { +func RuntimeOptions(cliContext *cli.Context) (interface{}, error) { return nil, nil } diff --git a/cmd/ctr/commands/containers/checkpoint.go b/cmd/ctr/commands/containers/checkpoint.go index fbcb38941..da048f1ca 100644 --- a/cmd/ctr/commands/containers/checkpoint.go +++ b/cmd/ctr/commands/containers/checkpoint.go @@ -44,16 +44,16 @@ var checkpointCommand = &cli.Command{ Usage: "Checkpoint container task", }, }, - Action: func(context *cli.Context) error { - id := context.Args().First() + Action: func(cliContext *cli.Context) error { + id := cliContext.Args().First() if id == "" { return errors.New("container id must be provided") } - ref := context.Args().Get(1) + ref := cliContext.Args().Get(1) if ref == "" { return errors.New("ref must be provided") } - client, ctx, cancel, err := commands.NewClient(context) + client, ctx, cancel, err := commands.NewClient(cliContext) if err != nil { return err } @@ -62,13 +62,13 @@ var checkpointCommand = &cli.Command{ containerd.WithCheckpointRuntime, } - if context.Bool("image") { + if cliContext.Bool("image") { opts = append(opts, containerd.WithCheckpointImage) } - if context.Bool("rw") { + if cliContext.Bool("rw") { opts = append(opts, containerd.WithCheckpointRW) } - if context.Bool("task") { + if cliContext.Bool("task") { opts = append(opts, containerd.WithCheckpointTask) } container, err := client.LoadContainer(ctx, id) diff --git a/cmd/ctr/commands/containers/containers.go b/cmd/ctr/commands/containers/containers.go index 146e7f857..4f7e53942 100644 --- a/cmd/ctr/commands/containers/containers.go +++ b/cmd/ctr/commands/containers/containers.go @@ -55,21 +55,21 @@ var createCommand = &cli.Command{ 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 { + Action: func(cliContext *cli.Context) error { var ( id string ref string - config = context.IsSet("config") + config = cliContext.IsSet("config") ) if config { - id = context.Args().First() - if context.NArg() > 1 { + id = cliContext.Args().First() + if cliContext.NArg() > 1 { return fmt.Errorf("with spec config file, only container id should be provided: %w", errdefs.ErrInvalidArgument) } } else { - id = context.Args().Get(1) - ref = context.Args().First() + id = cliContext.Args().Get(1) + ref = cliContext.Args().First() if ref == "" { return fmt.Errorf("image ref must be provided: %w", errdefs.ErrInvalidArgument) } @@ -77,12 +77,12 @@ var createCommand = &cli.Command{ if id == "" { return fmt.Errorf("container id must be provided: %w", errdefs.ErrInvalidArgument) } - client, ctx, cancel, err := commands.NewClient(context) + client, ctx, cancel, err := commands.NewClient(cliContext) if err != nil { return err } defer cancel() - _, err = run.NewContainer(ctx, client, context) + _, err = run.NewContainer(ctx, client, cliContext) if err != nil { return err } @@ -102,12 +102,12 @@ var listCommand = &cli.Command{ Usage: "Print only the container id", }, }, - Action: func(context *cli.Context) error { + Action: func(cliContext *cli.Context) error { var ( - filters = context.Args().Slice() - quiet = context.Bool("quiet") + filters = cliContext.Args().Slice() + quiet = cliContext.Bool("quiet") ) - client, ctx, cancel, err := commands.NewClient(context) + client, ctx, cancel, err := commands.NewClient(cliContext) if err != nil { return err } @@ -156,22 +156,22 @@ var deleteCommand = &cli.Command{ Usage: "Do not clean up snapshot with container", }, }, - Action: func(context *cli.Context) error { + Action: func(cliContext *cli.Context) error { var exitErr error - client, ctx, cancel, err := commands.NewClient(context) + client, ctx, cancel, err := commands.NewClient(cliContext) if err != nil { return err } defer cancel() deleteOpts := []containerd.DeleteOpts{} - if !context.Bool("keep-snapshot") { + if !cliContext.Bool("keep-snapshot") { deleteOpts = append(deleteOpts, containerd.WithSnapshotCleanup) } - if context.NArg() == 0 { + if cliContext.NArg() == 0 { return fmt.Errorf("must specify at least one container to delete: %w", errdefs.ErrInvalidArgument) } - for _, arg := range context.Args().Slice() { + for _, arg := range cliContext.Args().Slice() { if err := deleteContainer(ctx, client, arg, deleteOpts...); err != nil { if exitErr == nil { exitErr = err @@ -212,12 +212,12 @@ var setLabelsCommand = &cli.Command{ ArgsUsage: "[flags] CONTAINER [=, ...]", Description: "set and clear labels for a container", Flags: []cli.Flag{}, - Action: func(context *cli.Context) error { - containerID, labels := commands.ObjectWithLabelArgs(context) + Action: func(cliContext *cli.Context) error { + containerID, labels := commands.ObjectWithLabelArgs(cliContext) if containerID == "" { return fmt.Errorf("container id must be provided: %w", errdefs.ErrInvalidArgument) } - client, ctx, cancel, err := commands.NewClient(context) + client, ctx, cancel, err := commands.NewClient(cliContext) if err != nil { return err } @@ -254,12 +254,12 @@ var infoCommand = &cli.Command{ Usage: "Only display the spec", }, }, - Action: func(context *cli.Context) error { - id := context.Args().First() + Action: func(cliContext *cli.Context) error { + id := cliContext.Args().First() if id == "" { return fmt.Errorf("container id must be provided: %w", errdefs.ErrInvalidArgument) } - client, ctx, cancel, err := commands.NewClient(context) + client, ctx, cancel, err := commands.NewClient(cliContext) if err != nil { return err } @@ -272,7 +272,7 @@ var infoCommand = &cli.Command{ if err != nil { return err } - if context.Bool("spec") { + if cliContext.Bool("spec") { v, err := typeurl.UnmarshalAny(info.Spec) if err != nil { return err diff --git a/cmd/ctr/commands/containers/restore.go b/cmd/ctr/commands/containers/restore.go index 1d1859dbc..e63b25b99 100644 --- a/cmd/ctr/commands/containers/restore.go +++ b/cmd/ctr/commands/containers/restore.go @@ -43,16 +43,16 @@ var restoreCommand = &cli.Command{ Usage: "Restore the runtime and memory data from the checkpoint", }, }, - Action: func(context *cli.Context) error { - id := context.Args().First() + Action: func(cliContext *cli.Context) error { + id := cliContext.Args().First() if id == "" { return errors.New("container id must be provided") } - ref := context.Args().Get(1) + ref := cliContext.Args().Get(1) if ref == "" { return errors.New("ref must be provided") } - client, ctx, cancel, err := commands.NewClient(context) + client, ctx, cancel, err := commands.NewClient(cliContext) if err != nil { return err } @@ -76,7 +76,7 @@ var restoreCommand = &cli.Command{ containerd.WithRestoreSpec, containerd.WithRestoreRuntime, } - if context.Bool("rw") { + if cliContext.Bool("rw") { opts = append(opts, containerd.WithRestoreRW) } @@ -85,7 +85,7 @@ var restoreCommand = &cli.Command{ return err } topts := []containerd.NewTaskOpts{} - if context.Bool("live") { + if cliContext.Bool("live") { topts = append(topts, containerd.WithTaskCheckpoint(checkpoint)) } spec, err := ctr.Spec(ctx) diff --git a/cmd/ctr/commands/content/content.go b/cmd/ctr/commands/content/content.go index d7d1bfb6a..236b6e335 100644 --- a/cmd/ctr/commands/content/content.go +++ b/cmd/ctr/commands/content/content.go @@ -64,12 +64,12 @@ var ( Usage: "Get the data for an object", ArgsUsage: "[, ...]", Description: "display the image object", - Action: func(context *cli.Context) error { - dgst, err := digest.Parse(context.Args().First()) + Action: func(cliContext *cli.Context) error { + dgst, err := digest.Parse(cliContext.Args().First()) if err != nil { return err } - client, ctx, cancel, err := commands.NewClient(context) + client, ctx, cancel, err := commands.NewClient(cliContext) if err != nil { return err } @@ -103,11 +103,11 @@ var ( Usage: "Verify content against expected digest", }, }, - Action: func(context *cli.Context) error { + Action: func(cliContext *cli.Context) error { var ( - ref = context.Args().First() - expectedSize = context.Int64("expected-size") - expectedDigest = digest.Digest(context.String("expected-digest")) + ref = cliContext.Args().First() + expectedSize = cliContext.Int64("expected-size") + expectedDigest = digest.Digest(cliContext.String("expected-digest")) ) if err := expectedDigest.Validate(); expectedDigest != "" && err != nil { return err @@ -115,7 +115,7 @@ var ( if ref == "" { return errors.New("must specify a transaction reference") } - client, ctx, cancel, err := commands.NewClient(context) + client, ctx, cancel, err := commands.NewClient(cliContext) if err != nil { return err } @@ -148,9 +148,9 @@ var ( Value: "/tmp/content", // TODO(stevvooe): for now, just use the PWD/.content }, }, - Action: func(context *cli.Context) error { - match := context.Args().First() - client, ctx, cancel, err := commands.NewClient(context) + Action: func(cliContext *cli.Context) error { + match := cliContext.Args().First() + client, ctx, cancel, err := commands.NewClient(cliContext) if err != nil { return err } @@ -186,12 +186,12 @@ var ( Usage: "Print only the blob digest", }, }, - Action: func(context *cli.Context) error { + Action: func(cliContext *cli.Context) error { var ( - quiet = context.Bool("quiet") - args = context.Args().Slice() + quiet = cliContext.Bool("quiet") + args = cliContext.Args().Slice() ) - client, ctx, cancel, err := commands.NewClient(context) + client, ctx, cancel, err := commands.NewClient(cliContext) if err != nil { return err } @@ -239,9 +239,9 @@ var ( Usage: "Add labels to content", ArgsUsage: " [