github.com/jwhonce/docker@v0.6.7-0.20190327063223-da823cf3a5a3/integration-cli/requirements_unix_test.go (about)

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