Skip to content

Commit 78298f0

Browse files
acouvreurthaJeztah
authored andcommitted
feat: add blkio device options to docker container update
Signed-off-by: Alexis Couvreur <alexiscouvreur.pro@gmail.com>
1 parent 8c2e800 commit 78298f0

3 files changed

Lines changed: 54 additions & 29 deletions

File tree

cli/command/container/update.go

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,18 @@ import (
1717

1818
type updateOptions struct {
1919
blkioWeight uint16
20+
blkioWeightDevice opts.WeightdeviceOpt
2021
cpuPeriod int64
2122
cpuQuota int64
2223
cpuRealtimePeriod int64
2324
cpuRealtimeRuntime int64
2425
cpusetCpus string
2526
cpusetMems string
2627
cpuShares int64
28+
deviceReadBps opts.ThrottledeviceOpt
29+
deviceWriteBps opts.ThrottledeviceOpt
30+
deviceReadIOps opts.ThrottledeviceOpt
31+
deviceWriteIOps opts.ThrottledeviceOpt
2732
memory opts.MemBytes
2833
memoryReservation opts.MemBytes
2934
memorySwap opts.MemSwapBytes
@@ -58,6 +63,7 @@ func newUpdateCommand(dockerCLI command.Cli) *cobra.Command {
5863

5964
flags := cmd.Flags()
6065
flags.Uint16Var(&options.blkioWeight, "blkio-weight", 0, `Block IO (relative weight), between 10 and 1000, or 0 to disable (default 0)`)
66+
flags.Var(&options.blkioWeightDevice, "blkio-weight-device", "Block IO weight (relative device weight)")
6167
flags.Int64Var(&options.cpuPeriod, "cpu-period", 0, "Limit CPU CFS (Completely Fair Scheduler) period")
6268
flags.Int64Var(&options.cpuQuota, "cpu-quota", 0, "Limit CPU CFS (Completely Fair Scheduler) quota")
6369
flags.Int64Var(&options.cpuRealtimePeriod, "cpu-rt-period", 0, "Limit the CPU real-time period in microseconds")
@@ -67,6 +73,10 @@ func newUpdateCommand(dockerCLI command.Cli) *cobra.Command {
6773
flags.StringVar(&options.cpusetCpus, "cpuset-cpus", "", "CPUs in which to allow execution (0-3, 0,1)")
6874
flags.StringVar(&options.cpusetMems, "cpuset-mems", "", "MEMs in which to allow execution (0-3, 0,1)")
6975
flags.Int64VarP(&options.cpuShares, "cpu-shares", "c", 0, "CPU shares (relative weight)")
76+
flags.Var(&options.deviceReadBps, "device-read-bps", "Limit read rate (bytes per second) from a device")
77+
flags.Var(&options.deviceReadIOps, "device-read-iops", "Limit read rate (IO per second) from a device")
78+
flags.Var(&options.deviceWriteBps, "device-write-bps", "Limit write rate (bytes per second) to a device")
79+
flags.Var(&options.deviceWriteIOps, "device-write-iops", "Limit write rate (IO per second) to a device")
7080
flags.VarP(&options.memory, "memory", "m", "Memory limit")
7181
flags.Var(&options.memoryReservation, "memory-reservation", "Memory soft limit")
7282
flags.Var(&options.memorySwap, "memory-swap", `Swap limit equal to memory plus swap: -1 to enable unlimited swap`)
@@ -110,19 +120,24 @@ func runUpdate(ctx context.Context, dockerCli command.Cli, options *updateOption
110120

111121
updateConfig := client.ContainerUpdateOptions{
112122
Resources: &containertypes.Resources{
113-
BlkioWeight: options.blkioWeight,
114-
CpusetCpus: options.cpusetCpus,
115-
CpusetMems: options.cpusetMems,
116-
CPUShares: options.cpuShares,
117-
Memory: options.memory.Value(),
118-
MemoryReservation: options.memoryReservation.Value(),
119-
MemorySwap: options.memorySwap.Value(),
120-
CPUPeriod: options.cpuPeriod,
121-
CPUQuota: options.cpuQuota,
122-
CPURealtimePeriod: options.cpuRealtimePeriod,
123-
CPURealtimeRuntime: options.cpuRealtimeRuntime,
124-
NanoCPUs: options.cpus.Value(),
125-
PidsLimit: pidsLimit,
123+
BlkioWeight: options.blkioWeight,
124+
BlkioWeightDevice: options.blkioWeightDevice.GetList(),
125+
BlkioDeviceReadBps: options.deviceReadBps.GetList(),
126+
BlkioDeviceWriteBps: options.deviceWriteBps.GetList(),
127+
BlkioDeviceReadIOps: options.deviceReadIOps.GetList(),
128+
BlkioDeviceWriteIOps: options.deviceWriteIOps.GetList(),
129+
CpusetCpus: options.cpusetCpus,
130+
CpusetMems: options.cpusetMems,
131+
CPUShares: options.cpuShares,
132+
Memory: options.memory.Value(),
133+
MemoryReservation: options.memoryReservation.Value(),
134+
MemorySwap: options.memorySwap.Value(),
135+
CPUPeriod: options.cpuPeriod,
136+
CPUQuota: options.cpuQuota,
137+
CPURealtimePeriod: options.cpuRealtimePeriod,
138+
CPURealtimeRuntime: options.cpuRealtimeRuntime,
139+
NanoCPUs: options.cpus.Value(),
140+
PidsLimit: pidsLimit,
126141
},
127142
RestartPolicy: &restartPolicy,
128143
}

docs/reference/commandline/container_update.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Update configuration of one or more containers
1212
| Name | Type | Default | Description |
1313
|:---------------------------------------------------|:----------|:--------|:-----------------------------------------------------------------------------|
1414
| `--blkio-weight` | `uint16` | `0` | Block IO (relative weight), between 10 and 1000, or 0 to disable (default 0) |
15+
| `--blkio-weight-device` | `list` | | Block IO weight (relative device weight) |
1516
| `--cpu-period` | `int64` | `0` | Limit CPU CFS (Completely Fair Scheduler) period |
1617
| `--cpu-quota` | `int64` | `0` | Limit CPU CFS (Completely Fair Scheduler) quota |
1718
| `--cpu-rt-period` | `int64` | `0` | Limit the CPU real-time period in microseconds |
@@ -20,6 +21,10 @@ Update configuration of one or more containers
2021
| `--cpus` | `decimal` | | Number of CPUs |
2122
| `--cpuset-cpus` | `string` | | CPUs in which to allow execution (0-3, 0,1) |
2223
| `--cpuset-mems` | `string` | | MEMs in which to allow execution (0-3, 0,1) |
24+
| `--device-read-bps` | `list` | | Limit read rate (bytes per second) from a device |
25+
| `--device-read-iops` | `list` | | Limit read rate (IO per second) from a device |
26+
| `--device-write-bps` | `list` | | Limit write rate (bytes per second) to a device |
27+
| `--device-write-iops` | `list` | | Limit write rate (IO per second) to a device |
2328
| [`-m`](#memory), [`--memory`](#memory) | `bytes` | `0` | Memory limit |
2429
| `--memory-reservation` | `bytes` | `0` | Memory soft limit |
2530
| `--memory-swap` | `bytes` | `0` | Swap limit equal to memory plus swap: -1 to enable unlimited swap |

docs/reference/commandline/update.md

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,27 @@ Update configuration of one or more containers
99

1010
### Options
1111

12-
| Name | Type | Default | Description |
13-
|:-----------------------|:----------|:--------|:-----------------------------------------------------------------------------|
14-
| `--blkio-weight` | `uint16` | `0` | Block IO (relative weight), between 10 and 1000, or 0 to disable (default 0) |
15-
| `--cpu-period` | `int64` | `0` | Limit CPU CFS (Completely Fair Scheduler) period |
16-
| `--cpu-quota` | `int64` | `0` | Limit CPU CFS (Completely Fair Scheduler) quota |
17-
| `--cpu-rt-period` | `int64` | `0` | Limit the CPU real-time period in microseconds |
18-
| `--cpu-rt-runtime` | `int64` | `0` | Limit the CPU real-time runtime in microseconds |
19-
| `-c`, `--cpu-shares` | `int64` | `0` | CPU shares (relative weight) |
20-
| `--cpus` | `decimal` | | Number of CPUs |
21-
| `--cpuset-cpus` | `string` | | CPUs in which to allow execution (0-3, 0,1) |
22-
| `--cpuset-mems` | `string` | | MEMs in which to allow execution (0-3, 0,1) |
23-
| `-m`, `--memory` | `bytes` | `0` | Memory limit |
24-
| `--memory-reservation` | `bytes` | `0` | Memory soft limit |
25-
| `--memory-swap` | `bytes` | `0` | Swap limit equal to memory plus swap: -1 to enable unlimited swap |
26-
| `--pids-limit` | `int64` | `0` | Tune container pids limit (set -1 for unlimited) |
27-
| `--restart` | `string` | | Restart policy to apply when a container exits |
12+
| Name | Type | Default | Description |
13+
|:------------------------|:----------|:--------|:-----------------------------------------------------------------------------|
14+
| `--blkio-weight` | `uint16` | `0` | Block IO (relative weight), between 10 and 1000, or 0 to disable (default 0) |
15+
| `--blkio-weight-device` | `list` | | Block IO weight (relative device weight) |
16+
| `--cpu-period` | `int64` | `0` | Limit CPU CFS (Completely Fair Scheduler) period |
17+
| `--cpu-quota` | `int64` | `0` | Limit CPU CFS (Completely Fair Scheduler) quota |
18+
| `--cpu-rt-period` | `int64` | `0` | Limit the CPU real-time period in microseconds |
19+
| `--cpu-rt-runtime` | `int64` | `0` | Limit the CPU real-time runtime in microseconds |
20+
| `-c`, `--cpu-shares` | `int64` | `0` | CPU shares (relative weight) |
21+
| `--cpus` | `decimal` | | Number of CPUs |
22+
| `--cpuset-cpus` | `string` | | CPUs in which to allow execution (0-3, 0,1) |
23+
| `--cpuset-mems` | `string` | | MEMs in which to allow execution (0-3, 0,1) |
24+
| `--device-read-bps` | `list` | | Limit read rate (bytes per second) from a device |
25+
| `--device-read-iops` | `list` | | Limit read rate (IO per second) from a device |
26+
| `--device-write-bps` | `list` | | Limit write rate (bytes per second) to a device |
27+
| `--device-write-iops` | `list` | | Limit write rate (IO per second) to a device |
28+
| `-m`, `--memory` | `bytes` | `0` | Memory limit |
29+
| `--memory-reservation` | `bytes` | `0` | Memory soft limit |
30+
| `--memory-swap` | `bytes` | `0` | Swap limit equal to memory plus swap: -1 to enable unlimited swap |
31+
| `--pids-limit` | `int64` | `0` | Tune container pids limit (set -1 for unlimited) |
32+
| `--restart` | `string` | | Restart policy to apply when a container exits |
2833

2934

3035
<!---MARKER_GEN_END-->

0 commit comments

Comments
 (0)