Skip to content

internal/cri/server: remove remaining uses of k8s.io/utils - #14003

Merged
fuweid merged 1 commit into
containerd:mainfrom
thaJeztah:rm_k8s_utils
Aug 21, 2026
Merged

fuweid merged 1 commit into
containerd:mainfrom
thaJeztah:rm_k8s_utils

Conversation

@thaJeztah

Copy link
Copy Markdown
Member

k8s.io/utils/exec.CodeExitError was the only remaining direct use of k8s.io/utils. Replace it with a local error type implementing the same interface. The streaming server uses this interface to distinguish commands terminating with a non-zero exit status from errors executing the command, and to propagate the exit status to the client.

Add a FIXME to define this error contract in k8s.io/cri-streaming, where it is consumed, instead of requiring runtime implementations to implicitly match k8s.io/utils/exec.ExitError.

☝️ for the above; currently the interface is defined in utils (producer side) https://github.com/kubernetes/utils/blob/28399d86e0b55e612b83ad94dc6bac8e5de2a5ac/exec/exec.go#L83-L91

But it should be defined on the receiver side, because that's where it's part of the contract;
https://github.com/kubernetes/cri-streaming/blob/v0.36.3/pkg/streaming/remotecommand/exec.go#L48-L64

That interface must be documented as part of the contract (to avoid a 500 internal server error for expected cases); the interface can be simplified to only the parts needed;

type ExitError interface {
    error
    Exited() bool
    ExitStatus() int
}

BUT! It ... could .. even be more elegant. Instead of defining a Kubernetes-specific ExitStatus(), k8s.io/cri-streaming could define an interface stdlib:

type ExitError interface {
    error
    ExitCode() int
}

That interface would be satisfied by *os/exec.ExitError (through *os.ProcessState), and implementations could just return a *exec.ExitError directly without wrapping; and k8s.io/cri-streaming could have a small utility to match either; quick draw-up;

// ExitError is returned by Runtime.Exec when the command terminated with a
// non-zero exit code.
//
// *os/exec.ExitError implements ExitError.
type ExitError interface {
	error
	ExitCode() int
}
type legacyExitError interface {
	error
	Exited() bool
	ExitStatus() int
}

func exitCode(err error) (int, bool) {
	var exitErr ExitError
	if errors.As(err, &exitErr) {
		return exitErr.ExitCode(), true
	}

	var exitErrLegacy legacyExitError
	if errors.As(err, &exitErrLegacy) && exitErrLegacy.Exited() {
		return exitErrLegacy.ExitStatus(), true
	}

	return 0, false
}

And document it;

// Exec executes a command in a container.
//
// If the command terminates with a non-zero exit code, Exec should return an
// ExitError. In particular, *os/exec.ExitError satisfies this contract.
Exec(...) error

k8s.io/utils/exec.CodeExitError was the only remaining direct use of
k8s.io/utils. Replace it with a local error type implementing the same
interface. The streaming server uses this interface to distinguish commands
terminating with a non-zero exit status from errors executing the
command, and to propagate the exit status to the client.

Add a FIXME to define this error contract in k8s.io/cri-streaming,
where it is consumed, instead of requiring runtime implementations
to implicitly match k8s.io/utils/exec.ExitError.

Signed-off-by: Sebastiaan van Stijn <[email protected]>

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.

Pull request overview

This PR removes the last direct dependency of the CRI streaming runtime on k8s.io/utils/exec.CodeExitError by replacing it with a local error type that matches the exit-error interface expected by k8s.io/cri-streaming’s remotecommand.ServeExec.

Changes:

  • Replaces k8s.io/utils/exec.CodeExitError usage with a local codeExitError that implements the same exit-status contract.
  • Updates the streaming runtime’s Exec implementation/comments to reflect the local exit-error type.
  • Moves k8s.io/utils from a direct to an indirect dependency in go.mod.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
internal/cri/server/streaming.go Introduces a local exit-error interface + implementation and returns it from Exec on non-zero exit status.
go.mod Removes the direct k8s.io/utils requirement (keeps it as indirect via transitive deps).
Suppressed comments (1)

internal/cri/server/streaming.go:53

  • This comment mentions “the upper bits of os.exec.ExitStatus”, but os.exec isn’t a Go package path and this implementation just stores the exit code provided by containerd. Suggest simplifying the wording to avoid incorrect stdlib references.
// codeExitError is an implementation of exitError consisting of an error object
// and an exit code (the upper bits of os.exec.ExitStatus).

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

Comment thread internal/cri/server/streaming.go Resolved

@mikebrow mikebrow left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nod good change.. looking forward to the k8s pr to define the exit error contract in cri-streaming over on the server side

@github-project-automation github-project-automation Bot moved this from Needs Triage to Review In Progress in Pull Request Review Aug 21, 2026
@fuweid
fuweid added this pull request to the merge queue Aug 21, 2026
Merged via the queue into containerd:main with commit 829f576 Aug 21, 2026
81 of 90 checks passed
@github-project-automation github-project-automation Bot moved this from Review In Progress to Done in Pull Request Review Aug 21, 2026
@thaJeztah

Copy link
Copy Markdown
Member Author

nod good change.. looking forward to the k8s pr to define the exit error contract in cri-streaming over on the server side

@thaJeztah
thaJeztah deleted the rm_k8s_utils branch August 21, 2026 22:11
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