requirements_unix_test.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. // +build !windows
  2. package main
  3. import (
  4. "bytes"
  5. "io/ioutil"
  6. "os/exec"
  7. "strings"
  8. "github.com/docker/docker/pkg/parsers/kernel"
  9. "github.com/docker/docker/pkg/sysinfo"
  10. )
  11. var (
  12. // SysInfo stores information about which features a kernel supports.
  13. SysInfo *sysinfo.SysInfo
  14. )
  15. func cpuCfsPeriod() bool {
  16. return testEnv.DaemonInfo.CPUCfsPeriod
  17. }
  18. func cpuCfsQuota() bool {
  19. return testEnv.DaemonInfo.CPUCfsQuota
  20. }
  21. func cpuShare() bool {
  22. return testEnv.DaemonInfo.CPUShares
  23. }
  24. func oomControl() bool {
  25. return testEnv.DaemonInfo.OomKillDisable
  26. }
  27. func pidsLimit() bool {
  28. return SysInfo.PidsLimit
  29. }
  30. func kernelMemorySupport() bool {
  31. // TODO remove this once kmem support in RHEL kernels is fixed. See https://github.com/opencontainers/runc/pull/1921
  32. daemonV, err := kernel.ParseRelease(testEnv.DaemonInfo.KernelVersion)
  33. if err != nil {
  34. return false
  35. }
  36. requiredV := kernel.VersionInfo{Kernel: 3, Major: 10}
  37. if kernel.CompareKernelVersion(*daemonV, requiredV) < 1 {
  38. // On Kernel 3.10 and under, don't consider kernel memory to be supported,
  39. // even if the kernel (and thus the daemon) reports it as being supported
  40. return false
  41. }
  42. return testEnv.DaemonInfo.KernelMemory
  43. }
  44. func memoryLimitSupport() bool {
  45. return testEnv.DaemonInfo.MemoryLimit
  46. }
  47. func memoryReservationSupport() bool {
  48. return SysInfo.MemoryReservation
  49. }
  50. func swapMemorySupport() bool {
  51. return testEnv.DaemonInfo.SwapLimit
  52. }
  53. func memorySwappinessSupport() bool {
  54. return testEnv.IsLocalDaemon() && SysInfo.MemorySwappiness
  55. }
  56. func blkioWeight() bool {
  57. return testEnv.IsLocalDaemon() && SysInfo.BlkioWeight
  58. }
  59. func cgroupCpuset() bool {
  60. return testEnv.DaemonInfo.CPUSet
  61. }
  62. func seccompEnabled() bool {
  63. return supportsSeccomp && SysInfo.Seccomp
  64. }
  65. func bridgeNfIptables() bool {
  66. return !SysInfo.BridgeNFCallIPTablesDisabled
  67. }
  68. func unprivilegedUsernsClone() bool {
  69. content, err := ioutil.ReadFile("/proc/sys/kernel/unprivileged_userns_clone")
  70. return err != nil || !strings.Contains(string(content), "0")
  71. }
  72. func overlayFSSupported() bool {
  73. cmd := exec.Command(dockerBinary, "run", "--rm", "busybox", "/bin/sh", "-c", "cat /proc/filesystems")
  74. out, err := cmd.CombinedOutput()
  75. if err != nil {
  76. return false
  77. }
  78. return bytes.Contains(out, []byte("overlay\n"))
  79. }
  80. func init() {
  81. if testEnv.IsLocalDaemon() {
  82. SysInfo = sysinfo.New(true)
  83. }
  84. }