Explorar el Código

Move OomKillDisable to resource

1. It's a cgroup api, fit the general defination that we take
cgroup options as kind of resource options.
2. It's common usage and very helpful as explained here:
https://github.com/docker/docker/pull/18270#issuecomment-160561316
3. It's already in `Resource` struct in
daemon/execdriver/driver_unix.go

Signed-off-by: Qiang Huang <h.huangqiang@huawei.com>
Qiang Huang hace 9 años
padre
commit
8498ed73f7
Se han modificado 3 ficheros con 6 adiciones y 6 borrados
  1. 4 4
      daemon/daemon_unix.go
  2. 1 1
      runconfig/hostconfig.go
  3. 1 1
      runconfig/parse.go

+ 4 - 4
daemon/daemon_unix.go

@@ -265,6 +265,10 @@ func verifyContainerResources(resources *runconfig.Resources) ([]string, error)
 		warnings = append(warnings, "You specified a kernel memory limit on a kernel older than 4.0. Kernel memory limits are experimental on older kernels, it won't work as expected and can cause your system to be unstable.")
 		logrus.Warnf("You specified a kernel memory limit on a kernel older than 4.0. Kernel memory limits are experimental on older kernels, it won't work as expected and can cause your system to be unstable.")
 	}
+	if resources.OomKillDisable && !sysInfo.OomKillDisable {
+		resources.OomKillDisable = false
+		return warnings, fmt.Errorf("Your kernel does not support oom kill disable.")
+	}
 
 	// cpu subsystem checks and adjustments
 	if resources.CPUShares > 0 && !sysInfo.CPUShares {
@@ -364,10 +368,6 @@ func verifyPlatformContainerSettings(daemon *Daemon, hostConfig *runconfig.HostC
 		return warnings, fmt.Errorf("SHM size must be greater then 0")
 	}
 
-	if hostConfig.OomKillDisable && !sysInfo.OomKillDisable {
-		hostConfig.OomKillDisable = false
-		return warnings, fmt.Errorf("Your kernel does not support oom kill disable.")
-	}
 	if hostConfig.OomScoreAdj < -1000 || hostConfig.OomScoreAdj > 1000 {
 		return warnings, fmt.Errorf("Invalid value %d, range for oom score adj is [-1000, 1000].", hostConfig.OomScoreAdj)
 	}

+ 1 - 1
runconfig/hostconfig.go

@@ -188,6 +188,7 @@ type Resources struct {
 	MemoryReservation    int64            // Memory soft limit (in bytes)
 	MemorySwap           int64            // Total memory usage (memory + swap); set `-1` to disable swap
 	MemorySwappiness     *int64           // Tuning container memory swappiness behaviour
+	OomKillDisable       bool             // Whether to disable OOM Killer or not
 	Ulimits              []*ulimit.Ulimit // List of ulimits to be set in the container
 }
 
@@ -216,7 +217,6 @@ type HostConfig struct {
 	IpcMode         IpcMode               // IPC namespace to use for the container
 	Links           []string              // List of links (in the name:alias form)
 	OomScoreAdj     int                   // Container preference for OOM-killing
-	OomKillDisable  bool                  // Whether to disable OOM Killer or not
 	PidMode         PidMode               // PID namespace to use for the container
 	Privileged      bool                  // Is the container in privileged mode
 	PublishAllPorts bool                  // Should docker publish all exposed port for the container

+ 1 - 1
runconfig/parse.go

@@ -353,6 +353,7 @@ func Parse(cmd *flag.FlagSet, args []string) (*Config, *HostConfig, *flag.FlagSe
 		MemorySwap:           memorySwap,
 		MemorySwappiness:     flSwappiness,
 		KernelMemory:         KernelMemory,
+		OomKillDisable:       *flOomKillDisable,
 		CPUShares:            *flCPUShares,
 		CPUPeriod:            *flCPUPeriod,
 		CpusetCpus:           *flCpusetCpus,
@@ -397,7 +398,6 @@ func Parse(cmd *flag.FlagSet, args []string) (*Config, *HostConfig, *flag.FlagSe
 		Binds:           binds,
 		ContainerIDFile: *flContainerIDFile,
 		OomScoreAdj:     *flOomScoreAdj,
-		OomKillDisable:  *flOomKillDisable,
 		Privileged:      *flPrivileged,
 		PortBindings:    portBindings,
 		Links:           flLinks.GetAll(),