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_node: Docker Swarm node operations module #50584

Merged
merged 26 commits into from
Feb 4, 2019
Merged

docker_node: Docker Swarm node operations module #50584

merged 26 commits into from
Feb 4, 2019

Conversation

WojciechowskiPiotr
Copy link
Contributor

SUMMARY

New module to handle Docker Swarm node operations. It must be executed on Swarm manager node and allows changing the node availability, role, and labels (fixes #49547). Part of the commit is also a shared library for all common methods for other Swarm modules.

ISSUE TYPE
  • New Module Pull Request
COMPONENT NAME

docker_node

ADDITIONAL INFORMATION

This PR is a copy of #50428, required due to the wrong branch in original PR. The open discussion in old PR is on module name and where put some inspect features, either in docker_node or docker_node_facts (#50571). The upcoming docker_swarm_facts will use the shared code from this PR.
This module is equivalent of docker node CLI command allowing now changing the node availability and role as well as applying or removing the labels from the node. It must be executed on Swarm manager node otherwise exception is raised.
When RP is merged into ansible/devel then we can update docker_swarm module so it uses the shared methods from module_utils/docker_swarm instead of own local wherever it is possible.

@ansibot
Copy link
Contributor

ansibot commented Jan 6, 2019

@ansibot ansibot added affects_2.8 This issue/PR affects Ansible v2.8 cloud community_review In order to be merged, this PR must follow the community review workflow. docker module This issue/PR relates to a module. needs_triage Needs a first human triage before being processed. new_contributor This PR is the first contribution by a new community member. new_module This PR includes a new module. new_plugin This PR includes a new plugin. support:community This issue/PR relates to code supported by the Ansible community. labels Jan 6, 2019
@WojciechowskiPiotr
Copy link
Contributor Author

ansible/community#408

@ansibot
Copy link
Contributor

ansibot commented Jan 6, 2019

The test ansible-test sanity --test validate-modules [explain] failed with 2 errors:

lib/ansible/modules/cloud/docker/docker_node.py:0:0: E322 "force" is listed in the argument_spec, but not documented in the module
lib/ansible/modules/cloud/docker/docker_node.py:0:0: E325 argument_spec for "force" defines type="bool" but documentation does not

click here for bot help

@ansibot ansibot added ci_verified Changes made in this PR are causing tests to fail. 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. ci_verified Changes made in this PR are causing tests to fail. labels Jan 6, 2019
@ansibot
Copy link
Contributor

ansibot commented Jan 6, 2019

@DBendit @agronholm @akshay196 @cove @danihodovic @dariko @dusdanig @joshuaconner @jwitko @kassiansun @keitwb @olsaki @softzilla @tbouvet @ushuz @zfil

As a maintainer of a module in the same namespace this new module has been submitted to, your vote counts for shipits. Please review this module and add shipit if you would like to see it merged.

click here for bot help

@ansibot ansibot added community_review In order to be merged, this PR must follow the community review workflow. and removed needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. labels Jan 6, 2019
@WojciechowskiPiotr
Copy link
Contributor Author

ready_for_review

Would be nice to get this PR reviewed and hopefully merged in parallel to #50571 as those are not in conflict to each other

@felixfontein
Copy link
Contributor

I think it makes more sense to first get #50571 merged, and then modify docker_node_facts to use the new module_utils as well (in this PR) -- as well as discuss whether the list mode should be moved to docker_node_facts (I'm kind of in favor of this).

Anyway, to get something merged, some more reviews are needed. Anyone? :)

@ansibot ansibot removed the needs_triage Needs a first human triage before being processed. label Jan 8, 2019
@felixfontein
Copy link
Contributor

Now that #50571 has been merged, can you rebase this PR against devel and make docker_node_facts use the new module_utils as well?

@ansibot ansibot removed the new_contributor This PR is the first contribution by a new community member. label Jan 8, 2019
@WojciechowskiPiotr
Copy link
Contributor Author

The change in docker_node_facts is purely cosmetic, already committed in my repo, will be part of next push to this PR.

As @tbouvet agreed with me in #50428, we will use the docker_node as the module name. That would put changing the name of docker_service into docker_compose in more flavor so we can later rename docker_swarm_service into docker_service. It will take six releases, but I think it is good for modules convention sanity in cloud/docker.

