mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +00:00
Merge pull request #93931 from SataQiu/fix-kubelet-swap-20200812
kubelet: assume that swap is disabled when /proc/swaps does not exist
This commit is contained in:
commit
119c94214c
@ -215,17 +215,23 @@ func NewContainerManager(mountUtil mount.Interface, cadvisorInterface cadvisor.I
|
|||||||
|
|
||||||
if failSwapOn {
|
if failSwapOn {
|
||||||
// Check whether swap is enabled. The Kubelet does not support running with swap enabled.
|
// Check whether swap is enabled. The Kubelet does not support running with swap enabled.
|
||||||
swapData, err := ioutil.ReadFile("/proc/swaps")
|
swapFile := "/proc/swaps"
|
||||||
|
swapData, err := ioutil.ReadFile(swapFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
if os.IsNotExist(err) {
|
||||||
}
|
klog.Warningf("file %v does not exist, assuming that swap is disabled", swapFile)
|
||||||
swapData = bytes.TrimSpace(swapData) // extra trailing \n
|
} else {
|
||||||
swapLines := strings.Split(string(swapData), "\n")
|
return nil, err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
swapData = bytes.TrimSpace(swapData) // extra trailing \n
|
||||||
|
swapLines := strings.Split(string(swapData), "\n")
|
||||||
|
|
||||||
// If there is more than one line (table headers) in /proc/swaps, swap is enabled and we should
|
// If there is more than one line (table headers) in /proc/swaps, swap is enabled and we should
|
||||||
// error out unless --fail-swap-on is set to false.
|
// error out unless --fail-swap-on is set to false.
|
||||||
if len(swapLines) > 1 {
|
if len(swapLines) > 1 {
|
||||||
return nil, fmt.Errorf("running with swap on is not supported, please disable swap! or set --fail-swap-on flag to false. /proc/swaps contained: %v", swapLines)
|
return nil, fmt.Errorf("running with swap on is not supported, please disable swap! or set --fail-swap-on flag to false. /proc/swaps contained: %v", swapLines)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user