Commit Graph
462 Commits
Author SHA1 Message Date
Mike Brown 67336d701d modifies criSignalToOCIStopSignal to remove the extra cri SIGNAL_ prefixes
Signed-off-by: Mike Brown <brownwm@us.ibm.com>
2026-08-27 15:24:24 -05:00
Mike Brown ee09726316 fix for cri api Signal_ to Signal_SIGNAL_
Signed-off-by: Mike Brown <brownwm@us.ibm.com>
2026-08-27 15:24:24 -05:00
Sebastiaan van Stijn 10e82fac8d internal/cri/server: remove remaining uses of k8s.io/utils
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 <github@gone.nl>
2026-08-21 11:14:53 +02:00
Maksym Pavlenko 4e781946a6 Merge pull request #13997 from thaJeztah/rm_fakeclock
internal/cri/server/events: use testing/synctest
2026-08-20 21:34:24 +00:00
Sebastiaan van Stijn f7e8f30a05 internal/cri/server/events: use testing/synctest
stdlib can now handle this, without the need of the fakeclock utility.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2026-08-20 21:15:47 +02:00
Sebastiaan van Stijn fcb54dc5fa internal/cri/bandwidth: remove dead code
Most of this package is unused, except for the ExtractPodBandwidthResources
utility.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2026-08-20 19:37:54 +02:00
Eshaan Mathur 203578e2eb cri,nri: record resolved image name and digest in container metadata
- Populate the NRI container's Image field from the image identity recorded in the container metadata at creation, so plugins can identify and verify the container's image by digest. The following fields have been added:

- name: The image reference (ex. registry.k8s.io/pause:3.10)
- digest: Digest the image reference resolves to. Based on the image reference, it is a digest of one of:
  - image index
    - OCI: application/vnd.oci.image.index.v1+json
    - Docker: application/vnd.docker.distribution.manifest.list.v2+json
  - manifest
    - OCI: application/vnd.oci.image.manifest.v1+json
    - Docker: application/vnd.docker.distribution.manifest.v2+json
- config_digest: The image configuration digest
  - OCI: application/vnd.oci.image.config.v1+json
  - Docker: application/vnd.docker.container.image.v1+json

Signed-off-by: Eshaan Mathur <eshaanm25@gmail.com>
2026-08-19 11:24:59 -05:00
Fu Wei e125e77970 Merge pull request #13519 from tianon-sso/runtime-tools
Remove dependency on `github.com/opencontainers/runtime-tools`
2026-08-07 11:30:22 +00:00
HirazawaUi a909c305c4 Set the default of runtimeFeatures.UserNamespacesHostNetwork to true
Signed-off-by: HirazawaUi <695097494plus@gmail.com>
2026-08-06 15:18:39 -05:00
Tianon Gravi e01c004cc6 Remove dependency on github.com/opencontainers/runtime-tools
The direct use was two lines in `internal/cri/nri/nri_api_linux.go` -- constructing a `generate.Generator{Config: spec}` solely to satisfy the `nrigen.UnderlyingGenerator` interface defined in `containerd/nri`. Since that interface already exists, we just need an implementation. Add `spec_generator.go` in the same package, implementing `UnderlyingGenerator` directly on `*rspec.Spec` with no external dependencies beyond `runtime-spec`.

Assisted-By: "claude my eyes right out"
Signed-off-by: Tianon Gravi <tianon.gravi@docker.com>
2026-08-05 16:58:50 -07:00
Maksym Pavlenko 95f42a8f54 Merge pull request #13897 from dgrisonnet/worktree-fix-start-time-nanos
cri: fix container_start_time_seconds unit conversion
2026-08-05 19:21:11 +00:00
Maksym Pavlenko 49854964b2 Merge pull request #13395 from kolyshkin/selinux-1.15.0
bump selinux to v1.15.1, use SetProcessKind
2026-08-05 18:09:56 +00:00
Damien Grisonnet 71bc89b288 cri: fix container_start_time_seconds unit conversion
The container_start_time_seconds metric was reporting nanoseconds
instead of Unix seconds. The CRI container status stores StartedAt
as nanoseconds (per the CRI API spec), but the metric name and help
text indicate seconds. Convert by dividing by time.Second.

Signed-off-by: Damien Grisonnet <dgrisonn@redhat.com>
2026-08-04 09:29:55 -05:00
Damien Grisonnet 34524e8a68 cri: skip failed container instead of dropping entire sandbox metrics
When collectContainerMetrics fails for a single container, the
goroutine was returning nil which exited the loop entirely. The
sandbox metrics, including pod-level network metrics and any
successfully collected container metrics, were never appended to
the response.

