Skip to content

Commit 5a97e57

Browse files
herve4mHervé Quatremain
andauthored
New auto-pruning modules (#16)
Deprecate the auto_prune_method and auto_prune_value parameters in favor of the new quay_organization_prune and quay_repository_prune modules. --------- Co-authored-by: Hervé Quatremain <herve.quatremain@redhat.com>
1 parent 8f51f71 commit 5a97e57

File tree

31 files changed

+1430
-71
lines changed

31 files changed

+1430
-71
lines changed

CHANGELOG.rst

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,25 @@ Quay Container Registry Collection Release Notes
44

55
.. contents:: Topics
66

7+
v2.4.0
8+
======
9+
10+
Release Summary
11+
---------------
12+
13+
New ``infra.quay_configuration.quay_organization_prune`` and ``infra.quay_configuration.quay_repository_prune`` modules.
14+
15+
Deprecated Features
16+
-------------------
17+
18+
- The ``auto_prune_method`` and ``auto_prune_value`` parameters of the ``infra.quay_configuration.quay_organization`` and ``infra.quay_configuration.quay_repository`` modules are deprecated in favor of the new``infra.quay_configuration.quay_organization_prune`` and ``infra.quay_configuration.quay_repository_prune`` modules.
19+
20+
New Modules
21+
-----------
22+
23+
- infra.quay_configuration.quay_organization_prune - Manage auto-pruning policies for organizations and user namespaces
24+
- infra.quay_configuration.quay_repository_prune - Manage auto-pruning policies for repositories
25+
726
v2.2.0
827
======
928

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,12 @@ Name | Description
3030
`quay_message` | Manage Quay Container Registry global messages
3131
`quay_notification` | Manage Quay Container Registry repository notifications
3232
`quay_organization` | Manage Quay Container Registry organizations
33+
`quay_organization_prune` | Manage auto-pruning policies for organizations and user namespaces
3334
`quay_proxy_cache` | Manage Quay Container Registry proxy cache configurations
3435
`quay_quota` | Manage Quay Container Registry organizations quota
3536
`quay_repository` | Manage Quay Container Registry repositories
3637
`quay_repository_mirror` | Manage Quay Container Registry repository mirror configurations
38+
`quay_repository_prune` | Manage auto-pruning policies for repositories
3739
`quay_robot` | Manage Quay Container Registry robot accounts
3840
`quay_tag` | Manage Quay Container Registry image tags
3941
`quay_tag_info` | Gather information about tags in a Quay Container Registry repository

changelogs/changelog.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,3 +254,22 @@ releases:
254254
fragments:
255255
- PR5-v2.2.0-summary.yml
256256
release_date: '2024-08-05'
257+
2.4.0:
258+
changes:
259+
deprecated_features:
260+
- The ``auto_prune_method`` and ``auto_prune_value`` parameters of the ``infra.quay_configuration.quay_organization``
261+
and ``infra.quay_configuration.quay_repository`` modules are deprecated in
262+
favor of the new``infra.quay_configuration.quay_organization_prune`` and ``infra.quay_configuration.quay_repository_prune``
263+
modules.
264+
release_summary: New ``infra.quay_configuration.quay_organization_prune`` and
265+
``infra.quay_configuration.quay_repository_prune`` modules.
266+
fragments:
267+
- PR16-v2.4.0-summary.yml
268+
modules:
269+
- description: Manage auto-pruning policies for organizations and user namespaces
270+
name: quay_organization_prune
271+
namespace: ''
272+
- description: Manage auto-pruning policies for repositories
273+
name: quay_repository_prune
274+
namespace: ''
275+
release_date: '2024-11-23'

galaxy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
namespace: infra
33
name: quay_configuration
4-
version: 2.2.0
4+
version: 2.4.0
55
readme: README.md
66
authors:
77
- Hervé Quatremain <herve.quatremain@redhat.com>

meta/runtime.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@ action_groups:
1111
- quay_manifest_label
1212
- quay_message
1313
- quay_notification
14+
- quay_organization_prune
1415
- quay_organization
1516
- quay_proxy_cache
1617
- quay_quota
1718
- quay_repository_mirror
19+
- quay_repository_prune
1820
- quay_repository
1921
- quay_robot
2022
- quay_tag_info

plugins/doc_fragments/autoprune.py

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,32 +12,41 @@ class ModuleDocFragment(object):
1212
# Ansible Galaxy documentation fragment
1313
DOCUMENTATION = r"""
1414
options:
15-
auto_prune_method:
15+
method:
1616
description:
1717
- Method to use for the auto-pruning tags policy.
18-
- If V(none), then the module ensures that no policy is in place. The
19-
tags are not pruned.
2018
- If V(tags), then the policy keeps only the number of tags that you
21-
specify in O(auto_prune_value).
19+
specify in O(value).
2220
- If V(date), then the policy deletes the tags older than the time period
23-
that you specify in O(auto_prune_value).
24-
- O(auto_prune_value) is required when O(auto_prune_method) is V(tags) or
25-
V(date).
21+
that you specify in O(value).
22+
required: true
2623
type: str
27-
choices: [none, tags, date]
28-
auto_prune_value:
24+
choices: [tags, date]
25+
value:
2926
description:
30-
- Number of tags to keep when O(auto_prune_method) is V(tags).
27+
- Number of tags to keep when O(method) is V(tags).
3128
The value must be 1 or more.
32-
- Period of time when O(auto_prune_method) is V(date). The value must be 1
33-
or more, and must be followed by a suffix; s (for second), m (for
34-
minute), h (for hour), d (for day), or w (for week).
35-
- O(auto_prune_method) is required when O(auto_prune_value) is set.
29+
- Period of time when O(method) is V(date). The value must be 1 or more,
30+
and must be followed by a suffix; s (for second), m (for minute), h
31+
(for hour), d (for day), or w (for week).
32+
required: true
3633
type: str
34+
tag_pattern:
35+
description:
36+
- Regular expression to select the tags to process.
37+
- If you do not set the parameter, then Quay processes all the tags.
38+
type: str
39+
tag_pattern_matches:
40+
description:
41+
- If V(true), then Quay processes the tags matching the O(tag_pattern)
42+
parameter.
43+
- If V(false), then Quay excludes the tags matching the O(tag_pattern)
44+
parameter.
45+
- V(true) by default.
46+
type: bool
47+
default: true
3748
notes:
38-
- Your Quay administrator must enable the auto-prune capability of your Quay
39-
installation (C(FEATURE_AUTO_PRUNE) in C(config.yaml)) to use the
40-
O(auto_prune_method) and O(auto_prune_value) parameters.
41-
- Using O(auto_prune_method) and O(auto_prune_value) requires Quay version
42-
3.11 or later.
49+
- Your Quay administrator must enable the auto-pruning capability of your
50+
Quay installation (C(FEATURE_AUTO_PRUNE) in C(config.yaml)).
51+
- Auto-pruning requires Quay version 3.13 or later.
4352
"""
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# -*- coding: utf-8 -*-
2+
3+
# Copyright: (c) 2024 Hervé Quatremain <herve.quatremain@redhat.com>
4+
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
5+
6+
from __future__ import absolute_import, division, print_function
7+
8+
__metaclass__ = type
9+
10+
11+
class ModuleDocFragment(object):
12+
# Ansible Galaxy documentation fragment
13+
DOCUMENTATION = r"""
14+
options:
15+
auto_prune_method:
16+
description:
17+
- The O(auto_prune_method) parameter is deprecated and will be removed in
18+
future versions of the collection.
19+
Use the M(infra.quay_configuration.quay_organization_prune) and the
20+
M(infra.quay_configuration.quay_repository_prune) modules instead.
21+
- Method to use for the auto-pruning tags policy.
22+
- If V(none), then the module ensures that no policy is in place. The
23+
tags are not pruned.
24+
If several policies are available, then the module removes them all.
25+
- If V(tags), then the policy keeps only the number of tags that you
26+
specify in O(auto_prune_value).
27+
- If V(date), then the policy deletes the tags older than the time period
28+
that you specify in O(auto_prune_value).
29+
- O(auto_prune_value) is required when O(auto_prune_method) is V(tags) or
30+
V(date).
31+
type: str
32+
choices: [none, tags, date]
33+
auto_prune_value:
34+
description:
35+
- The O(auto_prune_value) parameter is deprecated and will be removed in
36+
future versions of the collection.
37+
Use the M(infra.quay_configuration.quay_organization_prune) and the
38+
M(infra.quay_configuration.quay_repository_prune) modules instead.
39+
- Number of tags to keep when O(auto_prune_method) is V(tags).
40+
The value must be 1 or more.
41+
- Period of time when O(auto_prune_method) is V(date). The value must be 1
42+
or more, and must be followed by a suffix; s (for second), m (for
43+
minute), h (for hour), d (for day), or w (for week).
44+
- O(auto_prune_method) is required when O(auto_prune_value) is set.
45+
type: str
46+
notes:
47+
- The O(auto_prune_method) and O(auto_prune_value) parameters are deprecated
48+
and will be removed in future versions of the collection.
49+
Use the M(infra.quay_configuration.quay_organization_prune) and the
50+
M(infra.quay_configuration.quay_repository_prune) modules instead.
51+
- Your Quay administrator must enable the auto-prune capability of your Quay
52+
installation (C(FEATURE_AUTO_PRUNE) in C(config.yaml)) to use the
53+
O(auto_prune_method) and O(auto_prune_value) parameters.
54+
- Using O(auto_prune_method) and O(auto_prune_value) requires Quay version
55+
3.11 or later.
56+
"""

plugins/module_utils/api_module.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1354,6 +1354,71 @@ def get_tags(self, namespace, repository, tag=None, digest=None, only_active_tag
13541354
break
13551355
return tag_list
13561356

1357+
def process_prune_parameters(
1358+
self, method, value, tag_pattern=None, tag_pattern_matches=True
1359+
):
1360+
"""Return the prune parameters in a dictionary ready for the API.
1361+
1362+
:param method: The prune method: "tags", or "date".
1363+
:type method: str
1364+
:param value: The pruning criteria, which depends on the method. It can
1365+
be a number of tags, or a period of time.
1366+
:type value: str
1367+
:param tag_pattern: A regular expression that is used to select the tags
1368+
to purge.
1369+
:type tag_pattern: str
1370+
:param tag_pattern_matches: If ``True``, then the tags matching
1371+
:py:attribute:``tag_pattern`` are processed.
1372+
If ``False``, then the tags matching
1373+
:py:attribute:``tag_pattern`` are excluded.
1374+
:type tag_pattern_matches: bool
1375+
1376+
:return: The prune parameters ready to be used for a call to the API.
1377+
For example::
1378+
1379+
{
1380+
"method": "creation_date",
1381+
"value": "7d",
1382+
"tagPattern": "dev.*",
1383+
"tagPatternMatches": True
1384+
}
1385+
"""
1386+
if method == "tags":
1387+
try:
1388+
auto_prune_value = int(value)
1389+
except ValueError:
1390+
self.fail_json(
1391+
msg=(
1392+
"Wrong format for the `value' parameter:"
1393+
" {auto_prune_value} is not a positive integer."
1394+
).format(auto_prune_value=value)
1395+
)
1396+
if auto_prune_value <= 0:
1397+
self.fail_json(
1398+
msg=(
1399+
"Wrong format for the `value' parameter:"
1400+
" {auto_prune_value} is not a positive integer."
1401+
).format(auto_prune_value=value)
1402+
)
1403+
data = {"method": "number_of_tags", "value": auto_prune_value}
1404+
else: # method == "date":
1405+
auto_prune_value = "".join(value.split())
1406+
if not re.match(r"[1-9]\d*[smhdw]$", auto_prune_value):
1407+
self.fail_json(
1408+
msg=(
1409+
"Wrong format for the `value' parameter:"
1410+
" {auto_prune_value} is not a positive integer followed by"
1411+
" the s, m, h, d, or w suffix."
1412+
).format(auto_prune_value=value)
1413+
)
1414+
data = {"method": "creation_date", "value": auto_prune_value}
1415+
if tag_pattern:
1416+
data["tagPattern"] = tag_pattern
1417+
data["tagPatternMatches"] = (
1418+
tag_pattern_matches if tag_pattern_matches is not None else True
1419+
)
1420+
return data
1421+
13571422

13581423
class APIModuleNoAuth(APIModule):
13591424
AUTH_ARGSPEC = dict(

plugins/modules/quay_default_perm.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@
3535
options:
3636
organization:
3737
description:
38-
- Name of the organization for the default permission.
39-
That organization must exist.
38+
- Name of the organization for the default permission. This organization
39+
must exist.
4040
required: true
4141
type: str
4242
name:

plugins/modules/quay_organization.py

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,6 @@
7272
default: present
7373
choices: [absent, present]
7474
notes:
75-
- Your Quay administrator must enable the auto-prune capability of your Quay
76-
installation (C(FEATURE_AUTO_PRUNE) in C(config.yaml)) to use the
77-
O(auto_prune_method) and O(auto_prune_value) parameters.
78-
- Using O(auto_prune_method) and O(auto_prune_value) requires Quay version
79-
3.11 or later.
8075
- The token that you provide in O(quay_token) must have the "Administer
8176
Organization" and "Administer User" permissions.
8277
- To rename organizations, the token must also have the "Super User Access"
@@ -93,7 +88,7 @@
9388
- ansible.builtin.action_common_attributes
9489
- infra.quay_configuration.auth
9590
- infra.quay_configuration.auth.login
96-
- infra.quay_configuration.autoprune
91+
- infra.quay_configuration.autoprune_deprecated
9792
"""
9893

9994
EXAMPLES = r"""
@@ -102,8 +97,6 @@
10297
name: production
10398
email: prodlist@example.com
10499
time_machine_expiration: "7d"
105-
auto_prune_method: tags
106-
auto_prune_value: 20
107100
state: present
108101
quay_host: https://quay.example.com
109102
quay_token: vgfH9zH5q6eV16Con7SvDQYSr0KPYQimMHVehZv7
@@ -144,8 +137,14 @@ def main():
144137
new_name=dict(),
145138
email=dict(),
146139
time_machine_expiration=dict(choices=list(tm_allowed_values.keys())),
147-
auto_prune_method=dict(choices=["none", "tags", "date"]),
148-
auto_prune_value=dict(),
140+
auto_prune_method=dict(
141+
choices=["none", "tags", "date"],
142+
removed_at_date="2025-12-01",
143+
removed_from_collection="infra.quay_configuration",
144+
),
145+
auto_prune_value=dict(
146+
removed_at_date="2025-12-01", removed_from_collection="infra.quay_configuration"
147+
),
149148
state=dict(choices=["present", "absent"], default="present"),
150149
)
151150

@@ -330,15 +329,14 @@ def main():
330329
except (TypeError, IndexError):
331330
policies = []
332331

333-
# Removing the auto-prune policies (the UI only manages one policy, but
334-
# the backend seems to allow several policies)
332+
# Removing all the auto-pruning policies
335333
if auto_prune_method == "none":
336334
deleted = False
337335
for policy in policies:
338336
uuid = policy.get("uuid")
339337
if module.delete(
340338
uuid,
341-
"organization auto-prune policy",
339+
"organization auto-pruning policy",
342340
name,
343341
"organization/{orgname}/autoprunepolicy/{uuid}",
344342
auto_exit=False,
@@ -366,7 +364,7 @@ def main():
366364
# then create the policy
367365
if len(policies) == 0 or policies[0].get("uuid") is None:
368366
module.create(
369-
"organization auto-prune policy",
367+
"organization auto-pruning policy",
370368
name,
371369
"organization/{orgname}/autoprunepolicy/",
372370
new_policy,
@@ -379,7 +377,7 @@ def main():
379377
uuid = policies[0]["uuid"]
380378
new_policy["uuid"] = uuid
381379
module.unconditional_update(
382-
"organization auto-prune policy",
380+
"organization auto-pruning policy",
383381
name,
384382
"organization/{orgname}/autoprunepolicy/{uuid}",
385383
new_policy,

0 commit comments

Comments
 (0)