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: 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 containers#15067 Signed-off-by: Charlie Doern <[email protected]>
- Loading branch information
Showing
48 changed files
with
879 additions
and
287 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
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,83 @@ | ||
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, entities.UpdateMode) | ||
} | ||
|
||
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 | ||
// use a specgen since this is the easiest way to hold resource info | ||
s := &specgen.SpecGenerator{} | ||
s.ResourceLimits = &specs.LinuxResources{} | ||
|
||
// we need to pass the whole specgen since throttle devices are parsed later due to cross compat. | ||
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
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 |
---|---|---|
|
@@ -27,3 +27,4 @@ podman-run.1.md | |
podman-search.1.md | ||
podman-stop.1.md | ||
podman-unpause.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,5 @@ | ||
#### **--device-read-bps**=*path:rate* | ||
|
||
Limit read rate (in bytes per second) from a device (e.g. **--device-read-bps=/dev/sda:1mb**). | ||
|
||
This option is not supported on cgroups V1 rootless systems. |
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,5 @@ | ||
#### **--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 option is not supported on cgroups V1 rootless systems. |
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,5 @@ | ||
#### **--device-write-bps**=*path:rate* | ||
|
||
Limit write rate (in bytes per second) to a device (e.g. **--device-write-bps=/dev/sda:1mb**). | ||
|
||
This option is not supported on cgroups V1 rootless systems. |
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,5 @@ | ||
#### **--device-write-iops**=*path:rate* | ||
|
||
Limit write rate (in IO operations per second) to a device (e.g. **--device-write-iops=/dev/sda:1000**). | ||
|
||
This option is not supported on cgroups V1 rootless systems. |
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,11 @@ | ||
#### **--memory-reservation**=*number[unit]* | ||
|
||
Memory soft limit. A _unit_ can be **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 option is not supported on cgroups V1 rootless systems. |
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,13 @@ | ||
#### **--memory-swap**=*number[unit]* | ||
|
||
A limit value equal to memory plus swap. | ||
A _unit_ can be **b** (bytes), **k** (kibibytes), **m** (mebibytes), or **g** (gibibytes). | ||
|
||
Must be used with the **-m** (**--memory**) flag. | ||
The argument value should always be larger than that of | ||
**-m** (**--memory**) By default, it is set to double | ||
the value of **--memory**. | ||
|
||
Set _number_ to **-1** to enable unlimited swap. | ||
|
||
This option is not supported on cgroups V1 rootless systems. |
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,11 @@ | ||
#### **--memory**, **-m**=*number[unit]* | ||
|
||
Memory limit. A _unit_ can be **b** (bytes), **k** (kibibytes), **m** (mebibytes), or **g** (gibibytes). | ||
|
||
Allows the memory available to a container to be constrained. 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 option is not supported on cgroups V1 rootless systems. |
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
Oops, something went wrong.