helm-wrapper 1.1.1 → 1.5.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: 76acfe4805299ed72c029326ed693127fe8518078eea2d5c81880be17d1823d4
4
- data.tar.gz: 6355e496234578a2f414cf8873b2ecfff6d0aa710a4045a3741e940e1996ada8
3
+ metadata.gz: b1d3f972839e1f9e7abd290193f07d57517d5ce589056e880c06d464bdd7bf37
4
+ data.tar.gz: 9bad65a1005854b57ccdfb14cea4f7e2c1305eb4669fb4d65c17b72e5004c27c
5
5
  SHA512:
6
- metadata.gz: 3ec82adad9abe9ad074f6f60fc4ed5711e9f08a7c92258b1b6e71fcf6da491c3a9a0f211796d7ccab3d2f30c027ad0cfdad06955233547bb788faef0e81172f5
7
- data.tar.gz: 0b1299e87f67e83c2a7289049a9222b7a269739fd50b8fc9e18e94f818076dd9c857607507911b690feebae91e6a7fe0c7a5a3408883361705ec6f61201c4d83
6
+ metadata.gz: ecf5901a01a7dccbb485db2d25467fec5759f243a8bd96d9ff3f0e22f7862f0e388d710190c95ab580cbdde27176923d3eeaf3573ebfc5571d779956a58fbf14
7
+ data.tar.gz: 81c011c1774a3649ecf4a5a68b3bca0f5769760a73455ac656aa624639cea78a1b99f7282cf64cd3a1f4a7dabd41ff50d8fcc7555fc5fe821f7416036008709f
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)
@@ -277,7 +280,7 @@ module HelmWrapper
277
280
  out, status = Open3.capture2e(cmdline, :stdin_data=>stdin)
278
281
  logger.debug("Helm output:")
279
282
  logger.debug(out)
280
- result = statrepo_usernameus.success?
283
+ result = status.success?
281
284
  rescue
282
285
  result = false
283
286
  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
- 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)
@@ -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.1"
7
+ VERSION = "1.5.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.1
4
+ version: 1.5.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