Skip to content
This repository has been archived by the owner on Jun 13, 2024. It is now read-only.

helm: Add option 'atomic' #115

Merged
merged 1 commit into from
Jun 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion meta/runtime.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
requires_ansible: '>=2.9,<2.11'
requires_ansible: '>=2.9'

action_groups:
helm:
Expand Down
28 changes: 14 additions & 14 deletions plugins/modules/helm.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@
description:
- Timeout when wait option is enabled (helm2 is a number of seconds, helm3 is a duration).
type: str
atomic:
description:
- If set, the installation process deletes the installation on failure.
type: bool
default: False
'''

EXAMPLES = r'''
Expand Down Expand Up @@ -230,6 +235,7 @@
sample: helm upgrade ...
"""

import tempfile
import traceback

try:
Expand Down Expand Up @@ -320,7 +326,7 @@ def fetch_chart_info(command, chart_ref):
return yaml.safe_load(out)


def deploy(command, release_name, release_values, chart_name, wait, wait_timeout, disable_hook, force):
def deploy(command, release_name, release_values, chart_name, wait, wait_timeout, disable_hook, force, atomic=False):
"""
Install/upgrade/rollback release chart
"""
Expand All @@ -334,24 +340,16 @@ def deploy(command, release_name, release_values, chart_name, wait, wait_timeout
if wait_timeout is not None:
deploy_command += " --timeout " + wait_timeout

if atomic:
deploy_command += " --atomic"

if force:
deploy_command += " --force"

if disable_hook:
deploy_command += " --no-hooks"

if release_values != {}:
try:
import tempfile
except ImportError:
module.fail_json(
msg=missing_required_lib("tempfile"),
exception=traceback.format_exc(),
stdout='',
stderr='',
command='',
)

fd, path = tempfile.mkstemp(suffix='.yml')
with open(path, 'w') as yaml_file:
yaml.dump(release_values, yaml_file, default_flow_style=False)
Expand Down Expand Up @@ -402,6 +400,7 @@ def main():
purge=dict(type='bool', default=True),
wait=dict(type='bool', default=False),
wait_timeout=dict(type='str'),
atomic=dict(type='bool', default=False),
),
required_if=[
('release_state', 'present', ['release_name', 'chart_ref']),
Expand Down Expand Up @@ -433,6 +432,7 @@ def main():
purge = module.params.get('purge')
wait = module.params.get('wait')
wait_timeout = module.params.get('wait_timeout')
atomic = module.params.get('atomic')

if bin_path is not None:
helm_cmd_common = bin_path
Expand Down Expand Up @@ -471,13 +471,13 @@ def main():

if release_status is None: # Not installed
helm_cmd = deploy(helm_cmd, release_name, release_values, chart_ref, wait, wait_timeout,
disable_hook, False)
disable_hook, False, atomic=atomic)
changed = True

elif force or release_values != release_status['values'] \
or (chart_info['name'] + '-' + chart_info['version']) != release_status["chart"]:
helm_cmd = deploy(helm_cmd, release_name, release_values, chart_ref, wait, wait_timeout,
disable_hook, force)
disable_hook, force, atomic=atomic)
changed = True

if module.check_mode:
Expand Down