mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-04 09:49:50 +00:00
Use kubelet owned directories for mounting rather than /tmp
Signed-off-by: Itamar Holder <iholder@redhat.com>
This commit is contained in:
parent
74f29880bd
commit
a6b971f14b
@ -214,7 +214,7 @@ func NewContainerManager(mountUtil mount.Interface, cadvisorInterface cadvisor.I
|
|||||||
return nil, fmt.Errorf("running with swap on is not supported, please disable swap or set --fail-swap-on flag to false")
|
return nil, fmt.Errorf("running with swap on is not supported, please disable swap or set --fail-swap-on flag to false")
|
||||||
}
|
}
|
||||||
|
|
||||||
if !swap.IsTmpfsNoswapOptionSupported(mountUtil) {
|
if !swap.IsTmpfsNoswapOptionSupported(mountUtil, nodeConfig.KubeletRootDir) {
|
||||||
nodeRef := nodeRefFromNode(string(nodeConfig.NodeName))
|
nodeRef := nodeRefFromNode(string(nodeConfig.NodeName))
|
||||||
recorder.Event(nodeRef, v1.EventTypeWarning, events.PossibleMemoryBackedVolumesOnDisk,
|
recorder.Event(nodeRef, v1.EventTypeWarning, events.PossibleMemoryBackedVolumesOnDisk,
|
||||||
"The tmpfs noswap option is not supported. Memory-backed volumes (e.g. secrets, emptyDirs, etc.) "+
|
"The tmpfs noswap option is not supported. Memory-backed volumes (e.g. secrets, emptyDirs, etc.) "+
|
||||||
|
@ -18,6 +18,7 @@ package swap
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"errors"
|
||||||
"os"
|
"os"
|
||||||
sysruntime "runtime"
|
sysruntime "runtime"
|
||||||
"strings"
|
"strings"
|
||||||
@ -39,7 +40,7 @@ var (
|
|||||||
|
|
||||||
const TmpfsNoswapOption = "noswap"
|
const TmpfsNoswapOption = "noswap"
|
||||||
|
|
||||||
func IsTmpfsNoswapOptionSupported(mounter mount.Interface) bool {
|
func IsTmpfsNoswapOptionSupported(mounter mount.Interface, mountPath string) bool {
|
||||||
isTmpfsNoswapOptionSupportedHelper := func() bool {
|
isTmpfsNoswapOptionSupportedHelper := func() bool {
|
||||||
if sysruntime.GOOS == "windows" {
|
if sysruntime.GOOS == "windows" {
|
||||||
return false
|
return false
|
||||||
@ -55,28 +56,32 @@ func IsTmpfsNoswapOptionSupported(mounter mount.Interface) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
mountDir, err := os.MkdirTemp("", "tmpfs-noswap-test-")
|
if mountPath == "" {
|
||||||
|
klog.ErrorS(errors.New("mount path is empty, falling back to /tmp"), "")
|
||||||
|
}
|
||||||
|
|
||||||
|
mountPath, err = os.MkdirTemp(mountPath, "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", mountPath, "error", err)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
err = os.RemoveAll(mountDir)
|
err = os.RemoveAll(mountPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
klog.ErrorS(err, "error removing test tmpfs dir", "mount path", mountDir)
|
klog.ErrorS(err, "error removing test tmpfs dir", "mount path", mountPath)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
err = mounter.MountSensitiveWithoutSystemd("tmpfs", mountDir, "tmpfs", []string{TmpfsNoswapOption}, nil)
|
err = mounter.MountSensitiveWithoutSystemd("tmpfs", mountPath, "tmpfs", []string{TmpfsNoswapOption}, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
klog.InfoS("error mounting tmpfs with the noswap option. Assuming not supported", "error", err)
|
klog.InfoS("error mounting tmpfs with the noswap option. Assuming not supported", "error", err)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
err = mounter.Unmount(mountDir)
|
err = mounter.Unmount(mountPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
klog.ErrorS(err, "error unmounting test tmpfs dir", "mount path", mountDir)
|
klog.ErrorS(err, "error unmounting test tmpfs dir", "mount path", mountPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
@ -328,7 +328,7 @@ func (ed *emptyDir) setupTmpfs(dir string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
options := ed.generateTmpfsMountOptions(swap.IsTmpfsNoswapOptionSupported(ed.mounter))
|
options := ed.generateTmpfsMountOptions(swap.IsTmpfsNoswapOptionSupported(ed.mounter, ed.plugin.host.GetPluginDir(emptyDirPluginName)))
|
||||||
|
|
||||||
klog.V(3).Infof("pod %v: mounting tmpfs for volume %v", ed.pod.UID, ed.volName)
|
klog.V(3).Infof("pod %v: mounting tmpfs for volume %v", ed.pod.UID, ed.volName)
|
||||||
return ed.mounter.MountSensitiveWithoutSystemd("tmpfs", dir, "tmpfs", options, nil)
|
return ed.mounter.MountSensitiveWithoutSystemd("tmpfs", dir, "tmpfs", options, nil)
|
||||||
|
Loading…
Reference in New Issue
Block a user