helm-wrapper 1.1.2 → 1.6.0

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: 4f2a1774f56874f1494f5d441842d3ccf9e3f72a4f781376168a00fbe29703e6
4
- data.tar.gz: 81bdd367e2eb5f6068c686b6f330731394d3c8ee4202d9a82b0ffc5b80cb4526
3
+ metadata.gz: 72fa726e0bcf42966405ff24deee6056c48963c80efd3fad168959e792474af7
4
+ data.tar.gz: 5536f1a0114a810d40ee956b57fe1b94f1ef70820bc498f44691cf553b316a83
5
5
  SHA512:
6
- metadata.gz: 6076c63eb92e478fb9da5cbbc6ca143a329077aa55f7222d22d75d570dd0dd6398fb5ccd836a0cc88f2533683b16eaed5a504f428e4c6e6837715dd5094e36e4
7
- data.tar.gz: 80676ad1ab70c79003f3834cdf5727c2ba784f9daef95f83b5e797f139e14013a66ae17a7e1183ab17adbe1b290cbff7953421493e89366e9cca7097543dbf4f
6
+ metadata.gz: 8337846abe06b68317223c7db401cd0f05357fd5e309d2edee184bdc4ee71305936621a0e8f777e4f92308957909c456801d3914fe6816f55086c7958cd93025
7
+ data.tar.gz: f6aa0aaee52bfee2598854e704285a1b1011a3b0bf334630781c684a8051183b50381340ecea5fa24238a2ab025530db914467e5edce8ee8d6457b3b2ba65d53
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")
@@ -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
@@ -154,6 +154,9 @@ module HelmWrapper
154
154
  parameters.append("--install") if install
155
155
  parameters.append("\"#{@config.release}\"")
156
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)
157
160
  parameters.append("--version=\"#{@chart.version}\"") unless @chart.version.strip.empty?
158
161
  parameters.concat(variable_files)
159
162
  parameters.concat(variable_strings)
@@ -35,22 +35,21 @@ 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
- user = cleanse(variables: identifiers, reserved: core.keys)
40
+ user = cleanse(variables: identifiers, reserved: core.keys, downcase: true)
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)
50
49
 
51
50
  @core = core
52
51
  @identifiers = sort ? merged.sort.to_h : merged
53
- @values = @identifiers
52
+ @values = Hash.new
54
53
  @files = Array.new
55
54
  end
56
55
 
@@ -99,7 +98,7 @@ module HelmWrapper
99
98
  ###############################################################################
100
99
 
101
100
  def clear_variables()
102
- @values = @identifers
101
+ @values = Hash.new
103
102
  end
104
103
 
105
104
  ###############################################################################
@@ -108,17 +107,20 @@ module HelmWrapper
108
107
 
109
108
  ###############################################################################
110
109
 
111
- def cleanse(variables:, reserved:)
110
+ def cleanse(variables:, reserved:, downcase: false)
112
111
  result = Hash.new
113
112
 
114
113
  variables.keys.each do |key|
115
114
  logger.fatal("Could not clean variables hash. All keys MUST be strings!") unless key.kind_of?(String)
116
- logger.fatal("Could not clean variables hash, key: #{key.downcase} is reserved or already in use and cannot be used!") if reserved.include?(key.downcase.to_sym)
117
- logger.fatal("Could not clean variables hash, duplicate key found: #{key.downcase}!") if result.key?(key.downcase.to_sym)
118
- logger.fatal("Could not clean variables hash, value for: #{key.downcase} is not a string!") unless variables[key].kind_of?(String)
119
- logger.fatal("Could not clean variables hash, value for: #{key.downcase} is empty!") if variables[key].strip.empty?
120
115
 
121
- result[key.downcase.to_sym] = variables[key].strip
116
+ sym = downcase ? key.downcase.to_sym : key.to_sym
117
+
118
+ logger.fatal("Could not clean variables hash, key: #{sym.to_s} is reserved or already in use and cannot be used!") if reserved.include?(sym)
119
+ logger.fatal("Could not clean variables hash, duplicate key found: #{sym.to_s}!") if result.key?(sym)
120
+ logger.fatal("Could not clean variables hash, value for: #{sym.to_s} is not a string!") unless variables[key].kind_of?(String)
121
+ logger.fatal("Could not clean variables hash, value for: #{sym.to_s} is empty!") if variables[key].strip.empty?
122
+
123
+ result[sym] = variables[key].strip
122
124
  end
123
125
 
124
126
  return result
@@ -4,7 +4,7 @@ module HelmWrapper
4
4
 
5
5
  ###############################################################################
6
6
 
7
- VERSION = "1.1.2"
7
+ VERSION = "1.6.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.2
4
+ version: 1.6.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-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake