kubelet: fix Turning off swap in unprivileged tmpfs mounts unsupported

Fix issue 125137

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
This commit is contained in:
Akihiro Suda 2024-05-27 15:48:35 +09:00
parent f5d62f738a
commit b3175b8e99
No known key found for this signature in database
GPG Key ID: 49524C6F9F638F1A

View File

@ -26,6 +26,7 @@ import (
"k8s.io/apimachinery/pkg/util/version" "k8s.io/apimachinery/pkg/util/version"
"k8s.io/klog/v2" "k8s.io/klog/v2"
"k8s.io/kubernetes/pkg/kubelet/userns/inuserns"
utilkernel "k8s.io/kubernetes/pkg/util/kernel" utilkernel "k8s.io/kubernetes/pkg/util/kernel"
"k8s.io/mount-utils" "k8s.io/mount-utils"
) )
@ -46,6 +47,14 @@ func IsTmpfsNoswapOptionSupported(mounter mount.Interface, mountPath string) boo
return false 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() kernelVersion, err := utilkernel.GetVersion()
if err != nil { if err != nil {
klog.ErrorS(err, "cannot determine kernel version, unable to determine is tmpfs noswap is supported") klog.ErrorS(err, "cannot determine kernel version, unable to determine is tmpfs noswap is supported")