kubelet: assume that swap is disabled when /proc/swaps does not exist

This commit is contained in:
SataQiu 2020-08-12 22:31:31 +08:00
parent c780554a64
commit ad1739f8bc

View File

@ -216,10 +216,15 @@ 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 {
if os.IsNotExist(err) {
klog.Warningf("file %v does not exist, assuming that swap is disabled", swapFile)
} else {
return nil, err return nil, err
} }
} else {
swapData = bytes.TrimSpace(swapData) // extra trailing \n swapData = bytes.TrimSpace(swapData) // extra trailing \n
swapLines := strings.Split(string(swapData), "\n") swapLines := strings.Split(string(swapData), "\n")
@ -229,6 +234,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. /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)
} }
} }
}
var internalCapacity = v1.ResourceList{} var internalCapacity = v1.ResourceList{}
// It is safe to invoke `MachineInfo` on cAdvisor before logically initializing cAdvisor here because // It is safe to invoke `MachineInfo` on cAdvisor before logically initializing cAdvisor here because