blob: b849676523b19f770e9af153064119ea47aad2e6 [file] [log] [blame]
Yuriy Taraday84a21032017-06-27 11:13:16 +04001import logging
2
3from salt.serializers import yaml
4
5HELM_HOME = '/srv/helm/home'
6LOG = logging.getLogger(__name__)
7
8def _helm_cmd(*args):
9 return {
10 'cmd': ('helm',) + args,
11 'env': {'HELM_HOME': HELM_HOME},
12 }
13
14
15def release_exists(name):
16 cmd = _helm_cmd('list', '--short', '--all', name)
17 return __salt__['cmd.run_stdout'](**cmd) == name
18
19
20def release_create(name, chart_name, version=None, values=None):
21 args = []
22 if version is not None:
23 args += ['--version', version]
24 if values is not None:
25 args += ['--values', '/dev/stdin']
26 cmd = _helm_cmd('install', '--name', name, chart_name, *args)
27 if values is not None:
28 cmd['stdin'] = yaml.serialize(values, default_flow_style=False)
29 LOG.debug('Creating release with args: %s', cmd)
30 return __salt__['cmd.retcode'](**cmd) == 0