helm-wrapper 1.0.1 → 1.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 23a98e1d049b80c3d5a7c4f78349d3c7cfee900b3ccc2d2d07253a8f5db77b41
4
- data.tar.gz: c4ad848608a1ac99eebfe8ed0e22cd51baa1c1a5369fd3ee5a30c4435b3f0b43
3
+ metadata.gz: 64fe7756c771f5de17023c164a926696c6514315542e35b444ef31d4396ac130
4
+ data.tar.gz: 79334dd60dfc68de644ca511ebefde9b2382ca13bbb7f65e7347868337a13aa8
5
5
  SHA512:
6
- metadata.gz: 8d4867c74ca557cab7e1f61d2ba8f26b6db6414f04cd21d20b447e192d31fab91553dd339aca23ba923c839ef6d47babe7c7f675188080260a536ab1a071313b
7
- data.tar.gz: 062e697684c166bff0c388031947575bbc8c39a39b0571ea072b2e74724abb2549f987fd911be6ebf0e733a053220a0e2f44f0ecf3b2bad13a41570cef46bf6d
6
+ metadata.gz: e69d4b002536594076ac8476f791a4e5b0fe3c2062de5cf5f4225e6df1919e21eb19b4ba362ed430d36cc2f01e8bda9edd14ab1f0cc2fa1701955c2d46944b61
7
+ data.tar.gz: 681c5bc705a01aa22730f6994ac975785701c16d1f39ef0265851cccfdf81404ea97d75b9a8edc868871ff51cdd1dc2a70bd89528411b9bf44698822ef60d76c
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 release: #{release}...")
27
27
 
28
28
  @logger.fatal("Options must be specified as a hash!") unless options.kind_of?(Hash)
29
29
 
@@ -33,15 +33,19 @@ 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
38
+ chart_options["release"] = release
37
39
  chart_options["version"] = options.key?("chart-version") ? options["chart-version"] : String.new
38
40
 
39
41
  config_options = Hash.new
42
+ config_options["atomic"] = options.key?("config-atomic") ? options["config-atomic"] : false
40
43
  config_options["auth-azure"] = options.key?("config-auth-azure") ? options["config-auth-azure"] : false
41
44
  config_options["auth-azure-options"] = options.key?("config-auth-azure-options") ? options["config-auth-azure-options"] : Hash.new
42
45
  config_options["base"] = options.key?("config-base") ? options["config-base"] : File.join(Dir.pwd, "config")
43
46
  config_options["namespace"] = namespace
44
- config_options["release"] = release
47
+ config_options["timeout"] = options.key?("config-timeout") ? options["config-timeout"] : "5m0s"
48
+ config_options["wait"] = options.key?("config-wait") ? options["config-wait"] : true
45
49
 
46
50
  binary = HelmWrapper::Shared::Binary.new(options: binary_options)
47
51
  chart = HelmWrapper::Shared::Chart.new(options: chart_options)
@@ -50,6 +54,34 @@ module HelmWrapper
50
54
  tasks << HelmWrapper::Tasks::Apply.new(binary: binary, chart: chart, options: config_options)
51
55
  tasks << HelmWrapper::Tasks::Binary.new(binary: binary)
52
56
  tasks << HelmWrapper::Tasks::Destroy.new(binary: binary, chart: chart, options: config_options)
