Commit Graph

1687 Commits

Author SHA1 Message Date
Samuel Karp
0c255158aa ctr: add --scrub-logs flag for Windows
Adds a new --scrub-logs flag to ctr run on Windows. This flag enables
the ScrubLogs option for the io.containerd.runhcs.v1 shim.

Assisted-by: gemini-cli
Signed-off-by: Samuel Karp <samuelkarp@google.com>
(cherry picked from commit 18a01c0020)
2026-08-04 13:31:50 -07:00
Maksim An
26dce170df Set SystemTemp env var to config temp on Windows
Since Go 1.21, os.MkdirTemp/os.TempDir resolve the temp directory via
Windows' GetTempPath2W. For processes running as SYSTEM (as containerd
does when running under the SCM), that API reads the temp location from
the SystemTemp environment variable rather than TMP/TEMP. As a result,
the existing TMP/TEMP overrides no longer steer the layer-extraction
tempdir for the containerd service, so it falls back to the default
C:\\Windows\\SystemTemp and unpacks on the SystemDrive, reintroducing the
cross-volume copy the 'temp' config option was meant to avoid.

Set SystemTemp to config.TempDir alongside TEMP/TMP so the override keeps
working on Go 1.21+.

Factor the env-var setting out of CreateTopLevelDirectories into a small
setTempDirEnv helper and add a focused unit test (TestSetTempDirEnv) that
verifies the expected variables are set: TEMP/TMP/SystemTemp on Windows,
TMPDIR on other platforms.

Ref: https://cs.opensource.google/go/go/+/refs/tags/go1.21.0:src/os/file_windows.go
Signed-off-by: Maksim An <maksiman@microsoft.com>
2026-06-30 19:48:04 +00:00
Akihiro Suda
9b0c0dc584 runc-shim: don't hold the service lock across runc create
The task service guards its containers map with s.mu, and getContainer()
takes it on behalf of effectively every task RPC (State, Connect, Stats,
Wait, Pause, Kill, ...). Create() held s.mu for its whole duration,
including runc.NewContainer(), which runs the actual `runc create`.

`runc create` can be slow on a loaded host. While it runs, any concurrent
task RPC blocks on s.mu. The tasks service applies a 2s timeout to State
(io.containerd.timeout.task.state), so a concurrent State waits on s.mu,
exceeds the deadline, and the ttrpc call is abandoned -- the late shim
reply then shows up as:

    ttrpc: received message on inactive stream stream=3

Since deadline errors are now surfaced to clients, this is treated as a
fatal failure and the just-created container is torn down right after
start (observed on Lima/vz: nginx -> Exited (1)).

Move runc.NewContainer() out of the s.mu critical section, mirroring the
runtime v1 shim lock optimization. s.mu is taken only once the container
exists, to guard the map and the remaining (fast) setup, so a slow create
no longer blocks concurrent State and other lookups.
preStart/handleStarted/cleanup only use s.lifecycleMu, so early-exit
handling is unchanged.

See lima-vm/lima#5030.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
2026-06-01 17:23:15 +00:00
Wei Fu
ac77917b2f config: preserve legacy grpc address across sparse imports
When migrating v3 [grpc] config to the v4 server plugin config, only
emit fields that were actually set in the legacy config. This prevents
a sparse imported [grpc] section, such as one only setting
max_send_message_size, from generating address = "" and overwriting the
address migrated from the root config.

Add table-driven coverage for sparse legacy grpc imports, including
address preservation, imported address override, and default address
retention when no imported config specifies address.

Signed-off-by: Wei Fu <fuweid89@gmail.com>
2026-04-29 13:13:33 -04:00
Derek McGowan
14fe0ac645 Merge pull request #13052 from delthas/fix-shim-sync
shim: fix send on closed channel race in task service
2026-04-28 02:24:13 +00:00
Davanum Srinivas
c30f23452c cri: use upstream Kubernetes modules
Switch the CRI integration layer from containerd's forked Kubernetes helpers
and clients to the upstream Kubernetes modules, and finalize the dependency
update to Kubernetes v0.36.0.

