mirror of
https://github.com/containers/podman.git
synced 2025-08-06 19:44:14 +08:00

podman update allows users to change the cgroup configuration of an existing container using the already defined resource limits flags from podman create/run. The supported flags in crun are: this command is also now supported in the libpod api via the /libpod/containers/<CID>/update endpoint where the resource limits are passed inthe request body and follow the OCI resource spec format –memory –cpus –cpuset-cpus –cpuset-mems –memory-swap –memory-reservation –cpu-shares –cpu-quota –cpu-period –blkio-weight –cpu-rt-period –cpu-rt-runtime -device-read-bps -device-write-bps -device-read-iops -device-write-iops -memory-swappiness -blkio-weight-device resolves #15067 Signed-off-by: Charlie Doern <cdoern@redhat.com>
32 lines
777 B
Go
32 lines
777 B
Go
package containers
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
"strings"
|
|
|
|
"github.com/containers/podman/v4/pkg/bindings"
|
|
"github.com/containers/podman/v4/pkg/domain/entities"
|
|
jsoniter "github.com/json-iterator/go"
|
|
)
|
|
|
|
func Update(ctx context.Context, options *entities.ContainerUpdateOptions) (string, error) {
|
|
conn, err := bindings.GetClient(ctx)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
resources, err := jsoniter.MarshalToString(options.Specgen.ResourceLimits)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
stringReader := strings.NewReader(resources)
|
|
response, err := conn.DoRequest(ctx, stringReader, http.MethodPost, "/containers/%s/update", nil, nil, options.NameOrID)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
defer response.Body.Close()
|
|
|
|
return options.NameOrID, response.Process(nil)
|
|
}
|