Add ability to delete releases
diff --git a/_modules/helm.py b/_modules/helm.py
index 19be742..23e28c4 100644
--- a/_modules/helm.py
+++ b/_modules/helm.py
@@ -30,6 +30,11 @@
return __salt__['cmd.retcode'](**cmd) == 0
+def release_delete(name):
+ cmd = _helm_cmd('delete', '--purge', name)
+ return __salt__['cmd.retcode'](**cmd) == 0
+
+
def release_upgrade(name, chart_name, version=None, values=None):
args = []
if version is not None:
@@ -39,7 +44,7 @@
cmd = _helm_cmd('upgrade', name, chart_name, *args)
if values is not None:
cmd['stdin'] = yaml.serialize(values, default_flow_style=False)
- LOG.debug('Creating release with args: %s', cmd)
+ LOG.debug('Upgrading release with args: %s', cmd)
return __salt__['cmd.retcode'](**cmd) == 0
diff --git a/_states/helm_release.py b/_states/helm_release.py
index 7a40899..d736045 100644
--- a/_states/helm_release.py
+++ b/_states/helm_release.py
@@ -50,3 +50,28 @@
'result': True,
'comment': 'Release "{}" was updated'.format(name),
}
+
+
+def absent(name):
+ exists = __salt__['helm.release_exists'](name)
+ if not exists:
+ return {
+ 'name': name,
+ 'changes': {},
+ 'result': True,
+ 'comment': 'Release "{}" doesn\'t exist'.format(name),
+ }
+ result = __salt__['helm.release_delete'](name)
+ if not result:
+ return {
+ 'name': name,
+ 'changes': {},
+ 'result': False,
+ 'comment': 'Failed to delete release "{}"'.format(name),
+ }
+ return {
+ 'name': name,
+ 'changes': {name: 'DELETED'},
+ 'result': True,
+ 'comment': 'Release "{}" was deleted'.format(name),
+ }
diff --git a/helm/client.sls b/helm/client.sls
index e51f15c..a4955f7 100644
--- a/helm/client.sls
+++ b/helm/client.sls
@@ -72,6 +72,7 @@
{%- for release_id, release in client.releases.items() %}
{%- set release_name = release.get('name', release_id) %}
+{%- if release.get('enabled', True) %}
ensure_{{ release_id }}_release:
helm_release.present:
- name: {{ release_name }}
@@ -85,6 +86,11 @@
{% endif %}
- require:
- cmd: wait_for_tiller
-{%- endfor %}
+{%- else %}{# not release.enabled #}
+absent_{{ release_id }}_release:
+ helm_release.absent:
+ - name: {{ release_name }}
+{%- endif %}{# release.enabled #}
+{%- endfor %}{# release_id, release in client.releases #}
{%- endif %}