-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
fix(modules/gitlab_runner): Use correct argument to list all runners #7790
fix(modules/gitlab_runner): Use correct argument to list all runners #7790
Conversation
python-gitlab 4.0.0 removed support for the `as_list=False` parameter. This functionality is now available as `iterator=True`. Without this change, the module actually only retrieves the first 20 results, which can lead to non-idempotent behavior, such as registering a runner again.
Hmm. It occurs to me that this change would cause issues if using python-gitlab older than 3.6. I know the new runner registration workflow stuff (#7199) requires >= 4.0.0, but the module will work on older versions as long as Should I change this to pass |
Thanks, I tried to search for this issue but somehow missed 7690. This PR is indeed a fix for that. The only issue I would take with using But it looks like 3.6.0 through 3.15.0 don't let you pass both (see https://github.com/python-gitlab/python-gitlab/blob/2fbd1bf73c15959f4345befd03a28df882b461bd/gitlab/client.py#L900). So I guess the options are:
My preference would be for option 2. Thoughts? |
@nejch does the PR look good to you? |
Sorry for the delay @felixfontein. LGTM, I would maybe even provide per_page in the |
…-collections#7790) I did not change every instance of all=True or all=False, only those which could obviously benefit from simplifying: * Code using `all=True` but then searching for any items that match a condition (no need to collect the full list). * Code that basically reimplements `all=True` with manual pagination. (These could be changed to `all=True`, but `list_all_kwargs` also sets per_page to 100, to gather data faster.)
@felixfontein @nejch I've implemented the requested changes (using There are a few instances that I left alone. For instance, if not force and len(group.projects.list(all=False)) >= 1: This is just a quick check for whether any groups still exist. No need to ask for "all" items, when the GitLab API defaults pages to size 20, so a single call here will be sufficient. But I did refactor a few " |
Two things I'm not sure about:
|
Yes, every changed module should be mentioned in a changelog fragment. (You can also mention them all in one.)
That's not necessary, unless there are conflicts. (Or you know that some of the GitLab modules have been modified and you need to rebase to get in the modifications because you need to change the corresponding code.) |
Done. Hopefully I've formatted it properly. The Ansible development docs say a changelog fragment can have multiple sections in it, so I kept |
Can someone please check all the new changes to this PR? Thanks :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@felixfontein LGTM, I left a comment about the redundant argument there but I don't want to block this any longer. It will have no effect.
return {'as_list': False, 'get_all': True, 'per_page': 100} | ||
else: | ||
return {'as_list': False, 'all': True, 'per_page': 100} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
quick note: as_list=False
in older versions and iterator=True
in newer versions takee precedence over all
and get_all
so IMO including the all
/ get_all
arguments here is not necessary. But not a blocker.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 I'll merge for now so I can do a release this evening, if someone wants to create a follow-up PR to clean this up, feel free :)
Backport to stable-7: 💔 cherry-picking failed — conflicts found❌ Failed to cleanly apply 787fa46 on top of patchback/backports/stable-7/787fa4621763879dae26c57aaf0028941dcaaefc/pr-7790 Backporting merged PR #7790 into main
🤖 @patchback |
Backport to stable-8: 💚 backport PR created✅ Backport PR branch: Backported as #8032 🤖 @patchback |
…7790) * fix(modules/gitlab_runner): Use correct argument to list all runners python-gitlab 4.0.0 removed support for the `as_list=False` parameter. This functionality is now available as `iterator=True`. Without this change, the module actually only retrieves the first 20 results, which can lead to non-idempotent behavior, such as registering a runner again. * Add changelog entry (#7790) * gitlab_runner: Check python-gitlab version when listing runners * gitlab: Add list_all_kwargs variable to module_utils * refactor(gitlab modules): use list_all_kwargs where it helps (#7790) I did not change every instance of all=True or all=False, only those which could obviously benefit from simplifying: * Code using `all=True` but then searching for any items that match a condition (no need to collect the full list). * Code that basically reimplements `all=True` with manual pagination. (These could be changed to `all=True`, but `list_all_kwargs` also sets per_page to 100, to gather data faster.) * gitlab_instance_variable: Use list_all_kwargs * Add new changelog entry for gitlab module changes (#7790) (cherry picked from commit 787fa46)
@mikewadsten thanks for your contribution! |
If someone is interested in a 7.5.x backport, you have to cherry-pick the commit manually ( |
…e correct argument to list all runners (#8032) fix(modules/gitlab_runner): Use correct argument to list all runners (#7790) * fix(modules/gitlab_runner): Use correct argument to list all runners python-gitlab 4.0.0 removed support for the `as_list=False` parameter. This functionality is now available as `iterator=True`. Without this change, the module actually only retrieves the first 20 results, which can lead to non-idempotent behavior, such as registering a runner again. * Add changelog entry (#7790) * gitlab_runner: Check python-gitlab version when listing runners * gitlab: Add list_all_kwargs variable to module_utils * refactor(gitlab modules): use list_all_kwargs where it helps (#7790) I did not change every instance of all=True or all=False, only those which could obviously benefit from simplifying: * Code using `all=True` but then searching for any items that match a condition (no need to collect the full list). * Code that basically reimplements `all=True` with manual pagination. (These could be changed to `all=True`, but `list_all_kwargs` also sets per_page to 100, to gather data faster.) * gitlab_instance_variable: Use list_all_kwargs * Add new changelog entry for gitlab module changes (#7790) (cherry picked from commit 787fa46) Co-authored-by: Mike Wadsten <[email protected]>
…/gitlab_runner): Use correct argument to list all runners (ansible-collections#8032) fix(modules/gitlab_runner): Use correct argument to list all runners (ansible-collections#7790) * fix(modules/gitlab_runner): Use correct argument to list all runners python-gitlab 4.0.0 removed support for the `as_list=False` parameter. This functionality is now available as `iterator=True`. Without this change, the module actually only retrieves the first 20 results, which can lead to non-idempotent behavior, such as registering a runner again. * Add changelog entry (ansible-collections#7790) * gitlab_runner: Check python-gitlab version when listing runners * gitlab: Add list_all_kwargs variable to module_utils * refactor(gitlab modules): use list_all_kwargs where it helps (ansible-collections#7790) I did not change every instance of all=True or all=False, only those which could obviously benefit from simplifying: * Code using `all=True` but then searching for any items that match a condition (no need to collect the full list). * Code that basically reimplements `all=True` with manual pagination. (These could be changed to `all=True`, but `list_all_kwargs` also sets per_page to 100, to gather data faster.) * gitlab_instance_variable: Use list_all_kwargs * Add new changelog entry for gitlab module changes (ansible-collections#7790) (cherry picked from commit 787fa46) Co-authored-by: Mike Wadsten <[email protected]>
…e correct argument to list all runners (#8311) [PR #7790/787fa462 backport][stable-8] fix(modules/gitlab_runner): Use correct argument to list all runners (#8032) fix(modules/gitlab_runner): Use correct argument to list all runners (#7790) * fix(modules/gitlab_runner): Use correct argument to list all runners python-gitlab 4.0.0 removed support for the `as_list=False` parameter. This functionality is now available as `iterator=True`. Without this change, the module actually only retrieves the first 20 results, which can lead to non-idempotent behavior, such as registering a runner again. * Add changelog entry (#7790) * gitlab_runner: Check python-gitlab version when listing runners * gitlab: Add list_all_kwargs variable to module_utils * refactor(gitlab modules): use list_all_kwargs where it helps (#7790) I did not change every instance of all=True or all=False, only those which could obviously benefit from simplifying: * Code using `all=True` but then searching for any items that match a condition (no need to collect the full list). * Code that basically reimplements `all=True` with manual pagination. (These could be changed to `all=True`, but `list_all_kwargs` also sets per_page to 100, to gather data faster.) * gitlab_instance_variable: Use list_all_kwargs * Add new changelog entry for gitlab module changes (#7790) (cherry picked from commit 787fa46) Co-authored-by: patchback[bot] <45432694+patchback[bot]@users.noreply.github.com> Co-authored-by: Mike Wadsten <[email protected]>
…nsible-collections#7790) * fix(modules/gitlab_runner): Use correct argument to list all runners python-gitlab 4.0.0 removed support for the `as_list=False` parameter. This functionality is now available as `iterator=True`. Without this change, the module actually only retrieves the first 20 results, which can lead to non-idempotent behavior, such as registering a runner again. * Add changelog entry (ansible-collections#7790) * gitlab_runner: Check python-gitlab version when listing runners * gitlab: Add list_all_kwargs variable to module_utils * refactor(gitlab modules): use list_all_kwargs where it helps (ansible-collections#7790) I did not change every instance of all=True or all=False, only those which could obviously benefit from simplifying: * Code using `all=True` but then searching for any items that match a condition (no need to collect the full list). * Code that basically reimplements `all=True` with manual pagination. (These could be changed to `all=True`, but `list_all_kwargs` also sets per_page to 100, to gather data faster.) * gitlab_instance_variable: Use list_all_kwargs * Add new changelog entry for gitlab module changes (ansible-collections#7790)
SUMMARY
python-gitlab 4.0.0 removed support for the
as_list=False
parameter. This functionality is now available asiterator=True
.Without this change, the module actually only retrieves the first 20 results, which can lead to non-idempotent behavior, such as registering a runner again.
ISSUE TYPE
COMPONENT NAME
gitlab_runner
ADDITIONAL INFORMATION
I am using community.general 8.1.0, python-gitlab 4.2.0 and a self-hosted instance of GitLab,
and was trying to register a new instance runner. Initial registration was successful, but if I run the playbook again,
a new runner (with the same description value) would be registered.
When I ran again using
--check
, I getAttributeError: 'bool' object has no attribute '_attrs'
(which is a separate bug that I will write up), but
module_stderr
also includes:The python-gitlab docs on pagination call this out: