diff --git a/pkg/kubelet/util/swap/swap_util.go b/pkg/kubelet/util/swap/swap_util.go index 025c36c35ff..62aaed45cfc 100644 --- a/pkg/kubelet/util/swap/swap_util.go +++ b/pkg/kubelet/util/swap/swap_util.go @@ -21,7 +21,9 @@ import ( sysruntime "runtime" "sync" + "k8s.io/apimachinery/pkg/util/version" "k8s.io/klog/v2" + utilkernel "k8s.io/kubernetes/pkg/util/kernel" "k8s.io/mount-utils" ) @@ -38,6 +40,16 @@ func IsTmpfsNoswapOptionSupported(mounter mount.Interface) bool { return false } + kernelVersion, err := utilkernel.GetVersion() + if err != nil { + klog.ErrorS(err, "cannot determine kernel version, unable to determine is tmpfs noswap is supported") + return false + } + + if kernelVersion.AtLeast(version.MustParseGeneric(utilkernel.TmpfsNoswapSupportKernelVersion)) { + return true + } + mountDir, err := os.MkdirTemp("", "tmpfs-noswap-test-") if err != nil { klog.InfoS("error creating dir to test if tmpfs noswap is enabled. Assuming not supported", "mount path", mountDir, "error", err) diff --git a/pkg/util/kernel/constants.go b/pkg/util/kernel/constants.go index 86ba8f6106c..5354f84272e 100644 --- a/pkg/util/kernel/constants.go +++ b/pkg/util/kernel/constants.go @@ -47,3 +47,5 @@ const IPVSConnReuseModeFixedKernelVersion = "5.9" // UserNamespacesSupportKernelVersion is the kernel version where idmap for tmpfs support was added // (ref: https://github.com/torvalds/linux/commit/05e6295f7b5e05f09e369a3eb2882ec5b40fff20) const UserNamespacesSupportKernelVersion = "6.3" + +const TmpfsNoswapSupportKernelVersion = "6.4"