kontena-mortar 0.4.2 → 0.4.3

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: 4a77fe16cb1595691797fd0e60f3ad6906f6d9f2cb8a6c00d3eeecaa1ab0124c
4
- data.tar.gz: c4e883dbf83f12ea59f9ff13fb758696bf3daa990ac56d87263584206340486f
3
+ metadata.gz: 3abcdd031398ea53f8329a09326ad77a033064828a22a09458f6f6280cebfd75
4
+ data.tar.gz: 4c75c22bfb4b3686648c5947ac9fb0a2892c1f81b80a5a734040231b33fc81dc
5
5
  SHA512:
6
- metadata.gz: b027bbc656766d3a0c5c29db0c72e8dc3f8e9f6a73b005ee2ea10109ae1f1de503bd91cbc5f9a168f4894faec5ac5e6948ee5f395c8b25725dc44d64fc6f707f
7
- data.tar.gz: e734681cb05dfda305b8baf120957f64419ef6111d0a95480cb7a514500c77cb6addc597df8a4215d57cb77f69fbc768141dfe32dac538bbbe12e5c162708094
6
+ metadata.gz: d9dc6c7c5e0c50258adc34284cef4ff6ec1372e0481a9487e1a0e678f052013351b4837d2c74a0143d5b555f2c66c60b89cad40ff16d60f326dbe97e485bb33b
7
+ data.tar.gz: 418a8adc43b49908614f2f5ad72f02353251e4db29f92b2ed6b4cd595a7b62f6a8bc9cb2e61b96fac0609208c48188c25ecff4dbfde0b258d1520016a3b6d9d3
@@ -1,10 +1,10 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- kontena-mortar (0.4.2)
4
+ kontena-mortar (0.4.3)
5
5
  clamp (~> 1.3)
6
6
  deep_merge (~> 1.2)
7
- k8s-client (~> 0.10.1)
7
+ k8s-client (~> 0.10.4)
8
8
  pastel (~> 0.7.2)
9
9
  rouge (~> 3.2)
10
10
  tty-table (~> 0.10.0)
@@ -13,17 +13,17 @@ GEM
13
13
  remote: https://rubygems.org/
14
14
  specs:
15
15
  ast (2.4.0)
16
- clamp (1.3.0)
16
+ clamp (1.3.1)
17
17
  concurrent-ruby (1.1.5)
18
18
  deep_merge (1.2.1)
19
19
  diff-lcs (1.3)
20
20
  dry-configurable (0.8.3)
21
21
  concurrent-ruby (~> 1.0)
22
22
  dry-core (~> 0.4, >= 0.4.7)
23
- dry-container (0.7.0)
23
+ dry-container (0.7.2)
24
24
  concurrent-ruby (~> 1.0)
25
25
  dry-configurable (~> 0.1, >= 0.1.3)
26
- dry-core (0.4.7)
26
+ dry-core (0.4.9)
27
27
  concurrent-ruby (~> 1.0)
28
28
  dry-equalizer (0.2.2)
29
29
  dry-inflector (0.1.2)
@@ -44,18 +44,18 @@ GEM
44
44
  dry-inflector (~> 0.1, >= 0.1.2)
45
45
  dry-logic (~> 0.4, >= 0.4.2)
46
46
  equatable (0.5.0)
47
- excon (0.62.0)
48
- hashdiff (0.3.9)
47
+ excon (0.67.0)
48
+ hashdiff (1.0.0)
49
49
  ice_nine (0.11.2)
50
50
  jaro_winkler (1.5.2)
51
51
  jsonpath (0.9.9)
52
52
  multi_json
53
53
  to_regexp (~> 0.2.1)
54
- k8s-client (0.10.1)
54
+ k8s-client (0.10.4)
55
55
  dry-struct (~> 0.5.0)
56
56
  dry-types (~> 0.13.0)
57
- excon (~> 0.62.0)
58
- hashdiff (~> 0.3.7)
57
+ excon (~> 0.66)
58
+ hashdiff (~> 1.0.0)
59
59
  jsonpath (~> 0.9.5)
60
60
  recursive-open-struct (~> 1.1.0)
