Commit Graph
337 Commits
Author SHA1 Message Date
Derek McGowan c37fe74c7d Merge pull request #9865 from kinvolk/rata/userns-update-podSandboxStatus-1.7
[release/1.7]  Include userns info in cri/server PodSandboxStatus
2024-04-22 08:22:31 -07:00
Evan Lezar 7a2f49f70f Bump tags.cncf.io/container-device-interface to v0.7.2
This includes migrating from cdi.GetRegistry() to cdi.Configure() and
using top-level cdi Refresh and InjectDevices functions as applicable.

Signed-off-by: Evan Lezar <elezar@nvidia.com>
2024-04-18 16:42:04 +02:00
Danny Canter 90c309fe2f Add IsNotFound case to ListPodSandboxStats
Fixes #10013. It seems we can end up in a spot where the sandbox store still
has a listing for a pod, whereas containerds underlying store has removed it.
It might be better to shield the caller (k8s) from these transient errors.

Signed-off-by: Danny Canter <danny@dcantah.dev>
(cherry picked from commit 2474a99c30)
Signed-off-by: Danny Canter <danny@dcantah.dev>
2024-04-05 11:35:53 -07:00
Derek McGowan 33b3e13e61 Merge pull request #9855 from ialidzhikov/cherry-pick-8337-to-release/1.7
[release/1.7] Register imagePullThroughput and count with MiB
2024-03-01 06:16:02 -08:00
Derek McGowan 94fed20205 Merge pull request #9900 from akhilerm/cherry-pick-9800-1.7
[release/1.7] Update golangci-lint to v1.56.1
2024-03-01 06:14:40 -08:00
Kohei Tokunaga b16ca72b2e Bump up golangci-lint to v1.54.2
Signed-off-by: Kohei Tokunaga <ktokunaga.mail@gmail.com>
(cherry picked from commit 6e2c915a44)
Signed-off-by: Akhil Mohan <akhil.mohan@broadcom.com>
2024-03-01 14:46:21 +05:30
Davanum Srinivas 39db3f18b2 adjust test cases to run for windows
Signed-off-by: Davanum Srinivas <davanum@gmail.com>
2024-02-29 22:57:20 -05:00
James Sturtevant 579d8b463b [cri] Handle Windows pod transitions gracefully
When the pods are transitioning there are several
cases where containers might not be in valid state.
There were several cases where the stats where
failing hard but we should just continue on as
they are transient and will be picked up again
when kubelet queries for the stats again.

Signed-off-by: James Sturtevant <jstur@microsoft.com>

Signed-off-by: Mark Rossetti <marosset@microsoft.com>
2024-02-29 22:17:22 -05:00
Rodrigo Campos b57dc9fd36 cri/server: Add userns tests in PodSandboxStatus
The cherry-pick has been amended to duplicate the tests in cri/sbserver and
cri/server.

Signed-off-by: Rodrigo Campos <rodrigoca@microsoft.com>
(cherry picked from commit 06ed897b22)
2024-02-28 15:36:20 -03:00
Rodrigo Campos 6e809ef13a cri: Expose userns in PodSandboxStatus rpc
We added support for userns but we weren't showing it in the
podSandboxStatus.

Let's just show the whole nsOpts, so we don't forget in the future
either if something else inside there changes.

Please note that this will expose the content of nsOpts.TargetId that we
weren't exposing before. But that seemed like a bug to me.

The cherry-pick has been amended to do the change in cri/sbserver and
cri/server.

Signed-off-by: Rodrigo Campos <rodrigoca@microsoft.com>
(cherry picked from commit 6c356a5c75)
2024-02-28 11:38:09 -03:00
Shukui Yang 711cebd484 Register imagePullThroughput and count with MiB
Signed-off-by: Shukui Yang <yangshukui@bytedance.com>
(cherry picked from commit db223271e3)
2024-02-26 09:31:47 +02:00
Akihiro Suda c79ffa2773 cri: propagate deprecation list to runtime status
Propagate the deprecation list to CRI runtime conditions.

The propagated conditions are visible via `crictl info`,
but not visible via `kubectl get nodes -o yaml` yet, although
the CRI API says "These conditions will be exposed to users to help
them understand the status of the system".

https://github.com/kubernetes/cri-api/blob/v0.29.1/pkg/apis/runtime/v1/api.proto#L1505-L1509

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
(cherry picked from commit 1b3a96da6c)
(cherry-pick was not clean)
Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
2024-02-14 15:18:55 +09:00
Henry Wang 26c057423c bug fix: make sure cri image is pinned when it is pulled outside cri
Signed-off-by: Henry Wang <henwang@amazon.com>
(cherry picked from commit 1eaf0c1f04)
2024-02-07 21:24:23 +00:00
Wei Fu ea0a92ec30 *: introduce image_pull_with_sync_fs in CRI
It's to ensure the data integrity during unexpected power failure.

