kucodiff 0.4.0 → 0.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: e0c86b43c39bc7d8aa5fcb41035d254e8ce47e89969d97b4b1d0e5829ffeb139
4
- data.tar.gz: b2da356c812dd537b04dfb5c327165ce895d182f1dc5a180cb1c335df93640d7
3
+ metadata.gz: 626cbfd398f264adaf284a4842ea250babe4d8bcb506f1700cb1629c2cfb3e3e
4
+ data.tar.gz: d3d33300480d745da896131cb1dba9881358b3d478e91ff516a3446661e33313
5
5
  SHA512:
6
- metadata.gz: 5ab4d4c2642f15fdf86798402f60115afd74787a81b49e6ce664f39e8d36873af440316c0c297d2543721ec43b11a4d22301810948786b5e4a6fc4b545b1f4e2
7
- data.tar.gz: fdd69911a3a957c611a947044cf8f16293eac9fcc707c4d712409dd019fef6c979bb9f2ddec1f5098da167beab165d63dbd460a16b06c36e303e5ce2e74d2731
6
+ metadata.gz: 2a87916da814015b02fcb1e5fa9b8027702eeab15a6104e3c9af2bb682daf98763d4260416962b70dda6b5b23f5e97bdfb7bc0877fb3989c1acf871f72b0c9fd
7
+ data.tar.gz: a4f29440331c0eae9a2447751e6c3b6653019d1f3f0198e591915ea8888495bf8667aa961097c5b23bd3a31c63c9f3b69a4313677c837376d8b1098f16b36256
@@ -1,3 +1,3 @@
1
1
  module Kucodiff
2
- VERSION = "0.4.0"
2
+ VERSION = "0.5.0"
3
3
  end
data/lib/kucodiff.rb CHANGED
@@ -10,12 +10,8 @@ module Kucodiff
10
10
 
11
11
  diff = files.each_with_object({}) do |other, all|
12
12
  other_template = read(other)
13
- result =
14
- if indent_pod
15
- different_keys_pod_indented(base_template, other_template)
16
- else
17
- different_keys(base_template, other_template)
18
- end
13
+ pod_indented!(base_template, other_template) if indent_pod
14
+ result = different_keys(base_template, other_template)
19
15
  result.reject! { |k| k =~ ignore } if ignore
20
16
  all["#{base}-#{other}"] = result.sort
21
17
  end
@@ -73,22 +69,23 @@ module Kucodiff
73
69
  annotations[key] = Hash[annotations[key].strip.split(/[\s,]/).map { |k| [k, true] }] if annotations[key]
74
70
  end
75
71
 
76
- def different_keys_pod_indented(*templates)
77
- ignore_unindented = false
78
- prefix = "spec.template."
79
-
80
- templates.map! do |template|
81
- if template["kind"] == "Pod"
82
- ignore_unindented = true
83
- Hash[template.map { |k,v| [prefix + k, v] }]
72
+ # templates are flat hashes already
73
+ def pod_indented!(*templates)
74
+ kinds = templates.map { |t| t["kind"] }
75
+ return if (kinds & ["Pod", "PodTemplate"]).empty? || kinds.uniq.size == 1
76
+
77
+ templates.each do |template|
78
+ case template["kind"]
79
+ when "Pod"
80
+ # all good
81
+ when "PodTemplate"
82
+ template.select! { |k, _| k.start_with?("template.") }
83
+ template.transform_keys! { |k| k.sub("template.", "") }
84
84
  else
85
- template
85
+ template.select! { |k, _| k.start_with?("spec.template.") }
86
+ template.transform_keys! { |k| k.sub("spec.template.", "") }
86
87
  end
87
88
  end
88
-
89
- diff = different_keys(*templates)
90
- diff.select! { |k| k.start_with?(prefix) } if ignore_unindented
91
- diff
92
89
  end
93
90
 
94
91
  def different_keys(a, b)
@@ -100,7 +97,11 @@ module Kucodiff
100
97
  end
101
98
 
102
99
  def template(content)
103
- content['kind'] == "Pod" ? content : content.fetch('spec', {}).fetch('template', {})
100
+ case content['kind']
101
+ when "Pod" then content
102
+ when "PodTemplate" then content.fetch('template')
103
+ else content.dig('spec', 'template') || {}
104
+ end
104
105
  end
105
106
 
106
107
  # http://stackoverflow.com/questions/9647997/converting-a-nested-hash-into-a-flat-hash
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kucodiff
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Grosser
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-04-01 00:00:00.000000000 Z
11
+ date: 2022-05-20 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: michael@grosser.it