61
61
  yajl-ruby (~> 1.4.0)
@@ -72,7 +72,7 @@ GEM
72
72
  rainbow (3.0.0)
73
73
  rake (10.5.0)
74
74
  recursive-open-struct (1.1.0)
75
- rouge (3.3.0)
75
+ rouge (3.11.0)
76
76
  rspec (3.8.0)
77
77
  rspec-core (~> 3.8.0)
78
78
  rspec-expectations (~> 3.8.0)
data/README.md CHANGED
@@ -146,7 +146,7 @@ See examples at [examples/templates](examples/templates).
146
146
 
147
147
  As for any process, environment variables are also available for Mortar during template processing.
148
148
 
149
- ```
149
+ ```yaml
150
150
  kind: Pod
151
151
  apiVersion: v1
152
152
  metadata:
@@ -168,7 +168,7 @@ Another option to use variables is via command-line options. Use `mortar --var f
168
168
 
169
169
  Each of the variables defined will be available in the template via `var.<variable name>`.
170
170
 
171
- ```
171
+ ```yaml
172
172
  kind: Pod
173
173
  apiVersion: v1
174
174
  metadata:
@@ -189,8 +189,9 @@ You could shoot this resource with `mortar --var port.name=some-port --var port.
189
189
 
190
190
  ### Shot configuration file
191
191
 
