From b3175b8e996460316d61ce9e53d7f523049b8e2b Mon Sep 17 00:00:00 2001 From: Akihiro Suda Date: Mon, 27 May 2024 15:48:35 +0900 Subject: [PATCH] kubelet: fix `Turning off swap in unprivileged tmpfs mounts unsupported` Fix issue 125137 Signed-off-by: Akihiro Suda --- pkg/kubelet/util/swap/swap_util.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pkg/kubelet/util/swap/swap_util.go b/pkg/kubelet/util/swap/swap_util.go index 2160820b6f1..c12f65b4d27 100644 --- a/pkg/kubelet/util/swap/swap_util.go +++ b/pkg/kubelet/util/swap/swap_util.go @@ -26,6 +26,7 @@ import ( "k8s.io/apimachinery/pkg/util/version" "k8s.io/klog/v2" + "k8s.io/kubernetes/pkg/kubelet/userns/inuserns" utilkernel "k8s.io/kubernetes/pkg/util/kernel" "k8s.io/mount-utils" ) @@ -46,6 +47,14 @@ func IsTmpfsNoswapOptionSupported(mounter mount.Interface, mountPath string) boo return false } + if inuserns.RunningInUserNS() { + // Turning off swap in unprivileged tmpfs mounts unsupported + // https://github.com/torvalds/linux/blob/v6.8/mm/shmem.c#L4004-L4011 + // https://github.com/kubernetes/kubernetes/issues/125137 + klog.InfoS("Running under a user namespace - tmpfs noswap is not supported") + return false + } + kernelVersion, err := utilkernel.GetVersion() if err != nil { klog.ErrorS(err, "cannot determine kernel version, unable to determine is tmpfs noswap is supported")