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.3.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
-
#stderr ⇒ Object
-
#stderr=(new_stderr) ⇒ Object
-
#stdout ⇒ Object
-
#stdout=(new_stdout) ⇒ Object
-
#update_repos ⇒ Object
-
#upgrade_chart(chart, release:, version:, namespace: 'default', params: {}) ⇒ Object
-
#with_pipes(out = STDOUT, err = STDERR) ⇒ Object
Constructor Details
#initialize(kubeconfig_path, executable = HelmRb.executable) ⇒ HelmCLI
Returns a new instance of HelmCLI.
13
14
15
16
|
# File 'lib/helm-cli.rb', line 13
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.
11
12
13
|
# File 'lib/helm-cli.rb', line 11
def executable
@executable
end
|
#kubeconfig_path ⇒ Object
Returns the value of attribute kubeconfig_path.
11
12
13
|
# File 'lib/helm-cli.rb', line 11
def kubeconfig_path
@kubeconfig_path
end
|
Instance Method Details
#add_repo(name, url) ⇒ Object
22
23
24
25
|
# File 'lib/helm-cli.rb', line 22
def add_repo(name, url)
cmd = base_cmd + ['repo', 'add', name, url]
systemm(cmd)
end
|
#get_release(release, namespace: 'default') ⇒ Object
32
33
34
35
36
37
38
39
40
|
# File 'lib/helm-cli.rb', line 32
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/helm-cli.rb', line 49
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
18
19
20
|
# File 'lib/helm-cli.rb', line 18
def last_status
Thread.current[status_key]
end
|
#release_exists?(release, namespace: 'default') ⇒ Boolean
42
43
44
45
46
47
|
# File 'lib/helm-cli.rb', line 42
def release_exists?(release, namespace: 'default')
get_release(release, namespace: namespace)
last_status.exitstatus == 0
rescue MissingReleaseError
false
end
|
#stderr ⇒ Object
102
103
104
|
# File 'lib/helm-cli.rb', line 102
def stderr
Thread.current[stderr_key] || STDERR
end
|
#stderr=(new_stderr) ⇒ Object
106
107
108
|
# File 'lib/helm-cli.rb', line 106
def stderr=(new_stderr)
Thread.current[stderr_key] = new_stderr
end
|
#stdout ⇒ Object
94
95
96
|
# File 'lib/helm-cli.rb', line 94
def stdout
Thread.current[stdout_key] || STDOUT
end
|
#stdout=(new_stdout) ⇒ Object
98
99
100
|
# File 'lib/helm-cli.rb', line 98
def stdout=(new_stdout)
Thread.current[stdout_key] = new_stdout
end
|
#update_repos ⇒ Object
27
28
29
30
|
# File 'lib/helm-cli.rb', line 27
def update_repos
cmd = base_cmd + ['repo', 'update']
systemm(cmd)
end
|
#upgrade_chart(chart, release:, version:, namespace: 'default', params: {}) ⇒ Object
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
# File 'lib/helm-cli.rb', line 66
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
|
#with_pipes(out = STDOUT, err = STDERR) ⇒ Object
83
84
85
86
87
88
89
90
91
92
|
# File 'lib/helm-cli.rb', line 83
def with_pipes(out = STDOUT, err = STDERR)
previous_stdout = self.stdout
previous_stderr = self.stderr
self.stdout = out
self.stderr = err
yield
ensure
self.stdout = previous_stdout
self.stderr = previous_stderr
end
|