Replace the remaining internal helper copies with upstream packages:
- internal/cri/clock -> k8s.io/utils/clock
- internal/cri/executil -> upstream CRI exec helpers
- internal/cri/resourcequantity -> k8s.io/apimachinery/pkg/api/resource
- internal/cri/setutils -> k8s.io/apimachinery/pkg/util/sets
- internal/cri/types/labels.go -> internal/cri/labels
- integration/cri-api/pkg/apis/services.go -> k8s.io/cri-api/pkg/apis/services.go

Adopt the upstream CRI clients directly:
- add k8s.io/cri-client v0.36.0, k8s.io/cri-streaming v0.36.0, and
  k8s.io/streaming v0.36.0 as direct dependencies
- promote k8s.io/utils to a direct dependency and pull in
  k8s.io/component-base v0.36.0 indirectly
- keep integration/remote as a thin containerd adapter around cri-client,
  because the integration tests still need the stream-shaped
  GetContainerEvents RPC

Finalize the Kubernetes dependency update from v0.36.0-rc.0 to v0.36.0,
refresh vendor/, and drop the obsolete internal utility copies.

Also fix the protobuf MessageState mutex-copy vet failures exposed by the new
APIs and close the temporary integration CRI clients explicitly.

Signed-off-by: Davanum Srinivas <davanum@gmail.com>
2026-04-23 12:59:58 +02:00
Fu Wei
46a7bd7acb Merge pull request #12562 from dmcgowan/plugin-api-handlers
Add plugins for server listeners
2026-04-22 17:27:28 +00:00
Derek McGowan
a0f3c53e2f Ensure Plugins is not nil during migration
Signed-off-by: Derek McGowan <derek@mcg.dev>
2026-04-21 18:02:41 -07:00
Derek McGowan
841c518a22 Add tests for serviceMigrate config migration
Signed-off-by: Derek McGowan <derek@mcg.dev>
2026-04-21 18:02:41 -07:00
Derek McGowan
a2b19072b8 Add metrics server plugin
Signed-off-by: Derek McGowan <derek@mcg.dev>
2026-04-21 18:02:40 -07:00
Derek McGowan
c15ec24857 Add server plugins for grpc and ttrpc
Migrate configuration and move server initialization

Signed-off-by: Derek McGowan <derek@mcg.dev>
2026-04-21 18:02:40 -07:00
Derek McGowan
06c23567c0 Add new server plugin type use for debug server
The new server plugin type allows services which have listeners to be
configured as plugins rather than defined directly in the global
configuration. This provides more configuration consistency and allows
containerd to be extended for new types of api handlers.

Signed-off-by: Derek McGowan <derek@mcg.dev>
2026-04-21 18:02:00 -07:00
Akihiro Suda
341401c1d5 Merge pull request #12785 from dmcgowan/pass-socket-address
Make shim socket directory use configured directory
2026-04-15 10:24:25 +00:00
Derek McGowan
59c3464a01 Remove the unnecessary mkdir on the default state directory
The default state directory does not need to be created and only the
configured state directory must be setup.

Signed-off-by: Derek McGowan <derek@mcg.dev>
2026-04-15 00:21:18 -07:00
Derek McGowan
d806373feb Make shim socket directory use configured state
Send the socket directory from containerd to the shim. The shim still
decides where the socket goes but can use the environment variable
passed from containerd to ensure the socket is placed in the configured
directory with proper permission.

This is needed for some rootless cases which do not have permission to
the default state directory as currently set. The directory being
hardcoded by the shim means it is currently not possible to change the
location the shim will listen at.

Signed-off-by: Derek McGowan <derek@mcg.dev>
2026-04-15 00:21:18 -07:00
ChengyuZhu6
64a2e62b52 erofs: wire os.features into conversion and selection
Mark converted EROFS manifests with the erofs OS feature and cover
feature-aware manifest selection and unpack routing for erofs images.

Signed-off-by: ChengyuZhu6 <hudson@cyzhu.com>
2026-04-15 10:28:54 +08:00
ChengyuZhu6
b320d3c855 ctr: add EROFS image conversion support
Add EROFS conversion support to ctr convert command with configurable
options for tar-index mode and mkfs parameters.

Usage:
  ctr image convert --erofs src:tag dst:tag
  ctr image convert --erofs --erofs-compression='lz4hc,12' src:tag dst:tag

Signed-off-by: ChengyuZhu6 <hudson@cyzhu.com>
2026-04-15 10:28:47 +08:00
Derek McGowan
2c102c6cbe Update bootstrap API log level definition
Avoid using logrus concepts in the API, use slog style log levels with
integer values and 0 meaning the default "info" level.

Signed-off-by: Derek McGowan <derek@mcg.dev>
2026-04-10 15:23:34 -07:00
Derek McGowan
a755ca16e5 Merge pull request #12865 from dmcgowan/readonly-overlay-erofs-no-mount
Support reading readonly overlays without mounting
2026-04-09 18:37:15 +00:00
Maksym Pavlenko
16b7ce2549 Address code review suggestions
Signed-off-by: Maksym Pavlenko <pavlenko.maksym@gmail.com>
2026-04-08 08:29:28 -05:00
Maksym Pavlenko
9bf65dcf02 Use enums instead of strings for capabilities and log level
Signed-off-by: Maksym Pavlenko <pavlenko.maksym@gmail.com>
2026-04-08 08:29:28 -05:00
Derek McGowan
243cab594e Deprecate old pkg/shim interfaces
Signed-off-by: Derek McGowan <derek@mcg.dev>
2026-04-08 08:29:28 -05:00
Maksym Pavlenko
eea1fa6516 Do not fail when failed to parse log level
Signed-off-by: Maksym Pavlenko <pavlenko.maksym@gmail.com>
2026-04-08 08:29:28 -05:00
Maksym Pavlenko
0f55bdd49c Fix extensions API and update tests
Signed-off-by: Maksym Pavlenko <pavlenko.maksym@gmail.com>
2026-04-08 08:29:28 -05:00
Maksym Pavlenko
58022a748a Parse log level when starting shim instance
Signed-off-by: Maksym Pavlenko <pavlenko.maksym@gmail.com>
2026-04-08 08:29:28 -05:00
Maksym Pavlenko
d957b1bf53 Use log level instead of debug flag
Signed-off-by: Maksym Pavlenko <pavlenko.maksym@gmail.com>
2026-04-08 08:29:28 -05:00
Maksym Pavlenko
9e9a095feb Read spec annotations from file
Revert changes related to reading annotations in runc v2 shim,
because this requires a special path for runc shim. This complicates
migration to the new bootstrap API.

Signed-off-by: Maksym Pavlenko <pavlenko.maksym@gmail.com>
2026-04-08 08:29:28 -05:00
Maksym Pavlenko
5ea993b48d Pass runc options as a separate extension
Signed-off-by: Maksym Pavlenko <pavlenko.maksym@gmail.com>
2026-04-08 08:29:28 -05:00
Maksym Pavlenko
7f39b2d933 Update shim to support new bootstrap api
Signed-off-by: Maksym Pavlenko <pavlenko.maksym@gmail.com>
2026-04-08 08:29:28 -05:00
Jintao Zhang
cf772973cf process/io: ignore SIGTERM exit in cancel() to fix flaky test
When cancel() sends SIGTERM to a short-lived logging binary that is
already mid-exit, cmd.Wait() may return 'signal: terminated'. This is
expected behavior since we sent the SIGTERM ourselves, so treat it as
a normal exit.

Fixes flaky TestNewBinaryIOBinaryV2Ready.

Signed-off-by: Jintao Zhang <zhangjintao9020@gmail.com>
2026-04-05 13:41:54 +00:00
Jintao Zhang
22e6e1541c Add binary-v2 logging readiness scheme
Expose log URI schemes in runtime v2 metadata

Signed-off-by: Jintao Zhang <zhangjintao9020@gmail.com>
2026-04-05 13:41:15 +00:00
Derek McGowan
21d666cfbc Update fsview to allow type registration
Move erofs implementation to plugin and register with fsview.