57
+ tasks << HelmWrapper::Tasks::Template.new(binary: binary, chart: chart, options: config_options)
58
+ return tasks
59
+ end
60
+
61
+ ###############################################################################
62
+
63
+ def self.development_tasks(chart:, path:, options: Hash.new)
64
+ @logger.info("Building development tasks for path: #{path}...")
65
+
66
+ @logger.fatal("Options must be specified as a hash!") unless options.kind_of?(Hash)
67
+
68
+ binary_options = Hash.new
69
+ binary_options["base"] = options.key?("binary-base") ? options["binary-base"] : File.join(Dir.pwd, "vendor", "helm")
70
+ binary_options["version"] = options.key?("binary-version") ? options["binary-version"] : Shared::Latest.instance.version
71
+
72
+ chart_options = Hash.new
73
+ chart_options["name"] = chart
74
+ chart_options["path"] = path
75
+ chart_options["repos"] = options.key?("chart-repos") ? options["chart-repos"] : Array.new
76
+ chart_options["version"] = String.new
77
+
78
+ binary = HelmWrapper::Shared::Binary.new(options: binary_options)
79
+ chart = HelmWrapper::Shared::Chart.new(options: chart_options)
80
+
81
+ tasks = Array.new
82
+ tasks << HelmWrapper::Tasks::Binary.new(binary: binary)
83
+ tasks << HelmWrapper::Tasks::Push.new(binary: binary, chart: chart)
84
+ tasks << HelmWrapper::Tasks::Validate.new(binary: binary, chart: chart)
53
85
  return tasks
54
86
  end
55
87
 
@@ -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,7 +18,9 @@ module HelmWrapper
18
18
 
19
19
  attr_reader :artefact
20
20
  attr_reader :name
21
+ attr_reader :path
21
22
  attr_reader :oci
23
+ attr_reader :release
22
24
  attr_reader :version
23
25
 
24
26
  ###############################################################################
@@ -29,6 +31,19 @@ module HelmWrapper
29
31
 
30
32
  @name = options["name"]
31
33
 
34
+ unless options["path"].nil? then
35
+ logger.fatal("Chart path must be a string!") unless options["path"].kind_of?(String)
36
+ logger.fatal("Chart path must not be blank!") if options["path"].strip.empty?
37
+ logger.fatal("Chart path must exist!") unless File.directory?(options["path"])
38
+ end
39
+
40
+ @path = options["path"]
41
+
42
+ logger.fatal("Chart release instance must be a string!") unless options["release"].kind_of?(String)
43
+ logger.fatal("Chart release instance must not be blank!") if options["release"].strip.empty?
44
+
45
+ @release = options["release"]
46
+
32
47
  logger.fatal("Chart version must be a string!") unless options["version"].kind_of?(String)
33
48
 
34
49
  @version = options["version"]
@@ -40,7 +55,11 @@ module HelmWrapper
40
55
  @oci = Array.new
41
56
  @artefact = Array.new
42
57
 
43
- repos.each do |repo|
58
+ repos.each do |repo| logger.fatal("Configuration name must be a string!") unless options["name"].kind_of?(String)
59
+ logger.fatal("Configuration name must not be blank!") if options["name"].strip.empty?
60
+
61
+ @name = options["name"]
62
+
44
63
  logger.fatal("All elements of chart repos must be hashes!") unless repo.kind_of?(Hash)
45
64
 
46
65
  logger.fatal("Chart repo: #{hash["name"]} must have a type attribute!") unless repo.key?("type")
@@ -68,23 +87,13 @@ module HelmWrapper
68
87
  logger.fatal("Chart repo: #{hash["name"]} username must be a string!") unless repo["username"].kind_of?(String)
69
88
  logger.fatal("Chart repo: #{hash["name"]} username must not be blank!") if repo["username"].strip.empty?
70
89
 
71
- repo_username = repo["username"].strip
72
-
73
- logger.fatal("Chart repo: #{hash["name"]} username attribute must refer to a valid environment variable that holds the actual repository username!") unless ENV.key?(repo_username)
74
- logger.fatal("Environment variable holding the username for chart repo: #{hash["name"]} is blank!") if ENV[repo_username].strip.empty?
75
-
76
- hash["username"] = ENV[repo_username].strip
90
+ hash["username"] = repo["username"].strip
77
91
 
78
92
  logger.fatal("Chart repo: #{hash["name"]} must have a password attribute if 'username' is set!") unless repo.key?("password")
79
93
  logger.fatal("Chart repo: #{hash["name"]} password must be a string!") unless repo["password"].kind_of?(String)
