kucodiff 0.4.0 → 0.6.1

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: 55d4cc59d67c00541e565e4e405d475baa13f2eb838997aca3914c9235a76933
4
+ data.tar.gz: 54dda7b72c618c8c290b41d8927e5b43fa95cc84e7c4b34d579652685493a685
5
5
  SHA512:
6
- metadata.gz: 5ab4d4c2642f15fdf86798402f60115afd74787a81b49e6ce664f39e8d36873af440316c0c297d2543721ec43b11a4d22301810948786b5e4a6fc4b545b1f4e2
7
- data.tar.gz: fdd69911a3a957c611a947044cf8f16293eac9fcc707c4d712409dd019fef6c979bb9f2ddec1f5098da167beab165d63dbd460a16b06c36e303e5ce2e74d2731
6
+ metadata.gz: 4ecb7b4155cce7a0ecca4ab341b7e75341fc9f5aced7358387fe61162415eea325b78077c6223d93821cb12b69ca68888ffb7ed11c5a703b474446bb56d66ed2
7
+ data.tar.gz: 36a03f8dcf963e873872142a881a4383201b35bd321a2538844445350ca08500cf6eae9c7e7a27f82e379c30cbcb88f9ef78a46b4228a3485dfd177861cece5a
@@ -1,3 +1,3 @@
1
1
  module Kucodiff
2
- VERSION = "0.4.0"
2
+ VERSION = "0.6.1"
3
3
  end
data/lib/kucodiff.rb CHANGED
@@ -2,20 +2,18 @@ require 'yaml'
2
2
 
3
3
  module Kucodiff
4
4
  class << self
5
- def diff(files, ignore: false, indent_pod: false, expected: {})
5
+ def diff(files, ignore: false, indent_pod: true, expected: {})
6
6
  raise ArgumentError, "Need 2+ files" if files.size < 2
7
7
 
8
8
  base = files.shift
9
- base_template = read(base)
10
9
 
11
10
  diff = files.each_with_object({}) do |other, all|
11
+ # re-read both since we modify them
12
+ base_template = read(base)
12
13
  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
14
+
15
+ pod_indented!(base_template, other_template) if indent_pod
16
+ result = different_keys(base_template, other_template)
19
17
  result.reject! { |k| k =~ ignore } if ignore
20
18
  all["#{base}-#{other}"] = result.sort
21
19
  end
@@ -73,22 +71,23 @@ module Kucodiff
73
71
  annotations[key] = Hash[annotations[key].strip.split(/[\s,]/).map { |k| [k, true] }] if annotations[key]
74
72
  end
75
73
 
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] }]
74
+ # templates are flat hashes already
75
+ def pod_indented!(*templates)
76
+ kinds = templates.map { |t| t["kind"] }
77
+ return if (kinds & ["Pod", "PodTemplate"]).empty? || kinds.uniq.size == 1
78
+
79
+ templates.each do |template|
80
+ case template["kind"]
81
+ when "Pod"
82
+ # all good
83
+ when "PodTemplate"
84
+ template.select! { |k, _| k.start_with?("template.") }
85
+ template.transform_keys! { |k| k.sub("template.", "") }
84
86
  else
85
- template
87
+ template.select! { |k, _| k.start_with?("spec.template.") }
88
+ template.transform_keys! { |k| k.sub("spec.template.", "") }
86
89
  end
87
90
  end
88
-
89
- diff = different_keys(*templates)
90
- diff.select! { |k| k.start_with?(prefix) } if ignore_unindented
91
- diff
92
91
  end
93
92
 
94
93
  def different_keys(a, b)
@@ -100,7 +99,11 @@ module Kucodiff
100
99
  end
101
100
 
102
101
  def template(content)
103
- content['kind'] == "Pod" ? content : content.fetch('spec', {}).fetch('template', {})
102
+ case content['kind']
103
+ when "Pod" then content
104
+ when "PodTemplate" then content.fetch('template')
105
+ else content.dig('spec', 'template') || {}
106
+ end
104
107
  end
105
108
 
106
109
  # 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.6.1
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-06-12 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: michael@grosser.it