Background:

Since release 1.3, in Linux system, containerD unpacks and writes files into
overlayfs snapshot directly. It doesn’t involve any mount-umount operations
so that the performance of pulling image has been improved.

As we know, the umount syscall for overlayfs will force kernel to flush
all the dirty pages into disk. Without umount syscall, the files’ data relies
on kernel’s writeback threads or filesystem's commit setting (for
instance, ext4 filesystem).

The files in committed snapshot can be loss after unexpected power failure.
However, the snapshot has been committed and the metadata also has been
fsynced. There is data inconsistency between snapshot metadata and files
in that snapshot.

We, containerd, received several issues about data loss after unexpected
power failure.

* https://github.com/containerd/containerd/issues/5854
* https://github.com/containerd/containerd/issues/3369#issuecomment-1787334907

Solution:

* Option 1: SyncFs after unpack

Linux platform provides [syncfs][syncfs] syscall to synchronize just the
filesystem containing a given file.

* Option 2: Fsync directories recursively and fsync on regular file

The fsync doesn't support symlink/block device/char device files. We
need to use fsync the parent directory to ensure that entry is
persisted.

However, based on [xfstest-dev][xfstest-dev], there is no case to ensure
fsync-on-parent can persist the special file's metadata, for example,
uid/gid, access mode.

Checkout [generic/690][generic/690]: Syncing parent dir can persist
symlink. But for f2fs, it needs special mount option. And it doesn't say
that uid/gid can be persisted. All the details are behind the
implemetation.

> NOTE: All the related test cases has `_flakey_drop_and_remount` in
[xfstest-dev].

Based on discussion about [Documenting the crash-recovery guarantees of Linux file systems][kernel-crash-recovery-data-integrity],
we can't rely on Fsync-on-parent.

* Option 1 is winner

This patch is using option 1.

There is test result based on [test-tool][test-tool].
All the networking traffic created by pull is local.

  * Image: docker.io/library/golang:1.19.4 (992 MiB)
    * Current: 5.446738579s
      * WIOS=21081, WBytes=1329741824, RIOS=79, RBytes=1197056
    * Option 1: 6.239686088s
      * WIOS=34804, WBytes=1454845952, RIOS=79, RBytes=1197056
    * Option 2: 1m30.510934813s
      * WIOS=42143, WBytes=1471397888, RIOS=82, RBytes=1209344

  * Image: docker.io/tensorflow/tensorflow:latest (1.78 GiB, ~32590 Inodes)
    * Current: 8.852718042s
      * WIOS=39417, WBytes=2412818432, RIOS=2673, RBytes=335987712
    * Option 1: 9.683387174s
      * WIOS=42767, WBytes=2431750144, RIOS=89, RBytes=1238016
    * Option 2: 1m54.302103719s
      * WIOS=54403, WBytes=2460528640, RIOS=1709, RBytes=208237568

The Option 1 will increase `wios`. So, the `image_pull_with_sync_fs` is
option in CRI plugin.

[syncfs]: <https://man7.org/linux/man-pages/man2/syncfs.2.html>
[xfstest-dev]: <https://git.kernel.org/pub/scm/fs/xfs/xfstests-dev.git>
[generic/690]: <https://git.kernel.org/pub/scm/fs/xfs/xfstests-dev.git/tree/tests/generic/690?h=v2023.11.19>
[kernel-crash-recovery-data-integrity]: <https://lore.kernel.org/linux-fsdevel/1552418820-18102-1-git-send-email-jaya@cs.utexas.edu/>
[test-tool]: <https://github.com/fuweid/go-dmflakey/blob/a17fb2010db22654b3e54cf506b0dbb5ef7b33ca/contrib/syncfs/containerd/main_test.go#L51>

Signed-off-by: Wei Fu <fuweid89@gmail.com>
(cherry picked from commit 23278c81fb)
Signed-off-by: Wei Fu <fuweid89@gmail.com>
2024-02-06 14:42:13 +08:00
Kirtana Ashok 3f75af7bf2 Move certain debug logs to trace logs
Signed-off-by: Kirtana Ashok <kiashok@microsoft.com>
(cherry picked from commit f261969507)
2024-02-05 15:57:57 -08:00
Evan Lezar 14628d4aaa Update container-device-interface to v0.6.2
This includes migrating from the github.com/container-orchestrated-devices
repo to tags.cncf.io.

