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

Refactor of consul modules #7826

Merged
merged 19 commits into from
Jan 21, 2024

Conversation

apollo13
Copy link
Contributor

SUMMARY

Refactors common code from consul_modules into module_utils

ISSUE TYPE
  • Refactoring Pull Request
COMPONENT NAME

consul

@ansibullbot

This comment was marked as outdated.

@ansibullbot
Copy link
Collaborator

@ansibullbot ansibullbot added docs_fragments docs_fragments plugin (shared docs) module module module_utils module_utils needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR plugins plugin (any type) labels Jan 12, 2024
@apollo13
Copy link
Contributor Author

Hopefully fixed the ansible-test issues. I noticed that consul_acl doesn't have any tests, so before merging this I should probably add those as well to ensure the refactor didn't break anything.

@ansibullbot

This comment was marked as outdated.

@felixfontein felixfontein added check-before-release PR will be looked at again shortly before release and merged if possible. backport-8 Automatically create a backport for the stable-8 branch labels Jan 12, 2024
Copy link
Collaborator

@felixfontein felixfontein left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution!

Two first comments:

plugins/modules/consul.py Outdated Show resolved Hide resolved
description:
- The protocol scheme on which the consul agent is running.
default: http
choices: [ http, https ]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Adding the choices here is a breaking change. (Or was it absolutely impossible to specify anything else than http and https as the scheme before?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wouldn't know what else one could specify. But I'll happily remove it if you think it is to dangerous.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess it's better to not have choices here then. You could mention both choices in the description if you want, if you want to make sure users know what they can specify here (that the second choices is https is probably not completely obvious to everyone).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is a weird setting anyways, in the long run it would probably make more sense to deprecate this and have a simple ssl on/off toggle.

Copy link
Collaborator

Choose a reason for hiding this comment

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

If this change remains, this PR cannot be merged because it contains a breaking change.

@ansibullbot ansibullbot removed the needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR label Jan 12, 2024
@ansibullbot ansibullbot added needs_ci This PR requires CI testing to be performed. Please close and re-open this PR to trigger CI needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR labels Jan 13, 2024
@apollo13
Copy link
Contributor Author

@felixfontein I think this is review ready. The rewrite does not cover consul_kv or consul_acl. The latter doesn't work in recent consul anymore and should be dropped in favor of a new consul_token in addition to the existing consul_policy. This is because it uses the legacy API: https://developer.hashicorp.com/consul/api-docs/v1.14.x/acl/legacy

As for consul_kv -- it would require a full rewrite maybe without the python-consul module which hasn't seen a release since 2018 or so.

While on it I dropped the dependency on requests as well, not really much of a reason to require it.

For me this is basically foundational work to be able to add binding rules and acl auth methods via later commits. But I'd love to get this reviewed and merged before because it improves stuff independently.

@ansibullbot ansibullbot removed the needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR label Jan 13, 2024
Copy link
Collaborator

@felixfontein felixfontein left a comment

Choose a reason for hiding this comment

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

I haven't yet checked the module code changes.

Please add a changelog fragment.

plugins/module_utils/consul.py Show resolved Hide resolved
plugins/module_utils/consul.py Show resolved Hide resolved
plugins/modules/consul_session.py Outdated Show resolved Hide resolved
@apollo13
Copy link
Contributor Author

apollo13 commented Jan 17, 2024 via email

@apollo13 apollo13 force-pushed the consul-refactor branch 3 times, most recently from 854c2c8 to 0d738bd Compare January 17, 2024 16:07
@ansibullbot ansibullbot added needs_ci This PR requires CI testing to be performed. Please close and re-open this PR to trigger CI needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR labels Jan 17, 2024
@apollo13
Copy link
Contributor Author

I think I managed to address all comments, let me know if I missed something, thanks!

@ansibullbot ansibullbot removed needs_ci This PR requires CI testing to be performed. Please close and re-open this PR to trigger CI needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR labels Jan 17, 2024
Copy link
Collaborator

@felixfontein felixfontein left a comment

Choose a reason for hiding this comment

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

Looks good to me. Do you want to do more changes, or should I merge this?

@apollo13
Copy link
Contributor Author

As far as the refactoring goes, I think I am done with it. If possible I would like to mark ConsulModule private for now till it's API is stable -- for that I would move it into _consul.py and mark document it as private?

@felixfontein
Copy link
Collaborator

I would simply rename ConsulModule to _ConsulModule and add a comment that it is a private API for now and breaking changes can appear at any time, even in bugfix releases.

That should be clear enough :)