Replace return nil with continue so that individual container
failures only skip that container.

Signed-off-by: Damien Grisonnet <dgrisonn@redhat.com>
2026-08-03 09:13:35 +02:00
Samuel Karp 91be73ba62 cri: remove restore in CreateContainer
Remove support for restoring checkpoint data during CreateContainer,
which was previously deprecated in v2.3.

Assisted-by: Antigravity
Signed-off-by: Samuel Karp <samuelkarp@google.com>
2026-07-29 09:32:24 -07:00
Kir Kolyshkin ba3a464b8d bump oc/selinux to v1.15.1, use SetProcessKind
Drop internal/cri/seutil/seutil.go in favor of direct call to newly
introduced selinux.SetProcessKind.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2026-07-28 16:23:54 -07:00
Kir Kolyshkin 4167499888 deps: bump oc/selinux to v1.14.1
Switch away from deprecated functionality.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2026-07-28 16:23:54 -07:00
Samuel Karp fda8a90116 Merge pull request #13838 from samuelkarp/deprecate-cri-checkpoint
cri: deprecate restore in CreateContainer
2026-07-28 17:36:14 +00:00
Samuel Karp a3f99ba690 cri: deprecate restore in CreateContainer
Assisted-by: Antigravity
Signed-off-by: Samuel Karp <samuelkarp@google.com>
2026-07-27 22:11:29 -07:00
Samuel Karp f4e7944625 cri/config: use ScrubLogs by default on Windows
The io.containerd.runhcs.v1 shim can scrub sensitive information from
logs it emits. Since v0.15.0-rc.2 this is done by default, but older
branches still require the option to be explicitly enabled. Explicitly
enable the scrubbing by default for the CRI configuration.

See also: https://github.com/microsoft/hcsshim/pull/2725

Google-Bug-Id: 481375460
Signed-off-by: Samuel Karp <samuelkarp@google.com>
2026-07-24 00:06:30 -07:00
Maksym Pavlenko a82706307a Merge pull request #13187 from bitoku/cri-list-streaming
cri: add streaming RPCs
2026-07-23 18:10:55 +00:00
Ayato Tokubi 47c7085d22 cri: add streaming RPCs
Add server-streaming variants of CRI list RPCs (StreamContainers,
StreamPodSandboxes, StreamContainerStats, StreamPodSandboxStats,
StreamPodSandboxMetrics, StreamImages) that send results in batches
of 5000 items.

Signed-off-by: Ayato Tokubi <atokubi@redhat.com>
2026-07-23 09:57:59 -05:00
Jordan Liggitt b824ddc0b5 Handle []byte envvar value
Signed-off-by: Jordan Liggitt <liggitt@google.com>
2026-07-23 10:39:48 -04:00
Maksym Pavlenko 71b2388e4c Merge pull request #13504 from a7i/fix-cri-introspect-non-runc-features
fix(cri): introspect OCI runtime features for non-runc runtimes
2026-07-12 21:16:00 +00:00
Samuel Karp cb66686cbb Merge pull request #13664 from samuelkarp/criu-check-fail-fast
Disable checkpoint restore codepath when CRIU is not installed
2026-07-08 06:10:01 +00:00
Maksym Pavlenko f45f82d834 Merge pull request #13513 from ningmingxiao/fix_image_name
cri: auto-add prefix for pause image
2026-07-01 21:49:01 +00:00
Samuel Karp 06495733b2 cri: add enable_criu configuration option
Add a new `enable_criu` configuration option under CRI plugin runtime
settings. When set to false, any checkpoint or restore request will fail
fast with an error indicating that CRIU support is disabled by
configuration. `enable_criu` currently defaults to true.

Add an integration test script to verify that setting `enable_criu` to
false in containerd configuration successfully disables checkpoint and
restore operations and fails fast.

Assisted-by: Antigravity
Signed-off-by: Samuel Karp <samuelkarp@google.com>
2026-06-30 12:47:48 -07:00
Samuel Karp 186397511b cri: validate CRIU availability and version early
Perform an early validation check on both container checkpoint and
restore paths to fail-fast if the CRIU binary is missing or is older
than the minimum required version (3.16.0).

To support runtime-configured environments, the validation respects the
custom PATH from the shim manager environment if configured, skipping
any relative paths to avoid incorrect daemon-relative resolution. If not
configured, it falls back to a standard system PATH lookup. The check
result is cached using sync.Once to prevent redundant process spawning.

