Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
| ... | ... |
@@ -24,6 +24,7 @@ import ( |
| 24 | 24 |
"github.com/docker/go-connections/nat" |
| 25 | 25 |
"github.com/opencontainers/selinux/go-selinux/label" |
| 26 | 26 |
"github.com/pkg/errors" |
| 27 |
+ "github.com/sirupsen/logrus" |
|
| 27 | 28 |
) |
| 28 | 29 |
|
| 29 | 30 |
// GetContainer looks for a container using the provided information, which could be |
| ... | ... |
@@ -231,7 +232,7 @@ func (daemon *Daemon) setHostConfig(container *container.Container, hostConfig * |
| 231 | 231 |
|
| 232 | 232 |
// verifyContainerSettings performs validation of the hostconfig and config |
| 233 | 233 |
// structures. |
| 234 |
-func (daemon *Daemon) verifyContainerSettings(platform string, hostConfig *containertypes.HostConfig, config *containertypes.Config, update bool) ([]string, error) {
|
|
| 234 |
+func (daemon *Daemon) verifyContainerSettings(platform string, hostConfig *containertypes.HostConfig, config *containertypes.Config, update bool) (warnings []string, err error) {
|
|
| 235 | 235 |
// First perform verification of settings common across all platforms. |
| 236 | 236 |
if config != nil {
|
| 237 | 237 |
if config.WorkingDir != "" {
|
| ... | ... |
@@ -343,13 +344,10 @@ func (daemon *Daemon) verifyContainerSettings(platform string, hostConfig *conta |
| 343 | 343 |
return nil, errors.Errorf("invalid isolation '%s' on %s", hostConfig.Isolation, runtime.GOOS)
|
| 344 | 344 |
} |
| 345 | 345 |
|
| 346 |
- var ( |
|
| 347 |
- err error |
|
| 348 |
- warnings []string |
|
| 349 |
- ) |
|
| 350 | 346 |
// Now do platform-specific verification |
| 351 |
- if warnings, err = verifyPlatformContainerSettings(daemon, hostConfig, config, update); err != nil {
|
|
| 352 |
- return warnings, err |
|
| 347 |
+ warnings, err = verifyPlatformContainerSettings(daemon, hostConfig, config, update) |
|
| 348 |
+ for _, w := range warnings {
|
|
| 349 |
+ logrus.Warn(w) |
|
| 353 | 350 |
} |
| 354 | 351 |
return warnings, err |
| 355 | 352 |
} |
| ... | ... |
@@ -354,8 +354,7 @@ func adaptSharedNamespaceContainer(daemon containerGetter, hostConfig *container |
| 354 | 354 |
} |
| 355 | 355 |
} |
| 356 | 356 |
|
| 357 |
-func verifyContainerResources(resources *containertypes.Resources, sysInfo *sysinfo.SysInfo, update bool) ([]string, error) {
|
|
| 358 |
- warnings := []string{}
|
|
| 357 |
+func verifyContainerResources(resources *containertypes.Resources, sysInfo *sysinfo.SysInfo, update bool) (warnings []string, err error) {
|
|
| 359 | 358 |
fixMemorySwappiness(resources) |
| 360 | 359 |
|
| 361 | 360 |
// memory subsystem checks and adjustments |
| ... | ... |
@@ -364,13 +363,11 @@ func verifyContainerResources(resources *containertypes.Resources, sysInfo *sysi |
| 364 | 364 |
} |
| 365 | 365 |
if resources.Memory > 0 && !sysInfo.MemoryLimit {
|
| 366 | 366 |
warnings = append(warnings, "Your kernel does not support memory limit capabilities or the cgroup is not mounted. Limitation discarded.") |
| 367 |
- logrus.Warn("Your kernel does not support memory limit capabilities or the cgroup is not mounted. Limitation discarded.")
|
|
| 368 | 367 |
resources.Memory = 0 |
| 369 | 368 |
resources.MemorySwap = -1 |
| 370 | 369 |
} |
| 371 | 370 |
if resources.Memory > 0 && resources.MemorySwap != -1 && !sysInfo.SwapLimit {
|
| 372 | 371 |
warnings = append(warnings, "Your kernel does not support swap limit capabilities or the cgroup is not mounted. Memory limited without swap.") |
| 373 |
- logrus.Warn("Your kernel does not support swap limit capabilities,or the cgroup is not mounted. Memory limited without swap.")
|
|
| 374 | 372 |
resources.MemorySwap = -1 |
| 375 | 373 |
} |
| 376 | 374 |
if resources.Memory > 0 && resources.MemorySwap > 0 && resources.MemorySwap < resources.Memory {
|
| ... | ... |
@@ -381,7 +378,6 @@ func verifyContainerResources(resources *containertypes.Resources, sysInfo *sysi |
| 381 | 381 |
} |
| 382 | 382 |
if resources.MemorySwappiness != nil && !sysInfo.MemorySwappiness {
|
| 383 | 383 |
warnings = append(warnings, "Your kernel does not support memory swappiness capabilities or the cgroup is not mounted. Memory swappiness discarded.") |
| 384 |
- logrus.Warn("Your kernel does not support memory swappiness capabilities, or the cgroup is not mounted. Memory swappiness discarded.")
|
|
| 385 | 384 |
resources.MemorySwappiness = nil |
| 386 | 385 |
} |
| 387 | 386 |
if resources.MemorySwappiness != nil {
|
| ... | ... |
@@ -392,7 +388,6 @@ func verifyContainerResources(resources *containertypes.Resources, sysInfo *sysi |
| 392 | 392 |
} |
| 393 | 393 |
if resources.MemoryReservation > 0 && !sysInfo.MemoryReservation {
|
| 394 | 394 |
warnings = append(warnings, "Your kernel does not support memory soft limit capabilities or the cgroup is not mounted. Limitation discarded.") |
| 395 |
- logrus.Warn("Your kernel does not support memory soft limit capabilities or the cgroup is not mounted. Limitation discarded.")
|
|
| 396 | 395 |
resources.MemoryReservation = 0 |
| 397 | 396 |
} |
| 398 | 397 |
if resources.MemoryReservation > 0 && resources.MemoryReservation < linuxMinMemory {
|
| ... | ... |
@@ -403,7 +398,6 @@ func verifyContainerResources(resources *containertypes.Resources, sysInfo *sysi |
| 403 | 403 |
} |
| 404 | 404 |
if resources.KernelMemory > 0 && !sysInfo.KernelMemory {
|
| 405 | 405 |
warnings = append(warnings, "Your kernel does not support kernel memory limit capabilities or the cgroup is not mounted. Limitation discarded.") |
| 406 |
- logrus.Warn("Your kernel does not support kernel memory limit capabilities or the cgroup is not mounted. Limitation discarded.")
|
|
| 407 | 406 |
resources.KernelMemory = 0 |
| 408 | 407 |
} |
| 409 | 408 |
if resources.KernelMemory > 0 && resources.KernelMemory < linuxMinMemory {
|
| ... | ... |
@@ -411,24 +405,20 @@ func verifyContainerResources(resources *containertypes.Resources, sysInfo *sysi |
| 411 | 411 |
} |
| 412 | 412 |
if resources.KernelMemory > 0 && !kernel.CheckKernelVersion(4, 0, 0) {
|
| 413 | 413 |
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.") |
| 414 |
- logrus.Warn("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.")
|
|
| 415 | 414 |
} |
| 416 | 415 |
if resources.OomKillDisable != nil && !sysInfo.OomKillDisable {
|
| 417 | 416 |
// only produce warnings if the setting wasn't to *disable* the OOM Kill; no point |
| 418 | 417 |
// warning the caller if they already wanted the feature to be off |
| 419 | 418 |
if *resources.OomKillDisable {
|
| 420 | 419 |
warnings = append(warnings, "Your kernel does not support OomKillDisable. OomKillDisable discarded.") |
| 421 |
- logrus.Warn("Your kernel does not support OomKillDisable. OomKillDisable discarded.")
|
|
| 422 | 420 |
} |
| 423 | 421 |
resources.OomKillDisable = nil |
| 424 | 422 |
} |
| 425 | 423 |
if resources.OomKillDisable != nil && *resources.OomKillDisable && resources.Memory == 0 {
|
| 426 | 424 |
warnings = append(warnings, "OOM killer is disabled for the container, but no memory limit is set, this can result in the system running out of resources.") |
| 427 |
- logrus.Warn("OOM killer is disabled for the container, but no memory limit is set, this can result in the system running out of resources.")
|
|
| 428 | 425 |
} |
| 429 | 426 |
if resources.PidsLimit != 0 && !sysInfo.PidsLimit {
|
| 430 | 427 |
warnings = append(warnings, "Your kernel does not support pids limit capabilities or the cgroup is not mounted. PIDs limit discarded.") |
| 431 |
- logrus.Warn("Your kernel does not support pids limit capabilities or the cgroup is not mounted. PIDs limit discarded.")
|
|
| 432 | 428 |
resources.PidsLimit = 0 |
| 433 | 429 |
} |
| 434 | 430 |
|
| ... | ... |
@@ -455,12 +445,10 @@ func verifyContainerResources(resources *containertypes.Resources, sysInfo *sysi |
| 455 | 455 |
|
| 456 | 456 |
if resources.CPUShares > 0 && !sysInfo.CPUShares {
|
| 457 | 457 |
warnings = append(warnings, "Your kernel does not support CPU shares or the cgroup is not mounted. Shares discarded.") |
| 458 |
- logrus.Warn("Your kernel does not support CPU shares or the cgroup is not mounted. Shares discarded.")
|
|
| 459 | 458 |
resources.CPUShares = 0 |
| 460 | 459 |
} |
| 461 | 460 |
if resources.CPUPeriod > 0 && !sysInfo.CPUCfsPeriod {
|
| 462 | 461 |
warnings = append(warnings, "Your kernel does not support CPU cfs period or the cgroup is not mounted. Period discarded.") |
| 463 |
- logrus.Warn("Your kernel does not support CPU cfs period or the cgroup is not mounted. Period discarded.")
|
|
| 464 | 462 |
resources.CPUPeriod = 0 |
| 465 | 463 |
} |
| 466 | 464 |
if resources.CPUPeriod != 0 && (resources.CPUPeriod < 1000 || resources.CPUPeriod > 1000000) {
|
| ... | ... |
@@ -468,7 +456,6 @@ func verifyContainerResources(resources *containertypes.Resources, sysInfo *sysi |
| 468 | 468 |
} |
| 469 | 469 |
if resources.CPUQuota > 0 && !sysInfo.CPUCfsQuota {
|
| 470 | 470 |
warnings = append(warnings, "Your kernel does not support CPU cfs quota or the cgroup is not mounted. Quota discarded.") |
| 471 |
- logrus.Warn("Your kernel does not support CPU cfs quota or the cgroup is not mounted. Quota discarded.")
|
|
| 472 | 471 |
resources.CPUQuota = 0 |
| 473 | 472 |
} |
| 474 | 473 |
if resources.CPUQuota > 0 && resources.CPUQuota < 1000 {
|
| ... | ... |
@@ -476,14 +463,12 @@ func verifyContainerResources(resources *containertypes.Resources, sysInfo *sysi |
| 476 | 476 |
} |
| 477 | 477 |
if resources.CPUPercent > 0 {
|
| 478 | 478 |
warnings = append(warnings, fmt.Sprintf("%s does not support CPU percent. Percent discarded.", runtime.GOOS))
|
| 479 |
- logrus.Warnf("%s does not support CPU percent. Percent discarded.", runtime.GOOS)
|
|
| 480 | 479 |
resources.CPUPercent = 0 |
| 481 | 480 |
} |
| 482 | 481 |
|
| 483 | 482 |
// cpuset subsystem checks and adjustments |
| 484 | 483 |
if (resources.CpusetCpus != "" || resources.CpusetMems != "") && !sysInfo.Cpuset {
|
| 485 | 484 |
warnings = append(warnings, "Your kernel does not support cpuset or the cgroup is not mounted. Cpuset discarded.") |
| 486 |
- logrus.Warn("Your kernel does not support cpuset or the cgroup is not mounted. Cpuset discarded.")
|
|
| 487 | 485 |
resources.CpusetCpus = "" |
| 488 | 486 |
resources.CpusetMems = "" |
| 489 | 487 |
} |
| ... | ... |
@@ -505,7 +490,6 @@ func verifyContainerResources(resources *containertypes.Resources, sysInfo *sysi |
| 505 | 505 |
// blkio subsystem checks and adjustments |
| 506 | 506 |
if resources.BlkioWeight > 0 && !sysInfo.BlkioWeight {
|
| 507 | 507 |
warnings = append(warnings, "Your kernel does not support Block I/O weight or the cgroup is not mounted. Weight discarded.") |
| 508 |
- logrus.Warn("Your kernel does not support Block I/O weight or the cgroup is not mounted. Weight discarded.")
|
|
| 509 | 508 |
resources.BlkioWeight = 0 |
| 510 | 509 |
} |
| 511 | 510 |
if resources.BlkioWeight > 0 && (resources.BlkioWeight < 10 || resources.BlkioWeight > 1000) {
|
| ... | ... |
@@ -516,28 +500,23 @@ func verifyContainerResources(resources *containertypes.Resources, sysInfo *sysi |
| 516 | 516 |
} |
| 517 | 517 |
if len(resources.BlkioWeightDevice) > 0 && !sysInfo.BlkioWeightDevice {
|
| 518 | 518 |
warnings = append(warnings, "Your kernel does not support Block I/O weight_device or the cgroup is not mounted. Weight-device discarded.") |
| 519 |
- logrus.Warn("Your kernel does not support Block I/O weight_device or the cgroup is not mounted. Weight-device discarded.")
|
|
| 520 | 519 |
resources.BlkioWeightDevice = []*pblkiodev.WeightDevice{}
|
| 521 | 520 |
} |
| 522 | 521 |
if len(resources.BlkioDeviceReadBps) > 0 && !sysInfo.BlkioReadBpsDevice {
|
| 523 | 522 |
warnings = append(warnings, "Your kernel does not support BPS Block I/O read limit or the cgroup is not mounted. Block I/O BPS read limit discarded.") |
| 524 |
- logrus.Warn("Your kernel does not support BPS Block I/O read limit or the cgroup is not mounted. Block I/O BPS read limit discarded")
|
|
| 525 | 523 |
resources.BlkioDeviceReadBps = []*pblkiodev.ThrottleDevice{}
|
| 526 | 524 |
} |
| 527 | 525 |
if len(resources.BlkioDeviceWriteBps) > 0 && !sysInfo.BlkioWriteBpsDevice {
|
| 528 | 526 |
warnings = append(warnings, "Your kernel does not support BPS Block I/O write limit or the cgroup is not mounted. Block I/O BPS write limit discarded.") |
| 529 |
- logrus.Warn("Your kernel does not support BPS Block I/O write limit or the cgroup is not mounted. Block I/O BPS write limit discarded.")
|
|
| 530 | 527 |
resources.BlkioDeviceWriteBps = []*pblkiodev.ThrottleDevice{}
|
| 531 | 528 |
|
| 532 | 529 |
} |
| 533 | 530 |
if len(resources.BlkioDeviceReadIOps) > 0 && !sysInfo.BlkioReadIOpsDevice {
|
| 534 | 531 |
warnings = append(warnings, "Your kernel does not support IOPS Block read limit or the cgroup is not mounted. Block I/O IOPS read limit discarded.") |
| 535 |
- logrus.Warn("Your kernel does not support IOPS Block I/O read limit in IO or the cgroup is not mounted. Block I/O IOPS read limit discarded.")
|
|
| 536 | 532 |
resources.BlkioDeviceReadIOps = []*pblkiodev.ThrottleDevice{}
|
| 537 | 533 |
} |
| 538 | 534 |
if len(resources.BlkioDeviceWriteIOps) > 0 && !sysInfo.BlkioWriteIOpsDevice {
|
| 539 | 535 |
warnings = append(warnings, "Your kernel does not support IOPS Block write limit or the cgroup is not mounted. Block I/O IOPS write limit discarded.") |
| 540 |
- logrus.Warn("Your kernel does not support IOPS Block I/O write limit or the cgroup is not mounted. Block I/O IOPS write limit discarded.")
|
|
| 541 | 536 |
resources.BlkioDeviceWriteIOps = []*pblkiodev.ThrottleDevice{}
|
| 542 | 537 |
} |
| 543 | 538 |
|
| ... | ... |
@@ -581,8 +560,7 @@ func UsingSystemd(config *config.Config) bool {
|
| 581 | 581 |
|
| 582 | 582 |
// verifyPlatformContainerSettings performs platform-specific validation of the |
| 583 | 583 |
// hostconfig and config structures. |
| 584 |
-func verifyPlatformContainerSettings(daemon *Daemon, hostConfig *containertypes.HostConfig, config *containertypes.Config, update bool) ([]string, error) {
|
|
| 585 |
- var warnings []string |
|
| 584 |
+func verifyPlatformContainerSettings(daemon *Daemon, hostConfig *containertypes.HostConfig, config *containertypes.Config, update bool) (warnings []string, err error) {
|
|
| 586 | 585 |
sysInfo := sysinfo.New(true) |
| 587 | 586 |
|
| 588 | 587 |
w, err := verifyContainerResources(&hostConfig.Resources, sysInfo, update) |
| ... | ... |
@@ -605,7 +583,6 @@ func verifyPlatformContainerSettings(daemon *Daemon, hostConfig *containertypes. |
| 605 | 605 |
// ip-forwarding does not affect container with '--net=host' (or '--net=none') |
| 606 | 606 |
if sysInfo.IPv4ForwardingDisabled && !(hostConfig.NetworkMode.IsHost() || hostConfig.NetworkMode.IsNone()) {
|
| 607 | 607 |
warnings = append(warnings, "IPv4 forwarding is disabled. Networking will not work.") |
| 608 |
- logrus.Warn("IPv4 forwarding is disabled. Networking will not work")
|
|
| 609 | 608 |
} |
| 610 | 609 |
if hostConfig.NetworkMode.IsHost() && len(hostConfig.PortBindings) > 0 {
|
| 611 | 610 |
warnings = append(warnings, "Published ports are discarded when using host network mode") |
| ... | ... |
@@ -75,8 +75,7 @@ func (daemon *Daemon) adaptContainerSettings(hostConfig *containertypes.HostConf |
| 75 | 75 |
return nil |
| 76 | 76 |
} |
| 77 | 77 |
|
| 78 |
-func verifyContainerResources(resources *containertypes.Resources, isHyperv bool) ([]string, error) {
|
|
| 79 |
- warnings := []string{}
|
|
| 78 |
+func verifyContainerResources(resources *containertypes.Resources, isHyperv bool) (warnings []string, err error) {
|
|
| 80 | 79 |
fixMemorySwappiness(resources) |
| 81 | 80 |
if !isHyperv {
|
| 82 | 81 |
// The processor resource controls are mutually exclusive on |
| ... | ... |
@@ -85,18 +84,15 @@ func verifyContainerResources(resources *containertypes.Resources, isHyperv bool |
| 85 | 85 |
if resources.CPUCount > 0 {
|
| 86 | 86 |
if resources.CPUShares > 0 {
|
| 87 | 87 |
warnings = append(warnings, "Conflicting options: CPU count takes priority over CPU shares on Windows Server Containers. CPU shares discarded") |
| 88 |
- logrus.Warn("Conflicting options: CPU count takes priority over CPU shares on Windows Server Containers. CPU shares discarded")
|
|
| 89 | 88 |
resources.CPUShares = 0 |
| 90 | 89 |
} |
| 91 | 90 |
if resources.CPUPercent > 0 {
|
| 92 | 91 |
warnings = append(warnings, "Conflicting options: CPU count takes priority over CPU percent on Windows Server Containers. CPU percent discarded") |
| 93 |
- logrus.Warn("Conflicting options: CPU count takes priority over CPU percent on Windows Server Containers. CPU percent discarded")
|
|
| 94 | 92 |
resources.CPUPercent = 0 |
| 95 | 93 |
} |
| 96 | 94 |
} else if resources.CPUShares > 0 {
|
| 97 | 95 |
if resources.CPUPercent > 0 {
|
| 98 | 96 |
warnings = append(warnings, "Conflicting options: CPU shares takes priority over CPU percent on Windows Server Containers. CPU percent discarded") |
| 99 |
- logrus.Warn("Conflicting options: CPU shares takes priority over CPU percent on Windows Server Containers. CPU percent discarded")
|
|
| 100 | 97 |
resources.CPUPercent = 0 |
| 101 | 98 |
} |
| 102 | 99 |
} |
| ... | ... |
@@ -131,7 +127,6 @@ func verifyContainerResources(resources *containertypes.Resources, isHyperv bool |
| 131 | 131 |
resources.NanoCPUs = ((resources.NanoCPUs + 1e9/2) / 1e9) * 1e9 |
| 132 | 132 |
warningString := fmt.Sprintf("Your current OS version does not support Hyper-V containers with NanoCPUs greater than 1000000000 but not divisible by 1000000000. NanoCPUs rounded to %d", resources.NanoCPUs)
|
| 133 | 133 |
warnings = append(warnings, warningString) |
| 134 |
- logrus.Warn(warningString) |
|
| 135 | 134 |
} |
| 136 | 135 |
} |
| 137 | 136 |
|
| ... | ... |
@@ -191,8 +186,7 @@ func verifyContainerResources(resources *containertypes.Resources, isHyperv bool |
| 191 | 191 |
|
| 192 | 192 |
// verifyPlatformContainerSettings performs platform-specific validation of the |
| 193 | 193 |
// hostconfig and config structures. |
| 194 |
-func verifyPlatformContainerSettings(daemon *Daemon, hostConfig *containertypes.HostConfig, config *containertypes.Config, update bool) ([]string, error) {
|
|
| 195 |
- warnings := []string{}
|
|
| 194 |
+func verifyPlatformContainerSettings(daemon *Daemon, hostConfig *containertypes.HostConfig, config *containertypes.Config, update bool) (warnings []string, err error) {
|
|
| 196 | 195 |
osv := system.GetOSVersion() |
| 197 | 196 |
hyperv := daemon.runAsHyperVContainer(hostConfig) |
| 198 | 197 |
|