@apollo13
Copy link
Contributor Author

Okay, I have marked it private and added a note to the doc string. Let me know if there is anything else needed. I will be working on the new modules now.

@@ -135,22 +103,11 @@
"""

from ansible.module_utils.basic import AnsibleModule
from ansible_collections.community.general.plugins.module_utils.consul import (
_ConsulModule, auth_argument_spec)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Here you could also do

Suggested change
_ConsulModule, auth_argument_spec)
_ConsulModule as ConsulModule, auth_argument_spec)

to avoid propagating the rename to the modules, but let's keep it at is now :)

@felixfontein felixfontein merged commit 44679e7 into ansible-collections:main Jan 21, 2024
120 of 121 checks passed
Copy link

patchback bot commented Jan 21, 2024

Backport to stable-8: 💚 backport PR created

✅ Backport PR branch: patchback/backports/stable-8/44679e71a23c37bfe9a047bd4243666d4b12c459/pr-7826

Backported as #7877

🤖 @patchback
I'm built with octomachinery and
my source is open — https://github.com/sanitizers/patchback-github-app.

patchback bot pushed a commit that referenced this pull request Jan 21, 2024
* Extract common functionality.

* Refactor duplicated code into module_utils.

* Fixed ansible-test issues.

* Address review comments.

* Revert changes to consul_acl.

It uses deprecated APIs disabled since Consul 1.11 (which is EOL), don't
bother updating the module anymore.

* Remove unused code.

* Merge token into default doc fragment.

* JSON all the way down.

* extract validation tests into custom file and prep for requests removal.

* Removed dependency on requests.

* Initial test for consul_kv.

* fixup license headers.

* Revert changes to consul.py since it utilizes python-consul.

* Disable the lookup test for now.

* Fix python 2.7 support.

* Address review comments.

* Address review comments.

* Addec changelog fragment.

* Mark ConsulModule as private.

(cherry picked from commit 44679e7)
@felixfontein
Copy link
Collaborator

@apollo13 thanks a lot for your contribution!

@felixfontein felixfontein removed the check-before-release PR will be looked at again shortly before release and merged if possible. label Jan 21, 2024
felixfontein pushed a commit that referenced this pull request Jan 21, 2024
)

Refactor of consul modules (#7826)

* Extract common functionality.

* Refactor duplicated code into module_utils.

* Fixed ansible-test issues.

* Address review comments.

* Revert changes to consul_acl.

It uses deprecated APIs disabled since Consul 1.11 (which is EOL), don't
bother updating the module anymore.

* Remove unused code.

* Merge token into default doc fragment.

* JSON all the way down.

* extract validation tests into custom file and prep for requests removal.

* Removed dependency on requests.

* Initial test for consul_kv.

* fixup license headers.

* Revert changes to consul.py since it utilizes python-consul.

* Disable the lookup test for now.

* Fix python 2.7 support.

* Address review comments.

* Address review comments.

* Addec changelog fragment.

* Mark ConsulModule as private.

(cherry picked from commit 44679e7)

Co-authored-by: Florian Apolloner <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-8 Automatically create a backport for the stable-8 branch docs_fragments docs_fragments plugin (shared docs) integration tests/integration module_utils module_utils module module plugins plugin (any type) tests tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants