helm-wrapper 1.1.0 → 1.4.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: 6c095374280df3b7dba01263e1122dd7d14903a18fb861219627685384f60aef
4
- data.tar.gz: a758c37877f7e813676603ab4db1fbb43207f60d64ddce7e488bec8b85b719ab
3
+ metadata.gz: adfede6ac33bcec8e6948dc9a0501b2ef86c36b985800badb621e64345d697d4
4
+ data.tar.gz: f2c9b7a4746def6c1e9c614710e3c5ba7cedf4bbc6797cbd75f319c6c4a09d12
5
5
  SHA512:
6
- metadata.gz: 0b92b882982cd95087c102d88313350278feccca52a0b2ccdafa883f7cf7b639419ef773272192ceabbf95358c37ca19ca6e7e25fcba9e49882effe40599cf70
7
- data.tar.gz: 2c79ed943dd0059f39a779b6f99459f84da16db76442e7a4f9b3ecedfac93f5cd44d658c663c0c62446f9b5975ab96ff9be2d0d14e5da46dfe17c007da4e05aa
6
+ metadata.gz: 947a1995f242c0a4dd5dca6b931f2d5acf0fc55488dec0a5df1399a9d110e729bd5b46d607eb9cb88a01e5e93c29088bb2cd205834f17cb0f7cb015f4d4c75a7
7
+ data.tar.gz: 87647c76ea61672ded735f840d7a3d9bf3a42587d74b3c7f34196adc99894c0ea47d04ef94ba3ac8bed4c2e078c24346f6ff77ae6d1f55b1e591520311e72eaf
data/lib/helm-wrapper.rb CHANGED
@@ -23,7 +23,7 @@ module HelmWrapper
23
23
  ###############################################################################
24
24
 
25
25
  def self.deployment_tasks(chart:, namespace:, release:, options: Hash.new)
26
- @logger.info("Building deployment tasks for chart: #{chart}...")
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
 
@@ -38,11 +38,14 @@ module HelmWrapper
38
38
  chart_options["version"] = options.key?("chart-version") ? options["chart-version"] : String.new
39
39
 
40
40
  config_options = Hash.new
41
+ config_options["atomic"] = options.key?("config-atomic") ? options["config-atomic"] : false
41
42
  config_options["auth-azure"] = options.key?("config-auth-azure") ? options["config-auth-azure"] : false
42
43
  config_options["auth-azure-options"] = options.key?("config-auth-azure-options") ? options["config-auth-azure-options"] : Hash.new
43
44
  config_options["base"] = options.key?("config-base") ? options["config-base"] : File.join(Dir.pwd, "config")
44
45
  config_options["namespace"] = namespace
45
46
  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
46
49
 
47
50
  binary = HelmWrapper::Shared::Binary.new(options: binary_options)
48
51
  chart = HelmWrapper::Shared::Chart.new(options: chart_options)
@@ -30,10 +30,6 @@ module HelmWrapper
30
30
 
31
31
  @name = options["name"]
32
32
 
33
- logger.fatal("Chart version must be a string!") unless options["version"].kind_of?(String)
34
-
35
- @version = options["version"]
36
-
37
33
  unless options["path"].nil? then
38
34
  logger.fatal("Chart path must be a string!") unless options["path"].kind_of?(String)
39
35
  logger.fatal("Chart path must not be blank!") if options["path"].strip.empty?
@@ -42,6 +38,10 @@ module HelmWrapper
42
38
 
43
39
  @path = options["path"]
44
40
 
41
+ logger.fatal("Chart version must be a string!") unless options["version"].kind_of?(String)
42
+
43
+ @version = options["version"]
44
+
45
45
  logger.fatal("Chart repos must be a list of hashes!") unless options["repos"].kind_of?(Array)
46
46
 
47
47
  repos = options["repos"]
@@ -49,7 +49,11 @@ module HelmWrapper
49
49
  @oci = Array.new
50
50
  @artefact = Array.new
51
51
 
52
- repos.each do |repo|
52
+ repos.each do |repo| logger.fatal("Configuration name must be a string!") unless options["name"].kind_of?(String)
53
+ logger.fatal("Configuration name must not be blank!") if options["name"].strip.empty?
54
+
55
+ @name = options["name"]
56
+
53
57
  logger.fatal("All elements of chart repos must be hashes!") unless repo.kind_of?(Hash)
