helm-cli 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 263c69fab404dc53e791fb3dea4d5243f621b2722088735489be6d046e6c991f
4
+ data.tar.gz: 251cd620965589773af0c8b143f379acafe264a174382ed4140198896a294ba2
5
+ SHA512:
6
+ metadata.gz: 32ced599fa6ac9ad5d76c1ec0aea2c8bffbce523cc5c887072b9a23d4c99e81ada3c221e2eebbd67516f6769e1735528d3010ff3f5f862e65c5322d18256b6d5
7
+ data.tar.gz: 45d0797a09e4fd3aa2276fc1cca90278c8db2be563996680749e2beb0c288e9e1ec1ff0bb6a159823b811e9f489690472e9fd3f093022a3b676e70f6f4d46787
@@ -0,0 +1,2 @@
1
+ ## 0.1.0
2
+ * Birthday!
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ # Declare platform-specific gems here so they install correctly.
6
+ # See: https://github.com/rubygems/rubygems/issues/3646
7
+ gem 'helm-rb'
8
+
9
+ group :development do
10
+ gem 'rake'
11
+ end
12
+
13
+ group :test do
14
+ gem 'rspec'
15
+ end
@@ -0,0 +1,14 @@
1
+ require 'bundler'
2
+ require 'rspec/core/rake_task'
3
+ require 'rubygems/package_task'
4
+
5
+ require 'helm-cli'
6
+
7
+ Bundler::GemHelper.install_tasks
8
+
9
+ task default: :spec
10
+
11
+ desc 'Run specs'
12
+ RSpec::Core::RakeTask.new do |t|
13
+ t.pattern = './spec/**/*_spec.rb'
14
+ end
@@ -0,0 +1,18 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), 'lib')
2
+ require 'helm-cli/version'
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = 'helm-cli'
6
+ s.version = ::HelmCLI::VERSION
7
+ s.authors = ['Cameron Dutro']
8
+ s.email = ['camertron@gmail.com']
9
+ s.homepage = 'http://github.com/getkuby/helm-cli'
10
+ s.license = 'MIT'
11
+
12
+ s.description = s.summary = 'Ruby wrapper around the Helm CLI.'
13
+
14
+ s.add_dependency 'helm-rb', '~> 0.1'
15
+
16
+ s.require_path = 'lib'
17
+ s.files = Dir['{lib,spec,vendor}/**/*', 'Gemfile', 'CHANGELOG.md', 'README.md', 'Rakefile', 'helm-cli.gemspec']
18
+ end
@@ -0,0 +1,109 @@
1
+ require 'helm-rb'
2
+
3
+ class HelmCLI
4
+ class HelmError < StandardError; end
5
+
6
+ class MissingReleaseError < HelmError; end
7
+ class InstallError < HelmError; end
8
+ class UpgradeError < HelmError; end
9
+
10
+ attr_reader :kubeconfig_path, :executable
11
+
12
+ def initialize(kubeconfig_path, executable = HelmRb.executable)
13
+ @kubeconfig_path = kubeconfig_path
14
+ @executable = executable
15
+ end
16
+
17
+ def last_status
18
+ Thread.current[status_key]
19
+ end
20
+
21
+ def add_repo(name, url)
22
+ cmd = base_cmd + ['repo', 'add', name, url]
23
+ systemm(cmd)
24
+ end
25
+
26
+ def update_repos
27
+ cmd = base_cmd + ['repo', 'update']
28
+ systemm(cmd)
29
+ end
30
+
31
+ def get_release(release, namespace: 'default')
32
+ cmd = base_cmd + ['get', 'all', release, '-n', namespace]
33
+ backticks(cmd).tap do
34
+ unless last_status.success?
35
+ raise MissingReleaseError, "could not get release '#{release}': helm "\
36
+ "exited with status code #{last_status.exitstatus}"
37
+ end
38
+ end
39
+ end
40
+
41
+ def release_exists?(release, namespace: 'default')
42
+ get_release(release, namespace: namespace)
43
+ last_status.exitstatus == 0
44
+ rescue MissingReleaseError
45
+ false
46
+ end
47
+
48
+ def install_chart(chart, release:, version:, namespace: 'default', params: {})
49
+ cmd = base_cmd + ['install', release, chart]
50
+ cmd += ['--version', version]
51
+ cmd += ['-n', namespace]
52
+
53
+ params.each_pair do |key, value|
54
+ cmd += ['--set', "#{key}=#{value}"]
55
+ end
56
+
57
+ systemm(cmd)
58
+
59
+ unless last_status.success?
60
+ raise InstallError, "could not install chart '#{release}': helm "\
61
+ "exited with status code #{last_status.exitstatus}"
62
+ end
63
+ end
64
+
65
+ def upgrade_chart(chart, release:, version:, namespace: 'default', params: {})
66
+ cmd = base_cmd + ['upgrade', release, chart]
67
+ cmd += ['--version', version]
68
+ cmd += ['-n', namespace]
69
+
70
+ params.each_pair do |key, value|
71
+ cmd += ['--set', "#{key}=#{value}"]
72
+ end
73
+
74
+ systemm(cmd)
75
+
76
+ unless last_status.success?
77
+ raise InstallError, "could not upgrade chart '#{name}': helm "\
78
+ "exited with status code #{last_status.exitstatus}"
79
+ end
80
+ end
81
+
82
+ private
83
+
84
+ def base_cmd
85
+ [executable, '--kubeconfig', kubeconfig_path]
86
+ end
87
+
88
+ def backticks(cmd)
89
+ cmd_s = cmd.join(' ')
90
+ `#{cmd_s}`.tap do
91
+ self.last_status = $?
92
+ end
93
+ end
94
+
95
+ def systemm(cmd)
96
+ cmd_s = cmd.join(' ')
97
+ system(cmd_s).tap do
98
+ self.last_status = $?
99
+ end
100
+ end
101
+
102
+ def last_status=(status)
103
+ Thread.current[status_key] = status
104
+ end
105
+
106
+ def status_key
107
+ :helm_rb_cli_last_status
108
+ end
109
+ end
@@ -0,0 +1,3 @@
1
+ class HelmCLI
2
+ VERSION = '0.1.0'
3
+ end
metadata ADDED
@@ -0,0 +1,63 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: helm-cli
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Cameron Dutro
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-05-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: helm-rb
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.1'
27
+ description: Ruby wrapper around the Helm CLI.
28
+ email:
29
+ - camertron@gmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - CHANGELOG.md
35
+ - Gemfile
36
+ - Rakefile
37
+ - helm-cli.gemspec
38
+ - lib/helm-cli.rb
39
+ - lib/helm-cli/version.rb
40
+ homepage: http://github.com/getkuby/helm-cli
41
+ licenses:
42
+ - MIT
43
+ metadata: {}
44
+ post_install_message:
45
+ rdoc_options: []
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ requirements: []
59
+ rubygems_version: 3.0.6
60
+ signing_key:
61
+ specification_version: 4
62
+ summary: Ruby wrapper around the Helm CLI.
63
+ test_files: []