80
94
  logger.fatal("Chart repo: #{hash["name"]} password must not be blank!") if repo["password"].strip.empty?
81
95
 
82
- repo_password = repo["password"].strip
83
-
84
- logger.fatal("Chart repo: #{hash["name"]} password attribute must refer to a valid environment variable that holds the actual repository password!") unless ENV.key?(repo_password)
85
- logger.fatal("Environment variable holding the password for chart repo: #{hash["name"]} is blank!") if ENV[repo_password].strip.empty?
86
-
87
- hash["password"] = ENV[repo_password].strip
96
+ hash["password"] = repo["password"].strip
88
97
  else
89
98
  fatal("Chart repo: #{hash["name"]} is an OCI repository therefore must have a username attribute! Public OCI repositories do not need to be declared.") if is_oci
90
99
  hash["username"] = nil
@@ -24,18 +24,24 @@ module HelmWrapper
24
24
 
25
25
  ###############################################################################
26
26
 
27
+ attr_reader :atomic
27
28
  attr_reader :auths
28
29
  attr_reader :base
29
30
  attr_reader :chart
30
31
  attr_reader :name
31
32
  attr_reader :namespace
32
33
  attr_reader :path
33
- attr_reader :release
34
+ attr_reader :timeout
34
35
  attr_reader :variables
36
+ attr_reader :wait
35
37
 
36
38
  ###############################################################################
37
39
 
38
40
  def initialize(chart:, options:)
41
+ logger.fatal("Configuration atomic mode must be a boolean!") unless [ true, false ].include?(options["atomic"])
42
+
43
+ @atomic = options["atomic"]
44
+
39
45
  logger.fatal("Configuration base path must be a string!") unless options["base"].kind_of?(String)
40
46
  logger.fatal("Configuration base path must not be blank!") if options["base"].strip.empty?
41
47
 
@@ -46,44 +52,60 @@ module HelmWrapper
46
52
 
47
53
  @name = options["name"]
48
54
 
49
- logger.fatal("Configuration destination namespace must be a string!") unless options["namespace"].kind_of?(String)
50
- logger.fatal("Configuration destination namespace must not be blank!") if options["namespace"].strip.empty?
51
-
52
- namespace = options["namespace"]
55
+ logger.fatal("Configuration wait timeout must be a string!") unless options["timeout"].kind_of?(String)
56
+ logger.fatal("Configuration wait timeout must not be blank!") if options["timeout"].strip.empty?
53
57
 
54
- logger.fatal("Configuration release name must be a string!") unless options["release"].kind_of?(String)
55
- logger.fatal("Configuration release name must not be blank!") if options["release"].strip.empty?
58
+ @timeout = options["timeout"]
56
59
 
57
- release = options["release"]
58
-
59
- logger.fatal("Configuration authenticator for Azure enabled must be a Boolean!") unless [ true, false ].include?(options["auth-azure"])
60
+ logger.fatal("Configuration authenticator for Azure enabled must be a boolean!") unless [ true, false ].include?(options["auth-azure"])
60
61
 
61
62
  auth_azure = options["auth-azure"]
62
63
 
63
- logger.fatal("Configuration authenticator for Azure options must be a Hash!") unless options["auth-azure-options"].kind_of?(Hash)
64
+ logger.fatal("Configuration authenticator for Azure options must be a hash!") unless options["auth-azure-options"].kind_of?(Hash)
64
65
 
65
66
  auth_azure_options = options["auth-azure-options"]
66
67
 
68
+ logger.fatal("Configuration destination namespace must be a string!") unless options["namespace"].kind_of?(String)
69
+ logger.fatal("Configuration destination namespace must not be blank!") if options["namespace"].strip.empty?
70
+
71
+ namespace = options["namespace"]
72
+
73
+ logger.fatal("Configuration wait mode must be a boolean!") unless [ true, false ].include?(options["wait"])
74
+
75
+ wait = options["wait"]
76
+
67
77
  @chart = chart
68
78
  @path = ::HelmWrapper.find(base: @base, name: @name, exts: @@config_exts, description: "Configuration")
79
+ @wait = (not @atomic) and wait
69
80
 
70
81
  yaml = YAML.load(File.read(@path))
71
82
  logger.fatal("Invalid YAML in configuration file: #{@path}") unless yaml.kind_of?(Hash)
72
83
 
73
84
  identifers = yaml.key?("identifiers") ? yaml["identifiers"] : Hash.new
74
- @variables = HelmWrapper::Shared::Variables.new(chart: @chart.name, config: @name, namespace: namespace, release: release, identifiers: identifers)
75
- @variables.add_variables(variables: yaml["globals"]) if yaml.key?("globals")
85
+ @variables = HelmWrapper::Shared::Variables.new(chart: @chart.name, config: @name, namespace: namespace, release: @chart.release, identifiers: identifers)
86
+ @namespace = @variables.core[:namespace]
87
+
88
+ if yaml.key?("globals") then
89
+ logger.fatal("Key 'globals' is not a hash in configuration file: #{@path}") unless yaml["globals"].kind_of?(Hash)
90
+ globals = yaml["globals"]
91
+
92
+ @variables.add_variables(variables: globals["variables"]) if globals.key?("variables")
93
+ end
76
94
 
77
95
  if yaml.key?("helm") then
78
96
  logger.fatal("Key 'helm' is not a hash in configuration file: #{@path}") unless yaml["helm"].kind_of?(Hash)
79
97
  helm = yaml["helm"]
80
98
 
81
- @variables.add_variables(variables: helm["variables"]) if helm.key?("variables")
82
- @variables.add_files(base: @base, files: helm["files"]) if helm.key?("files")
83
- end
99
+ [ "globals", @chart.release ].each do |extra|
100
+ if helm.key?(extra) then
101
+ logger.fatal("Key '#{extra}' under 'helm' is not a hash in configuration file: #{@path}") unless helm[extra].kind_of?(Hash)
102
+ section = helm[extra]
84
103
 
85
- @namespace = @variables.core[:namespace]
86
- @release = @variables.core[:release]
104
+ @variables.add_variables(variables: section["variables"]) if section.key?("variables")
105
+ @variables.add_files(base: @base, files: section["files"]) if section.key?("files")
106
+ end
107
+ end
108
+ end
87
109
 
88
110
  @auths = Array.new
89
111
  @auths.append(HelmWrapper::Shared::Auths::Azure.new(options: auth_azure_options, variables: @variables)) if auth_azure
@@ -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)
@@ -62,28 +64,36 @@ module HelmWrapper
62
64
 
63
65
  @chart.oci.each_with_index do |oci_repo, oci_index|
64
66
  logger.info("Logging into OCI repository: #{oci_repo["name"]}")
67
+
68
+ username = from_environment(variable: oci_repo["username"])
69
+ password = from_environment(variable: oci_repo["password"])
70
+
65
71
  @chart.oci_active(active: true, index: oci_index)
66
72
 
67
73
  parameters = Array.new
68
74
  parameters.append("login")
69
75
  parameters.append("\"#{oci_repo["url"]}\"")
70
- parameters.append("--username=\"#{oci_repo["username"]}\"")
76
+ parameters.append("--username=\"#{username}\"")
71
77
  parameters.append("--password-stdin")
72
- logger.fatal("Failed to login to Helm OCI repository: #{oci_repo["name"]}, url: #{oci_repo["url"]}") unless run(action: "registry", parameters: parameters, stdin: oci_repo["password"])
78
+ logger.fatal("Failed to login to Helm OCI repository: #{oci_repo["name"]}, url: #{oci_repo["url"]}") unless run(action: "registry", parameters: parameters, stdin: password)
73
79
  end
74
80
 
75
81
  if @chart.artefact.length > 0 then
76
82
 
