If the kernel version is at least 6.4, assume tmpfs noswap is supported

Signed-off-by: Itamar Holder <iholder@redhat.com>
This commit is contained in:
Itamar Holder 2024-05-15 10:47:45 +03:00
parent 3b9b03935e
commit 2a174d09fa
2 changed files with 14 additions and 0 deletions

View File

@ -21,7 +21,9 @@ import (
sysruntime "runtime" sysruntime "runtime"
"sync" "sync"
"k8s.io/apimachinery/pkg/util/version"
"k8s.io/klog/v2" "k8s.io/klog/v2"
utilkernel "k8s.io/kubernetes/pkg/util/kernel"
"k8s.io/mount-utils" "k8s.io/mount-utils"
) )
@ -38,6 +40,16 @@ func IsTmpfsNoswapOptionSupported(mounter mount.Interface) bool {
return false 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-") mountDir, err := os.MkdirTemp("", "tmpfs-noswap-test-")
if err != nil { if err != nil {
klog.InfoS("error creating dir to test if tmpfs noswap is enabled. Assuming not supported", "mount path", mountDir, "error", err) klog.InfoS("error creating dir to test if tmpfs noswap is enabled. Assuming not supported", "mount path", mountDir, "error", err)

View File

@ -47,3 +47,5 @@ const IPVSConnReuseModeFixedKernelVersion = "5.9"
// UserNamespacesSupportKernelVersion is the kernel version where idmap for tmpfs support was added // UserNamespacesSupportKernelVersion is the kernel version where idmap for tmpfs support was added
// (ref: https://github.com/torvalds/linux/commit/05e6295f7b5e05f09e369a3eb2882ec5b40fff20) // (ref: https://github.com/torvalds/linux/commit/05e6295f7b5e05f09e369a3eb2882ec5b40fff20)
const UserNamespacesSupportKernelVersion = "6.3" const UserNamespacesSupportKernelVersion = "6.3"
const TmpfsNoswapSupportKernelVersion = "6.4"