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

Fixes #19103 - Set Volumes field only for anonymous volumes #19105

Closed
wants to merge 1 commit into from

Conversation

rsanr
Copy link

@rsanr rsanr commented Dec 9, 2016

ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

docker_container

ANSIBLE VERSION
ansible 2.3.0 (devel 7e84bcec30) last updated 2016/12/06 19:10:54 (GMT +000)
  config file = 
  configured module search path = ['/opt/ansible/ansible/library']
SUMMARY

Currently docker_container module sets Volumes field for all volumes passed. This behavior is inconsistent with docker run command. This commit fixes docker_container.py to set Volumes field only when anonymous volumes are passed.

This behavior is also clarified in the following comment:
moby/moby#2949 (comment)

Playbook:

- name: assert state of my container
  docker_container:
    name: mc
    image: "my_container:1.0"
    command: "execute"
    state: started
    restart_policy: always
    exposed_ports:
    - 12345
    network_mode: host
    detach: True
    volumes:
    - "/a/b:/a/b"
    log_driver: "json-file"
    log_options:
      max-size: "10m"
      max-file: "10"

Before:

DEBU[0111] form data: {"AttachStderr":false,"AttachStdin":false,"AttachStdout":false,"Cmd":["execute"],"Env":[],"ExposedPorts":{"12345/tcp":{}},"HostConfig":{"Binds":["/a/b:/a/b:rw"],"LogConfig":{"Config":{"max-file":"10","max-size":"10m"},"Type":"json-file"},"Memory":0,"NetworkMode":"host","ReadonlyRootfs":false,"RestartPolicy":{"MaximumRetryCount":null,"Name":"always"}},"Image":"my_container:1.0","NetworkDisabled":false,"OpenStdin":false,"StdinOnce":false,"Tty":false,"Volumes":{"/a/b":{}}} 

After:

DEBU[0111] form data: {"AttachStderr":false,"AttachStdin":false,"AttachStdout":false,"Cmd":["execute"],"Env":[],"ExposedPorts":{"12345/tcp":{}},"HostConfig":{"Binds":["/a/b:/a/b:rw"],"LogConfig":{"Config":{"max-file":"10","max-size":"10m"},"Type":"json-file"},"Memory":0,"NetworkMode":"host","ReadonlyRootfs":false,"RestartPolicy":{"MaximumRetryCount":null,"Name":"always"}},"Image":"my_container:1.0","NetworkDisabled":false,"OpenStdin":false,"StdinOnce":false,"Tty":false,"Volumes":{}} 

Fixes #19103

…nonymous volumes

Currently docker_container module sets `Volumes` field for all volumes passed.  This behavior is inconsistent with `docker run` command.  This commit fixes `docker_container.py` to set `Volumes` field only when anonymous volumes are passed.

Fixes ansible#4974
@rsanr
Copy link
Author

rsanr commented Dec 9, 2016

Migrated from ansible/ansible-modules-core#5848

@rsanr rsanr changed the title Fixes #4974 - Set Volumes field only for anonymous volumes Fixes #19103 - Set Volumes field only for anonymous volumes Dec 9, 2016
@ansibot ansibot added affects_2.3 This issue/PR affects Ansible v2.3 bugfix_pullrequest module This issue/PR relates to a module. cloud docker labels Dec 13, 2016
@ansibot ansibot added needs_rebase https://docs.ansible.com/ansible/devel/dev_guide/developing_rebasing.html needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. and removed needs_rebase https://docs.ansible.com/ansible/devel/dev_guide/developing_rebasing.html needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. labels Dec 19, 2016
@amcrn
Copy link

amcrn commented Dec 28, 2016

cc @chouseknecht

@ansibot ansibot added needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. and removed needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. labels Jan 3, 2017
@jimi-c jimi-c removed the plugin label Jan 4, 2017
@ansibot ansibot added needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. committer_review In order to be merged, this PR must follow the certified review workflow. and removed needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. labels Jan 5, 2017
@amcrn
Copy link

amcrn commented Jan 20, 2017

Hey @jimi-c , not sure if there's an active maintainer for this. Should we be pinging someone in particular to take a look at this? Thanks!

@amcrn
Copy link

amcrn commented Mar 8, 2017

@abadger @chouseknecht

@amcrn
Copy link

amcrn commented Apr 12, 2017

Hey @jimi-c , congrats on the Ansible 2.3 release! I'm re-ping'ing you on this pull request given your comments on https://news.ycombinator.com/item?id=14100434

Given this has been open for 4 months, and it's not a new module (it's a bug fix), I think the issue that's unique here is that there isn't really an active maintainer for Docker-related Ansible changes. Thoughts? Thanks!

@ansibot ansibot added the support:community This issue/PR relates to code supported by the Ansible community. label Jun 29, 2017
@ansibot
Copy link
Contributor

ansibot commented Jul 19, 2017

@chouseknecht
Copy link
Contributor

@amcrn

Testing this. It seems your change is causing the module to no longer be idempotent. It returns the following differences:

