Commit Graph

1001 Commits

Author SHA1 Message Date
Derek McGowan
2e747a0ae7 Merge pull request #12332 from henry118/parallel-unpack
Implement parallel unpack
2025-10-24 20:16:52 +00:00
Henry Wang
0198b87fcf Implement parallel unpack
Signed-off-by: Henry Wang <henwang@amazon.com>
2025-10-24 17:54:26 +00:00
Wei Fu
2042e805b8 cri/server/podsandbox: disable event subscriber
We have individual goroutine for each sandbox container. If there is any
error in handler, that goroutine will put event in that backoff queue.
So we don't need event subscriber for podsandbox. Otherwise, there will
be two goroutines to cleanup sandbox container.

```
>>>> From EventMonitor
  time="2025-10-23T19:30:59.626254404Z" level=debug msg="Received containerd event timestamp - 2025-10-23 19:30:59.624494674 +0000 UTC, namespace - \"k8s.io\", topic - \"/tasks/exit\""
  time="2025-10-23T19:30:59.626301912Z" level=debug msg="TaskExit event in podsandbox handler container_id:\"22e15114133e4d461ab380654fb76f3e73d3e0323989c422fa17882762979ccf\" id:\"22e15114133e4d461ab380654fb76f3e73d3e0323989c422fa17882762979ccf\" pid:203121 exit_status:137 exited_at:{seconds:1761247859 nanos:624467824}"

>>> If EventMonitor handles task exit well, it will close ttrpc
connection and then waitSandboxExit could encounter ttrpc-closed error

  time="2025-10-23T19:30:59.688031150Z" level=error msg="failed to delete task" error="ttrpc: closed" id=22e15114133e4d461ab380654fb76f3e73d3e0323989c422fa17882762979ccf
```

If both task.Delete calls fail but the shim has already been shut down, it
could trigger a new task.Exit event sent by cleanupAfterDeadShim. This would
result in three events in the EventMonitor's backoff queue, which is unnecessary
and could cause confusion due to duplicate events.

The worst-case scenario caused by two concurrent task.Delete calls is a shim
leak. The timeline for this scenario is as follows:

| Timestamp | Component       | Action                        | Result                                                                                           |
| ------    | -----------     | --------                      | --------                                                                                         |
| T1        | EventMonitor    | Sends `task.Delete`           | Marked as Req-1                                                                                  |
| T2        | waitSandboxExit | Sends `task.Delete`           | Marked as Req-2                                                                                  |
| T3        | containerd-shim | Handles Req-2                 | Container transitions from stopped to deleted                                                    |
| T4        | containerd-shim | Handles Req-1                 | Fails - container already deleted<br>Returns error: `cannot delete a deleted process: not found` |
| T5        | EventMonitor    | Receives `not found` error    | -                                                                                                |
| T6        | EventMonitor    | Sends `shim.Shutdown` request | No-op (active container record still exists)                                                     |
| T7        | EventMonitor    | Closes ttrpc connection       | Clean container state dir                                                                        |
| T8        | containerd-shim | Handles Req-2                 | Removes container record from memory                                                             |
| T9        | waitSandboxExit | Receives error                | Error: `ttrpc: closed`                                                                           |
| T10       | waitSandboxExit | Sends `shim.Shutdown` request | Fails (connection already closed)                                                                |
| T11       | waitSandboxExit | Closes ttrpc connection       | No-op (already closed)                                                                           |

The containerd-shim is still running because shim.Shutdown was sent at T6
before T8. Because container's state dir is deleted at T7, it's unable to clean
it up after containerd restarted.

We should avoid concurrent task.Delete calls here.

I also add subcommand - shutdown - in `ctr shim` for debug.

Fixed: #12344

Signed-off-by: Wei Fu <fuweid89@gmail.com>
2025-10-24 12:19:52 -04:00
Wei Fu
4f130dbe73 cri: retry stopSandboxContainer if shim connection is closed
Background:

The TestRunPodSandboxWithShimDeleteFailure test case validates that the sandbox
can be properly cleaned up when RunPodSandbox returns an error.