Signed-off-by: Derek McGowan <derek@mcg.dev>
2026-04-04 22:37:38 -07:00
Maksym Pavlenko
43d906b6ff Merge pull request #13117 from HASidd/log-trace
tracing: add option to inject trace ID into logrus fields
2026-03-31 23:44:09 +00:00
Hasan Siddiqui
10c30fb74a tracing: add option to inject trace ID into logrus fields
Introduce functional options to NewLogrusHook to allow optional Trace ID
injection into log fields. This enables log-trace correlation via the
[debug] config without breaking existing external consumers of
pkg/tracing.

Signed-off-by: Hasan Siddiqui <hasiddiqui@google.com>
2026-03-24 21:51:27 +00:00
Hasan Siddiqui
dc5806cd94 Propagate OpenTelemetry traces in outgoing RPCs from plugin clients
While incoming gRPC requests are already being traced via the
server-side handler, outgoing RPCs to proxy plugins are missing the
client-side equivalent. Adding otelgrpc.NewClientHandler() ensures trace
context is successfully propagated to the plugins.

Signed-off-by: Hasan Siddiqui <hasiddiqui@google.com>
2026-03-24 01:57:46 +00:00
Weixie Cui
ee7441ddfc runc-shim: fix exec PID error message and fmt verb
Correct the typo in the error string (pi -> pid) and use %w for error wrapping instead of the invalid %wd verb when reading the exec PID file.

Signed-off-by: Weixie Cui <cuiweixie@gmail.com>
2026-03-22 20:27:44 +08:00
delthas
1dcd765fa6 shim: fix send on closed channel race in task service
The runc v2 shim's event forwarding has a race condition between
send() and the shutdown callback that closes the events channel.
When a Delete or processExit RPC runs concurrently with shim
shutdown, the following panic occurs:

  panic: send on closed channel

  goroutine 153 [running]:
  github.com/containerd/containerd/v2/cmd/containerd-shim-runc-v2/task.(*service).send(...)
          /containerd/cmd/containerd-shim-runc-v2/task/service.go:694
  github.com/containerd/containerd/v2/cmd/containerd-shim-runc-v2/task.(*service).Delete(0xc000228120, ...)
          /containerd/cmd/containerd-shim-runc-v2/task/service.go:366 +0x229

The root cause is that send() performs a bare channel send on
s.events with no synchronization:

  func (s *service) send(evt any) {
      s.events <- evt
  }

Meanwhile, a shutdown callback registered in NewTaskService closes
the same channel:

  sd.RegisterCallback(func(context.Context) error {
      close(s.events)
      return nil
  })

Since shutdownService.Shutdown() runs all callbacks concurrently via
errgroup, close(s.events) can execute while a Delete, Start, Create,
Exec, Pause, Resume, or handleProcessExit goroutine is in send().

This was observed in CI on a Kind cluster (containerd v2.1.1) under
heavy pod churn: the shim panic crashed containerd on the worker
node, breaking the kubectl attach stream to the test pod and causing
the CI job to fail.

Fix this by removing the close(s.events) shutdown callback entirely
and instead using select with s.shutdown.Done() in both send() and
forward(), which is the established pattern for shutdown-safe channel
operations throughout the containerd codebase (see
client/events.go, core/events/exchange/exchange.go). The events
channel is never closed; it is garbage collected when the shim
process exits after shutdown.

In forward(), after s.shutdown.Done() fires, remaining buffered
events are drained with a non-blocking receive loop before
returning, preserving the previous behavior where range over the
closed channel would drain buffered items.

Alternative designs considered:

- recover() in send(): while compact, this pattern is not used
  anywhere in the containerd codebase for closed-channel protection,
  and silently swallowing panics makes the code harder to reason
  about.

- RWMutex guarding the channel send (RLock) and close (WLock): this
  would work correctly and allows concurrent sends, but no existing
  containerd code uses a mutex to guard channel send+close. It also
  adds lock contention on every event send during normal operation.

- select with a dedicated "closing" channel closed before
  s.events: this does not work in Go because select panics on a
  send to a closed channel regardless of whether other cases are
  ready (verified empirically).

