Debian Codegraph @

ansible_collections/community/okd/plugins/modules/openshift_adm_prune_deployments.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_deployments
15
16 short_description: Remove old completed and failed deployment configs
17
18 version_added: "2.2.0"
19
20 author:
21 - Aubin Bikouo (@abikouo)
22
23 description:
24 - This module allow administrators to remove old completed and failed deployment configs.
25 - Analogous to C(oc adm prune deployments).
26
27 extends_documentation_fragment:
28 - kubernetes.core.k8s_auth_options
29
30 options:
31 namespace:
32 description:
33 - Use to specify namespace for deployments to be deleted.
34 type: str
35 keep_younger_than:
36 description:
37 - Specify the minimum age (in minutes) of a deployment for it to be considered a candidate for pruning.
38 type: int
39 orphans:
40 description:
41 - If C(true), prune all deployments where the associated DeploymentConfig no longer exists,
42 the status is complete or failed, and the replica size is C(0).
43 type: bool
44 default: False
45
46 requirements:
47 - python >= 3.6
48 - kubernetes >= 12.0.0
49 """
50
51 EXAMPLES = r"""
52 - name: Prune Deployments from testing namespace
53 community.okd.openshift_adm_prune_deployments:
54 namespace: testing
55
56 - name: Prune orphans deployments, keep younger than 2hours
57 community.okd.openshift_adm_prune_deployments:
58 orphans: true
59 keep_younger_than: 120
60 """
61
62
63 RETURN = r"""
64 replication_controllers:
65 type: list
66 description: list of replication controllers candidate for pruning.
67 returned: always
68 """
69 # ENDREMOVE (downstream)
70
71 import copy
72
73 try:
74 from ansible_collections.kubernetes.core.plugins.module_utils.args_common import (
75 AUTH_ARG_SPEC,
76 )
77 except ImportError as e:
78 pass
79
80
81 def argument_spec():
82 args = copy.deepcopy(AUTH_ARG_SPEC)
83 args.update(
84 dict(
85 namespace=dict(
86 type="str",
87 ),
88 keep_younger_than=dict(
89 type="int",
90 ),
91 orphans=dict(type="bool", default=False),
92 )
93 )
94 return args
95
96
97 def main():
98 from ansible_collections.community.okd.plugins.module_utils.openshift_adm_prune_deployments import (
99 OpenShiftAdmPruneDeployment,
100 )
101
102 module = OpenShiftAdmPruneDeployment(
103 argument_spec=argument_spec(), supports_check_mode=True
104 )
105 module.run_module()
106
107
108 if __name__ == "__main__":
109 main()