This test simulates a RunPodSandbox failure by using a failpoint to inject an
error during the startup of the sandbox container. It also blocks the first
task deletion attempt within the deferred cleanup logic of RunPodSandbox.
As a result, the sandbox remains after the failed RunPodSandbox call, allowing
the test to verify the subsequent cleanup process.

Race-condition causes flaky issue:

The defer cleanup invokes `task.Delete` with `containerd.WithProcessKill` option
so that it will kill sandbox container first. Since we don't block `Kill` call,
cleanup will kill sandbox container successfully, even if `task.Delete`
fails.

```go
// Link 04fe0ff9d2/internal/cri/server/podsandbox/sandbox_run.go (L248-L258)

	defer func() {
		if retErr != nil && cleanupErr == nil {
			deferCtx, deferCancel := ctrdutil.DeferContext()
			defer deferCancel()
			// Cleanup the sandbox container if an error is returned.
			if _, err := task.Delete(deferCtx, WithNRISandboxDelete(id), containerd.WithProcessKill); err != nil && !errdefs.IsNotFound(err) {
				log.G(ctx).WithError(err).Errorf("Failed to delete sandbox container %q", id)
				cleanupErr = err
			}
		}
	}()
```

That podSandboxEventHandler.HandleEvent receives task exit event
during defer cleanup of RunPodSandbox and then it will delete task. That
`task.Delete` call could take few second to shutdown containerd-shim. It
could bring race-condition if we invoke RemovePodSandbox.

```go
// Link 04fe0ff9d2/internal/cri/server/podsandbox/events.go (L43-L61)

func (p *podSandboxEventHandler) HandleEvent(any interface{}) error {
	switch e := any.(type) {
	case *eventtypes.TaskExit:
		log.L.Debugf("TaskExit event in podsandbox handler %+v", e)
		// Use ID instead of ContainerID to rule out TaskExit event for exec.
		sb := p.controller.store.Get(e.ID)
		if sb == nil || sb.Container == nil {
			return nil
		}
		ctx := ctrdutil.NamespacedContext()
		ctx, cancel := context.WithTimeout(ctx, handleEventTimeout)
		defer cancel()
		if err := handleSandboxTaskExit(ctx, sb, e); err != nil {
			return fmt.Errorf("failed to handle container TaskExit event: %w", err)
		}
		return nil
	}
	return nil
}
```

If shim exits, that RemovePodSandbox could return error like

```
... failed to kill pod sandbox container: ttrpc: closed
```

Retry and fix this transient issue:

If `a ttrpc: closed` error occurs, we should retry the operation.
There’s no need to introduce a mutex for this, as the kubelet already
has retry logic to ensure the sandbox is eventually cleaned up.

Other flaky issue:

The event handle could be able to cleanup shim asynchronously. That
could cause ListPodSandbox returns empty, which is not expected. Updated
that test case with `Kill` failpoint instead of `Delete`.

Fixes: #11107
Close: #11967

Signed-off-by: Wei Fu <fuweid89@gmail.com>
2025-10-20 21:16:00 -04:00
ningmingxiao
932b65a492 restart:use goroutine to speedup loadShims
Signed-off-by: ningmingxiao <ning.mingxiao@zte.com.cn>
2025-10-09 09:48:09 +08:00
Fu Wei
61ddcd5372 Merge pull request #12063 from dmcgowan/mount-manager
Add mount manager
2025-10-03 14:01:38 +00:00
Derek McGowan
67f0970a54 Add mount activation integration test
Signed-off-by: Derek McGowan <derek@mcg.dev>
2025-09-29 17:08:35 -07:00
Derek McGowan
76a877bb5c Add mount activation support to task service
Signed-off-by: Derek McGowan <derek@mcg.dev>
2025-09-29 17:08:35 -07:00
Henry Wang
5a00693e7f Fix integ-test: looking for sleep inf as longCommand
Signed-off-by: Henry Wang <henwang@amazon.com>
2025-09-29 19:44:33 +00:00
Kohei Tokunaga
8112ca64f0 cri: remove copying of message structs
Copying of message structs is not allowed and results in the following
govet error. This commit fixes these errors by avoiding copying of the
messages.

> google.golang.org/protobuf/runtime/protoimpl.MessageState contains sync.Mutex (govet)

