Skip to content

cmd: refactor in preparation of urfave/cli/v3 migration - #14103

Merged
dmcgowan merged 10 commits into
containerd:mainfrom
thaJeztah:urfave_v3_step1
Sep 9, 2026
Merged

dmcgowan merged 10 commits into
containerd:mainfrom
thaJeztah:urfave_v3_step1

Conversation

@thaJeztah

Copy link
Copy Markdown
Member

cmd/ctr: remove unused pluginCmds

cmd: remove uses of urfave/cli.Commands

The Commands type is removed in v3 and already identical to []*Command
in v2; remove its uses to ease the transition to v3.

cmd: remove redundant empty slice flag values

Leave the Value field unset for slice flags without default values. The CLI
initializes these flags with an empty value when they are applied, making
the explicit initializations unnecessary.

cmd: use urfave/cli RunContext

This allows explicitly setting up the context inside main, and makes the
transition to urfave/cli/v3 more transparent.

cmd: rename some vars that shadowed

cmd: edit: pass editor name instead of cli.Context

cmd: rename cliContext -> cmd in preparation of v3 migration

In urfave/cli/v3, cli.Context is replaced with cli.Command, making cmd
a more logical name. Rename the vars ahead of time to make the v3
migration a more mechanical change.

cmd: initialize CLI apps with struct literals

Although urfave/cli v2 recommends constructing apps with cli.NewApp,
App.Run initializes unset fields through App.Setup, making the zero
value usable. Use struct literals to define the application fields
directly without changing behavior.

This prepares for urfave/cli v3, which removes cli.NewApp and replaces
cli.App with cli.Command.

cmd: commands.AppContext: explicitly pass context

urfave/cli/v3 no longer passes the context through the Command; pass
it explicitly to prepare for the v3 migration.

cmd: commands.NewClient: explicitly pass context

urfave/cli/v3 no longer passes the context through the Command; pass
it explicitly to prepare for the v3 migration.

Copilot AI lite review requested due to automatic review settings September 3, 2026 11:48
@github-project-automation github-project-automation Bot moved this to Needs Triage in Pull Request Review Sep 3, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

There are at least two correctness/documentation issues to address (a broken tracing doc snippet and a potential nil dereference during early cancellation in containerd startup).

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR refactors the cmd/* CLI codepaths to make the upcoming github.com/urfave/cli/v3 migration more mechanical, primarily by removing v2-only APIs (cli.Commands, implicit context access) and consistently threading context.Context through CLI setup and client creation.

Changes:

  • Replace uses of cli.Commands with []*cli.Command and remove redundant empty slice defaults for slice flags.
  • Switch CLI entrypoints to RunContext, and refactor helpers (commands.AppContext, commands.NewClient) to accept an explicit context.Context.
  • Rename variables to avoid shadowing and to align naming with planned v3 concepts (e.g., cliContext → cmd), plus small API tweaks (e.g., pass editor name string instead of *cli.Context).
File summaries
File Description
docs/tracing.md Update tracing documentation snippet to match new client/context plumbing.
cmd/ctr/main.go Use RunContext and drop unused plugin command slice.
cmd/ctr/commands/version/version.go Pass explicit context.Context into NewClient; rename handler parameter.
cmd/ctr/commands/tasks/tasks_unix.go Rename cliContext parameter usage to cmd.
cmd/ctr/commands/tasks/start.go Thread explicit ctx/cmd into NewClient and flag lookups.
cmd/ctr/commands/tasks/resume.go Thread explicit ctx/cmd into NewClient and args usage.
cmd/ctr/commands/tasks/ps.go Thread explicit ctx/cmd into NewClient and args usage.
cmd/ctr/commands/tasks/pause.go Thread explicit ctx/cmd into NewClient and args usage.
cmd/ctr/commands/tasks/metrics.go Thread explicit ctx/cmd into NewClient and flag lookups.
cmd/ctr/commands/tasks/list.go Thread explicit ctx/cmd into NewClient; reorder quiet flag read.
cmd/ctr/commands/tasks/kill.go Thread explicit ctx/cmd into NewClient and flag lookups.
cmd/ctr/commands/tasks/exec.go Thread explicit ctx/cmd into NewClient and flag lookups.
cmd/ctr/commands/tasks/delete.go Thread explicit ctx/cmd into NewClient and args usage.
cmd/ctr/commands/tasks/checkpoint.go Thread explicit ctx/cmd into NewClient and helper opts.
cmd/ctr/commands/tasks/attach.go Thread explicit ctx/cmd into NewClient and args usage.
cmd/ctr/commands/snapshots/snapshots.go Replace cli.Commands and thread explicit ctx/cmd throughout.
cmd/ctr/commands/shim/shim.go Replace cliContext with cmd; remove redundant empty slice defaults.
cmd/ctr/commands/shim/pprof.go Rename cliContext parameter usage to cmd for pprof commands.
cmd/ctr/commands/sandboxes/sandboxes.go Replace cli.Commands and thread explicit ctx/cmd throughout.
cmd/ctr/commands/run/run.go Thread explicit ctx/cmd and rename parameters for v3 preparation.
cmd/ctr/commands/run/run_windows.go Rename cliContext parameter usage to cmd throughout.
cmd/ctr/commands/run/run_unix.go Rename cliContext parameter usage to cmd throughout.
cmd/ctr/commands/resolver.go Rename cliContext parameter usage to cmd in resolver helpers.
cmd/ctr/commands/pprof/pprof.go Rename cliContext parameter usage to cmd and update client func type.
cmd/ctr/commands/plugins/plugins.go Thread explicit ctx/cmd into NewClient and writer usage.
cmd/ctr/commands/oci/oci.go Use cmd.Context + explicit commands.AppContext(ctx, cmd).
cmd/ctr/commands/namespaces/namespaces.go Replace cli.Commands and thread explicit ctx/cmd throughout.
cmd/ctr/commands/namespaces/namespaces_other.go Rename deleteOpts parameter to cmd.
cmd/ctr/commands/namespaces/namespaces_linux.go Rename deleteOpts parameter to cmd and flag lookup.
cmd/ctr/commands/leases/leases.go Replace cli.Commands and thread explicit ctx/cmd throughout.
cmd/ctr/commands/install/install.go Thread explicit ctx/cmd into NewClient and flag lookups.
cmd/ctr/commands/info/info.go Thread explicit ctx/cmd into NewClient.
cmd/ctr/commands/images/usage.go Thread explicit ctx/cmd into NewClient and flag lookups.
cmd/ctr/commands/images/unmount.go Thread explicit ctx/cmd into NewClient and writer usage.
cmd/ctr/commands/images/tag.go Thread explicit ctx/cmd into NewClient and flag lookups.
cmd/ctr/commands/images/push.go Remove redundant slice defaults; thread explicit ctx/cmd throughout.
cmd/ctr/commands/images/pull.go Remove redundant slice defaults; thread explicit ctx/cmd throughout.
cmd/ctr/commands/images/mount.go Thread explicit ctx/cmd into NewClient and flag lookups.
cmd/ctr/commands/images/inspect.go Thread explicit ctx/cmd into NewClient and flag lookups.
cmd/ctr/commands/images/import.go Thread explicit ctx/cmd into NewClient and flag lookups.
cmd/ctr/commands/images/images.go Replace cli.Commands and thread explicit ctx/cmd throughout.
cmd/ctr/commands/images/export.go Remove redundant slice defaults; thread explicit ctx/cmd throughout.
cmd/ctr/commands/images/convert.go Remove redundant slice defaults; thread explicit ctx/cmd throughout.
cmd/ctr/commands/images/build_erofs_cache.go Thread explicit ctx/cmd into NewClient and flag lookups.
cmd/ctr/commands/events/events.go Thread explicit ctx/cmd into NewClient and args usage.
cmd/ctr/commands/deprecations/deprecations.go Thread explicit ctx/cmd into NewClient; ignore Setenv error.
cmd/ctr/commands/content/prune.go Replace cli.Commands and thread explicit ctx/cmd.
cmd/ctr/commands/content/fetch.go Thread explicit ctx/cmd into NewClient and NewFetchConfig.
cmd/ctr/commands/content/content.go Replace cli.Commands; thread explicit ctx/cmd; pass editor name string.
cmd/ctr/commands/containers/restore.go Thread explicit ctx/cmd into NewClient and flag lookups.
cmd/ctr/commands/containers/containers.go Thread explicit ctx/cmd into NewClient and args usage.
cmd/ctr/commands/containers/checkpoint.go Thread explicit ctx/cmd into NewClient and flag lookups.
cmd/ctr/commands/commands.go Rename ObjectWithLabelArgs parameter and usages to cmd.
cmd/ctr/commands/commands_windows.go Rename RuntimeOptions parameter to cmd.
cmd/ctr/commands/commands_unix.go Rename RuntimeOptions parameter to cmd and update helpers.
cmd/ctr/commands/client.go Make AppContext/NewClient accept explicit context.Context.
cmd/ctr/app/main.go Construct *cli.App via struct literal; update hooks and command list.
cmd/containerd/main.go Use RunContext for containerd entrypoint.
cmd/containerd/command/service_windows.go Rename applyPlatformFlags parameter to cmd and update uses.
cmd/containerd/command/service_unsupported.go Make applyPlatformFlags a no-op with simplified signature.
cmd/containerd/command/publish.go Rename handler parameter to cmd and use cmd.Context.
cmd/containerd/command/oci-hook.go Rename template context var and use cmd.Args().
cmd/containerd/command/main.go Construct *cli.App via struct literal; thread explicit context usage.
cmd/containerd/command/main_windows.go Avoid shadowing server by renaming local variable to srv.
cmd/containerd/command/main_unix.go Avoid shadowing server by renaming local variable to srv.
cmd/containerd/command/config.go Rename dumpConfig parameter to cmd and update uses.
cmd/containerd-stress/main.go Construct *cli.App via struct literal and use RunContext.
cmd/containerd-stress/density.go Rename variables (config → cfg) and use cmd consistently.
Review details

Suppressed comments (1)

docs/tracing.md:88

  • The example calls commands.NewClient(ctx, cmd, ...) but the snippet does not define a cli.Context (cmd), making the documentation example unusable. Since this section is about instrumenting the containerd Go client, use containerd.New with dial options instead of ctr's commands.NewClient helper.
  • Files reviewed: 68/68 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +246 to 251
case r := <-chsrv:
if r.err != nil {
return r.err
}
srv = r.s
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot that's a pre-existing issue; this PR only makes mechanical changes in this code, so I prefer fixing that separately.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The updated tracing documentation example references an undefined cmd/internal ctr helper, making the snippet misleading for readers and needing correction before merge.

Review details

Suppressed comments (1)

docs/tracing.md:88

  • The tracing example now references cmd (a *cli.Context) but the snippet doesn’t define it, and commands.NewClient is an internal helper from cmd/ctr rather than the containerd Go client API. This makes the documentation example confusing/non-usable for readers outside the ctr codebase. Prefer showing containerd.New(...) directly (and closing the client) or update the snippet to explicitly be a cli.Action/accept a *cli.Context.
  • Files reviewed: 68/68 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

Signed-off-by: Sebastiaan van Stijn <[email protected]>
The `Commands` type is removed in v3 and already identical to `[]*Command`
in v2; remove its uses to ease the transition to v3.

Signed-off-by: Sebastiaan van Stijn <[email protected]>
Leave the Value field unset for slice flags without default values. The CLI
initializes these flags with an empty value when they are applied, making
the explicit initializations unnecessary.

Signed-off-by: Sebastiaan van Stijn <[email protected]>
Copilot AI review requested due to automatic review settings September 5, 2026 01:14

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The updated tracing documentation example now references an undefined cmd variable (and is inconsistent with the example’s function signature), so the snippet should be corrected before merging.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details
  • Files reviewed: 68/68 changed files
  • Comments generated: 1
  • Review effort level: Lite

Comment thread docs/tracing.md
grpc.WithStatsHandler(otelgrpc.NewClientHandler()),
}
client, ctx, cancel, err := commands.NewClient(context, containerd.WithDialOpts(dialOpts))
client, ctx, cancel, err := commands.NewClient(ctx, cmd, containerd.WithDialOpts(dialOpts))

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pre-existing issue; it's a partial example (see the ...); old example also didn't have context defined;

...
dialOpts := []grpc.DialOption{
grpc.WithTransportCredentials(insecure.NewCredentials()),
grpc.WithStatsHandler(otelgrpc.NewClientHandler()),
}
client, ctx, cancel, err := commands.NewClient(context, containerd.WithDialOpts(dialOpts))

This allows explicitly setting up the context inside main, and makes the
transition to urfave/cli/v3 more transparent.

Signed-off-by: Sebastiaan van Stijn <[email protected]>
Signed-off-by: Sebastiaan van Stijn <[email protected]>
In urfave/cli/v3, cli.Context is replaced with cli.Command, making cmd
a more logical name. Rename the vars ahead of time to make the v3
migration a more mechanical change.

Signed-off-by: Sebastiaan van Stijn <[email protected]>
Although urfave/cli v2 recommends constructing apps with cli.NewApp,
App.Run initializes unset fields through App.Setup, making the zero
value usable. Use struct literals to define the application fields
directly without changing behavior.

This prepares for urfave/cli v3, which removes cli.NewApp and replaces
cli.App with cli.Command.

Signed-off-by: Sebastiaan van Stijn <[email protected]>
urfave/cli/v3 no longer passes the context through the Command; pass
it explicitly to prepare for the v3 migration.

Signed-off-by: Sebastiaan van Stijn <[email protected]>
urfave/cli/v3 no longer passes the context through the Command; pass
it explicitly to prepare for the v3 migration.

Signed-off-by: Sebastiaan van Stijn <[email protected]>
Copilot AI review requested due to automatic review settings September 5, 2026 08:41

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The changes are mechanical, consistently applied across call sites, and align with the stated v3-migration preparation goals without introducing evident behavioral regressions.

Review details
  • Files reviewed: 68/68 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

@thaJeztah
thaJeztah requested a review from dmcgowan September 8, 2026 16:38
@github-project-automation github-project-automation Bot moved this from Needs Triage to Review In Progress in Pull Request Review Sep 9, 2026
@dmcgowan
dmcgowan added this pull request to the merge queue Sep 9, 2026
Merged via the queue into containerd:main with commit e822e78 Sep 9, 2026
95 of 98 checks passed
@github-project-automation github-project-automation Bot moved this from Review In Progress to Done in Pull Request Review Sep 9, 2026
@thaJeztah
thaJeztah deleted the urfave_v3_step1 branch September 9, 2026 06:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

4 participants