Assisted-by: Antigravity
Signed-off-by: Samuel Karp <samuelkarp@google.com>
2026-06-30 12:35:16 -07:00
Samuel Karp 0c226d2adb Merge pull request #13683 from chrishenzie/fix-nri-nil-sandbox
Fix nil pointer dereference in NRI GetIPs
2026-06-30 19:09:58 +00:00
Chris Henzie c2dae310af Fix nil pointer dereference in NRI GetIPs
Adds a nil guard to GetIPs on criPodSandbox before accessing promoted
struct fields on the embedded Sandbox pointer.

During pod sandbox teardown or race conditions during container exit
events, nriPodSandbox can return a criPodSandbox instance where the
embedded Sandbox pointer is nil.

Assisted-by: Antigravity
Signed-off-by: Chris Henzie <chrishenzie@gmail.com>
2026-06-30 11:13:17 -07:00
Maksym Pavlenko b13f929f15 Merge pull request #13312 from mxpv/stats
cri: route sandbox stats through Controller.Metrics
2026-06-29 19:23:05 +00:00
Mike Brown 7de5a292c2 Merge pull request #13245 from ahmetb/fix-image-pulling-throughput-cached-layers
cri: exclude cached layer bytes from image_pulling_throughput_mibps
2026-06-26 14:06:14 +00:00
Maksym Pavlenko 99d01fc51e Merge pull request #13623 from yugstar/fix-13611-checkpoint-env-dedup
cri: fix duplicated image env vars on checkpoint import
2026-06-25 19:05:02 +00:00
Maksym Pavlenko 028999d45d Merge pull request #13654 from crawfordxx/fix-createcontainer-reject-stopped-sandbox
cri: reject CreateContainer when sandbox is not running
2026-06-25 19:01:36 +00:00
Amir AlaviandCursor fd7819bcb7 fix(cri): introspect OCI runtime features for non-runc runtimes
introspectRuntimeFeatures returned an error for any runtime type other
than io.containerd.runc.v2, so non-runc shims such as
containerd-shim-runsc-v1 never had their OCI features surfaced to the
CRI RuntimeHandlerFeatures, even though they implement the shim "-info"
command.

The runc-only guard worked around a nil-pointer panic when marshalling
nil runtime options. That case is already covered by the "if options !=
nil" check, making the guard redundant. Dropping it lets all runtimes be
introspected; shims that do not implement "-info" still fail gracefully
and are logged at debug level, so behavior for those is unchanged.

Guard against nil plugin info Extra, nil runtime Features, and nil
features.Linux before unmarshalling or evaluating CRI user namespace
support.

Signed-off-by: Amir Alavi <amiralavi7@gmail.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-25 09:26:14 -04:00
Ahmet Alp Balkan 16ff70b861 cri: add image_pulling_throughput_mibps and deprecate image_pulling_throughput
Address review feedback on the previous commit:

- Use MiB/s (binary, 1024^2) consistently. The divisor was already
  1024*1024; the constant name (mbToByte) and the Help/comment text
  mislabeled the unit.
- Keep image_pulling_throughput for backwards compatibility but mark
  it Deprecated. Its prom.DefBuckets top out at 10 MiB/s, which
  saturates almost immediately on modern hardware.
- Add image_pulling_throughput_mibps with buckets covering 0.1 MiB/s
  through 4000 MiB/s (~31 Gbps), enough for 10G+ NICs. Above that,
  disk write throughput becomes the bottleneck rather than the
  network, so finer buckets aren't worth the cardinality.
- Both metrics observe the same value (fetched bytes / pull duration,
  cached layers excluded; fully-cached pulls skipped). Only the
  buckets and deprecation status differ.

Signed-off-by: Ahmet Alp Balkan <ahmet@linkedin.com>
2026-06-25 07:55:52 -05:00
Ahmet Alp Balkan 1755053a78 cri: exclude cached layer bytes from image_pulling_throughput
The image_pulling_throughput histogram divided the full image size (all
layers plus config) by wall-clock pull duration. Layers already present
in the content store were counted in the numerator, so the reported
MB/s came out way higher than what was actually fetched. Fully-cached
pulls were the worst case: they "pulled" in milliseconds but reported
the full image size, showing up as huge outliers in the histogram.

Both pull paths (local client.Pull and the transfer service) already
maintain a totalBytesRead counter in pullRequestReporter for progress
and timeout checks. Cached blobs never trigger a fetch, so the counter
naturally excludes them. Plumb that value out of both helpers and use
it in place of image.Size(ctx). Fully-cached pulls (bytesPulled == 0)
are not observed, so they don't produce near-infinite samples.

Also updates the metric's Help text to say the denominator is the
end-to-end pull duration including layer extraction and snapshotter
unpack, not just network transfer.

Addresses #13244