Signed-off-by: Kohei Tokunaga <ktokunaga.mail@gmail.com>
2025-09-16 13:49:45 +09:00
Kohei Tokunaga
9d351805bc go.mod: Bump up k8s.io to 0.34.1
Signed-off-by: Kohei Tokunaga <ktokunaga.mail@gmail.com>
2025-09-16 11:36:35 +09:00
Enji Cooper
f45716efed Clean up issues cited by usetesting package with golangci
This commit makes all of the recommended changes to use the `testing`
package helper functions instead of doing the equivalent longhand
versions of the same thing.

This change was needed in order to properly detect errors, as the code
would previously skip running `tenv` stating that it had been deprecated
in favor of `usetesting`.

Signed-off-by: Enji Cooper <yaneurabeya@gmail.com>
2025-09-07 14:07:40 -07:00
Rodrigo Campos
f0ee598ff7 integration: Add test for directives with userns
Signed-off-by: Rodrigo Campos <rodrigoca@microsoft.com>
2025-08-26 16:28:59 +02:00
ningmingxiao
dc38aaf6c2 ci:fix TestSandboxRemoveWithoutIPLeakage failed
Signed-off-by: ningmingxiao <ning.mingxiao@zte.com.cn>
2025-08-15 23:26:20 +08:00
Akihiro Suda
a92d8700bf Merge pull request #12085 from akhilerm/pause-3.10.1
update pause image to pause:3.10.1
2025-07-15 06:12:20 +00:00
Kirtana Ashok
117179ae1a Remove WS2025 from CIs due to regression
Signed-off-by: Kirtana Ashok <kiashok@microsoft.com>
2025-07-11 10:56:37 -07:00
Akhil Mohan
222b2d3e72 update pause image to pause:3.10.1
Signed-off-by: Akhil Mohan <akhilerm@gmail.com>
2025-07-11 11:29:02 +05:30
Derek McGowan
4d89721f23 Merge pull request #11623 from yashsingh74/update-golangci-v2
ci: bump golangci from 6.5.2 to 7.0.0
2025-07-01 18:06:14 +00:00
Phil Estes
38e119814b Merge pull request #12008 from ningmingxiao/fix_ci3
ci:fix ci TestContainerExecLargeOutputWithTTY panic
2025-06-30 15:57:45 +00:00
Akihiro Suda
9300d03899 Merge pull request #11885 from ningmingxiao/fix_nerdctl_unknown
bugfix:close container io when runtime create failed
2025-06-22 01:00:09 +00:00
ningmingxiao
a79e791413 ci:fix ci TestContainerExecLargeOutputWithTTY panic
Signed-off-by: ningmingxiao <ning.mingxiao@zte.com.cn>
2025-06-21 13:16:27 +08:00
yashsingh74
4ba81d4296 fix: ST1001: should not use dot imports (staticcheck)
Signed-off-by: yashsingh74 <yashsingh1774@gmail.com>
2025-06-18 14:16:41 +05:30
yashsingh74
b3eec6d8e9 fix: ST1005: error strings should not end with punctuation or newlines
Signed-off-by: yashsingh74 <yashsingh1774@gmail.com>
2025-06-18 14:16:41 +05:30
yashsingh74
1ff5900044 fix: QF1004: strings.ReplaceAll instead (staticcheck)
Signed-off-by: yashsingh74 <yashsingh1774@gmail.com>
2025-06-18 14:16:41 +05:30
yashsingh74
56516173d0 fix: QF1002: could use tagged switch on host (staticcheck)
Signed-off-by: yashsingh74 <yashsingh1774@gmail.com>
2025-06-18 14:16:40 +05:30
ningmingxiao
e6708bddfb bugfix:close container io when runtime create failed
Signed-off-by: ningmingxiao <ning.mingxiao@zte.com.cn>
2025-06-15 11:35:25 +08:00
yylt
9de26f3150 [e2e] add case for shim wait interface
Signed-off-by: yang yang <yang8518296@163.com>
2025-06-10 23:05:44 +08:00
Fu Wei
eeb9065242 Merge pull request #11916 from fuweid/fix-11871
*: properly shutdown non-groupable shims to prevent resource leaks
2025-06-08 00:16:29 +00:00
Kirtana Ashok
2f1948a503 Enable CIs to run on WS2022 and WS2025
Signed-off-by: Kirtana Ashok <kiashok@microsoft.com>
2025-06-05 15:25:03 -07:00
Akihiro Suda
bcd000f443 Merge pull request #11578 from djdongjin/image-volume-subpath
[KEP-4639] Support image volume mount subpath
2025-06-04 04:11:09 +00:00
Jin Dong
cff8184ffb support image volume sub path
Signed-off-by: Jin Dong <djdongjin95@gmail.com>
2025-06-03 21:53:29 -04:00
Wei Fu
1ac97c2c13 *: properly shutdown non-groupable shims to prevent resource leaks
Previously, to address issue #11708, PR #11793 changed containerd to always
invoke the shim binary to establish shim connections, rather than reusing the
sandbox shim. However, this change did not ensure that the Shutdown API was
called to stop the shim process.