"differences": [
            {
                "expected_volumes": {
                    "container": {
                        "/things": {}
                    },
                    "parameter": {
                        "/projects": {},
                        "/testing": {},
                        "/things": {}
                    }
                }
            }
        ]

Here's my playbook:

- name: Test
  hosts: localhost
  connection: local
  tasks:
    - name: Assert state of my container
      docker_container:
        name: mc
        image: 'centos:7'
        command: ['/bin/sleep', '1d']
        state: started
        restart_policy: always
        exposed_ports:
        - 12345
        network_mode: host
        detach: True
        volumes:
        - /Users/chouseknecht/projects:/projects:rw
        - test-volume:/testing:rw
        - /things
        log_driver: 'json-file'
        log_options:
          max-size: '10m'
          max-file: '10'
        debug: yes

@chouseknecht
Copy link
Contributor

@amcrn

I think the _get_expected_volumes method at line 1552 should look something like this:

def _get_expected_volumes(self, image):
    self.log('_get_expected_volumes')
    expected_vols = dict()
    if image and image['ContainerConfig'].get('Volumes'):
        expected_vols.update(image['ContainerConfig'].get('Volumes'))

    if self.parameters.volumes:
        for vol in self.parameters.volumes:
            parts = vol.split(':')
            if len(parts) == 1:
                new_vol = dict()
                new_vol[vol] = dict()
                expected_vols.update(new_vol)

    if not expected_vols:
        expected_vols = None
    self.log("expected_volumes:")
    self.log(expected_vols, pretty_print=True)
    return expected_vols

@chouseknecht
Copy link
Contributor

needs_revision

@ansibot ansibot added needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. and removed community_review In order to be merged, this PR must follow the community review workflow. labels Aug 16, 2017
@ansibot ansibot added the new_contributor This PR is the first contribution by a new community member. label Oct 18, 2017
@ansibot ansibot removed the new_contributor This PR is the first contribution by a new community member. label Nov 3, 2017
@ansibot ansibot added the new_contributor This PR is the first contribution by a new community member. label Jan 22, 2018
@ansibot ansibot added bug This issue/PR relates to a bug. and removed bugfix_pull_request labels Mar 2, 2018
@ansibot ansibot added support:core This issue/PR relates to code supported by the Ansible Engineering Team. support:community This issue/PR relates to code supported by the Ansible community. and removed support:community This issue/PR relates to code supported by the Ansible community. support:core This issue/PR relates to code supported by the Ansible Engineering Team. labels Jun 6, 2018
@ansibot
Copy link
Contributor

ansibot commented Aug 25, 2018

@ansibot ansibot added the needs_rebase https://docs.ansible.com/ansible/devel/dev_guide/developing_rebasing.html label Oct 12, 2018
@ansibot
Copy link
Contributor

ansibot commented Nov 2, 2018

@felixfontein
Copy link
Contributor

@rsanr are you still around? Can you rebase this PR?

@gundalow
Copy link
Contributor

gundalow commented Dec 4, 2018

Hi,
This PR seems to have gotten stuck, so we are going to close it. We like to include community contributions, so this is a difficult call for us. Here's why we're closing this one:

  • Given the discussion in Docker Agenda/Task list community#408 (comment)
  • It was created from an old version of the code
  • We want to clear out the backlog so it's easier to find bug fixes
  • There haven't been any comments or other activity in a long time

If you're the PR author, and you want to start the conversation back up, please:

  • reopen the PR and
  • rebase the branch

If you're a community member, and you want to see this change merged, please:

  • Create a new PR and
  • Reference this author in the git commit & PR and
  • Reference this PR in the new PR

If you've like to help with the Docker modules please comment on the Docker Agenda/Task List

How to rebase a branch: https://docs.ansible.com/ansible/latest/dev_guide/developing_rebasing.html
How to communicate with the Ansible community: https://docs.ansible.com/ansible/devel/community/communication.html
How to contribute to Ansible: https://docs.ansible.com/ansible/devel/community/index.html

needs_info

@ansibot ansibot added the needs_info This issue requires further information. Please answer any outstanding questions. label Dec 4, 2018
@ansibot
Copy link
Contributor

ansibot commented Dec 12, 2018

@ansibot
Copy link
Contributor

ansibot commented Jan 9, 2019

@rsanr This pullrequest is waiting for your response. Please respond or the pullrequest will be closed.

click here for bot help

@gundalow gundalow closed this Jan 14, 2019
@ansible ansible locked and limited conversation to collaborators Jul 22, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.3 This issue/PR affects Ansible v2.3 bug This issue/PR relates to a bug. cloud docker module This issue/PR relates to a module. needs_info This issue requires further information. Please answer any outstanding questions. needs_rebase https://docs.ansible.com/ansible/devel/dev_guide/developing_rebasing.html needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. new_contributor This PR is the first contribution by a new community member. stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. support:community This issue/PR relates to code supported by the Ansible community.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

docker_container sends volume to docker API erroneously
8 participants