Signed-off-by: Ahmet Alp Balkan <ahmet@linkedin.com>
2026-06-25 07:55:52 -05:00
Maksym Pavlenko 33fb482a85 Merge pull request #13656 from erofs/cri-image-volume
cri: don't leak the new mount if mutateImageMount() fails
2026-06-23 17:43:39 +00:00
Gao Xiang a88ce40fd1 cri: don't leak the new mount if mutateImageMount() fails
Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
2026-06-23 17:09:27 +08:00
crawfordxx ae30a5cad2 cri: reject CreateContainer when sandbox is not running
Before this fix, CreateContainer would proceed even if the sandbox
had already stopped or was in an unknown state. This could result in
containers being created in an unusable sandbox, leading to confusing
errors downstream.

StartContainer already guards with the same check:

  if sandbox.Status.Get().State != sandboxstore.StateReady {
      return nil, fmt.Errorf("sandbox container %q is not running", ...)
  }

Apply the identical guard in CreateContainer, immediately after the
sandbox state is known, so that callers receive a clear error instead
of a partial container object.

Fixes #13599

Signed-off-by: crawfordxx <crawfordxx@users.noreply.github.com>
2026-06-23 12:07:39 +08:00
Aman Raj 6a677e0fd6 cri: fix duplicated image env vars on checkpoint import
CRImportCheckpoint built the combined environment (image env followed by
the CRI container env) into a local slice, then re-appended that slice to
imageConfig.Env, duplicating every image environment variable on the
restored container. Assign the combined slice directly instead.

Fixes #13611

Signed-off-by: Aman Raj <aman.yug@gmail.com>
2026-06-18 22:04:33 +05:30
Maksym Pavlenko 749d8fbe45 Use metric timestamp for sandbox stats samples
Signed-off-by: Maksym Pavlenko <pavlenko.maksym@gmail.com>
2026-06-17 12:37:10 -07:00
Maksym Pavlenko e8dbd24ac5 cri: route stats collector's sandbox path through Controller.Metrics
Signed-off-by: Maksym Pavlenko <pavlenko.maksym@gmail.com>
2026-06-17 11:43:00 -07:00
Maksym Pavlenko 309aaba2a5 cri: route sandbox stats through Controller.Metrics
Signed-off-by: Maksym Pavlenko <pavlenko.maksym@gmail.com>
2026-06-17 11:43:00 -07:00
Chris Henzie a0086cfcee Merge commit from fork 2026-06-15 21:26:29 -07:00
Chris Henzie 432a7af299 Merge commit from fork 2026-06-15 21:25:18 -07:00
Chris Henzie 3977106b53 Merge commit from fork 2026-06-15 21:25:18 -07:00
Chris Henzie a834385de9 Merge commit from fork 2026-06-15 21:25:17 -07:00
Brian Goff 8196411f24 cri: make checkpoint restore robust to unexpected archive content
The CRI checkpoint restore path unpacked checkpoint archive/OCI image content
directly into the container's persistent state directory and read files such as
container.log back from it with a symlink-following copy. Checkpoint content is
externally provided, so make restore more defensive about what it unpacks and
how it reads those files back.

Behavior changes:

- Only unpack regular files and directories from the checkpoint archive.

- Unpack checkpoint content into a dedicated <state>/ctrd-restore
  subdirectory created fresh rather than into the state dir itself, so
  checkpoint content cannot collide with containerd's own files (e.g.
  the "status" blob). Restore and cleanup operate on that subdir;
  cleanup is now a single RemoveAll of it.

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
2026-06-15 15:11:36 -07:00
Ben Cressey 0ec1af4cae Do not propagate reserved labels from image configs
Image config labels are copied onto the container by both the CRI
plugin (BuildLabels) and the client's WithImageConfigLabels option
used by `ctr run`. Labels in the containerd.io/* namespace are
interpreted by containerd itself and labels in the io.cri-containerd*
namespace are interpreted by the CRI plugin. An image config is not a
trusted source for labels in either namespace.

Skip labels in both reserved namespaces when copying labels from an
image config to a container, and warn about each label skipped: an
image that tries to set them may be attempting to alter containerd
behavior. Oversized image labels are already skipped this way by
the CRI plugin.

Labels set explicitly by clients, for example via `ctr run --label`
or in the CRI request, are unaffected.

Verified with the CRI plugin and with `ctr run` against an image
whose config carries labels like these: the labels are no longer
present on the created container and a warning is logged for each.

Assisted-by: Claude Code
Signed-off-by: Ben Cressey <ben@cressey.org>
Signed-off-by: Samuel Karp <samuelkarp@google.com>
2026-06-10 13:18:24 -07:00