Starting with containerd v2.0.0, the Shutdown API is only invoked for sandbox
containers (when container.SandboxID is empty). This approach works for
groupable shims, where multiple containers share a single socket address and
only require a single Shutdown call. However, for non-groupable shims, each
container requires its own Shutdown call during cleanup to avoid leaking shim
processes.

Additionally, PR #11793 introduced a corner case during upgrades:
- T1: An old container-shim-runc-v2 (<=v1.7.X) is running for pod A.
- T2: containerd is upgraded to v2.X.Y.
- T3: A new container A-C1 is created in pod A using the new shim-runc-v2 binary.
- T4: bootstrap.json indicates version:3 protocol, but it is downgraded to version:2 in memory.
- T5: containerd is restarted.
- T6: containerd fails to connect to A-C1.
- T7: The A-C1 container is left in EXITED status in the CRI plugin.

To address this, ensure that loadShimTask downgrades to version:2 if necessary,
and always invoke the Shutdown API for each non-groupable shim during cleanup to
prevent resource leaks and handle upgrade scenarios correctly.

(Introduced by #11793)

Signed-off-by: Wei Fu <fuweid89@gmail.com>
2025-06-02 00:01:08 -04:00
Jin Dong
213337ce4e Fetch image with default platform only in TestExportAndImportMultiLayer
`TestExportAndImportMultiLayer` has been very flaky due to upstream
registry throttling/unavailability. E.g.,

https://github.com/containerd/containerd/actions/runs/15168768477/job/42653479864

```shell
    log_hook.go:47: time="2025-05-21T17:42:37.345336659Z" level=debug msg="fetch failed" func=docker.dockerFetcher.open file="/home/runner/work/containerd/containerd/core/remotes/docker/fetcher.go:470" digest="sha256:5178da1ca6af8a14a235f58eb31955ca5f4c72f950d35f9bb67a8bd20232d840" error="unexpected status code https://mcr.microsoft.com/v2/windows/nanoserver/blobs/sha256:5178da1ca6af8a14a235f58eb31955ca5f4c72f950d35f9bb67a8bd20232d840: 503 Service Unavailable" mediatype=application/vnd.docker.image.rootfs.foreign.diff.tar.gzip size=116254563 testcase=TestExportAndImportMultiLayer url="https://mcr.microsoft.com/v2/windows/nanoserver/blobs/sha256:5178da1ca6af8a14a235f58eb31955ca5f4c72f950d35f9bb67a8bd20232d840"
```

Notice this test fetches all platform images which is
unnecessary I think. E.g., the 503 from mcr above caused Linux test failures.
This change should reduce requests to `mcr.microsoft.com`.

Signed-off-by: Jin Dong <djdongjin95@gmail.com>
2025-05-21 16:08:39 -04:00
Mike Brown
d498e690eb clones k8s util exec used by streaming code removing k8s util dependencies
Signed-off-by: Mike Brown <brownwm@us.ibm.com>
2025-05-15 16:34:09 +00:00
Samuel Karp
0721b22c75 Merge pull request #11824 from ningmingxiao/fix_ci_timeout
ci:fix ci timeout on almalinux
2025-05-08 05:32:05 +00:00
ningmingxiao
2be7a7310a ci:fix ci timeout on almalinux
Signed-off-by: ningmingxiao <ning.mingxiao@zte.com.cn>
2025-05-08 12:35:26 +08:00
Fu Wei
3a1c2db95a Merge pull request #11793 from fuweid/carry-on-11761
[carry-11761] core/runtime: should invoke shim binary if it doesn't support Sandbox API
2025-05-06 22:37:07 +00:00
Wei Fu
1c70f237cb integration: add testcase to recover ungroupable shim
Signed-off-by: Wei Fu <fuweid89@gmail.com>
Co-authored-by: yang yang <yang8518296@163.com>
2025-05-06 01:54:43 -04:00
Danny Canter
33ee060a35 Use Go 1.19 atomic wrappers everywhere
We've long been able to use these and they have a couple
great benefits:

1. Forces you to always access them atomically. With the pointer
variants it's completely valid to access the regular ol' int64/uint32
etc. without using the atomic.* methods. These wrappers don't provide
access to the underlying value so it forces correct usage always.

2. Conveys intent much better. Seeing the type be atomic.Int32 immediately
lets the reader know that this var will be used in a concurrent context,
and we no longer need comments like "this MUST be accessed atomically"
or similar.

Signed-off-by: Danny Canter <danny@dcantah.dev>
2025-05-03 03:46:20 -07:00
Mike Brown
5f3f84f567 removes use of klog from containerd repo
Signed-off-by: Mike Brown <brownwm@us.ibm.com>
2025-05-02 13:34:46 +00:00
Mike Brown
bfd85405db clones k8s component-base logreduction for integration test
Signed-off-by: Mike Brown <brownwm@us.ibm.com>
2025-05-01 20:42:31 +00:00
Derek McGowan
ee7189d1df Add retries for flaky Windows test
Partially addressing issue #8422
This does not fix an underlying race in the output

Signed-off-by: Derek McGowan <derek@mcg.dev>
2025-04-30 16:16:39 -07:00
Adrien Delorme
72c8c7708c only keep one setting: concurrent_layer_fetch_buffer
Signed-off-by: Adrien Delorme <azr@users.noreply.github.com>
2025-04-24 11:41:33 +02:00
Adrien Delorme
024775dab1 set dl options on resolver
Signed-off-by: Adrien Delorme <azr@users.noreply.github.com>
2025-04-24 11:41:33 +02:00
Adrien Delorme
f9af08820b perf(pull): multipart layer fetch
Signed-off-by: Adrien Delorme <azr@users.noreply.github.com>
Co-Authored-By: Corentin REGAL <143578+co42@users.noreply.github.com>
2025-04-24 11:39:42 +02:00
Tony Fang
b694be29a0 Update CRI image service to pull using transfer service
- adds a transfer service progress reporter to handle timeouts. Also other test fixes
- fallback to local image pull when configuration conflict

Signed-off-by: Tony Fang <nhfang@amazon.com>

Co-authored-by: Swagat Bora <sbora@amazon.com>
2025-04-23 18:18:27 +00:00
Maksym Pavlenko
1e8955d8b7 Merge pull request #11547 from dmcgowan/upgrade-tests-1.7
Fix upgrade tests for 1.7
2025-04-21 21:30:16 +00:00
Akihiro Suda
d9c889568e Remove the support for Schema 1 images
Schema 1 (`application/vnd.docker.distribution.manifest.v1+prettyjws`) has been
officially deprecated since containerd v1.7 (PR 6884), and disabled since v2.0 (PR 9765).

Users who have been seeing warnings like `conversion from schema 1 images is deprecated`
now have to rebuild the image with Schema 2 or OCI.

Schema 2 was introduced in Docker 1.10 (Feb 2016), so most users should have been already
using Schema 2 or OCI.

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
2025-04-11 09:03:26 +09:00
Derek McGowan
bca39a6f46 Add documentation for test for issue 10467
Signed-off-by: Derek McGowan <derek@mcg.dev>
2025-03-31 17:32:56 -07:00
Derek McGowan
713f753e5d Update release upgrade tests to test 1.7 and 2.0
Fix 1.7 config to match previous version which allowed upgrade to 2.x.

Signed-off-by: Derek McGowan <derek@mcg.dev>
2025-03-31 17:32:55 -07:00