@@ -17,9 +17,9 @@ package common
17
17
import (
18
18
"fmt"
19
19
"io/ioutil"
20
+ "math"
20
21
"os"
21
22
"path"
22
- "path/filepath"
23
23
"strconv"
24
24
"strings"
25
25
"time"
@@ -50,25 +50,6 @@ func DebugInfo(watches map[string][]string) map[string][]string {
50
50
return out
51
51
}
52
52
53
- // findFileInAncestorDir returns the path to the parent directory that contains the specified file.
54
- // "" is returned if the lookup reaches the limit.
55
- func findFileInAncestorDir (current , file , limit string ) (string , error ) {
56
- for {
57
- fpath := path .Join (current , file )
58
- _ , err := os .Stat (fpath )
59
- if err == nil {
60
- return current , nil
61
- }
62
- if ! os .IsNotExist (err ) {
63
- return "" , err
64
- }
65
- if current == limit {
66
- return "" , nil
67
- }
68
- current = filepath .Dir (current )
69
- }
70
- }
71
-
72
53
var bootTime = func () time.Time {
73
54
now := time .Now ()
74
55
var sysinfo unix.Sysinfo_t
@@ -165,11 +146,7 @@ func GetSpec(cgroupPaths map[string]string, machineInfoFactory info.MachineInfoF
165
146
spec .Memory .Reservation = readUInt64 (memoryRoot , "memory.soft_limit_in_bytes" )
166
147
}
167
148
} else {
168
- memoryRoot , err := findFileInAncestorDir (memoryRoot , "memory.max" , "/sys/fs/cgroup" )
169
- if err != nil {
170
- return spec , err
171
- }
172
- if memoryRoot != "" {
149
+ if utils .FileExists (path .Join (memoryRoot , "memory.max" )) {
173
150
spec .HasMemory = true
174
151
spec .Memory .Reservation = readUInt64 (memoryRoot , "memory.high" )
175
152
spec .Memory .Limit = readUInt64 (memoryRoot , "memory.max" )
@@ -226,7 +203,10 @@ func readString(dirpath string, file string) string {
226
203
227
204
func readUInt64 (dirpath string , file string ) uint64 {
228
205
out := readString (dirpath , file )
229
- if out == "" || out == "max" {
206
+ if out == "max" {
207
+ return math .MaxUint64
208
+ }
209
+ if out == "" {
230
210
return 0
231
211
}
232
212
0 commit comments