Add support for configuring garbage collection (#334)

* Add support for configuring garbage collection

This surfaces deleteOptions functionality in a top-level delete_options
parameter.

* Add changelog fragment

* Remove kind and apiVersion from delete_options

* Add release version to docs
This commit is contained in:
Mike Graves
2021-01-12 14:17:18 -05:00
committed by GitHub
parent 9059f2c526
commit a9b8cc68d5
6 changed files with 298 additions and 1 deletions

View File

@@ -189,6 +189,27 @@ WAIT_ARG_SPEC = dict(
)
)
DELETE_OPTS_ARG_SPEC = {
'propagationPolicy': {
'choices': ['Foreground', 'Background', 'Orphan'],
},
'gracePeriodSeconds': {
'type': 'int',
},
'preconditions': {
'type': 'dict',
'options': {
'resourceVersion': {
'type': 'str',
},
'uid': {
'type': 'str',
}
}
}
}
# Map kubernetes-client parameters to ansible parameters
AUTH_ARG_MAP = {
'kubeconfig': 'kubeconfig',
@@ -594,6 +615,7 @@ class K8sAnsibleMixin(object):
return definition
def perform_action(self, resource, definition):
delete_options = self.params.get('delete_options')
result = {'changed': False, 'result': {}}
state = self.params.get('state', None)
force = self.params.get('force', False)
@@ -646,6 +668,13 @@ class K8sAnsibleMixin(object):
# Delete the object
result['changed'] = True
if not self.check_mode:
if delete_options:
body = {
'apiVersion': 'v1',
'kind': 'DeleteOptions',
}
body.update(delete_options)
params['body'] = body
try:
k8s_obj = resource.delete(**params)
result['result'] = k8s_obj.to_dict()