mirror of
https://github.com/containers/ansible-podman-collections.git
synced 2026-02-04 07:11:49 +00:00
Add options for resource limits to podman_pod (#635)
* Add resource limiting paramters for podman_pod Signed-off-by: nishipy <goodisonev4@gmail.com> * Fix doc-elements-mismatch Signed-off-by: nishipy <goodisonev4@gmail.com> * Update tests for podman_pod Signed-off-by: nishipy <goodisonev4@gmail.com> --------- Signed-off-by: nishipy <goodisonev4@gmail.com>
This commit is contained in:
parent
e025e928b2
commit
2a8aaf4522
4 changed files with 128 additions and 0 deletions
|
|
@ -27,10 +27,15 @@ ARGUMENTS_SPEC_POD = dict(
|
|||
recreate=dict(type='bool', default=False),
|
||||
add_host=dict(type='list', required=False, elements='str'),
|
||||
cgroup_parent=dict(type='str', required=False),
|
||||
blkio_weight=dict(type='str', required=False),
|
||||
blkio_weight_device=dict(type='list', elements='str', required=False),
|
||||
cpus=dict(type='str', required=False),
|
||||
cpuset_cpus=dict(type='str', required=False),
|
||||
cpuset_mems=dict(type='str', required=False),
|
||||
cpu_shares=dict(type='str', required=False),
|
||||
device=dict(type='list', elements='str', required=False),
|
||||
device_read_bps=dict(type='list', elements='str', required=False),
|
||||
device_write_bps=dict(type='list', elements='str', required=False),
|
||||
dns=dict(type='list', elements='str', required=False),
|
||||
dns_opt=dict(type='list', elements='str', required=False),
|
||||
dns_search=dict(type='list', elements='str', required=False),
|
||||
|
|
@ -46,6 +51,8 @@ ARGUMENTS_SPEC_POD = dict(
|
|||
label=dict(type='dict', required=False),
|
||||
label_file=dict(type='str', required=False),
|
||||
mac_address=dict(type='str', required=False),
|
||||
memory=dict(type='str', required=False),
|
||||
memory_swap=dict(type='str', required=False),
|
||||
name=dict(type='str', required=True),
|
||||
network=dict(type='list', elements='str', required=False),
|
||||
network_alias=dict(type='list', elements='str', required=False,
|
||||
|
|
@ -135,25 +142,52 @@ class PodmanPodModuleParams:
|
|||
c += ['--add-host', g]
|
||||
return c
|
||||
|
||||
def addparam_blkio_weight(self, c):
|
||||
self.check_version('--blkio-weight', minv='4.3.0')
|
||||
return c + ['--blkio-weight', self.params['blkio_weight']]
|
||||
|
||||
def addparam_blkio_weight_device(self, c):
|
||||
self.check_version('--blkio-weight-device', minv='4.3.0')
|
||||
for dev in self.params['blkio_weight_device']:
|
||||
c += ['--blkio-weight-device', dev]
|
||||
return c
|
||||
|
||||
def addparam_cgroup_parent(self, c):
|
||||
return c + ['--cgroup-parent', self.params['cgroup_parent']]
|
||||
|
||||
def addparam_cpus(self, c):
|
||||
self.check_version('--cpus', minv='4.2.0')
|
||||
return c + ['--cpus', self.params['cpus']]
|
||||
|
||||
def addparam_cpuset_cpus(self, c):
|
||||
self.check_version('--cpus', minv='4.2.0')
|
||||
return c + ['--cpuset-cpus', self.params['cpuset_cpus']]
|
||||
|
||||
def addparam_cpuset_mems(self, c):
|
||||
self.check_version('--cpuset-mems', minv='4.3.0')
|
||||
return c + ['--cpuset-mems', self.params['cpuset_mems']]
|
||||
|
||||
def addparam_cpu_shares(self, c):
|
||||
self.check_version('--cpu-shares', minv='4.3.0')
|
||||
return c + ['--cpu-shares', self.params['cpu_shares']]
|
||||
|
||||
def addparam_device(self, c):
|
||||
for dev in self.params['device']:
|
||||
c += ['--device', dev]
|
||||
return c
|
||||
|
||||
def addparam_device_read_bps(self, c):
|
||||
self.check_version('--device-read-bps', minv='4.3.0')
|
||||
for dev in self.params['device_read_bps']:
|
||||
c += ['--device-read-bps', dev]
|
||||
return c
|
||||
|
||||
def addparam_device_write_bps(self, c):
|
||||
self.check_version('--device-write-bps', minv='4.3.0')
|
||||
for dev in self.params['device_write_bps']:
|
||||
c += ['--device-write-bps', dev]
|
||||
return c
|
||||
|
||||
def addparam_dns(self, c):
|
||||
for g in self.params['dns']:
|
||||
c += ['--dns', g]
|
||||
|
|
@ -209,6 +243,14 @@ class PodmanPodModuleParams:
|
|||
def addparam_mac_address(self, c):
|
||||
return c + ['--mac-address', self.params['mac_address']]
|
||||
|
||||
def addparam_memory(self, c):
|
||||
self.check_version('--memory', minv='4.2.0')
|
||||
return c + ['--memory', self.params['memory']]
|
||||
|
||||
def addparam_memory_swap(self, c):
|
||||
self.check_version('--memory-swap', minv='4.3.0')
|
||||
return c + ['--memory-swap', self.params['memory_swap']]
|
||||
|
||||
def addparam_name(self, c):
|
||||
return c + ['--name', self.params['name']]
|
||||
|
||||
|
|
|
|||
|
|
@ -42,6 +42,18 @@ options:
|
|||
type: list
|
||||
elements: str
|
||||
required: false
|
||||
blkio_weight:
|
||||
description:
|
||||
- Block IO relative weight. The weight is a value between 10 and 1000.
|
||||
- This option is not supported on cgroups V1 rootless systems.
|
||||
type: str
|
||||
required: false
|
||||
blkio_weight_device:
|
||||
description:
|
||||
- Block IO relative device weight.
|
||||
type: list
|
||||
elements: str
|
||||
required: false
|
||||
cgroup_parent:
|
||||
description:
|
||||
- Path to cgroups under which the cgroup for the pod will be created. If the path
|
||||
|
|
@ -61,6 +73,16 @@ options:
|
|||
Unlike `cpus` this is of type string and parsed as a list of numbers. Format is 0-3,0,1
|
||||
required: false
|
||||
type: str
|
||||
cpuset_mems:
|
||||
description:
|
||||
- Memory nodes in which to allow execution (0-3, 0,1). Only effective on NUMA systems.
|
||||
required: false
|
||||
type: str
|
||||
cpu_shares:
|
||||
description:
|
||||
- CPU shares (relative weight).
|
||||
required: false
|
||||
type: str
|
||||
device:
|
||||
description:
|
||||
- Add a host device to the pod. Optional permissions parameter can be used to specify
|
||||
|
|
@ -74,6 +96,12 @@ options:
|
|||
elements: str
|
||||
required: false
|
||||
type: list
|
||||
device_write_bps:
|
||||
description:
|
||||
- Limit write rate (in bytes per second) to a device.
|
||||
type: list
|
||||
elements: str
|
||||
required: false
|
||||
dns:
|
||||
description:
|
||||
- Set custom DNS servers in the /etc/resolv.conf file that will be shared between
|
||||
|
|
@ -254,6 +282,18 @@ options:
|
|||
- Set a static MAC address for the pod's shared network.
|
||||
type: str
|
||||
required: false
|
||||
memory:
|
||||
description:
|
||||
- Set memory limit.
|
||||
- A unit can be b (bytes), k (kibibytes), m (mebibytes), or g (gibibytes).
|
||||
type: str
|
||||
required: false
|
||||
memory_swap:
|
||||
description:
|
||||
- Set limit value equal to memory plus swap.
|
||||
- A unit can be b (bytes), k (kibibytes), m (mebibytes), or g (gibibytes).
|
||||
type: str
|
||||
required: false
|
||||
name:
|
||||
description:
|
||||
- Assign a name to the pod.
|
||||
|
|
|
|||
|
|
@ -925,3 +925,11 @@
|
|||
args:
|
||||
apply:
|
||||
become: true
|
||||
|
||||
- name: Test podman_pod for limiting resources
|
||||
include_tasks: resource-limit.yml
|
||||
vars:
|
||||
ansible_python_interpreter: "/usr/bin/python3"
|
||||
args:
|
||||
apply:
|
||||
become: true
|
||||
|
|
|
|||
|
|
@ -0,0 +1,38 @@
|
|||
- name: Test podman_pod for limiting resources
|
||||
block:
|
||||
|
||||
- name: Set variables for limiting resources
|
||||
set_fact:
|
||||
limit:
|
||||
blkio_weight: 123
|
||||
cpuset_mems: '0-1'
|
||||
cpu_shares: 1024
|
||||
device_write_bps: ['/dev/zero:1048576']
|
||||
|
||||
- name: Create pod for limiting resources
|
||||
containers.podman.podman_pod:
|
||||
name: limited-pod
|
||||
state: created
|
||||
blkio_weight: "{{ limit.blkio_weight }}"
|
||||
cpuset_mems: "{{ limit.cpuset_mems }}"
|
||||
cpu_shares: "{{ limit.cpu_shares }}"
|
||||
device_write_bps: "{{ limit.device_write_bps }}"
|
||||
|
||||
- name: Get information on pod for limiting resources
|
||||
containers.podman.podman_pod_info:
|
||||
name: limited-pod
|
||||
register: pod_info
|
||||
|
||||
- name: Check if the result is as expected
|
||||
assert:
|
||||
that:
|
||||
- item.blkio_weight == limit.blkio_weight
|
||||
- item.cpuset_mems == limit.cpuset_mems
|
||||
- item.cpu_shares == limit.cpu_shares
|
||||
with_items: "{{ pod_info.pods }}"
|
||||
|
||||
always:
|
||||
- name: Cleanup
|
||||
containers.podman.podman_pod:
|
||||
name: limited-pod
|
||||
state: absent
|
||||
Loading…
Add table
Add a link
Reference in a new issue