Signed-off-by: Evan Lezar <elezar@nvidia.com>
2024-01-24 14:51:15 +01:00
Wei Fu 2068061289 remotes/docker: close connection if no more data
Close connection if no more data. It's to fix false alert filed by image
pull progress.

```
dst = OpenWriter (--> Content Store)

src = Fetch
        Open (--> Registry)
        Mark it as active request

Copy(dst, src) (--> Keep updating total received bytes)

   ^
   |  (Active Request > 0, but total received bytes won't be updated)
   v

defer src.Close()
content.Commit(dst)
```

Before migrating to transfer service, CRI plugin doesn't limit global
concurrent downloads for ImagePulls. Each ImagePull requests have 3 concurrent
goroutines to download blob and 1 goroutine to unpack blob. Like ext4
filesystem [1][1], the fsync from content.Commit may sync unrelated dirty pages
into disk. The host is running under IO pressure, and then the content.Commit
will take long time and block other goroutines. If httpreadseeker
doesn't close the connection after io.EOF, this connection will be
considered as active. The pull progress reporter reports there is no
bytes transfered and cancels the ImagePull.

The original 1-minute timeout[2][2] is from kubelet settting. Since CRI-plugin
can't limit the total concurrent downloads, this patch is to update 1-minute
to 5-minutes to prevent from unexpected cancel.

[1]: https://lwn.net/Articles/842385/
[2]: https://github.com/kubernetes/kubernetes/blob/release-1.23/pkg/kubelet/config/flags.go#L45-L48

Signed-off-by: Wei Fu <fuweid89@gmail.com>
2023-11-21 23:31:42 +00:00
Wei Fu d1aab27cbd fix: deflake TestCRIImagePullTimeout/HoldingContentOpenWriter
The new active request is filed and there is no bytes read yet when the
progress reporter just wakes up. If the timeout / 2 is less than the
minPullProgressReportInternal, it's easy to file false alert.

We should remove the minPullProgressReportInternal limit.

Fixes: #8024

Signed-off-by: Wei Fu <fuweid89@gmail.com>
2023-11-21 23:12:14 +00:00
ruiwen-zhao d62cba40c8 Expose usage of cri-api v1alpha2
Signed-off-by: ruiwen-zhao <ruiwen@google.com>
2023-11-07 23:10:34 +00:00
Akihiro Suda 6013b5e03e cri: stop recommending disable_cgroup
Disabling cgroup is no longer needed since cgroup v2

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
(cherry picked from commit 8ffb03d689)
(cherry-pick was not clean)
Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
2023-09-30 12:30:07 +09:00
Wei Fu 88ff575c5c pkg/cri/server: fix leaked shim issue
Fixes: #7496 #8931

Signed-off-by: Wei Fu <fuweid89@gmail.com>
(cherry picked from commit 72bc63d83d)
Signed-off-by: Wei Fu <fuweid89@gmail.com>
2023-08-24 08:22:37 +08:00
Rodrigo Campos 4e97a115f7 cri: Don't use rel path for image volumes
Runc 1.1 throws a warning when using rel destination paths, and runc 1.2
is planning to thow an error (i.e. won't start the container).

Let's just make this an abs path in the only place it might not be: the
mounts created due to `VOLUME` directives in the Dockerfile.

Signed-off-by: Rodrigo Campos <rodrigoca@microsoft.com>
(cherry picked from commit 2d64ab8d79)
2023-08-07 17:25:10 +02:00
Phil Estes 68bd89ecbb Merge pull request #8824 from thaJeztah/1.7_backport_fix-additiona-gids-to-read-image-user
[release/1.7 backport] [CRI] fix additionalGids: it should fallback to imageConfig.User when securityContext.RunAsUser,RunAsUsername are empty
2023-07-17 10:54:07 -04:00
Samuel Karp 186eb64b7c cri: write generated CNI config atomically on Unix
The 10-containerd-net.conflist file generated from the conf_template
should be written atomically so that partial writes are not visible to
CNI plugins. Use the new consistentfile package to ensure this on
Unix-like platforms such as Linux, FreeBSD, and Darwin.

Fixes https://github.com/containerd/containerd/issues/8607

Signed-off-by: Samuel Karp <samuelkarp@google.com>
(cherry picked from commit 3c4a1ab1cb)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-07-14 13:25:35 +02:00
Shingo Omura 083f571609 capture desc variable in range variable just in case that it run in parallel mode
Signed-off-by: Shingo Omura <everpeace@gmail.com>
(cherry picked from commit dc2fc987ca)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-07-14 13:18:16 +02:00
Shingo Omura a9440ce6b5 Use t.TempDir instead of os.MkdirTemp
Signed-off-by: Shingo Omura <everpeace@gmail.com>
(cherry picked from commit 05bb52b273)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-07-14 13:18:08 +02:00
Shingo Omura eea3440d89 use strings.Cut instead of strings.Split for parsing imageConfig.User
Signed-off-by: Shingo Omura <everpeace@gmail.com>
(cherry picked from commit 50740a1a0c)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-07-14 13:17:56 +02:00
Shingo Omura eace671808 fix userstr for dditionalGids on Linux
It should fallback to imageConfig.User when no securityContext.RunAsUser/RunAsUsername

Signed-off-by: Shingo Omura <everpeace@gmail.com>
(cherry picked from commit 727b254039)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2023-07-14 13:17:48 +02:00
Rodrigo Campos 241514815d pkg/cri/server: Test net.ipv4.ping_group_range works with userns
Signed-off-by: Rodrigo Campos <rodrigoca@microsoft.com>
(cherry picked from commit c17d3bdb54)
2023-07-07 11:34:15 +02:00
Rodrigo Campos 801e8c8069 pkg/cri/server: Fix net.ipv4.ping_group_range with userns
userns.RunningInUserNS() checks if the code calling that function is
running inside a user namespace. But we need to check if the container
we will create will use a user namespace, in that case we need to
disable the sysctl too (or we would need to take the userns mapping into
account to set the IDs).

This was added in PR:
        https://github.com/containerd/containerd/pull/6170/

And the param documentation says it is not enabled when user namespaces
are in use:
        https://github.com/containerd/containerd/pull/6170/files#diff-91d0a4c61f6d3523b5a19717d1b40b5fffd7e392d8fe22aed7c905fe195b8902R118

I'm not sure if the intention was to disable this if containerd is
running inside a userns (rootless, if that is even supported) or just
when the pod has user namespaces.

Out of an abundance of caution, I'm keeping the userns.RunningInUserNS()
so it is still not used if containerd runs inside a user namespace.

With this patch and "enable_unprivileged_icmp = true" in the config,
running containerd as root on the host, pods with user namespaces start
just fine. Without this patch they fail with:
        ... failed to create containerd task: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: error during container init: w
 /proc/sys/net/ipv4/ping_group_range: invalid argument: unknown

Thanks a lot to Andy on the k8s slack for reporting the issue. He also
mentions he hits this with k3s on a default installation (the param
is off by default on containerd, but k3s turns that on by default it
seems). He also debugged which part of the stack was setting that
sysctl, found the PR that added this code in containerd and a workaround
(to turn the bool off).

Signed-off-by: Rodrigo Campos <rodrigoca@microsoft.com>
(cherry picked from commit 9bf5aeca77)
2023-07-07 11:28:22 +02:00
Aditi Sharma 699d6701ae Pinned image support
Signed-off-by: Aditi Sharma <adi.sky17@gmail.com>
(cherry picked from commit fe4f8bd884)
Signed-off-by: ruiwen-zhao <ruiwen@google.com>
2023-06-21 23:06:54 +00:00
James Sturtevant 58b6b99cd6 Add a check to skip stats for containers that are not running
When a container is just created, exited state the container will not have stats. A common case for this in k8s is the init containers for a pod. The will be present in the listed containers but will not have a running task and there for no stats.

Signed-off-by: James Sturtevant <jstur@microsoft.com>
2023-06-07 13:10:30 -07:00
James Sturtevant 89415fe361 Fix issue for HPC pod metrics
The initial PR had a check for nil metrics but after some refactoring in the PR the test case that was suppose cover HPC was missing a scenario where the metric was not nil but didn't contain any metrics. This fixes that case and adds a testcase to cover it.

Signed-off-by: James Sturtevant <jstur@microsoft.com>
2023-06-02 16:29:26 -07:00
Henry Wang 2c38cad77c notify readiness when registered plugins are ready
Signed-off-by: Henry Wang <henwang@amazon.com>
(cherry picked from commit 4bfcac85fa)
2023-05-27 00:33:05 +00:00
Ed Bartosh 6a5e54c15a Get CDI devices from CRI Config.CDIDevices field
Signed-off-by: Ed Bartosh <eduard.bartosh@intel.com>
(cherry picked from commit cd16b31cd2)
Signed-off-by: Ed Bartosh <eduard.bartosh@intel.com>
2023-05-16 18:49:49 +03:00
Brad Davidson 95ef67e195 Fix umarshal metrics for CRI server
Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
(cherry picked from commit 27f56e607f)
Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
2023-05-04 16:36:40 +00:00
Kirtana Ashok 6b3ae01297 Remove entry for container from container store on error
If containerd does not see a container but criservice's
container store does, then we should try to recover from
this error state by removing the container from criservice's
container store as well.

Signed-off-by: Kirtana Ashok <Kirtana.Ashok@microsoft.com>
(cherry picked from commit d9f3e387c6)
Signed-off-by: Kirtana Ashok <Kirtana.Ashok@microsoft.com>
2023-04-27 05:20:32 -07:00
Vinayak Goyal 5e953cfa62 Test to ensure nosuid,nodev,noexec are set on /etc/reolv.conf mount.
Signed-off-by: Vinayak Goyal <vinaygo@google.com>
(cherry picked from commit 990199a021)
Signed-off-by: Vinayak Goyal <vinaygo@google.com>
2023-03-31 04:03:30 +00:00
Vinayak Goyal 0aad93f08c Add noexec nodev and nosuid to sandbox /etc/resolv.conf mount bind.
Signed-off-by: Vinayak Goyal <vinaygo@google.com>
(cherry picked from commit ae4dbb60d5)
Signed-off-by: Vinayak Goyal <vinaygo@google.com>
2023-03-31 04:03:14 +00:00
Danny Canter 1c1b6bcb2b CRI: Don't always close netConfMonitor channel
In the CRI server initialization a syncgroup is setup that adds to the
counter for every cni config found/registered. This functions on platforms
where CNI is supported/theres an assumption that there will always be
the loopback config. However, on platforms like Darwin where there's generally
nothing registered the Wait() on the syncgroup returns immediately and the
channel used to return any Network config sync errors is closed. This channel
is one of three that's used to monitor if we should Close the CRI service in
containerd, so it's not great if this happens.

Signed-off-by: Danny Canter <danny@dcantah.dev>
(cherry picked from commit 62f98a1c11)
Signed-off-by: Danny Canter <danny@dcantah.dev>
2023-03-16 11:29:45 -07:00
Akihiro Suda c77ddf5381 Merge pull request #8131 from lucacome/bump-k8s.io-deps
Bump k8s.io deps
2023-03-07 21:44:13 +09:00
Fu Wei 5ae3a7f417 Merge pull request #8198 from kiashok/argsEscapedSupportInCri
Add ArgsEscaped support for CRI
2023-03-07 16:12:24 +08:00
Kevin Parsons 31c9a66385 Merge pull request #7099 from jsturtevant/cri-only-stats-windows
[cri] Implement CRI Pod and Container stats for Windows
2023-03-06 09:31:41 -08:00
James Sturtevant 08aa576a95 Add Windows Sandbox Stats
Signed-off-by: James Sturtevant <jstur@microsoft.com>
2023-03-03 14:37:38 -08:00
Kirtana Ashok 8137e41c48 Add ArgsEscaped support for CRI
This commit adds supports for the ArgsEscaped
value for the image got from the dockerfile.
It is used to evaluate and process the image
entrypoint/cmd and container entrypoint/cmd
options got from the podspec.

Signed-off-by: Kirtana Ashok <Kirtana.Ashok@microsoft.com>
2023-03-03 13:38:06 -08:00
Wei Fu 5946c1051e *: fix code style issue
1. it's easy to check wrong input if using drain_exec_sync_io_timeout in error
2. avoid to use full error message, as part of error generated by go
   stdlib would be changed in the future
3. delete the extra empty line

Signed-off-by: Wei Fu <fuweid89@gmail.com>
2023-03-03 17:51:03 +08:00
Wei Fu ffebcb1223 cri: disable drain-exec-IO if it is empty timeout
Signed-off-by: Wei Fu <fuweid89@gmail.com>
2023-03-03 11:59:07 +08:00
Wei Fu 3c18decea7 *: add DrainExecSyncIOTimeout config and disable as by default
Signed-off-by: Wei Fu <fuweid89@gmail.com>
2023-03-03 00:21:55 +08:00
Wei Fu a9cbddd65d *: fix typo and skip exec-io-drain-testcase in win
Signed-off-by: Wei Fu <fuweid89@gmail.com>
2023-03-02 21:57:43 +08:00
Luca Comellini f25ec98d0d Fix linting error sets.String is deprecated
Signed-off-by: Luca Comellini <luca.com@gmail.com>
2023-03-01 21:37:30 -08:00