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 +4 -4
- data/lib/kucodiff/version.rb +1 -1
- data/lib/kucodiff.rb +25 -22
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 55d4cc59d67c00541e565e4e405d475baa13f2eb838997aca3914c9235a76933
|
4
|
+
data.tar.gz: 54dda7b72c618c8c290b41d8927e5b43fa95cc84e7c4b34d579652685493a685
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4ecb7b4155cce7a0ecca4ab341b7e75341fc9f5aced7358387fe61162415eea325b78077c6223d93821cb12b69ca68888ffb7ed11c5a703b474446bb56d66ed2
|
7
|
+
data.tar.gz: 36a03f8dcf963e873872142a881a4383201b35bd321a2538844445350ca08500cf6eae9c7e7a27f82e379c30cbcb88f9ef78a46b4228a3485dfd177861cece5a
|
data/lib/kucodiff/version.rb
CHANGED
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:
|
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
|
-
|
14
|
-
|
15
|
-
|
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
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
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']
|
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
|
+
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-
|
11
|
+
date: 2022-06-12 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email: michael@grosser.it
|