Просмотр исходного кода

Change OomKillDisable to be pointer

It's like `MemorySwappiness`, the default value has specific
meaning (default false means enable oom kill).

We need to change it to pointer so we can update it after
container is created.

Signed-off-by: Qiang Huang <h.huangqiang@huawei.com>
(cherry picked from commit 9c2ea42329179c589f5a8991ccf0253eb10fc897)

Conflicts:
	vendor/src/github.com/docker/engine-api/types/container/host_config.go
Qiang Huang 9 лет назад
Родитель
Сommit
f4a687334b
4 измененных файлов с 9 добавлено и 5 удалено
  1. 1 1
      api/client/run.go
  2. 1 1
      daemon/container_operations_unix.go
  3. 6 2
      daemon/daemon_unix.go
  4. 1 1
      runconfig/opts/parse.go

+ 1 - 1
api/client/run.go

@@ -90,7 +90,7 @@ func (cli *DockerCli) CmdRun(args ...string) error {
 		os.Exit(125)
 		os.Exit(125)
 	}
 	}
 
 
-	if hostConfig.OomKillDisable && hostConfig.Memory == 0 {
+	if hostConfig.OomKillDisable != nil && *hostConfig.OomKillDisable && hostConfig.Memory == 0 {
 		fmt.Fprintf(cli.err, "WARNING: Dangerous only disable the OOM Killer on containers but not set the '-m/--memory' option\n")
 		fmt.Fprintf(cli.err, "WARNING: Dangerous only disable the OOM Killer on containers but not set the '-m/--memory' option\n")
 	}
 	}
 
 

+ 1 - 1
daemon/container_operations_unix.go

@@ -209,7 +209,7 @@ func (daemon *Daemon) populateCommand(c *container.Container, env []string) erro
 		BlkioThrottleWriteBpsDevice:  writeBpsDevice,
 		BlkioThrottleWriteBpsDevice:  writeBpsDevice,
 		BlkioThrottleReadIOpsDevice:  readIOpsDevice,
 		BlkioThrottleReadIOpsDevice:  readIOpsDevice,
 		BlkioThrottleWriteIOpsDevice: writeIOpsDevice,
 		BlkioThrottleWriteIOpsDevice: writeIOpsDevice,
-		OomKillDisable:               c.HostConfig.OomKillDisable,
+		OomKillDisable:               *c.HostConfig.OomKillDisable,
 		MemorySwappiness:             -1,
 		MemorySwappiness:             -1,
 	}
 	}
 
 

+ 6 - 2
daemon/daemon_unix.go

@@ -210,6 +210,10 @@ func (daemon *Daemon) adaptContainerSettings(hostConfig *containertypes.HostConf
 		defaultSwappiness := int64(-1)
 		defaultSwappiness := int64(-1)
 		hostConfig.MemorySwappiness = &defaultSwappiness
 		hostConfig.MemorySwappiness = &defaultSwappiness
 	}
 	}
+	if hostConfig.OomKillDisable == nil {
+		defaultOomKillDisable := false
+		hostConfig.OomKillDisable = &defaultOomKillDisable
+	}
 
 
 	return nil
 	return nil
 }
 }
@@ -270,8 +274,8 @@ func verifyContainerResources(resources *containertypes.Resources) ([]string, er
 		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.")
 		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.")
 		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
+	if resources.OomKillDisable != nil && !sysInfo.OomKillDisable {
+		resources.OomKillDisable = nil
 		return warnings, fmt.Errorf("Your kernel does not support oom kill disable.")
 		return warnings, fmt.Errorf("Your kernel does not support oom kill disable.")
 	}
 	}
 
 

+ 1 - 1
runconfig/opts/parse.go

@@ -327,7 +327,7 @@ func Parse(cmd *flag.FlagSet, args []string) (*container.Config, *container.Host
 		MemorySwap:           memorySwap,
 		MemorySwap:           memorySwap,
 		MemorySwappiness:     flSwappiness,
 		MemorySwappiness:     flSwappiness,
 		KernelMemory:         KernelMemory,
 		KernelMemory:         KernelMemory,
-		OomKillDisable:       *flOomKillDisable,
+		OomKillDisable:       flOomKillDisable,
 		CPUShares:            *flCPUShares,
 		CPUShares:            *flCPUShares,
 		CPUPeriod:            *flCPUPeriod,
 		CPUPeriod:            *flCPUPeriod,
 		CpusetCpus:           *flCpusetCpus,
 		CpusetCpus:           *flCpusetCpus,