77
83
  @chart.artefact.each_with_index do |artefact_repo, artefact_index|
78
84
  logger.info("Adding artefact repository: #{artefact_repo["name"]}")
85
+
86
+ username = artefact_repo["username"].nil? ? nil : from_environment(variable: artefact_repo["username"])
87
+ password = artefact_repo["password"].nil? ? nil : from_environment(variable: artefact_repo["password"])
88
+
79
89
  @chart.artefact_active(active: true, index: artefact_index)
80
90
 
81
91
  parameters = Array.new
82
92
  parameters.append("add")
83
93
  parameters.append("\"#{artefact_repo["name"]}\"")
84
94
  parameters.append("\"#{artefact_repo["url"]}\"")
85
- parameters.append("--username=\"#{artefact_repo["username"]}\"") unless artefact_repo["username"].nil?
86
- parameters.append("--password=\"#{artefact_repo["password"]}\"") unless artefact_repo["password"].nil?
95
+ parameters.append("--username=\"#{username}\"") unless username.nil?
96
+ parameters.append("--password=\"#{password}\"") unless password.nil?
87
97
  parameters.append("--force-update") if force
88
98
  logger.fatal("Failed to add Helm repository: #{artefact_repo["name"]}, url: #{artefact_repo["url"]}") unless run(action: "repo", parameters: parameters)
89
99
  end
@@ -105,26 +115,48 @@ module HelmWrapper
105
115
  ###############################################################################
106
116
 
107
117
  def delete()
118
+ logger.fatal("Cannot Helm delete without a valid configuration!") if @config.nil?
108
119
  logger.fatal("Cannot Helm delete before initialising authenticators!") unless auths
109
120
 
110
121
  parameters = Array.new
111
122
  parameters.append("--namespace=\"#{@config.namespace}\"")
112
- parameters.append(@config.release)
123
+ parameters.append("\"#{@chart.release}\"")
113
124
 
114
125
  logger.fatal("Helm delete failed!") unless run(action: "delete", parameters: parameters)
115
126
  end
116
127
 
128
+ ###############################################################################
129
+
130
+ def template()
131
+ logger.fatal("Cannot Helm template without a valid configuration!") if @config.nil?
132
+ logger.fatal("Cannot Helm template before initialising repositories!") unless repos
133
+
134
+ parameters = Array.new
135
+ parameters.append("--namespace=\"#{@config.namespace}\"")
136
+ parameters.append("\"#{@chart.release}\"")
137
+ parameters.append("\"#{@chart.name}\"")
138
+ parameters.append("--version=\"#{@chart.version}\"") unless @chart.version.strip.empty?
139
+ parameters.concat(variable_files)
140
+ parameters.concat(variable_strings)
141
+
142
+ logger.fatal("Helm template failed!") unless run(action: "template", parameters: parameters)
143
+ end
144
+
117
145
  ###############################################################################
118
146
 
119
147
  def upgrade(install: true)
148
+ logger.fatal("Cannot Helm upgrade without a valid configuration!") if @config.nil?
120
149
  logger.fatal("Cannot Helm upgrade before initialising authenticators!") unless auths
121
150
  logger.fatal("Cannot Helm upgrade before initialising repositories!") unless repos
122
151
 
123
152
  parameters = Array.new
124
153
  parameters.append("--namespace=\"#{@config.namespace}\"")
125
154
  parameters.append("--install") if install
126
- parameters.append(@config.release)
127
- parameters.append(@chart.name)
155
+ parameters.append("\"#{@chart.release}\"")
156
+ parameters.append("\"#{@chart.name}\"")
157
+ parameters.append("--atomic") if @config.atomic
158
+ parameters.append("--wait") if @config.wait
159
+ parameters.append("--timeout=\"#{@config.timeout}\"") if (@config.atomic or @config.wait)
128
160
  parameters.append("--version=\"#{@chart.version}\"") unless @chart.version.strip.empty?
129
161
  parameters.concat(variable_files)