As for the list as I said before in #50428 only the docker_image_facts does not require name parameter, and it accepts a list of strings. Other modules require a single string as name. The CLI commands aways allows a list of objects to inspect (empty list not allowed) and provides the ls action to just list objects with basic information. I like the approach where the _facts module is like an inspect and non-_facts have an implementation of ls command.

I think the options to consider are:

  1. Leave docker_node_facts as it is, so it returns information on a single node, adjusts the docker_image_facts to this approach, create the ls command implementation in an operational module, it may cover the filters as well
  • Pros: Easy docker_*_facts modules in code, the single way you can use them in playbooks
  • Cons: Playbook developer need to know the name of the object to inspect every time, so there should be some kind of implementation of CLI command docker [network,image,container,etc] ls in each module to give a list of objects
  • Consistency with CLI - partial
  1. Let parameter name optional in all docker_*_facts modules and accept the list as a parameter, if name not provided then return information about all objects.
  • Pros: Easy way to get information on every object, specific objects or a single object, shouldn't be hard to implement. May include filters too.
  • Cons: If called without a name parameter it returns lots of information, and later the playbook code may not be so clear due to big multi-levels structures user have to parse. If it covers the filters as well, it will increase the complexity of the facts modules
  • Consistency with CLI - partial
  1. Let parameter name optional in all docker_*_facts modules and accept the list as a parameter, if name not provided then return information about all objects but also add the ls command output to the operation modules.
  • Pros: Easy way to get information on every object, specific objects or a single object, shouldn't be hard to implement. The _facts will not allow additional filtering, this feature will be implemented as part of the non-_facts module.
  • Cons: If called without a name parameter it returns lots of information and later the playbook code may not be so clear due to big multi-levels structures user have to parse. If it covers the filters as well, it will increase the complexity of the facts modules
  • Consistency with CLI - full
  1. Let parameter name required as list of strings and implement the ls method in each non-facts module. This way facts modules will return the full information on at least single object, while ls command implementation returns limited information and can cover filters
  • Pros: Playbook developer will call the facts module to inspect known objects, because it will be a list it will be possible to get information in one task, the ls command implementation in each module may return the structure identical to the CLI, so limited in number of information, it can also cover the filters
  • Cons: Need a ls command implementation in each module
  • Consistency with CLI - full

One more thing worth noticing is the difference between Swarm and non-Swarm hosts. The non-Swarm modules (image, container, volume, network) you need to run on every host in inventory while swarm modules (with some exceptions of node operations not proposed yet in this PR) have to be run on hosts acting as Swarm Managers. This role is dynamic by its nature and promoting/demoting nodes shouldn't be unusual operation to keep a quorum in the cluster. Also, each manager will return same information about the cluster and its components (node, config, secret, other swarm modules) so it will be a waste of time and resources to run facts module on each node from inventory every time.

With the approach in point 4) the playbook developer may fetch the nodes lists and roles from docker_node using state: list to get a simple structure with just 6 or 7 attributes as in docker node ls command output, he may use additional filters as well. It is easy to use the list if playbook runs on localhost and uses the API. With SSH and hosts in inventory dynamic states in Swarm are not so easy to handle when you try to minimize number of tasks in playbook, time to run it and resources it will require.

To sum this up - I like the consistency between the modules and I like the idea that modules are working in similar way as CLI because most people will first know the CLI then will try automate the tasks. My preference is option 4 in this case, but I am happy to go with approach most of the docker modules maintainers here will recommend as preferred.

@felixfontein
Copy link
Contributor

There are a few things to consider:

  1. Normal modules should do something (except for check mode), and _facts modules should query stuff without modifying. Having data querying functionality in normal modules is discouraged. I'm definitely against adding a list/ls method to any non-_facts module. If there is list/ls support, it should be handled by the _facts module (or by a new module).
  2. Ansible should not mirror exactly what can be done via CLI or API, but what is useful. Is there a concrete need for getting a list of containers, images, ...? I can see that it makes sense for Swarm nodes, but I doubt it for other objects.

Also, for offering lists in a _facts module, I would prefer having a choices option results with default value single, and alternative choice list (names open for bikeshedding as usual ;) ). For single, name would be required; for list, it would not be (and will be ignored).

