forked from containers/podman
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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: –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 containers#15067 Signed-off-by: Charlie Doern <cdoern@redhat.com>
- Loading branch information
Showing
30 changed files
with
501 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package containers | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/containers/podman/v4/cmd/podman/common" | ||
"github.com/containers/podman/v4/cmd/podman/registry" | ||
"github.com/containers/podman/v4/pkg/domain/entities" | ||
"github.com/containers/podman/v4/pkg/specgen" | ||
"github.com/containers/podman/v4/pkg/specgenutil" | ||
"github.com/opencontainers/runtime-spec/specs-go" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var ( | ||
updateDescription = `Updates the cgroup configuration of a given container` | ||
|
||
updateCommand = &cobra.Command{ | ||
Use: "update [options] CONTAINER", | ||
Short: "update an existing container", | ||
Long: updateDescription, | ||
RunE: update, | ||
Args: cobra.ExactArgs(1), | ||
ValidArgsFunction: common.AutocompleteContainers, | ||
Example: `podman update --cpus=5 foobar_container`, | ||
} | ||
|
||
containerUpdateCommand = &cobra.Command{ | ||
Args: updateCommand.Args, | ||
Use: updateCommand.Use, | ||
Short: updateCommand.Short, | ||
Long: updateCommand.Long, | ||
RunE: updateCommand.RunE, | ||
ValidArgsFunction: updateCommand.ValidArgsFunction, | ||
Example: `podman container update --cpus=5 foobar_container`, | ||
} | ||
) | ||
var ( | ||
updateOpts entities.ContainerCreateOptions | ||
) | ||
|
||
func updateFlags(cmd *cobra.Command) { | ||
common.DefineCreateDefaults(&updateOpts) | ||
common.DefineCreateFlags(cmd, &updateOpts, false, false) | ||
} | ||
|
||
func init() { | ||
registry.Commands = append(registry.Commands, registry.CliCommand{ | ||
Command: updateCommand, | ||
}) | ||
updateFlags(updateCommand) | ||
|
||
registry.Commands = append(registry.Commands, registry.CliCommand{ | ||
Command: containerUpdateCommand, | ||
Parent: containerCmd, | ||
}) | ||
updateFlags(containerUpdateCommand) | ||
} | ||
|
||
func update(cmd *cobra.Command, args []string) error { | ||
var err error | ||
// so here we are going to want to maybe create a new type and/or fill out a | ||
// container resource spec. Might make sense to go specgen --> | ||
|
||
s := &specgen.SpecGenerator{} | ||
s.ResourceLimits = &specs.LinuxResources{} | ||
|
||
// JUST pass the resource limits. We do not need an entire specgen. | ||
s.ResourceLimits, err = specgenutil.GetResources(s, &updateOpts) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
opts := &entities.ContainerUpdateOptions{ | ||
NameOrID: args[0], | ||
Specgen: s, | ||
} | ||
rep, err := registry.ContainerEngine().ContainerUpdate(context.Background(), opts) | ||
if err != nil { | ||
return err | ||
} | ||
fmt.Println(rep) | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,4 @@ podman-pod-clone.1.md | |
podman-pod-create.1.md | ||
podman-pull.1.md | ||
podman-run.1.md | ||
podman-update.1.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.so man1/podman-update.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#### **--cpus**=*number* | ||
|
||
Number of CPUs. The default is *0.0* which means no limit. This is shorthand | ||
for **--cpu-period** and **--cpu-quota**, so you may only set either | ||
**--cpus** or **--cpu-period** and **--cpu-quota**. | ||
|
||
On some systems, changing the CPU limits may not be allowed for non-root | ||
users. For more details, see | ||
https://github.com/containers/podman/blob/main/troubleshooting.md#26-running-containers-with-cpu-limits-fails-with-a-permissions-error |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#### **--device-read-bps**=*path* | ||
|
||
Limit read rate (bytes per second) from a device (e.g. --device-read-bps=/dev/sda:1mb). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#### **--device-read-iops**=*path:rate* | ||
|
||
Limit read rate (in IO operations per second) from a device (e.g. **--device-read-iops=/dev/sda:1000**). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#### **--device-write-bps**=*path:rate* | ||
|
||
Limit write rate (in bytes per second) to a device (e.g. **--device-write-bps=/dev/sda:1mb**). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#### **--device-write-iops**=*path* | ||
|
||
Limit write rate (IO per second) to a device (e.g. --device-write-iops=/dev/sda:1000) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#### **--memory-reservation**=*limit* | ||
|
||
Memory soft limit (format: `<number>[<unit>]`, where unit = b (bytes), k (kibibytes), m (mebibytes), or g (gibibytes)) | ||
|
||
After setting memory reservation, when the system detects memory contention | ||
or low memory, containers are forced to restrict their consumption to their | ||
reservation. So you should always set the value below **--memory**, otherwise the | ||
hard limit will take precedence. By default, memory reservation will be the same | ||
as memory limit. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#### **--memory-swap**=*limit* | ||
|
||
A limit value equal to memory plus swap. Must be used with the **-m** | ||
(**--memory**) flag. The swap `LIMIT` should always be larger than **-m** | ||
(**--memory**) value. By default, the swap `LIMIT` will be set to double | ||
the value of --memory. | ||
|
||
The format of `LIMIT` is `<number>[<unit>]`. Unit can be `b` (bytes), | ||
`k` (kibibytes), `m` (mebibytes), or `g` (gibibytes). If you don't specify a | ||
unit, `b` is used. Set LIMIT to `-1` to enable unlimited swap. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#### **--memory**, **-m**=*limit* | ||
|
||
Memory limit (format: `<number>[<unit>]`, where unit = b (bytes), k (kibibytes), m (mebibytes), or g (gibibytes)) | ||
|
||
Allows you to constrain the memory available to a container. If the host | ||
supports swap memory, then the **-m** memory setting can be larger than physical | ||
RAM. If a limit of 0 is specified (not using **-m**), the container's memory is | ||
not limited. The actual limit may be rounded up to a multiple of the operating | ||
system's page size (the value would be very large, that's millions of trillions). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
% podman-update(1) | ||
|
||
## NAME | ||
podman\-update - Updates the cgroup configuration of a given container | ||
|
||
## SYNOPSIS | ||
**podman update** [*options*] *container* | ||
|
||
**podman container update** [*options*] *container* | ||
|
||
## DESCRIPTION | ||
|
||
Updates the cgroup configuration of an already existing container. The currently supported options are a susbet of the | ||
podman create/run resource limits options. This command takes one argument, a container name or ID, alongside the resource flags to modify the cgroup. | ||
|
||
## OPTIONS | ||
|
||
@@option blkio-weight | ||
|
||
@@option blkio-weight-device | ||
|
||
@@option cpu-period | ||
|
||
@@option cpu-quota | ||
|
||
@@option cpu-rt-period | ||
|
||
@@option cpu-rt-runtime | ||
|
||
@@option cpu-shares | ||
|
||
@@option cpus | ||
|
||
@@option cpuset-cpus | ||
|
||
@@option cpuset-mems | ||
|
||
@@option device-read-bps | ||
|
||
@@option device-read-iops | ||
|
||
@@option device-write-bps | ||
|
||
@@option device-write-iops | ||
|
||
@@option memory | ||
|
||
@@option memory-reservation | ||
|
||
@@option memory-swappiness | ||
|
||
@@option memory-swap | ||
|
||
## SEE ALSO | ||
**[podman(1)](podman.1.md)**, **[podman-create(1)](podman-create.1.md.in)**, **[podman-run(1)](podman-run.1.md.in)** | ||
|
||
## HISTORY | ||
August 2022, Originally written by Charlie Doern <cdoern@redhat.com> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.