diff --git a/changelogs/fragments/164-add-history-max.yaml b/changelogs/fragments/164-add-history-max.yaml new file mode 100644 index 00000000..ebe44c57 --- /dev/null +++ b/changelogs/fragments/164-add-history-max.yaml @@ -0,0 +1,2 @@ +minor_changes: + - helm - add support for history_max cli parameter (https://github.com/ansible-collections/kubernetes.core/pull/164). diff --git a/plugins/modules/helm.py b/plugins/modules/helm.py index 8971ebf1..67f25111 100644 --- a/plugins/modules/helm.py +++ b/plugins/modules/helm.py @@ -130,6 +130,7 @@ options: description: - Reuse the given name, only if that name is a deleted release which remains in the history. - This is unsafe in production environment. + - mutually exclusive with with C(history_max). type: bool default: False version_added: "1.11.0" @@ -139,6 +140,12 @@ options: type: bool default: False version_added: "1.2.0" + history_max: + description: + - Limit the maximum number of revisions saved per release. + - mutually exclusive with with C(replace). + type: int + version_added: "2.2.0" extends_documentation_fragment: - kubernetes.core.helm_common_options ''' @@ -357,7 +364,7 @@ def fetch_chart_info(module, command, chart_ref): def deploy(command, release_name, release_values, chart_name, wait, - wait_timeout, disable_hook, force, values_files, atomic=False, + wait_timeout, disable_hook, force, values_files, history_max, atomic=False, create_namespace=False, replace=False, skip_crds=False): """ Install/upgrade/rollback release chart @@ -404,8 +411,10 @@ def deploy(command, release_name, release_values, chart_name, wait, if skip_crds: deploy_command += " --skip-crds" - deploy_command += " " + release_name + " " + chart_name + if history_max is not None: + deploy_command += " --history-max=%s" % str(history_max) + deploy_command += " " + release_name + " " + chart_name return deploy_command @@ -532,6 +541,7 @@ def main(): create_namespace=dict(type='bool', default=False), replace=dict(type='bool', default=False), skip_crds=dict(type='bool', default=False), + history_max=dict(type='int'), # Generic auth key host=dict(type='str', fallback=(env_fallback, ['K8S_AUTH_HOST'])), @@ -546,6 +556,7 @@ def main(): mutually_exclusive=[ ("context", "ca_cert"), ("kubeconfig", "ca_cert"), + ("replace", "history_max"), ], supports_check_mode=True, ) @@ -575,6 +586,7 @@ def main(): create_namespace = module.params.get('create_namespace') replace = module.params.get('replace') skip_crds = module.params.get('skip_crds') + history_max = module.params.get('history_max') if bin_path is not None: helm_cmd_common = bin_path @@ -610,7 +622,7 @@ def main(): helm_cmd = deploy(helm_cmd, release_name, release_values, chart_ref, wait, wait_timeout, disable_hook, False, values_files=values_files, atomic=atomic, create_namespace=create_namespace, replace=replace, - skip_crds=skip_crds) + skip_crds=skip_crds, history_max=history_max) changed = True else: @@ -627,7 +639,7 @@ def main(): helm_cmd = deploy(helm_cmd, release_name, release_values, chart_ref, wait, wait_timeout, disable_hook, force, values_files=values_files, atomic=atomic, create_namespace=create_namespace, replace=replace, - skip_crds=skip_crds) + skip_crds=skip_crds, history_max=history_max) changed = True if module.check_mode: