requirements_unix.go 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. // +build !windows
  2. package main
  3. import (
  4. "io/ioutil"
  5. "strings"
  6. "github.com/docker/docker/pkg/sysinfo"
  7. )
  8. var (
  9. // SysInfo stores information about which features a kernel supports.
  10. SysInfo *sysinfo.SysInfo
  11. cpuCfsPeriod = testRequirement{
  12. func() bool {
  13. return SysInfo.CPUCfsPeriod
  14. },
  15. "Test requires an environment that supports cgroup cfs period.",
  16. }
  17. cpuCfsQuota = testRequirement{
  18. func() bool {
  19. return SysInfo.CPUCfsQuota
  20. },
  21. "Test requires an environment that supports cgroup cfs quota.",
  22. }
  23. cpuShare = testRequirement{
  24. func() bool {
  25. return SysInfo.CPUShares
  26. },
  27. "Test requires an environment that supports cgroup cpu shares.",
  28. }
  29. oomControl = testRequirement{
  30. func() bool {
  31. return SysInfo.OomKillDisable
  32. },
  33. "Test requires Oom control enabled.",
  34. }
  35. pidsLimit = testRequirement{
  36. func() bool {
  37. return SysInfo.PidsLimit
  38. },
  39. "Test requires pids limit enabled.",
  40. }
  41. kernelMemorySupport = testRequirement{
  42. func() bool {
  43. return SysInfo.KernelMemory
  44. },
  45. "Test requires an environment that supports cgroup kernel memory.",
  46. }
  47. memoryLimitSupport = testRequirement{
  48. func() bool {
  49. return SysInfo.MemoryLimit
  50. },
  51. "Test requires an environment that supports cgroup memory limit.",
  52. }
  53. memoryReservationSupport = testRequirement{
  54. func() bool {
  55. return SysInfo.MemoryReservation
  56. },
  57. "Test requires an environment that supports cgroup memory reservation.",
  58. }
  59. swapMemorySupport = testRequirement{
  60. func() bool {
  61. return SysInfo.SwapLimit
  62. },
  63. "Test requires an environment that supports cgroup swap memory limit.",
  64. }
  65. memorySwappinessSupport = testRequirement{
  66. func() bool {
  67. return SysInfo.MemorySwappiness
  68. },
  69. "Test requires an environment that supports cgroup memory swappiness.",
  70. }
  71. blkioWeight = testRequirement{
  72. func() bool {
  73. return SysInfo.BlkioWeight
  74. },
  75. "Test requires an environment that supports blkio weight.",
  76. }
  77. cgroupCpuset = testRequirement{
  78. func() bool {
  79. return SysInfo.Cpuset
  80. },
  81. "Test requires an environment that supports cgroup cpuset.",
  82. }
  83. seccompEnabled = testRequirement{
  84. func() bool {
  85. return supportsSeccomp && SysInfo.Seccomp
  86. },
  87. "Test requires that seccomp support be enabled in the daemon.",
  88. }
  89. bridgeNfIptables = testRequirement{
  90. func() bool {
  91. return !SysInfo.BridgeNFCallIPTablesDisabled
  92. },
  93. "Test requires that bridge-nf-call-iptables support be enabled in the daemon.",
  94. }
  95. bridgeNfIP6tables = testRequirement{
  96. func() bool {
  97. return !SysInfo.BridgeNFCallIP6TablesDisabled
  98. },
  99. "Test requires that bridge-nf-call-ip6tables support be enabled in the daemon.",
  100. }
  101. unprivilegedUsernsClone = testRequirement{
  102. func() bool {
  103. content, err := ioutil.ReadFile("/proc/sys/kernel/unprivileged_userns_clone")
  104. if err == nil && strings.Contains(string(content), "0") {
  105. return false
  106. }
  107. return true
  108. },
  109. "Test cannot be run with 'sysctl kernel.unprivileged_userns_clone' = 0",
  110. }
  111. )
  112. func init() {
  113. SysInfo = sysinfo.New(true)
  114. }