From 32c265f60c175cedbd685f30e389c95fb1e66ee3 Mon Sep 17 00:00:00 2001 From: linyouchong Date: Wed, 14 Mar 2018 14:36:30 +0800 Subject: [PATCH] Skip checking when failSwapOn=false --- pkg/kubelet/cm/container_manager_linux.go | 25 +++++++++++++---------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/pkg/kubelet/cm/container_manager_linux.go b/pkg/kubelet/cm/container_manager_linux.go index 42ad3125bf2..9ede8065edf 100644 --- a/pkg/kubelet/cm/container_manager_linux.go +++ b/pkg/kubelet/cm/container_manager_linux.go @@ -200,19 +200,22 @@ func NewContainerManager(mountUtil mount.Interface, cadvisorInterface cadvisor.I return nil, fmt.Errorf("failed to get mounted cgroup subsystems: %v", err) } - // Check whether swap is enabled. The Kubelet does not support running with swap enabled. - swapData, err := ioutil.ReadFile("/proc/swaps") - if err != nil { - return nil, err - } - swapData = bytes.TrimSpace(swapData) // extra trailing \n - swapLines := strings.Split(string(swapData), "\n") + if failSwapOn { + // Check whether swap is enabled. The Kubelet does not support running with swap enabled. + swapData, err := ioutil.ReadFile("/proc/swaps") + if err != nil { + return nil, err + } + 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 - // error out unless --fail-swap-on is set to false. - if failSwapOn && 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) + // 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. + 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) + } } + var capacity = v1.ResourceList{} // It is safe to invoke `MachineInfo` on cAdvisor before logically initializing cAdvisor here because // machine info is computed and cached once as part of cAdvisor object creation.