54
58
 
55
59
  logger.fatal("Chart repo: #{hash["name"]} must have a type attribute!") unless repo.key?("type")
@@ -77,23 +81,13 @@ module HelmWrapper
77
81
  logger.fatal("Chart repo: #{hash["name"]} username must be a string!") unless repo["username"].kind_of?(String)
78
82
  logger.fatal("Chart repo: #{hash["name"]} username must not be blank!") if repo["username"].strip.empty?
79
83
 
80
- repo_username = repo["username"].strip
81
-
82
- 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)
83
- logger.fatal("Environment variable holding the username for chart repo: #{hash["name"]} is blank!") if ENV[repo_username].strip.empty?
84
-
85
- hash["username"] = ENV[repo_username].strip
84
+ hash["username"] = repo["username"].strip
86
85
 
87
86
  logger.fatal("Chart repo: #{hash["name"]} must have a password attribute if 'username' is set!") unless repo.key?("password")
88
87
  logger.fatal("Chart repo: #{hash["name"]} password must be a string!") unless repo["password"].kind_of?(String)
89
88
  logger.fatal("Chart repo: #{hash["name"]} password must not be blank!") if repo["password"].strip.empty?
90
89
 
91
- repo_password = repo["password"].strip
92
-
93
- 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)
94
- logger.fatal("Environment variable holding the password for chart repo: #{hash["name"]} is blank!") if ENV[repo_password].strip.empty?
95
-
96
- hash["password"] = ENV[repo_password].strip
90
+ hash["password"] = repo["password"].strip
97
91
  else
98
92
  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
99
93
  hash["username"] = nil
@@ -24,18 +24,25 @@ 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
- attr_reader :path
33
33
  attr_reader :release
34
+ attr_reader :path
35
+ attr_reader :timeout
34
36
  attr_reader :variables
37
+ attr_reader :wait
35
38
 
36
39
  ###############################################################################
37
40
 
38
41
  def initialize(chart:, options:)
42
+ logger.fatal("Configuration atomic mode must be a boolean!") unless [ true, false ].include?(options["atomic"])
43
+
44
+ @atomic = options["atomic"]
45
+
39
46
  logger.fatal("Configuration base path must be a string!") unless options["base"].kind_of?(String)
40
47
  logger.fatal("Configuration base path must not be blank!") if options["base"].strip.empty?
41
48
 
@@ -46,44 +53,65 @@ module HelmWrapper
46
53
 
47
54
  @name = options["name"]
48
55
 
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"]
53
-
54
56
  logger.fatal("Configuration release name must be a string!") unless options["release"].kind_of?(String)
55
57
  logger.fatal("Configuration release name must not be blank!") if options["release"].strip.empty?
56
58
 
57
- release = options["release"]
59
+ @release = options["release"]
60
+
61
+ logger.fatal("Configuration wait timeout must be a string!") unless options["timeout"].kind_of?(String)
62
+ logger.fatal("Configuration wait timeout must not be blank!") if options["timeout"].strip.empty?
58
63
 
59
- logger.fatal("Configuration authenticator for Azure enabled must be a Boolean!") unless [ true, false ].include?(options["auth-azure"])
64
+ @timeout = options["timeout"]
65
+
66
+ logger.fatal("Configuration authenticator for Azure enabled must be a boolean!") unless [ true, false ].include?(options["auth-azure"])
60
67
 
61
68
  auth_azure = options["auth-azure"]
62
69
 
63
- logger.fatal("Configuration authenticator for Azure options must be a Hash!") unless options["auth-azure-options"].kind_of?(Hash)
70
+ logger.fatal("Configuration authenticator for Azure options must be a hash!") unless options["auth-azure-options"].kind_of?(Hash)
64
71
 
65
72
  auth_azure_options = options["auth-azure-options"]
66
73
 
74
+ logger.fatal("Configuration destination namespace must be a string!") unless options["namespace"].kind_of?(String)
75
+ logger.fatal("Configuration destination namespace must not be blank!") if options["namespace"].strip.empty?
76
+
77
+ namespace = options["namespace"]
78
+
79
+ logger.fatal("Configuration wait mode must be a boolean!") unless [ true, false ].include?(options["wait"])
80
+
81
+ wait = options["wait"]
82
+
67
83
  @chart = chart
