Jelajahi Sumber

Merge pull request #21760 from hqhq/hq_minimum_reservation

Add minimum limit for memory reservation
David Calavera 9 tahun lalu
induk
melakukan
e626011bfb
2 mengubah file dengan 8 tambahan dan 0 penghapusan
  1. 3 0
      daemon/daemon_unix.go
  2. 5 0
      integration-cli/docker_cli_run_unix_test.go

+ 3 - 0
daemon/daemon_unix.go

@@ -355,6 +355,9 @@ func verifyContainerResources(resources *containertypes.Resources, sysInfo *sysi
 		logrus.Warnf("Your kernel does not support memory soft limit capabilities. Limitation discarded.")
 		resources.MemoryReservation = 0
 	}
+	if resources.MemoryReservation > 0 && resources.MemoryReservation < linuxMinMemory {
+		return warnings, fmt.Errorf("Minimum memory reservation allowed is 4MB")
+	}
 	if resources.Memory > 0 && resources.MemoryReservation > 0 && resources.Memory < resources.MemoryReservation {
 		return warnings, fmt.Errorf("Minimum memory limit should be larger than memory reservation limit, see usage")
 	}

+ 5 - 0
integration-cli/docker_cli_run_unix_test.go

@@ -615,6 +615,11 @@ func (s *DockerSuite) TestRunWithMemoryReservationInvalid(c *check.C) {
 	c.Assert(err, check.NotNil)
 	expected := "Minimum memory limit should be larger than memory reservation limit"
 	c.Assert(strings.TrimSpace(out), checker.Contains, expected, check.Commentf("run container should fail with invalid memory reservation"))
+
+	out, _, err = dockerCmdWithError("run", "--memory-reservation", "1k", "busybox", "true")
+	c.Assert(err, check.NotNil)
+	expected = "Minimum memory reservation allowed is 4MB"
+	c.Assert(strings.TrimSpace(out), checker.Contains, expected, check.Commentf("run container should fail with invalid memory reservation"))
 }
 
 func (s *DockerSuite) TestStopContainerSignal(c *check.C) {