Skip to content

Commit

Permalink
Update role with new quay_organization_prune module
Browse files Browse the repository at this point in the history
  • Loading branch information
Hervé Quatremain committed Nov 23, 2024
1 parent 92cc2c5 commit 2b5050c
Show file tree
Hide file tree
Showing 10 changed files with 111 additions and 17 deletions.
8 changes: 4 additions & 4 deletions plugins/doc_fragments/autoprune_deprecated.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ class ModuleDocFragment(object):
options:
auto_prune_method:
description:
- The O(auto_prune_method) is deprecated and will be removed in future
versions of the collection.
- The O(auto_prune_method) parameter is deprecated and will be removed in
future versions of the collection.
Use the M(infra.quay_configuration.quay_organization_prune) and the
M(infra.quay_configuration.quay_repository_prune) modules instead.
- Method to use for the auto-pruning tags policy.
Expand All @@ -32,8 +32,8 @@ class ModuleDocFragment(object):
choices: [none, tags, date]
auto_prune_value:
description:
- The O(auto_prune_value) is deprecated and will be removed in future
versions of the collection.
- The O(auto_prune_value) parameter is deprecated and will be removed in
future versions of the collection.
Use the M(infra.quay_configuration.quay_organization_prune) and the
M(infra.quay_configuration.quay_repository_prune) modules instead.
- Number of tags to keep when O(auto_prune_method) is V(tags).
Expand Down
9 changes: 8 additions & 1 deletion plugins/modules/quay_organization_prune.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,13 @@ def main():
# "value": 20,
# "tagPattern": "prod.*",
# "tagPatternMatches": false
# },
# {
# "uuid": "71fd827c-6dec-4ecd-ac92-a200e821afa9",
# "method": "number_of_tags",
# "value": 25,
# "tagPattern": null,
# "tagPatternMatches": true
# }
# ]
# }
Expand All @@ -207,7 +214,7 @@ def main():
policy.get("method") == data.get("method")
and policy.get("value") == data.get("value")
and policy.get("tagPattern") == data.get("tagPattern")
and policy.get("tagPatternMatches") == data.get("tagPatternMatches")
and policy.get("tagPatternMatches") == data.get("tagPatternMatches", True)
):
policy_details = policy
break
Expand Down
9 changes: 8 additions & 1 deletion plugins/modules/quay_repository_prune.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,13 @@ def main():
# "value": 20,
# "tagPattern": "prod.*",
# "tagPatternMatches": false
# },
# {
# "uuid": "71fd827c-6dec-4ecd-ac92-a200e821afa9",
# "method": "number_of_tags",
# "value": 25,
# "tagPattern": null,
# "tagPatternMatches": true
# }
# ]
# }
Expand All @@ -232,7 +239,7 @@ def main():
policy.get("method") == data.get("method")
and policy.get("value") == data.get("value")
and policy.get("tagPattern") == data.get("tagPattern")
and policy.get("tagPatternMatches") == data.get("tagPatternMatches")
and policy.get("tagPatternMatches") == data.get("tagPatternMatches", True)
):
policy_details = policy
break
Expand Down
13 changes: 8 additions & 5 deletions roles/quay_org/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ The following list gives a short descriptions of the variables:
* `quay_validate_certs`: Whether to allow insecure connections to the API.
* `quay_org_name`: Name of the organization to create.
* `quay_org_email`: Email address to associate with the organization.
* `quay_org_auto_prune_method`: Method to use for the auto-pruning tags policy.
* `quay_org_auto_prune_value`: Number or period of time to keep tags.
* `quay_org_prune`: List of auto-pruning tags policies for the organization.
* `quay_org_users`: List of user accounts to create.
* `quay_org_robots`: List of robot accounts to create in the organization.
* `quay_org_teams`: List of the teams to create in the organization.
Expand Down Expand Up @@ -87,16 +86,20 @@ Example Playbook
# Organization name and email
quay_org_name: production
quay_org_email: [email protected]
# Organization auto-prune policy
quay_org_auto_prune_method: tags
quay_org_auto_prune_value: 15
# Proxy cache
quay_org_cache_registry: quay.io/sclorg
quay_org_cache_expiration: 259200
# Quota
quay_org_quota: 1.5 TiB
quay_org_warning_pct: 90
quay_org_reject_pct: 97
# Organization auto-pruning tags policies
quay_org_prune:
- method: tags
value: 15
tag_pattern: nightly
- method: date
value: 5w
# User accounts to create
quay_org_users:
- username: lvasquez
Expand Down
8 changes: 6 additions & 2 deletions roles/quay_org/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
# quay_org_validate_certs: false
# quay_org_name: production
# quay_org_email: [email protected]
# quay_org_auto_prune_method: date
# quay_org_auto_prune_value: 4w
# quay_org_cache_registry: quay.io/sclorg
# quay_org_cache_insecure: false
# quay_org_cache_username: ""
Expand All @@ -17,6 +15,12 @@
# quay_org_quota: 1.5 TiB
# quay_org_warning_pct: 90
# quay_org_reject_pct: 97
# quay_org_prune:
# - method: tags
# value: 25
# - method: date
# value: 1w
# tag_pattern: nightly
# quay_org_users:
# - username: lvasquez
# email: [email protected]
Expand Down
47 changes: 47 additions & 0 deletions roles/quay_org/meta/argument_specs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ argument_specs:
type: str
quay_org_auto_prune_method:
description:
- The O(quay_org_auto_prune_method) parameter is deprecated and will
be removed in future versions of the collection.
Use the O(quay_org_prune) parameter instead.
- Method to use for the auto-pruning tags policy.
- If V(none), then the module ensures that no policy is in place. The
tags are not pruned.
Expand All @@ -85,6 +88,9 @@ argument_specs:
choices: [none, tags, date]
quay_org_auto_prune_value:
description:
- The O(quay_org_auto_prune_value) parameter is deprecated and will
be removed in future versions of the collection.
Use the O(quay_org_prune) parameter instead.
- Number of tags to keep when O(quay_org_auto_prune_value) is V(tags).
The value must be 1 or more.
- Period of time when O(quay_org_auto_prune_value) is V(date). The
Expand Down Expand Up @@ -144,6 +150,47 @@ argument_specs:
is reached.
- Set O(quay_org_reject_pct) to V(0) to remove the reject limit.
type: int
quay_org_prune:
description:
- List of auto-pruning tags policies for the organization.
type: list
elements: dict
options:
method:
description:
- Method to use for the auto-pruning tags policy.
- If V(tags), then the policy keeps only the number of tags that
you specify in O(quay_org_prune[].value).
- If V(date), then the policy deletes the tags older than the
time period that you specify in O(quay_org_prune[].value).
required: true
type: str
choices: [tags, date]
value:
description:
- Number of tags to keep when O(quay_org_prune[].method) is
V(tags). The value must be 1 or more.
- Period of time when O(quay_org_prune[].method) is V(date). The
value must be 1 or more, and must be followed by a suffix;
s (for second), m (for minute), h (for hour), d (for day),
or w (for week).
required: true
type: str
tag_pattern:
description:
- Regular expression to select the tags to process.
- If you do not set the parameter, then Quay processes all the
tags.
type: str
tag_pattern_matches:
description:
- If V(true), then Quay processes the tags matching the
O(quay_org_prune[].tag_pattern) parameter.
- If V(false), then Quay excludes the tags matching the
O(quay_org_prune[].tag_pattern) parameter.
- V(true) by default.
type: bool
default: true
quay_org_users:
description:
- List of user account to create.
Expand Down
3 changes: 3 additions & 0 deletions roles/quay_org/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
- name: Ensure the organization exists
ansible.builtin.import_tasks: organization.yml

