Skip to content

ctr: fix flag parsing issues in run, containers create, tasks exec, and oci-hook - #14209

Merged
samuelkarp merged 2 commits into
containerd:mainfrom
samuelkarp:ctr-stop-on-nth-arg
Sep 23, 2026
Merged

samuelkarp merged 2 commits into
containerd:mainfrom
samuelkarp:ctr-stop-on-nth-arg

Conversation

@samuelkarp

Copy link
Copy Markdown
Member

Fixes #14208

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.

Copilot review overview

🟡 Changes recommended

Critical compile errors and an OCI hook separator-handling issue remain unresolved.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 4 High severity

Open (4)
What changed in this PR

Fixes flag parsing for ctr commands and containerd oci-hook, preserving dash-prefixed positional arguments.

Changes:

  • Stops flag parsing after required positional arguments.
  • Disables flag parsing for OCI hook arguments.
  • Adds regression tests for argument passthrough.
File Summary Review
cmd/​ctr/​commands/​tasks/​exec.go Preserves arguments after the container ID. Critical (1 vote): new(1) is a compile-time error.
cmd/​ctr/​commands/​tasks/​exec_test.go Tests exec arguments containing flags. No findings.
cmd/​ctr/​commands/​run/​run.go Preserves run command arguments. Critical (1 vote): new(2) is a compile-time error.
cmd/​ctr/​commands/​run/​run_test.go Tests run arguments containing flags. No findings.
cmd/​ctr/​commands/​containers/​containers.go Preserves create command arguments. Critical (1 vote): new(2) is a compile-time error.
cmd/​ctr/​commands/​containers/​containers_test.go Tests create arguments containing flags. No findings.
cmd/​containerd/​command/​oci-hook.go Preserves OCI hook arguments. Critical (3 votes): The -- separator remains in cmd.Args() and may be executed as the hook.
cmd/​containerd/​command/​oci-hook_test.go Tests OCI hook argument passthrough. No findings.

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

Comment thread cmd/containerd/command/oci-hook.go Resolved
Comment thread cmd/ctr/commands/run/run.go Resolved
Comment thread cmd/ctr/commands/tasks/exec.go Resolved

@koriyoshi2041 koriyoshi2041 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The completed integration matrix now reproduces a causal regression in every Linux/VM job: TestContainerHook invokes containerd oci-hook -- <hook> ..., but SkipFlagParsing preserves the separator in c.Args(), so the action attempts to execute -- instead of the hook. The representative failure is error running createRuntime hook #0 ... stderr: containerd: no such file or directory in job 107009687969; all 199 integration tests pass except this test.

Could the command preserve dash-prefixed hook arguments while still consuming the CLI separator, and add the existing production-shaped oci-hook -- <path> --pid ... form as a regression? The current unit test covers only the no-separator invocation, so it cannot detect this path.

@github-project-automation github-project-automation Bot moved this from Needs Triage to Needs Update in Pull Request Review Sep 23, 2026
@samuelkarp

Copy link
Copy Markdown
Member Author

@koriyoshi2041

Please don't have your LLM pretend to be a maintainer.

@koriyoshi2041

Copy link
Copy Markdown

You're right — using CHANGES_REQUESTED from an external account was inappropriate. I meant to report a blocking CI regression, not imply maintainer authority. I'll use a normal review comment for this kind of finding going forward. Sorry.

@samuelkarp

Copy link
Copy Markdown
Member Author

Our contributing guidelines state that this behavior is unacceptable:

Using AI to generate replies to review comments or issue discussions; code review is a conversation between humans, not bots

@thaJeztah

Copy link
Copy Markdown
Member

Failure could be legit; looks like it's failing across the board;

=== FAIL: integration/client TestContainerHook (0.20s)
    log_hook.go:47: time="2026-09-23T01:44:29.736928380Z" level=debug msg="remote introspection plugin filters" func="proxy.(*introspectionRemote).Plugins" file="/home/runner/work/containerd/containerd/core/introspection/proxy/remote.go:59" filters="[type==io.containerd.snapshotter.v1, id==overlayfs]" testcase=TestContainerHook
    container_test.go:1840: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: error during container init: error running createRuntime hook #0: exit status 1, stdout: , stderr: containerd: no such file or directory

@samuelkarp

Copy link
Copy Markdown
Member Author

@thaJeztah Yeah, the failure is legit. I'm looking at it this morning.

urfave/cli/v3 scans for flags across all positional arguments by
default, which causes flags meant for the container process to be
parsed as ctr flags.

Configure StopOnNthArg to stop flag parsing before the container
command and its arguments:
- "ctr run" and "ctr containers create": after Image|RootFS and
  CONTAINER (2 args)
- "ctr tasks exec": after CONTAINER (1 arg)

Fixes containerd#14208

Assisted-by: Antigravity
Signed-off-by: Samuel Karp <[email protected]>
"containerd oci-hook" defines no flags of its own and passes all
arguments directly to the target hook binary via syscall.Exec. Set
StopOnNthArg to 1 so urfave/cli/v3 stops flag parsing after the hook
binary path while still stripping an optional "--" separator.

Assisted-by: Antigravity
Signed-off-by: Samuel Karp <[email protected]>
Copilot AI review requested due to automatic review settings September 23, 2026 17:23

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.

Copilot review overview

🟢 Approval recommended

No unresolved review issues were identified.

Review effort: Lite
Findings: None

Resolved since last review (4)

@estesp
estesp dismissed koriyoshi2041’s stale review September 23, 2026 17:33

LLM, not human review comments

@github-project-automation github-project-automation Bot moved this from Needs Update to Review In Progress in Pull Request Review Sep 23, 2026
@samuelkarp
samuelkarp added this pull request to the merge queue Sep 23, 2026
@samuelkarp

Copy link
Copy Markdown
Member Author

/cherry-pick release/2.4

@k8s-infra-cherrypick-robot

Copy link
Copy Markdown

@samuelkarp: once the present PR merges, I will cherry-pick it on top of release/2.4 in a new PR and assign it to you.

Details

In response to this:

/cherry-pick release/2.4

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

Merged via the queue into containerd:main with commit 5c4dc96 Sep 23, 2026
96 of 98 checks passed
@github-project-automation github-project-automation Bot moved this from Review In Progress to Done in Pull Request Review Sep 23, 2026
@k8s-infra-cherrypick-robot

Copy link
Copy Markdown

@samuelkarp: new pull request created: #14215

Details

In response to this:

/cherry-pick release/2.4

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@samuelkarp
samuelkarp deleted the ctr-stop-on-nth-arg branch September 23, 2026 22:53
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.

[Regression 2.4.0] ctr run treats container command flags as ctr flags ("flag provided but not defined")

7 participants