mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-06-25 23:11:57 +00:00
runtime: newContainer: Handle the annotations of SWAP
This commit add code to handle the annotations "io.katacontainers.container.resource.swappiness" and "io.katacontainers.container.resource.swap_in_bytes". It will set the value of "io.katacontainers.resource.swappiness" to c.config.Resources.Memory.Swappiness and set the value of "io.katacontainers.resource.swap_in_bytes" to c.config.Resources.Memory.Swap. Fixes: #2201 Signed-off-by: Hui Zhu <teawater@antfin.com>
This commit is contained in:
parent
2c835b60ed
commit
a733f537e5
@ -13,6 +13,7 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strconv"
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -20,6 +21,7 @@ import (
|
|||||||
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/device/config"
|
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/device/config"
|
||||||
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/device/manager"
|
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/device/manager"
|
||||||
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/agent/protocols/grpc"
|
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/agent/protocols/grpc"
|
||||||
|
vcAnnotations "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/annotations"
|
||||||
vccgroups "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/cgroups"
|
vccgroups "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/cgroups"
|
||||||
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/rootless"
|
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/rootless"
|
||||||
vcTypes "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/types"
|
vcTypes "github.com/kata-containers/kata-containers/src/runtime/virtcontainers/pkg/types"
|
||||||
@ -767,6 +769,26 @@ func newContainer(ctx context.Context, sandbox *Sandbox, contConfig *ContainerCo
|
|||||||
ctx: sandbox.ctx,
|
ctx: sandbox.ctx,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set the Annotations of SWAP to Resources
|
||||||
|
if resourceSwappinessStr, ok := c.config.Annotations[vcAnnotations.ContainerResourcesSwappiness]; ok {
|
||||||
|
resourceSwappiness, err := strconv.ParseUint(resourceSwappinessStr, 0, 64)
|
||||||
|
if err == nil && resourceSwappiness > 200 {
|
||||||
|
err = fmt.Errorf("swapiness should not bigger than 200")
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return &Container{}, fmt.Errorf("Invalid container configuration Annotations %s %v", vcAnnotations.ContainerResourcesSwappiness, err)
|
||||||
|
}
|
||||||
|
c.config.Resources.Memory.Swappiness = &resourceSwappiness
|
||||||
|
}
|
||||||
|
if resourceSwapInBytesStr, ok := c.config.Annotations[vcAnnotations.ContainerResourcesSwapInBytes]; ok {
|
||||||
|
resourceSwapInBytesInUint, err := strconv.ParseUint(resourceSwapInBytesStr, 0, 64)
|
||||||
|
if err != nil {
|
||||||
|
return &Container{}, fmt.Errorf("Invalid container configuration Annotations %s %v", vcAnnotations.ContainerResourcesSwapInBytes, err)
|
||||||
|
}
|
||||||
|
resourceSwapInBytes := int64(resourceSwapInBytesInUint)
|
||||||
|
c.config.Resources.Memory.Swap = &resourceSwapInBytes
|
||||||
|
}
|
||||||
|
|
||||||
// experimental runtime use "persist.json" instead of legacy "state.json" as storage
|
// experimental runtime use "persist.json" instead of legacy "state.json" as storage
|
||||||
err := c.Restore()
|
err := c.Restore()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
@ -9,6 +9,7 @@ const (
|
|||||||
kataAnnotationsPrefix = "io.katacontainers."
|
kataAnnotationsPrefix = "io.katacontainers."
|
||||||
kataConfAnnotationsPrefix = kataAnnotationsPrefix + "config."
|
kataConfAnnotationsPrefix = kataAnnotationsPrefix + "config."
|
||||||
kataAnnotHypervisorPrefix = kataConfAnnotationsPrefix + "hypervisor."
|
kataAnnotHypervisorPrefix = kataConfAnnotationsPrefix + "hypervisor."
|
||||||
|
kataAnnotContainerPrefix = kataAnnotationsPrefix + "container."
|
||||||
|
|
||||||
//
|
//
|
||||||
// OCI
|
// OCI
|
||||||
@ -277,6 +278,17 @@ const (
|
|||||||
ContainerPipeSizeKernelParam = "agent." + ContainerPipeSizeOption
|
ContainerPipeSizeKernelParam = "agent." + ContainerPipeSizeOption
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Container resource related annotations
|
||||||
|
const (
|
||||||
|
kataAnnotContainerResourcePrefix = kataAnnotContainerPrefix + "resource."
|
||||||
|
|
||||||
|
// ContainerResourcesSwappiness is a container annotation to specify the Resources.Memory.Swappiness
|
||||||
|
ContainerResourcesSwappiness = kataAnnotContainerResourcePrefix + "swappiness"
|
||||||
|
|
||||||
|
// ContainerResourcesSwapInBytes is a container annotation to specify the Resources.Memory.Swap
|
||||||
|
ContainerResourcesSwapInBytes = kataAnnotContainerResourcePrefix + "swap_in_bytes"
|
||||||
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// SHA512 is the SHA-512 (64) hash algorithm
|
// SHA512 is the SHA-512 (64) hash algorithm
|
||||||
SHA512 string = "sha512"
|
SHA512 string = "sha512"
|
||||||
|
Loading…
Reference in New Issue
Block a user