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 |