Signed-off-by: delthas <delthas@dille.cc>
2026-03-18 17:00:04 +01:00
Derek McGowan
621cedde94 Merge pull request #12521 from chris-henderson-alation/fix_permissions_rootless
Permission denied when attempting os.Chmod the config.Root during server startup
2026-03-17 15:54:02 +00:00
Sebastiaan van Stijn
a122afe13b cmd: modernize: any
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2026-03-17 13:36:16 +01:00
Derek McGowan
489b653034 Merge pull request #13022 from thaJeztah/modernize
*: modernize code
2026-03-16 22:23:04 +00:00
Samuel Karp
9eecce32b8 Merge pull request #13018 from crawfordxx/fix-typos-in-source-code
fix: correct typos found by codespell
2026-03-16 21:22:50 +00:00
Sebastiaan van Stijn
16e340f326 *: modernize: plusbuild
go install golang.org/x/tools/go/analysis/passes/modernize/cmd/modernize@latest
    modernize -plusbuild -fix ./...

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2026-03-15 18:24:16 +01:00
Sebastiaan van Stijn
29030ff927 cmd: modernize: any
go install golang.org/x/tools/go/analysis/passes/modernize/cmd/modernize@latest
    modernize -any -fix ./...

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2026-03-15 18:24:14 +01:00
Sebastiaan van Stijn
09f7154dbd *: modernize: mapsloop
go install golang.org/x/tools/go/analysis/passes/modernize/cmd/modernize@latest
    modernize -mapsloop -fix ./...

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2026-03-15 15:01:38 +01:00
Derek McGowan
efc4825551 Merge pull request #12608 from dmcgowan/migration-logic-update
Update plugin config migration to run on load
2026-03-13 14:27:18 +00:00
majianhan
aa600f65dd fix: correct typos found by codespell
Fix various typos across source code, tests, and documentation:
- README.md: Preforming → Performing
- pull.go: commpleted → completed
- server_test.go: unxpected → unexpected
- diff.go: atleast → at least
- content.go: desciptor → descriptor
- remote.go: requst → request
- imagestore_test.go: expeceted → expected
- pull_test.go: shoule → should

Signed-off-by: majianhan <majianhan@kylinos.cn>
2026-03-12 08:54:56 +08:00
majianhan
01d094d663 docs: update outdated content fetch help text
The 'content fetch' command description has been unchanged since it was
first added over 8 years ago. It described the feature as "experimental"
with "few leaps to make this work", which no longer reflects reality.

Update the help text to accurately describe what the command does: it
pulls image content into the content store without unpacking, and can
be used to pre-fetch images.

Fixes #11754

Signed-off-by: Crawford Ma <crawfordxx@users.noreply.github.com>
2026-03-11 20:20:20 +08:00
Maksym Pavlenko
f4681e01d0 Merge pull request #12839 from shiv-tyagi/vendor-discovery-gpus
Detect vendor in cdi specs to generate deviceIDs for --gpus
2026-02-20 04:13:12 +00:00
Phil Estes
ddc8502cd6 Merge pull request #12868 from thaJeztah/cleanup_cli_flags
cmd: fix inconsistencies in command-line flags, and add missing `--version` flags
2026-02-19 21:51:16 +00:00
Derek McGowan
0d7fee0623 Update plugin config migration to run on load
Perform the plugin migrations on load to allow stepping through plugin
migration versions to happen alongside migration of the global
configuration object. When the configuration migrations happen
separately, the version in the config can get increasd on load and cause
plugin migration not to occur. This does not cause issues today because
global config migrations only occur for version 0 and 1, which was
before plugin config migration was introduced. Any new version which
does migrations either cannot get called on load or will break plugin
migration later.

This change simplifies configuration load and migration, preventing the
need to migrate the configurations on load and again later when plugins
are loaded. This also allows includes to work at different versions,
which may currently break or cause inconsistent results.

Signed-off-by: Derek McGowan <derek@mcg.dev>
2026-02-19 09:13:25 -08:00