- name: Ensure the auto-pruning policies for the organization exist
ansible.builtin.import_tasks: organization_prune.yml

- name: Ensure the proxy cache configuration exists
ansible.builtin.import_tasks: proxy_cache.yml

Expand Down
15 changes: 15 additions & 0 deletions roles/quay_org/tasks/organization_prune.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
- name: Ensure the auto-pruning policies for the organization exist
infra.quay_configuration.quay_organization_prune:
namespace: "{{ quay_org_name }}"
method: "{{ item['method'] }}"
value: "{{ item['value'] }}"
tag_pattern: "{{ item['tag_pattern'] | default(omit) }}"
tag_pattern_matches: "{{ item['tag_pattern_matches'] | default(omit) }}"
state: present
quay_token: "{{ quay_org_token | default(omit) }}"
quay_username: "{{ quay_org_username | default(omit) }}"
quay_password: "{{ quay_org_password | default(omit) }}"
quay_host: "{{ quay_org_host | default(omit) }}"
validate_certs: "{{ quay_org_validate_certs | default(omit) }}"
loop: "{{ quay_org_prune }}"
8 changes: 6 additions & 2 deletions roles/quay_org/tests/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,17 @@
quay_org_token: vgfH9zH5q6eV16Con7SvDQYSr0KPYQimMHVehZv7
quay_org_name: production
quay_org_email: [email protected]
quay_org_auto_prune_method: tags
quay_org_auto_prune_value: 15
quay_org_cache_registry: public.ecr.aws/nginx
quay_org_cache_expiration: 345600
quay_org_quota: 500 GiB
quay_org_warning_pct: 80
quay_org_reject_pct: 90
quay_org_prune:
- method: tags
value: 25
- method: date
value: 1w
tag_pattern: nightly
quay_org_users:
- username: lvasquez
email: [email protected]
Expand Down
8 changes: 6 additions & 2 deletions tests/integration/targets/role_quay_org/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,18 @@
quay_org_validate_certs: false
quay_org_name: testorg
quay_org_email: [email protected]
quay_org_auto_prune_method: tags
quay_org_auto_prune_value: 15
quay_org_cache_registry: public.ecr.aws/nginx
quay_org_cache_expiration: 345600
quay_org_cache_insecure: true
quay_org_quota: 1.5 TiB
quay_org_warning_pct: 90
quay_org_reject_pct: 97
quay_org_prune:
- method: tags
value: 25
- method: date
value: 1w
tag_pattern: nightly
quay_org_users:
- username: testuser1
email: [email protected]
Expand Down

0 comments on commit 2b5050c

Please sign in to comment.