130
162
  parameters.concat(variable_strings)
@@ -132,6 +164,38 @@ module HelmWrapper
132
164
  logger.fatal("Helm upgrade failed!") unless run(action: "upgrade", parameters: parameters)
133
165
  end
134
166
 
167
+ ###############################################################################
168
+
169
+ def lint()
170
+ parameters = Array.new
171
+ parameters.append("\"#{@chart.path}\"")
172
+
173
+ logger.fatal("Helm validate failed!") unless run(action: "lint", parameters: parameters)
174
+ end
175
+
176
+ ###############################################################################
177
+
178
+ def push(tag:)
179
+ logger.fatal("Cannot Helm push before initialising repositories!") unless repos
180
+
181
+ parameters = Array.new
182
+ parameters.append("push")
183
+ parameters.append("\"#{@chart.name}:#{tag}\"")
184
+
185
+ logger.fatal("Helm push failed!") unless run(action: "chart", parameters: parameters)
186
+ end
187
+
188
+ ###############################################################################
189
+
190
+ def save(tag:)
191
+ parameters = Array.new
192
+ parameters.append("save")
193
+ parameters.append("\"#{@chart.path}\"")
194
+ parameters.append("\"#{@chart.name}:#{tag}\"")
195
+
196
+ logger.fatal("Helm save failed!") unless run(action: "chart", parameters: parameters)
197
+ end
198
+
135
199
  ###############################################################################
136
200
 
137
201
  private
@@ -234,6 +298,15 @@ module HelmWrapper
234
298
  return result
235
299
  end
236
300
 
301
+ ###############################################################################
302
+
303
+ def from_environment(variable:)
304
+ logger.fatal("Environment variable: #{variable} does not exist") unless ENV.key?(variable)
305
+ logger.fatal("Environment variable: #{variable} is blank!") if ENV[variable].strip.empty?
306
+
307
+ return ENV[variable].strip
308
+ end
309
+
237
310
  ###############################################################################
238
311
 
239
312
  end
@@ -35,15 +35,14 @@ module HelmWrapper
35
35
  core[:chart] = chart
36
36
  core[:config] = config
37
37
  core[:namespace] = nil
38
- core[:release] = nil
38
+ core[:release] = release
39
39
 
40
40
  user = cleanse(variables: identifiers, reserved: core.keys)
41
41
 
42
42
  begin
43
43
  core[:namespace] = namespace % user
44
- core[:release] = release % user
45
44
  rescue
46
- logger.fatal("Provided configuration options include identifiers that are not included in the configuration file!")
45
+ logger.fatal("Provided namespace includes identifiers that are not included in the configuration file!")
47
46
  end
48
47
 
49
48
  merged = core.merge(user)
@@ -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
  ###############################################################################
@@ -45,7 +45,7 @@ module HelmWrapper
45
45
  config = HelmWrapper::Shared::Config.new(chart: @chart, options: options)
46
46
  runner = HelmWrapper::Shared::Runner.new(binary: @binary, chart: @chart, config: config)
47
47
 
48
- logger.info("Running Helm upgrade for release: #{config.release}, namespace: #{config.namespace}...")
48
+ logger.info("Running Helm upgrade for release: #{@chart.release}, namespace: #{config.namespace}...")
49
49
 
50
50
  begin
51
51
  runner.init_repos
@@ -44,7 +44,7 @@ module HelmWrapper
44
44
  config = HelmWrapper::Shared::Config.new(chart: @chart, options: options)
45
45
  runner = HelmWrapper::Shared::Runner.new(binary: @binary, chart: @chart, config: config)
46
46
 
47
- logger.info("Running Helm delete for release: #{config.release}, namespace: #{config.namespace}...")
47
+ logger.info("Running Helm delete for release: #{@chart.release}, namespace: #{config.namespace}...")
48
48
 
49
49
  begin
50
50
  runner.init_auths
@@ -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: #{@chart.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.3.1"
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.3.1
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-11 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: