helm-wrapper 1.0.1 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 23a98e1d049b80c3d5a7c4f78349d3c7cfee900b3ccc2d2d07253a8f5db77b41
4
- data.tar.gz: c4ad848608a1ac99eebfe8ed0e22cd51baa1c1a5369fd3ee5a30c4435b3f0b43
3
+ metadata.gz: 6c095374280df3b7dba01263e1122dd7d14903a18fb861219627685384f60aef
4
+ data.tar.gz: a758c37877f7e813676603ab4db1fbb43207f60d64ddce7e488bec8b85b719ab
5
5
  SHA512:
6
- metadata.gz: 8d4867c74ca557cab7e1f61d2ba8f26b6db6414f04cd21d20b447e192d31fab91553dd339aca23ba923c839ef6d47babe7c7f675188080260a536ab1a071313b
7
- data.tar.gz: 062e697684c166bff0c388031947575bbc8c39a39b0571ea072b2e74724abb2549f987fd911be6ebf0e733a053220a0e2f44f0ecf3b2bad13a41570cef46bf6d
6
+ metadata.gz: 0b92b882982cd95087c102d88313350278feccca52a0b2ccdafa883f7cf7b639419ef773272192ceabbf95358c37ca19ca6e7e25fcba9e49882effe40599cf70
7
+ data.tar.gz: 2c79ed943dd0059f39a779b6f99459f84da16db76442e7a4f9b3ecedfac93f5cd44d658c663c0c62446f9b5975ab96ff9be2d0d14e5da46dfe17c007da4e05aa
data/lib/helm-wrapper.rb CHANGED
@@ -22,8 +22,8 @@ module HelmWrapper
22
22
 
23
23
  ###############################################################################
24
24
 
25
- def self.define_tasks(chart:, namespace:, release:, options: Hash.new)
26
- @logger.info("Building tasks for chart: #{chart}...")
25
+ def self.deployment_tasks(chart:, namespace:, release:, options: Hash.new)
26
+ @logger.info("Building deployment tasks for chart: #{chart}...")
27
27
 
28
28
  @logger.fatal("Options must be specified as a hash!") unless options.kind_of?(Hash)
29
29
 
@@ -33,6 +33,7 @@ module HelmWrapper
33
33
 
34
34
  chart_options = Hash.new
35
35
  chart_options["name"] = chart
36
+ chart_options["path"] = nil
36
37
  chart_options["repos"] = options.key?("chart-repos") ? options["chart-repos"] : Array.new
37
38
  chart_options["version"] = options.key?("chart-version") ? options["chart-version"] : String.new
38
39
 
@@ -50,6 +51,34 @@ module HelmWrapper
50
51
  tasks << HelmWrapper::Tasks::Apply.new(binary: binary, chart: chart, options: config_options)
51
52
  tasks << HelmWrapper::Tasks::Binary.new(binary: binary)
52
53
  tasks << HelmWrapper::Tasks::Destroy.new(binary: binary, chart: chart, options: config_options)
54
+ tasks << HelmWrapper::Tasks::Template.new(binary: binary, chart: chart, options: config_options)
55
+ return tasks
56
+ end
57
+
58
+ ###############################################################################
59
+
60
+ def self.development_tasks(chart:, path:, options: Hash.new)
61
+ @logger.info("Building development tasks for path: #{path}...")
62
+
63
+ @logger.fatal("Options must be specified as a hash!") unless options.kind_of?(Hash)
64
+
65
+ binary_options = Hash.new
66
+ binary_options["base"] = options.key?("binary-base") ? options["binary-base"] : File.join(Dir.pwd, "vendor", "helm")
67
+ binary_options["version"] = options.key?("binary-version") ? options["binary-version"] : Shared::Latest.instance.version
68
+
69
+ chart_options = Hash.new
70
+ chart_options["name"] = chart
71
+ chart_options["path"] = path
72
+ chart_options["repos"] = options.key?("chart-repos") ? options["chart-repos"] : Array.new
73
+ chart_options["version"] = String.new
74
+
75
+ binary = HelmWrapper::Shared::Binary.new(options: binary_options)
76
+ chart = HelmWrapper::Shared::Chart.new(options: chart_options)
77
+
78
+ tasks = Array.new
79
+ tasks << HelmWrapper::Tasks::Binary.new(binary: binary)
80
+ tasks << HelmWrapper::Tasks::Push.new(binary: binary, chart: chart)
81
+ tasks << HelmWrapper::Tasks::Validate.new(binary: binary, chart: chart)
53
82
  return tasks
54
83
  end
55
84
 
@@ -29,13 +29,14 @@ module HelmWrapper
29
29
 
30
30
  ###############################################################################
31
31
 
32
- @ca_tempfile = nil
33
- @token = nil
32
+ @keyvault
33
+ @secret_ca
34
+ @secret_endpoint
35
+ @secret_token
34
36
 
35
37
  ###############################################################################
36
38
 
37
- attr_reader :ca
38
- attr_reader :endpoint
39
+ @ca_tempfile = nil
39
40
 
40
41
  ###############################################################################
41
42
 
@@ -46,6 +47,10 @@ module HelmWrapper
46
47
  ###############################################################################
47
48
 
48
49
  def auth()
50
+ ca = secret(vault: @keyvault, name: @secret_ca)
51
+ endpoint = secret(vault: @keyvault, name: @secret_endpoint)
52
+ token = secret(vault: @keyvault, name: @secret_token)
53
+
49
54
  @ca_tempfile = Tempfile.new('helm-wrapper-auths-azure-ca')
50
55
 
51
56
  begin
@@ -57,8 +62,8 @@ module HelmWrapper
57
62
  logger.success("Azure authenticator successfully written Kubernetes CA to file!")
58
63
 
59
64
  ENV["HELM_KUBECAFILE"] = @ca_tempfile.path
60
- ENV["HELM_KUBEAPISERVER"] = @endpoint
61
- ENV["HELM_KUBETOKEN"] = @token
65
+ ENV["HELM_KUBEAPISERVER"] = endpoint
66
+ ENV["HELM_KUBETOKEN"] = token
62
67
 
63
68
  logger.success("Azure authenticator environment variables set!")
64
69
  end
@@ -109,7 +114,7 @@ module HelmWrapper
109
114
  ###############################################################################
110
115
 
111
116
  def specific()
112
- logger.fatal("Azure CLI must bpassworde installed and accessible to use the Azure authenticator.") unless cli
117
+ logger.fatal("Azure CLI must be installed and accessible to use the Azure authenticator.") unless cli
113
118
 
114
119
  logger.fatal("Azure authenticator mandatory option 'keyvault' has not been set!") unless @options.key?("keyvault")
115
120
  logger.fatal("Azure authenticator keyvault must be a string!") unless @options["keyvault"].kind_of?(String)
@@ -144,17 +149,13 @@ module HelmWrapper
144
149
  end
145
150
 
146
151
  begin
147
- keyvault = keyvault % @variables.identifiers
148
- ca = ca % @variables.identifiers
149
- endpoint = endpoint % @variables.identifiers
150
- token = token % @variables.identifiers
152
+ @keyvault = keyvault % @variables.identifiers
153
+ @secret_ca = ca % @variables.identifiers
154
+ @secret_endpoint = endpoint % @variables.identifiers
155
+ @secret_token = token % @variables.identifiers
151
156
  rescue
152
157
  logger.fatal("Azure authenticator options contain identifiers that are not included in the configuration file!")
153
158
  end
154
-
155
- @ca = secret(vault: keyvault, name: ca)
156
- @endpoint = secret(vault: keyvault, name: endpoint)
157
- @token = secret(vault: keyvault, name: token)
158
159
  end
159
160
 
160
161
  ###############################################################################
@@ -18,6 +18,7 @@ module HelmWrapper
18
18
 
19
19
  attr_reader :artefact