68
84
  @path = ::HelmWrapper.find(base: @base, name: @name, exts: @@config_exts, description: "Configuration")
85
+ @wait = (not @atomic) and wait
69
86
 
70
87
  yaml = YAML.load(File.read(@path))
71
88
  logger.fatal("Invalid YAML in configuration file: #{@path}") unless yaml.kind_of?(Hash)
72
89
 
73
90
  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")
91
+ @variables = HelmWrapper::Shared::Variables.new(chart: @chart.name, config: @name, namespace: namespace, release: @release, identifiers: identifers)
92
+ @namespace = @variables.core[:namespace]
93
+
94
+ if yaml.key?("globals") then
95
+ logger.fatal("Key 'globals' is not a hash in configuration file: #{@path}") unless yaml["globals"].kind_of?(Hash)
96
+ globals = yaml["globals"]
97
+
98
+ @variables.add_variables(variables: globals["variables"]) if globals.key?("variables")
99
+ end
76
100
 
77
101
  if yaml.key?("helm") then
78
102
  logger.fatal("Key 'helm' is not a hash in configuration file: #{@path}") unless yaml["helm"].kind_of?(Hash)
79
103
  helm = yaml["helm"]
80
104
 
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
105
+ [ "globals", @release ].each do |extra|
106
+ if helm.key?(extra) then
107
+ logger.fatal("Key '#{extra}' under 'helm' is not a hash in configuration file: #{@path}") unless helm[extra].kind_of?(Hash)
108
+ section = helm[extra]
84
109
 
85
- @namespace = @variables.core[:namespace]
86
- @release = @variables.core[:release]
110
+ @variables.add_variables(variables: section["variables"]) if section.key?("variables")
111
+ @variables.add_files(base: @base, files: section["files"]) if section.key?("files")
112
+ end
113
+ end
114
+ end
87
115
 
88
116
  @auths = Array.new
89
117
  @auths.append(HelmWrapper::Shared::Auths::Azure.new(options: auth_azure_options, variables: @variables)) if auth_azure
@@ -64,28 +64,36 @@ module HelmWrapper
64
64
 
65
65
  @chart.oci.each_with_index do |oci_repo, oci_index|
66
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
+
67
71
  @chart.oci_active(active: true, index: oci_index)
68
72
 
69
73
  parameters = Array.new
70
74
  parameters.append("login")
71
75
  parameters.append("\"#{oci_repo["url"]}\"")
72
- parameters.append("--username=\"#{oci_repo["username"]}\"")
76
+ parameters.append("--username=\"#{username}\"")
73
77
  parameters.append("--password-stdin")
74
- 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)
75
79
  end
76
80
 
77
81
  if @chart.artefact.length > 0 then
78
82
 
79
83
  @chart.artefact.each_with_index do |artefact_repo, artefact_index|
80
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
+
81
89
  @chart.artefact_active(active: true, index: artefact_index)
82
90
 
83
91
  parameters = Array.new
84
92
  parameters.append("add")
85
93
  parameters.append("\"#{artefact_repo["name"]}\"")
86
94
  parameters.append("\"#{artefact_repo["url"]}\"")
87
- parameters.append("--username=\"#{artefact_repo["username"]}\"") unless artefact_repo["username"].nil?
88
- 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?
89
97
  parameters.append("--force-update") if force
90
98
  logger.fatal("Failed to add Helm repository: #{artefact_repo["name"]}, url: #{artefact_repo["url"]}") unless run(action: "repo", parameters: parameters)
91
99
  end
@@ -146,6 +154,9 @@ module HelmWrapper
146
154
  parameters.append("--install") if install
147
155
  parameters.append("\"#{@config.release}\"")
148
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)
149
160
  parameters.append("--version=\"#{@chart.version}\"") unless @chart.version.strip.empty?
150
161
  parameters.concat(variable_files)
151
162
  parameters.concat(variable_strings)
@@ -287,6 +298,15 @@ module HelmWrapper
287
298
  return result
288
299
  end
289
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
+
290
310
  ###############################################################################
291
311
 
292
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)
@@ -4,7 +4,7 @@ module HelmWrapper
4
4
 
5
5
  ###############################################################################
6
6
 
7
- VERSION = "1.1.0"
7
+ VERSION = "1.4.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.1.0
4
+ version: 1.4.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-09 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