192
- It is also possible to pass both [variables](#variables) and [overlays](#overlays) through a configuration file. As your templates complexity and the amount of variables used grows, it might be easier to manage the variables with an yaml configuration file. The config file has the following syntax:
193
- ```
192
+ It is also possible to pass [variables](#variables), [overlays](#overlays) and [labels](#labels) through a configuration file. As your templates complexity and the amount of variables used grows, it might be easier to manage the variables with an yaml configuration file. The config file has the following syntax:
193
+
194
+ ```yaml
194
195
  variables:
195
196
  ports:
196
197
  - name: http
@@ -202,12 +203,28 @@ overlays:
202
203
  - bar
203
204
  ```
204
205
 
205
- Both `variables` and `overlays` are optional.
206
+ `variables`, `overlays` and `labels` are optional.
206
207
 
207
208
  For variables the hash is translated into a `RecursiveOpenStruct` object. What that means is that you can access each element with dotted path notation, just like the vars given through `--var` option. And of course arrays can be looped etc.. Check examples folder how to use variables effectively.
208
209
 
209
210
  The configuration file can be given using `-c` option to `mortar fire` command. By default Mortar will look for `shot.yml` or `shot.yaml` files present in current working directory.
210
211
 
212
+ ### Labels
213
+
214
+ It's possible to set global labels for all resources in a shot via options or configuration file.
215
+
216
+ #### Labels via options
217
+
218
+ Use `mortar --label foo=bar my-app resource` to set label to all resources in a shot.
219
+
220
+ #### Labels via configuration file
221
+
222
+ ```yaml
223
+ labels:
224
+ foo: bar
225
+ bar: baz
226
+ ```
227
+
211
228
  ## Contributing
212
229
 
213
230
  Bug reports and pull requests are welcome on GitHub at https://github.com/kontena/mortar.
@@ -26,7 +26,7 @@ Gem::Specification.new do |spec|
26
26
  spec.post_install_message = "To install shell auto-completions, use:\n mortar install-completions"
27
27
 
28
28
  spec.add_runtime_dependency "clamp", "~> 1.3"
29
- spec.add_runtime_dependency "k8s-client", "~> 0.10.1"
29
+ spec.add_runtime_dependency "k8s-client", "~> 0.10.4"
30
30
  spec.add_runtime_dependency "rouge", "~> 3.2"
31
31
  spec.add_runtime_dependency "deep_merge", "~> 1.2"
32
32
  spec.add_runtime_dependency "pastel", "~> 0.7.2"
@@ -10,14 +10,25 @@ module Mortar
10
10
  raise ConfigError, "Failed to load config, check config file syntax" unless cfg.is_a? Hash
11
11
  raise ConfigError, "Failed to load config, overlays needs to be an array" if cfg.key?('overlays') && !cfg['overlays'].is_a?(Array)
12
12
 
13
- new(variables: cfg['variables'] || {}, overlays: cfg['overlays'] || [])
13
+ if cfg.key?('labels')
14
+ raise ConfigError, "Failed to load config, labels needs to be a hash" if !cfg['labels'].is_a?(Hash)
15
+ raise ConfigError, "Failed to load config, label values need to be strings" if cfg['labels'].values.any? { |value| !value.is_a?(String) }
16
+ end
17
+
18
+ new(
19
+ variables: cfg['variables'] || {},
20
+ overlays: cfg['overlays'] || [],
21
+ labels: cfg['labels'] || {}
22
+ )
14
23
  end
15
24
 
16
- def initialize(variables: {}, overlays: [])
25
+ def initialize(variables: {}, overlays: [], labels: {})
17
26
  @variables = variables
18
27
  @overlays = overlays
28
+ @labels = labels
19
29
  end
20
30
 
31
+ # @param other [Hash]
21
32
  # @return [RecursiveOpenStruct]
22
33
  def variables(other = {})
23
34
  hash = @variables.dup
@@ -25,10 +36,20 @@ module Mortar
25
36
  RecursiveOpenStruct.new(hash, recurse_over_arrays: true)
26
37
  end
27
38
 
39
+ # @param other [Array<Object>]
40
+ # @return [Array<Object>]
28
41
  def overlays(other = [])
29
42
  return @overlays unless other
30
43
 
31
44
  (@overlays + other).uniq.compact
32
45
  end
46
+
47
+ # @param other [Hash]
48
+ # @return [RecursiveOpenStruct]
49
+ def labels(other = {})
50
+ hash = @labels.dup
51
+ hash.merge!(other)
52
+ RecursiveOpenStruct.new(hash)
53
+ end
33
54
  end
34
55
  end
@@ -17,6 +17,7 @@ module Mortar
17
17
  parameter "NAME", "deployment name"
18
18
 
19
19
  option ["--var"], "VAR", "set template variables", multivalued: true
20
+ option ["--label"], "LABEL", "extra labels that are set to all resources", multivalued: true
20
21
  option ["--output"], :flag, "only output generated yaml"
21
22
  option ["--[no-]prune"], :flag, "automatically delete removed resources", default: true
22
23
  option ["--overlay"], "OVERLAY", "overlay dirs", multivalued: true
@@ -45,6 +46,7 @@ module Mortar
45
46
  load_config
46
47
 
47
48
  resources = process_overlays
49
+ resources = inject_extra_labels(resources, process_extra_labels)
48
50
 
49
51
  if output?
50
52
  puts resources_output(resources)
@@ -89,6 +91,37 @@ module Mortar
89
91
  resources
90
92
  end
91
93
 
94
+ # @return [Hash]
95
+ def extra_labels
96
+ return @extra_labels if @extra_labels
97
+
98
+ @extra_labels = {}
99
+ label_list.each do |label|
100
+ key, value = label.split('=')
101
+ @extra_labels[key] = value
102
+ end
103
+
104
+ @extra_labels
105
+ end
106
+
107
+ # @return [Hash]
108
+ def process_extra_labels
109
+ @config.labels(extra_labels)
110
+ end
111
+
112
+ # @param resources [Array<K8s::Resource>]
113
+ # @param labels [Hash]
114
+ # @return [Array<K8s::Resource>]
115
+ def inject_extra_labels(resources, labels)
116
+ resources.map { |resource|
117
+ resource.merge(
118
+ metadata: {
119
+ labels: labels
120
+ }
121
+ )
122
+ }
123
+ end
124
+
92
125
  # @return [RecursiveOpenStruct]
93
126
  def variables_struct
94
127
  @variables_struct ||= @configuration.variables(variables_hash)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Mortar
4
- VERSION = "0.4.2"
4
+ VERSION = "0.4.3"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kontena-mortar
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kontena, Inc
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-06-05 00:00:00.000000000 Z
11
+ date: 2019-09-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: clamp
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 0.10.1
33
+ version: 0.10.4
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 0.10.1
40
+ version: 0.10.4
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rouge
43
43
  requirement: !ruby/object:Gem::Requirement