mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-04-30 12:44:39 +00:00
runtime: fix handling container spec's memory limit
The OCI container spec specifies a limit of -1 signifies unlimited memory. Update the sandbox memory calculator to reflect this part of the spec. Fixes: #3512 Signed-off-by: Braden Rayhorn <bradenrayhorn@fastmail.com>
This commit is contained in:
parent
8a8ae8aae7
commit
fc0e095180
@ -1989,7 +1989,7 @@ func (s *Sandbox) calculateSandboxMemory() (int64, bool, int64) {
|
|||||||
|
|
||||||
if m := c.Resources.Memory; m != nil {
|
if m := c.Resources.Memory; m != nil {
|
||||||
currentLimit := int64(0)
|
currentLimit := int64(0)
|
||||||
if m.Limit != nil {
|
if m.Limit != nil && *m.Limit > 0 {
|
||||||
currentLimit = *m.Limit
|
currentLimit = *m.Limit
|
||||||
memorySandbox += currentLimit
|
memorySandbox += currentLimit
|
||||||
}
|
}
|
||||||
|
@ -178,6 +178,20 @@ func TestCalculateSandboxMem(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestCalculateSandboxMemHandlesNegativeLimits(t *testing.T) {
|
||||||
|
sandbox := &Sandbox{}
|
||||||
|
sandbox.config = &SandboxConfig{}
|
||||||
|
container := newTestContainerConfigNoop("cont-00001")
|
||||||
|
limit := int64(-1)
|
||||||
|
container.Resources.Memory = &specs.LinuxMemory{Limit: &limit}
|
||||||
|
|
||||||
|
sandbox.config.Containers = []ContainerConfig{container}
|
||||||
|
mem, needSwap, swap := sandbox.calculateSandboxMemory()
|
||||||
|
assert.Equal(t, mem, int64(0))
|
||||||
|
assert.Equal(t, needSwap, false)
|
||||||
|
assert.Equal(t, swap, int64(0))
|
||||||
|
}
|
||||||
|
|
||||||
func TestCreateSandboxEmptyID(t *testing.T) {
|
func TestCreateSandboxEmptyID(t *testing.T) {
|
||||||
hConfig := newHypervisorConfig(nil, nil)
|
hConfig := newHypervisorConfig(nil, nil)
|
||||||
_, err := testCreateSandbox(t, "", MockHypervisor, hConfig, NetworkConfig{}, nil, nil)
|
_, err := testCreateSandbox(t, "", MockHypervisor, hConfig, NetworkConfig{}, nil, nil)
|
||||||
|
Loading…
Reference in New Issue
Block a user