Yuriy Taraday | 84a2103 | 2017-06-27 11:13:16 +0400 | [diff] [blame] | 1 | import logging |
| 2 | |
| 3 | from salt.serializers import yaml |
| 4 | |
| 5 | HELM_HOME = '/srv/helm/home' |
| 6 | LOG = logging.getLogger(__name__) |
| 7 | |
| 8 | def _helm_cmd(*args): |
| 9 | return { |
| 10 | 'cmd': ('helm',) + args, |
| 11 | 'env': {'HELM_HOME': HELM_HOME}, |
| 12 | } |
| 13 | |
| 14 | |
| 15 | def release_exists(name): |
| 16 | cmd = _helm_cmd('list', '--short', '--all', name) |
| 17 | return __salt__['cmd.run_stdout'](**cmd) == name |
| 18 | |
| 19 | |
| 20 | def 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 |
Yuriy Taraday | aeeaa74 | 2017-06-28 15:54:56 +0400 | [diff] [blame] | 31 | |
| 32 | |
| 33 | def release_upgrade(name, chart_name, version=None, values=None): |
| 34 | args = [] |
| 35 | if version is not None: |
| 36 | args += ['--version', version] |
| 37 | if values is not None: |
| 38 | args += ['--values', '/dev/stdin'] |
| 39 | cmd = _helm_cmd('upgrade', name, chart_name, *args) |
| 40 | if values is not None: |
| 41 | cmd['stdin'] = yaml.serialize(values, default_flow_style=False) |
| 42 | LOG.debug('Creating release with args: %s', cmd) |
| 43 | return __salt__['cmd.retcode'](**cmd) == 0 |
| 44 | |
| 45 | |
| 46 | def get_values(name): |
| 47 | cmd = _helm_cmd('get', 'values', '--all', name) |
| 48 | return yaml.deserialize(__salt__['cmd.run_stdout'](**cmd)) |