Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docker_container: add "device_cgroup_rules" option #910

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- "docker_container - add support for ``device_cgroup_rules`` (https://github.com/ansible-collections/community.docker/pull/910)."
6 changes: 6 additions & 0 deletions plugins/module_utils/module_container/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -895,6 +895,11 @@ def _compare_platform(option, param_value, container_value):
))
)

OPTION_DEVICE_CGROUP_RULES = (
OptionGroup()
.add_option('device_cgroup_rules', type='list', elements='str')
)

OPTION_DNS_SERVERS = (
OptionGroup()
.add_option('dns_servers', type='list', elements='str')
Expand Down Expand Up @@ -1194,6 +1199,7 @@ def _compare_platform(option, param_value, container_value):
OPTION_DEVICE_READ_IOPS,
OPTION_DEVICE_WRITE_IOPS,
OPTION_DEVICE_REQUESTS,
OPTION_DEVICE_CGROUP_RULES,
OPTION_DNS_SERVERS,
OPTION_DNS_OPTS,
OPTION_DNS_SEARCH_DOMAINS,
Expand Down
3 changes: 3 additions & 0 deletions plugins/module_utils/module_container/docker_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
OPTION_DEVICE_READ_IOPS,
OPTION_DEVICE_WRITE_IOPS,
OPTION_DEVICE_REQUESTS,
OPTION_DEVICE_CGROUP_RULES,
OPTION_DNS_SERVERS,
OPTION_DNS_OPTS,
OPTION_DNS_SEARCH_DOMAINS,
Expand Down Expand Up @@ -1290,6 +1291,8 @@ def _preprocess_container_names(module, client, api_version, value):
OPTION_DEVICE_REQUESTS.add_engine('docker_api', DockerAPIEngine.host_config_value(
'DeviceRequests', min_api_version='1.40', preprocess_value=_preprocess_device_requests))

OPTION_DEVICE_CGROUP_RULES.add_engine('docker_api', DockerAPIEngine.host_config_value('DeviceCgroupRules', min_api_version='1.28'))

OPTION_DNS_SERVERS.add_engine('docker_api', DockerAPIEngine.host_config_value('Dns'))

OPTION_DNS_OPTS.add_engine('docker_api', DockerAPIEngine.host_config_value('DnsOptions'))
Expand Down
6 changes: 6 additions & 0 deletions plugins/modules/docker_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,12 @@
- Driver-specific options.
type: dict
version_added: 0.1.0
device_cgroup_rules:
description:
- List of cgroup rules to apply to the container.
type: list
elements: str
version_added: 3.11.0
dns_opts:
description:
- List of DNS options.
Expand Down
60 changes: 60 additions & 0 deletions tests/integration/targets/docker_container/tasks/tests/options.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1143,6 +1143,66 @@
('API version is ' ~ docker_api_version ~ '.') in device_requests_1.msg and 'Minimum version required is 1.40 ' in device_requests_1.msg
when: docker_api_version is version('1.40', '<')

####################################################################
## device_cgroup_rules ###################################################
####################################################################

- name: device_cgroup_rules
docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
state: started
force_kill: true
device_cgroup_rules:
- "c 42:* rmw"
register: device_cgroup_rules_1
ignore_errors: true

- name: cgroupns_mode (idempotency)
docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
state: started
force_kill: true
device_cgroup_rules:
- "c 42:* rmw"
register: device_cgroup_rules_2
ignore_errors: true

- name: cgroupns_mode (changed)
docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
state: started
force_kill: true
device_cgroup_rules:
- "c 189:* rmw"
register: device_cgroup_rules_3
ignore_errors: true

- name: cleanup
docker_container:
name: "{{ cname }}"
state: absent
force_kill: true
diff: false

- assert:
that:
- device_cgroup_rules_1 is changed
- device_cgroup_rules_2 is not changed
- device_cgroup_rules_3 is changed
when: docker_api_version is version('1.28', '>=')
- assert:
that:
- device_cgroup_rules_1 is failed
- |
('API version is ' ~ docker_api_version ~ '.') in device_cgroup_rules_1.msg and 'Minimum version required is 1.28 ' in device_cgroup_rules_1.msg
when: docker_api_version is version('1.28', '<')

####################################################################
## dns_opts ########################################################
####################################################################
Expand Down
Loading