20
20
  attr_reader :name
21
+ attr_reader :path
21
22
  attr_reader :oci
22
23
  attr_reader :version
23
24
 
@@ -33,6 +34,14 @@ module HelmWrapper
33
34
 
34
35
  @version = options["version"]
35
36
 
37
+ unless options["path"].nil? then
38
+ logger.fatal("Chart path must be a string!") unless options["path"].kind_of?(String)
39
+ logger.fatal("Chart path must not be blank!") if options["path"].strip.empty?
40
+ logger.fatal("Chart path must exist!") unless File.directory?(options["path"])
41
+ end
42
+
43
+ @path = options["path"]
44
+
36
45
  logger.fatal("Chart repos must be a list of hashes!") unless options["repos"].kind_of?(Array)
37
46
 
38
47
  repos = options["repos"]
@@ -36,7 +36,7 @@ module HelmWrapper
36
36
 
37
37
  ###############################################################################
38
38
 
39
- def initialize(binary:, chart:, config:)
39
+ def initialize(binary:, chart:, config: nil)
40
40
  @binary = binary
41
41
  @chart = chart
42
42
  @config = config
@@ -48,6 +48,8 @@ module HelmWrapper
48
48
  ###############################################################################
49
49
 
50
50
  def init_auths()
51
+ logger.fatal("Cannot initialise authenticators without a valid configuration!") if @config.nil?
52
+
51
53
  @auths_attempted = true
52
54
 
53
55
  config.auths.map(&:auth)
@@ -105,26 +107,45 @@ module HelmWrapper
105
107
  ###############################################################################
106
108
 
107
109
  def delete()
110
+ logger.fatal("Cannot Helm delete without a valid configuration!") if @config.nil?
108
111
  logger.fatal("Cannot Helm delete before initialising authenticators!") unless auths
109
112
 
110
113
  parameters = Array.new
111
114
  parameters.append("--namespace=\"#{@config.namespace}\"")
112
- parameters.append(@config.release)
115
+ parameters.append("\"#{@config.release}\"")
113
116
 
114
117
  logger.fatal("Helm delete failed!") unless run(action: "delete", parameters: parameters)
115
118
  end
116
119
 
120
+ ###############################################################################
121
+
122
+ def template()
123
+ logger.fatal("Cannot Helm template without a valid configuration!") if @config.nil?
124
+ logger.fatal("Cannot Helm template before initialising repositories!") unless repos
125
+
126
+ parameters = Array.new
127
+ parameters.append("--namespace=\"#{@config.namespace}\"")
128
+ parameters.append("\"#{@config.release}\"")
129
+ parameters.append("\"#{@chart.name}\"")
130
+ parameters.append("--version=\"#{@chart.version}\"") unless @chart.version.strip.empty?
131
+ parameters.concat(variable_files)
132
+ parameters.concat(variable_strings)
133
+
134
+ logger.fatal("Helm template failed!") unless run(action: "template", parameters: parameters)
135
+ end
136
+
117
137
  ###############################################################################
118
138
 
119
139
  def upgrade(install: true)
140
+ logger.fatal("Cannot Helm upgrade without a valid configuration!") if @config.nil?
120
141
  logger.fatal("Cannot Helm upgrade before initialising authenticators!") unless auths
121
142
  logger.fatal("Cannot Helm upgrade before initialising repositories!") unless repos
122
143
 
123
144
  parameters = Array.new
124
145
  parameters.append("--namespace=\"#{@config.namespace}\"")
125
146
  parameters.append("--install") if install
126
- parameters.append(@config.release)
127
- parameters.append(@chart.name)
147
+ parameters.append("\"#{@config.release}\"")
148
+ parameters.append("\"#{@chart.name}\"")
128
149
  parameters.append("--version=\"#{@chart.version}\"") unless @chart.version.strip.empty?
129
150
  parameters.concat(variable_files)
130
151
  parameters.concat(variable_strings)
@@ -132,6 +153,38 @@ module HelmWrapper
132
153
  logger.fatal("Helm upgrade failed!") unless run(action: "upgrade", parameters: parameters)
133
154
  end
134
155
 
156
+ ###############################################################################
157
+
158
+ def lint()
159
+ parameters = Array.new
160
+ parameters.append("\"#{@chart.path}\"")
161
+
162
+ logger.fatal("Helm validate failed!") unless run(action: "lint", parameters: parameters)
163
+ end
164
+
165
+ ###############################################################################
166
+
167
+ def push(tag:)
168
+ logger.fatal("Cannot Helm push before initialising repositories!") unless repos
169
+
170
+ parameters = Array.new
171
+ parameters.append("push")
172
+ parameters.append("\"#{@chart.name}:#{tag}\"")
173
+
174
+ logger.fatal("Helm push failed!") unless run(action: "chart", parameters: parameters)
175
+ end
176
+
177
+ ###############################################################################
178
+
179
+ def save(tag:)
180
+ parameters = Array.new
181
+ parameters.append("save")
182
+ parameters.append("\"#{@chart.path}\"")
183
+ parameters.append("\"#{@chart.name}:#{tag}\"")
184
+
185
+ logger.fatal("Helm save failed!") unless run(action: "chart", parameters: parameters)
186
+ end
187
+
135
188
  ###############################################################################
136
189
 
137
190
  private
@@ -7,5 +7,8 @@ require 'rake/tasklib'
7
7
  require_relative 'tasks/apply'
8
8
  require_relative 'tasks/binary'
9
9
  require_relative 'tasks/destroy'
10
+ require_relative 'tasks/push'
11
+ require_relative 'tasks/template'
12
+ require_relative 'tasks/validate'
10
13
 
11
14
  ###############################################################################
@@ -0,0 +1,67 @@
1
+ ###############################################################################
2
+
3
+ module HelmWrapper
4
+
5
+ ###############################################################################
6
+
7
+ module Tasks
8
+
9
+ ###############################################################################
10
+
11
+ class Push < ::Rake::TaskLib
12
+
13
+ ###############################################################################
14
+
15
+ include HelmWrapper::Shared::Logging
16
+
17
+ ###############################################################################
18
+
19
+ @binary
20
+ @chart
21
+
22
+ ###############################################################################
23
+
24
+ def initialize(binary:, chart:)
25
+ @binary = binary
26
+ @chart = chart
27
+
28
+ yield self if block_given?
29
+
30
+ push_task
31
+ end
32
+
33
+ ###############################################################################
34
+
35
+ def push_task
36
+ desc "Pushes a Helm chart to an OCI Helm repository."
37
+ task :push, [:tag, :clean] => :binary do |t, args|
38
+ tag = (args[:tag].kind_of?(String) and (not args[:tag].strip.empty?)) ? args[:tag].strip : "latest"
39
+ clean = args[:clean].kind_of?(String) ? args[:clean].downcase == "true" : true
40
+
41
+ runner = HelmWrapper::Shared::Runner.new(binary: @binary, chart: @chart)
42
+
43
+ logger.info("Running Helm push for path: #{@chart.path}...")
44
+
45
+ begin
46
+ runner.init_repos
47
+ runner.save(tag: tag)
48
+ runner.push(tag: tag)
49
+ ensure
50
+ runner.clean(repos: clean)
51
+ end
52
+ end
53
+ end
54
+
55
+ ###############################################################################
56
+
57
+ end
58
+
59
+ ###############################################################################
60
+
61
+ end
62
+
63
+ ###############################################################################
64
+
65
+ end
66
+
67
+ ###############################################################################
@@ -0,0 +1,71 @@
1
+ ###############################################################################
2
+
3
+ module HelmWrapper
4
+
5
+ ###############################################################################
6
+
7
+ module Tasks
8
+
9
+ ###############################################################################
10
+
11
+ class Template < ::Rake::TaskLib
12
+
13
+ ###############################################################################
14
+
15
+ include HelmWrapper::Shared::Logging
16
+
17
+ ###############################################################################
18
+
19
+ @binary
20
+ @chart
21
+ @options
22
+
23
+ ###############################################################################
24
+
25
+ def initialize(binary:, chart:, options:)
26
+ @binary = binary
27
+ @chart = chart
28
+ @options = options
29
+
30
+ yield self if block_given?
31
+
32
+ template_task
33
+ end
34
+
35
+ ###############################################################################
36
+
37
+ def template_task
38
+ desc "Templates a chart with Helm for a given configuration."
39
+ task :template, [:config, :clean] => :binary do |t, args|
40
+ options = @options.merge({"name" => args[:config]})
41
+ clean = args[:clean].kind_of?(String) ? args[:clean].downcase == "true" : true
42
+
43
+ logger.info("Processing configuration for Helm template...")
44
+
45
+ config = HelmWrapper::Shared::Config.new(chart: @chart, options: options)
46
+ runner = HelmWrapper::Shared::Runner.new(binary: @binary, chart: @chart, config: config)
47
+
48
+ logger.info("Running Helm template for release: #{config.release}, namespace: #{config.namespace}...")
49
+
50
+ begin
51
+ runner.init_repos
52
+ runner.template
53
+ ensure
54
+ runner.clean(repos: clean)
55
+ end
56
+ end
57
+ end
58
+
59
+ ###############################################################################
60
+
61
+ end
62
+
63
+ ###############################################################################
64
+
65
+ end
66
+
67
+ ###############################################################################
68
+
69
+ end
70
+
71
+ ###############################################################################
@@ -0,0 +1,58 @@
1
+ ###############################################################################
2
+
3
+ module HelmWrapper
4
+
5
+ ###############################################################################
6
+
7
+ module Tasks
8
+
9
+ ###############################################################################
10
+
11
+ class Validate < ::Rake::TaskLib
12
+
13
+ ###############################################################################
14
+
15
+ include HelmWrapper::Shared::Logging
16
+
17
+ ###############################################################################
18
+
19
+ @binary
20
+ @chart
21
+
22
+ ###############################################################################
23
+
24
+ def initialize(binary:, chart:)
25
+ @binary = binary
26
+ @chart = chart
27
+
28
+ yield self if block_given?
29
+
30
+ validate_task
31
+ end
32
+
33
+ ###############################################################################
34
+
35
+ def validate_task
36
+ desc "Validates a Helm chart stored locally."
37
+ task :validate => :binary do |t, args|
38
+ runner = HelmWrapper::Shared::Runner.new(binary: @binary, chart: @chart)
39
+
40
+ logger.info("Running Helm validate for path: #{@chart.path}...")
41
+
42
+ runner.lint
43
+ end
44
+ end
45
+
46
+ ###############################################################################
47
+
48
+ end
49
+
50
+ ###############################################################################
51
+
52
+ end
53
+
54
+ ###############################################################################
55
+
56
+ end
57
+
58
+ ###############################################################################
@@ -4,7 +4,7 @@ module HelmWrapper
4
4
 
5
5
  ###############################################################################
6
6
 
7
- VERSION = "1.0.1"
7
+ VERSION = "1.1.0"
8
8
 
9
9
  ###############################################################################
10
10
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: helm-wrapper
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Lees
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-03-08 00:00:00.000000000 Z
11
+ date: 2021-03-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -58,6 +58,9 @@ files:
58
58
  - lib/helm-wrapper/tasks/apply.rb
59
59
  - lib/helm-wrapper/tasks/binary.rb
60
60
  - lib/helm-wrapper/tasks/destroy.rb
61
+ - lib/helm-wrapper/tasks/push.rb
62
+ - lib/helm-wrapper/tasks/template.rb
63
+ - lib/helm-wrapper/tasks/validate.rb
61
64
  - lib/helm-wrapper/version.rb
62
65
  homepage: https://gitlab.com/rlees85-ruby/helm-wrapper/
63
66
  licenses: