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: cgroup_parent #59

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
2 changes: 2 additions & 0 deletions changelogs/fragments/59-docker_container-cgroup-parent.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- "docker_container - support specifying ``cgroup_parent`` (https://github.com/ansible-collections/community.docker/issues/6, https://github.com/ansible-collections/community.docker/pull/59)."
6 changes: 6 additions & 0 deletions plugins/doc_fragments/docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ class ModuleDocFragment(object):

DOCKER_PY_1_DOCUMENTATION = r'''
options: {}
notes:
- This module uses the L(Docker SDK for Python,https://docker-py.readthedocs.io/en/stable/) to
communicate with the Docker daemon.
requirements:
- "Docker SDK for Python: Please note that the L(docker-py,https://pypi.org/project/docker-py/)
Python module has been superseded by L(docker,https://pypi.org/project/docker/)
Expand All @@ -127,6 +130,9 @@ class ModuleDocFragment(object):

DOCKER_PY_2_DOCUMENTATION = r'''
options: {}
notes:
- This module uses the L(Docker SDK for Python,https://docker-py.readthedocs.io/en/stable/) to
communicate with the Docker daemon.
requirements:
- "Python >= 2.7"
- "Docker SDK for Python: Please note that the L(docker-py,https://pypi.org/project/docker-py/)
Expand Down
8 changes: 8 additions & 0 deletions plugins/modules/docker_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@
- List of capabilities to drop from the container.
type: list
elements: str
cgroup_parent:
description:
- Specify the parent cgroup for the container.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see in the tests you added alongside you pass an empty string, what does it do? perhaps it should be added this is supported and the behaviour ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, the test doesn't really do anything :) The problem with testing this properly in integration tests is that you need to know which cgroups are around on the systems you run the tests on, which is pretty much impossible since they can run on any system (if you run ansible-test integration --docker xxx locally, your own docker daemon will be used, and thus it depends on your local system). That's why I put in an empty string, which by the module is treated as "value specified by user", but by the Docker daemon as "no value supplied" resp. "user does not care whether/which cgroup parent to use". This test mainly makes sure that all related code is run through at least once.

type: str
version_added: 1.1.0
cleanup:
description:
- Use with I(detach=false) to remove the container after successful execution.
Expand Down Expand Up @@ -1589,6 +1594,7 @@ def _host_config(self):
publish_all_ports='publish_all_ports',
links='links',
privileged='privileged',
cgroup_parent='cgroup_parent',
dns='dns_servers',
dns_opt='dns_opts',
dns_search='dns_search_domains',
Expand Down Expand Up @@ -2175,6 +2181,7 @@ def has_different_configuration(self, image):
interactive=config.get('OpenStdin'),
capabilities=host_config.get('CapAdd'),
cap_drop=host_config.get('CapDrop'),
cgroup_parent=host_config.get('CgroupParent'),
expected_devices=host_config.get('Devices'),
dns_servers=host_config.get('Dns'),
dns_opts=host_config.get('DnsOptions'),
Expand Down Expand Up @@ -3371,6 +3378,7 @@ def main():
blkio_weight=dict(type='int'),
capabilities=dict(type='list', elements='str'),
cap_drop=dict(type='list', elements='str'),
cgroup_parent=dict(type='str'),
cleanup=dict(type='bool', default=False),
command=dict(type='raw'),
comparisons=dict(type='dict'),
Expand Down
34 changes: 34 additions & 0 deletions tests/integration/targets/docker_container/tasks/tests/options.yml
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,40 @@
- capabilities_3 is not changed
- capabilities_4 is changed

####################################################################
## cgroup_parent ###################################################
####################################################################

- name: cgroup_parent
docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
state: started
cgroup_parent: ''
register: cgroup_parent_1

- name: cgroup_parent (idempotency)
docker_container:
image: "{{ docker_test_image_alpine }}"
command: '/bin/sh -c "sleep 10m"'
name: "{{ cname }}"
state: started
cgroup_parent: ''
register: cgroup_parent_2

- name: cleanup
docker_container:
name: "{{ cname }}"
state: absent
force_kill: yes
diff: no

- assert:
that:
- cgroup_parent_1 is changed
- cgroup_parent_2 is not changed

####################################################################
## command #########################################################
####################################################################
Expand Down