Debian Codegraph @

ansible_collections/community/okd/plugins/modules/openshift_adm_prune_builds.py

raw
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 # Copyright (c) 2021, Red Hat
5 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
6
7 from __future__ import absolute_import, division, print_function
8
9 __metaclass__ = type
10
11 # STARTREMOVE (downstream)
12 DOCUMENTATION = r"""
13
14 module: openshift_adm_prune_builds
15
16 short_description: Prune old completed and failed builds
17
18 version_added: "2.3.0"
19
20 author:
21 - Aubin Bikouo (@abikouo)
22
23 description:
24 - This module allow administrators to delete old completed and failed builds.
25 - Analogous to C(oc adm prune builds).
26
27 extends_documentation_fragment:
28 - kubernetes.core.k8s_auth_options
29
30 options:
31 namespace:
32 description:
33 - Use to specify namespace for builds to be deleted.
34 type: str
35 keep_younger_than:
36 description:
37 - Specify the minimum age (in minutes) of a Build for it to be considered a candidate for pruning.
38 type: int
39 orphans:
40 description:
41 - If C(true), prune all builds whose associated BuildConfig no longer exists and whose status is
42 complete, failed, error, or cancelled.
43 type: bool
44 default: False
45
46 requirements:
47 - python >= 3.6
48 - kubernetes >= 12.0.0
49 """
50
51 EXAMPLES = r"""
52 # Run deleting older completed and failed builds and also including
53 # all builds whose associated BuildConfig no longer exists
54 - name: Run delete orphan Builds
55 community.okd.openshift_adm_prune_builds:
56 orphans: true
57
58 # Run deleting older completed and failed builds keep younger than 2hours
59 - name: Run delete builds, keep younger than 2h
60 community.okd.openshift_adm_prune_builds:
61 keep_younger_than: 120
62
63 # Run deleting builds from specific namespace
64 - name: Run delete builds from namespace
65 community.okd.openshift_adm_prune_builds:
66 namespace: testing_namespace
67 """
68
69 RETURN = r"""
70 builds:
71 description:
72 - The builds that were deleted
73 returned: success
74 type: complex
75 contains:
76 api_version:
77 description: The versioned schema of this representation of an object.
78 returned: success
79 type: str
80 kind:
81 description: Represents the REST resource this object represents.
82 returned: success
83 type: str
84 metadata:
85 description: Standard object metadata. Includes name, namespace, annotations, labels, etc.
86 returned: success
87 type: dict
88 spec:
89 description: Specific attributes of the object. Will vary based on the I(api_version) and I(kind).
90 returned: success
91 type: dict
92 status:
93 description: Current status details for the object.
94 returned: success
95 type: dict
96 """
97 # ENDREMOVE (downstream)
98
99 import copy
100
101 from ansible_collections.kubernetes.core.plugins.module_utils.args_common import (
102 AUTH_ARG_SPEC,
103 )
104
105
106 def argument_spec():
107 args = copy.deepcopy(AUTH_ARG_SPEC)
108 args.update(
109 dict(
110 namespace=dict(type="str"),
111 keep_younger_than=dict(type="int"),
112 orphans=dict(type="bool", default=False),
113 )
114 )
115 return args
116
117
118 def main():
119 from ansible_collections.community.okd.plugins.module_utils.openshift_builds import (
120 OpenShiftPruneBuilds,
121 )
122
123 module = OpenShiftPruneBuilds(
124 argument_spec=argument_spec(), supports_check_mode=True
125 )
126 module.run_module()
127
128
129 if __name__ == "__main__":
130 main()