* Runtime: validate memory limits & error out if it's less than 524288
| ... | ... |
@@ -658,6 +658,10 @@ func (srv *Server) ImageImport(src, repo, tag string, in io.Reader, out io.Write |
| 658 | 658 |
|
| 659 | 659 |
func (srv *Server) ContainerCreate(config *Config) (string, error) {
|
| 660 | 660 |
|
| 661 |
+ if config.Memory != 0 && config.Memory < 524288 {
|
|
| 662 |
+ return "", fmt.Errorf("Memory limit must be given in bytes (minimum 524288 bytes)")
|
|
| 663 |
+ } |
|
| 664 |
+ |
|
| 661 | 665 |
if config.Memory > 0 && !srv.runtime.capabilities.MemoryLimit {
|
| 662 | 666 |
config.Memory = 0 |
| 663 | 667 |
} |
| ... | ... |
@@ -147,3 +147,25 @@ func TestCreateStartRestartStopStartKillRm(t *testing.T) {
|
| 147 | 147 |
} |
| 148 | 148 |
|
| 149 | 149 |
} |
| 150 |
+ |
|
| 151 |
+func TestRunWithTooLowMemoryLimit(t *testing.T) {
|
|
| 152 |
+ runtime, err := newTestRuntime() |
|
| 153 |
+ srv := &Server{runtime: runtime}
|
|
| 154 |
+ if err != nil {
|
|
| 155 |
+ t.Fatal(err) |
|
| 156 |
+ } |
|
| 157 |
+ defer nuke(runtime) |
|
| 158 |
+ // Try to create a container with a memory limit of 1 byte less than the minimum allowed limit. |
|
| 159 |
+ _, err = srv.ContainerCreate( |
|
| 160 |
+ &Config{
|
|
| 161 |
+ Image: GetTestImage(runtime).ID, |
|
| 162 |
+ Memory: 524287, |
|
| 163 |
+ CpuShares: 1000, |
|
| 164 |
+ Cmd: []string{"/bin/cat"},
|
|
| 165 |
+ }, |
|
| 166 |
+ ) |
|
| 167 |
+ if err == nil {
|
|
| 168 |
+ t.Errorf("Memory limit is smaller than the allowed limit. Container creation should've failed!")
|
|
| 169 |
+ } |
|
| 170 |
+ |
|
| 171 |
+} |