Class: HelmCLI
- Inherits:
-
Object
show all
- Defined in:
- lib/helm-cli.rb,
lib/helm-cli/version.rb
Defined Under Namespace
Classes: HelmError, InstallError, MissingReleaseError, UpgradeError
Constant Summary
collapse
- VERSION =
'0.2.0'
Instance Attribute Summary collapse
Instance Method Summary
collapse
-
#add_repo(name, url) ⇒ Object
-
#get_release(release, namespace: 'default') ⇒ Object
-
#initialize(kubeconfig_path, executable = HelmRb.executable) ⇒ HelmCLI
constructor
A new instance of HelmCLI.
-
#install_chart(chart, release:, version:, namespace: 'default', params: {}) ⇒ Object
-
#last_status ⇒ Object
-
#release_exists?(release, namespace: 'default') ⇒ Boolean
-
#update_repos ⇒ Object
-
#upgrade_chart(chart, release:, version:, namespace: 'default', params: {}) ⇒ Object
Constructor Details
#initialize(kubeconfig_path, executable = HelmRb.executable) ⇒ HelmCLI
Returns a new instance of HelmCLI.
12
13
14
15
|
# File 'lib/helm-cli.rb', line 12
def initialize(kubeconfig_path, executable = HelmRb.executable)
@kubeconfig_path = kubeconfig_path
@executable = executable
end
|
Instance Attribute Details
#executable ⇒ Object
Returns the value of attribute executable.
10
11
12
|
# File 'lib/helm-cli.rb', line 10
def executable
@executable
end
|
#kubeconfig_path ⇒ Object
Returns the value of attribute kubeconfig_path.
10
11
12
|
# File 'lib/helm-cli.rb', line 10
def kubeconfig_path
@kubeconfig_path
end
|
Instance Method Details
#add_repo(name, url) ⇒ Object
21
22
23
24
|
# File 'lib/helm-cli.rb', line 21
def add_repo(name, url)
cmd = base_cmd + ['repo', 'add', name, url]
systemm(cmd)
end
|
#get_release(release, namespace: 'default') ⇒ Object
31
32
33
34
35
36
37
38
39
|
# File 'lib/helm-cli.rb', line 31
def get_release(release, namespace: 'default')
cmd = base_cmd + ['get', 'all', release, '-n', namespace]
backticks(cmd).tap do
unless last_status.success?
raise MissingReleaseError, "could not get release '#{release}': helm "\
"exited with status code #{last_status.exitstatus}"
end
end
end
|
#install_chart(chart, release:, version:, namespace: 'default', params: {}) ⇒ Object
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/helm-cli.rb', line 48
def install_chart(chart, release:, version:, namespace: 'default', params: {})
cmd = base_cmd + ['install', release, chart]
cmd += ['--version', version]
cmd += ['-n', namespace]
params.each_pair do |key, value|
cmd += ['--set', "#{key}=#{value}"]
end
systemm(cmd)
unless last_status.success?
raise InstallError, "could not install chart '#{release}': helm "\
"exited with status code #{last_status.exitstatus}"
end
end
|
#last_status ⇒ Object
17
18
19
|
# File 'lib/helm-cli.rb', line 17
def last_status
Thread.current[status_key]
end
|
#release_exists?(release, namespace: 'default') ⇒ Boolean
41
42
43
44
45
46
|
# File 'lib/helm-cli.rb', line 41
def release_exists?(release, namespace: 'default')
get_release(release, namespace: namespace)
last_status.exitstatus == 0
rescue MissingReleaseError
false
end
|
#update_repos ⇒ Object
26
27
28
29
|
# File 'lib/helm-cli.rb', line 26
def update_repos
cmd = base_cmd + ['repo', 'update']
systemm(cmd)
end
|
#upgrade_chart(chart, release:, version:, namespace: 'default', params: {}) ⇒ Object
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
# File 'lib/helm-cli.rb', line 65
def upgrade_chart(chart, release:, version:, namespace: 'default', params: {})
cmd = base_cmd + ['upgrade', release, chart]
cmd += ['--version', version]
cmd += ['-n', namespace]
params.each_pair do |key, value|
cmd += ['--set', "#{key}=#{value}"]
end
systemm(cmd)
unless last_status.success?
raise InstallError, "could not upgrade chart '#{release}': helm "\
"exited with status code #{last_status.exitstatus}"
end
end
|