1
2
3
4
19
20 package preflight
21
22 import (
23 "syscall"
24
25 "github.com/pkg/errors"
26
27 system "k8s.io/system-validators/validators"
28 utilsexec "k8s.io/utils/exec"
29 )
30
31
32 func (mc MemCheck) Check() (warnings, errorList []error) {
33 info := syscall.Sysinfo_t{}
34 err := syscall.Sysinfo(&info)
35 if err != nil {
36 errorList = append(errorList, errors.Wrapf(err, "failed to get system info"))
37 }
38
39
40 actual := uint64(info.Totalram) * uint64(info.Unit) / 1024 / 1024
41 if actual < mc.Mem {
42 errorList = append(errorList, errors.Errorf("the system RAM (%d MB) is less than the minimum %d MB", actual, mc.Mem))
43 }
44 return warnings, errorList
45 }
46
47
48 func addOSValidator(validators []system.Validator, reporter *system.StreamReporter) []system.Validator {
49 validators = append(validators, &system.OSValidator{Reporter: reporter}, &system.CgroupsValidator{Reporter: reporter})
50 return validators
51 }
52
53
54 func addIPv6Checks(checks []Checker) []Checker {
55 checks = append(checks,
56 FileContentCheck{Path: ipv6DefaultForwarding, Content: []byte{'1'}},
57 )
58 return checks
59 }
60
61
62 func addIPv4Checks(checks []Checker) []Checker {
63 checks = append(checks,
64 FileContentCheck{Path: ipv4Forward, Content: []byte{'1'}})
65 return checks
66 }
67
68
69 func addSwapCheck(checks []Checker) []Checker {
70 checks = append(checks, SwapCheck{})
71 return checks
72 }
73
74
75 func addExecChecks(checks []Checker, execer utilsexec.Interface) []Checker {
76 checks = append(checks,
77 InPathCheck{executable: "crictl", mandatory: true, exec: execer},
78 InPathCheck{executable: "conntrack", mandatory: true, exec: execer},
79 InPathCheck{executable: "ip", mandatory: true, exec: execer},
80 InPathCheck{executable: "iptables", mandatory: true, exec: execer},
81 InPathCheck{executable: "mount", mandatory: true, exec: execer},
82 InPathCheck{executable: "nsenter", mandatory: true, exec: execer},
83 InPathCheck{executable: "ebtables", mandatory: false, exec: execer},
84 InPathCheck{executable: "ethtool", mandatory: false, exec: execer},
85 InPathCheck{executable: "socat", mandatory: false, exec: execer},
86 InPathCheck{executable: "tc", mandatory: false, exec: execer},
87 InPathCheck{executable: "touch", mandatory: false, exec: execer})
88 return checks
89 }
90
View as plain text