@ansibot ansibot removed needs_rebase https://docs.ansible.com/ansible/devel/dev_guide/developing_rebasing.html support:core This issue/PR relates to code supported by the Ansible Engineering Team. labels Feb 2, 2019
@ansibot ansibot added the support:core This issue/PR relates to code supported by the Ansible Engineering Team. label Feb 2, 2019
@WojciechowskiPiotr
Copy link
Contributor Author

@felixfontein no problem :) Rebased and waiting for review and merging now

@ansibot ansibot added core_review In order to be merged, this PR must follow the core review workflow. and removed needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. labels Feb 2, 2019
@@ -584,6 +584,7 @@ files:
maintainers: $team_windows_core
support: core
$module_utils/docker_common.py: *docker
$module_utils/docker_swarm.py: *docker
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for remembering to update this, if you replace the above line with:

  $module_utils/docker: *docker

We can future proof this.

extends_documentation_fragment:
- docker
requirements:
- "python >= 2.6"
Copy link
Contributor

Choose a reason for hiding this comment

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

Ansible 2.8 only supports Python 2.6+ on the remote, so this line isn't needed.

- "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/)
(see L(here,https://github.com/docker/docker-py/issues/1310) for details).
For Python 2.6, C(docker-py) must be used. Otherwise, it is recommended to
Copy link
Contributor

Choose a reason for hiding this comment

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

Ansible 2.8 only supports Python 2.6+ on the remote, so this could be reworded.

Copy link
Contributor

Choose a reason for hiding this comment

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

Let's keep this for now, and let's change all of these in a subsequent PR for all docker_* modules, so that all modules get the same text.

Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed, follow up PR is a good idea.

'''

RETURN = '''
node_facts:
Copy link
Contributor

Choose a reason for hiding this comment

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

If we know the structure of the dict then adding some of those details would be good, see the example at https://docs.ansible.com/ansible/latest/dev_guide/developing_modules_documenting.html#return-block

Copy link
Contributor

Choose a reason for hiding this comment

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

We only know a subset of the structure, as newer API versions will add more data here. For other docker_* modules, we "solved" this by adding sample: with an excerpt of a result containing the most interesting things. No idea what's the best approach here.

(Another thing is that depending on the data returned, this can be really complex. For docker_container, the returned inspect result is a huge dict; documenting everything would be a big task.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe a direct link to the latest Docker API documentation instead if sample: and information to check the API documentation for the specific API version on remote?

Copy link
Contributor

Choose a reason for hiding this comment

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

That would be fine, too. Maybe also have sample: as well, so people get an idea what they will get.

@gundalow gundalow merged commit daf1cfb into ansible:devel Feb 4, 2019
@gundalow
Copy link
Contributor

gundalow commented Feb 4, 2019

@WojciechowskiPiotr Thank you for this PR
@felixfontein Thank you for the review

@WojciechowskiPiotr WojciechowskiPiotr deleted the devel-docker_node branch February 4, 2019 13:26
@felixfontein
Copy link
Contributor

@WojciechowskiPiotr thanks for the PR! You will notice that you'll get CC'ed in all docker issues/PRs; ansibot will take some time to add you to all existing issues/PRs.
@tbouvet thanks for your feedback!
@gundalow thanks for reviewing and merging!

I've opened a first follow-up PR in #51700 with some things discussed with @gundalow.

@felixfontein
Copy link
Contributor

felixfontein commented Feb 4, 2019

More stuff for follow-up PRs (before I forget about this):

@WojciechowskiPiotr anything else? :)

@WojciechowskiPiotr
Copy link
Contributor Author

@felixfontein docker_swarm_facts from #50622

@felixfontein
Copy link
Contributor

@WojciechowskiPiotr that already has a PR (and is in the tab to the left of this PR in my Ansible docker tab collection ;-) ), so I didn't mention it.

@dagwieers dagwieers added the botmeta This PR modifies the BOTMETA.yml and this requires special attention! label Feb 21, 2019
@ansible ansible locked and limited conversation to collaborators Jul 25, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.8 This issue/PR affects Ansible v2.8 botmeta This PR modifies the BOTMETA.yml and this requires special attention! c:inventory/contrib_script cloud core_review In order to be merged, this PR must follow the core review workflow. docker docs This issue/PR relates to or includes documentation. docsite This issue/PR relates to the documentation website. inventory Inventory category module This issue/PR relates to a module. new_module This PR includes a new module. new_plugin This PR includes a new plugin. 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. test This PR relates to tests.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

docker_swarm: labels not applied
6 participants