Skip to content

Commit ad1739f

Browse files
committed
kubelet: assume that swap is disabled when /proc/swaps does not exist
1 parent c780554 commit ad1739f

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

pkg/kubelet/cm/container_manager_linux.go

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -216,17 +216,23 @@ func NewContainerManager(mountUtil mount.Interface, cadvisorInterface cadvisor.I
216216

217217
if failSwapOn {
218218
// Check whether swap is enabled. The Kubelet does not support running with swap enabled.
219-
swapData, err := ioutil.ReadFile("/proc/swaps")
219+
swapFile := "/proc/swaps"
220+
swapData, err := ioutil.ReadFile(swapFile)
220221
if err != nil {
221-
return nil, err
222-
}
223-
swapData = bytes.TrimSpace(swapData) // extra trailing \n
224-
swapLines := strings.Split(string(swapData), "\n")
222+
if os.IsNotExist(err) {
223+
klog.Warningf("file %v does not exist, assuming that swap is disabled", swapFile)
224+
} else {
225+
return nil, err
226+
}
227+
} else {
228+
swapData = bytes.TrimSpace(swapData) // extra trailing \n
229+
swapLines := strings.Split(string(swapData), "\n")
225230

226-
// If there is more than one line (table headers) in /proc/swaps, swap is enabled and we should
227-
// error out unless --fail-swap-on is set to false.
228-
if len(swapLines) > 1 {
229-
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)
231+
// If there is more than one line (table headers) in /proc/swaps, swap is enabled and we should
232+
// error out unless --fail-swap-on is set to false.
233+
if len(swapLines) > 1 {
234+
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)
235+
}
230236
}
231237
}
232238

0 commit comments

Comments
 (0)