kucodiff 0.3.0 → 0.6.0
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 +39 -31
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 76444ee014253e7f3336e78ef6ddb39a5b6eb6052964644af058bff8e3fd3531
|
4
|
+
data.tar.gz: a0410e79490633c00e68e3ea263b25dc012154ab3e52b980ab4ce746807c72de
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c3223cb54dc70464911e6f01ea8a745a208180a7f659b1ef7397c7091bc1dddd272364495494c67d10dfceba429d301dee185e342e1796bf354f1ddaa7aed089
|
7
|
+
data.tar.gz: ca69382adba297961dc1ccc6c9aa662670e58fd32d64e2bdc584832383680377247cc5f74242c5fbe650821835c3f0c447bd88cace1aa3cc27104085db57652d
|
data/lib/kucodiff/version.rb
CHANGED
data/lib/kucodiff.rb
CHANGED
@@ -2,7 +2,7 @@ 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
|
@@ -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
|
-
|
14
|
-
|
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
|
@@ -42,21 +38,28 @@ module Kucodiff
|
|
42
38
|
raise ArgumentError, "unknown file format in #{file}"
|
43
39
|
end.first
|
44
40
|
|
45
|
-
|
41
|
+
template = template(content)
|
42
|
+
template.dig("spec", "containers")&.each do |container|
|
43
|
+
hashify_named_array!(container, "env", first: true)
|
44
|
+
hashify_named_array!(container, "volumeMounts", first: false)
|
45
|
+
end
|
46
|
+
hashify_named_array!(template["spec"], "volumes", first: false)
|
46
47
|
hashify_required_env!(content)
|
47
48
|
|
48
49
|
flat_hash(content)
|
49
50
|
end
|
50
51
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
52
|
+
def hashify_named_array!(object, key, first:)
|
53
|
+
return if !object || !(array = object[key])
|
54
|
+
object[key] = array.to_h do |v|
|
55
|
+
keep = (v.keys - ['name'])
|
56
|
+
value =
|
57
|
+
if first
|
58
|
+
v.fetch(keep.first)
|
59
|
+
else
|
60
|
+
v.slice(*keep)
|
61
|
+
end
|
62
|
+
[v.fetch('name'), value]
|
60
63
|
end
|
61
64
|
end
|
62
65
|
|
@@ -66,22 +69,23 @@ module Kucodiff
|
|
66
69
|
annotations[key] = Hash[annotations[key].strip.split(/[\s,]/).map { |k| [k, true] }] if annotations[key]
|
67
70
|
end
|
68
71
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
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.", "") }
|
77
84
|
else
|
78
|
-
template
|
85
|
+
template.select! { |k, _| k.start_with?("spec.template.") }
|
86
|
+
template.transform_keys! { |k| k.sub("spec.template.", "") }
|
79
87
|
end
|
80
88
|
end
|
81
|
-
|
82
|
-
diff = different_keys(*templates)
|
83
|
-
diff.select! { |k| k.start_with?(prefix) } if ignore_unindented
|
84
|
-
diff
|
85
89
|
end
|
86
90
|
|
87
91
|
def different_keys(a, b)
|
@@ -93,7 +97,11 @@ module Kucodiff
|
|
93
97
|
end
|
94
98
|
|
95
99
|
def template(content)
|
96
|
-
content['kind']
|
100
|
+
case content['kind']
|
101
|
+
when "Pod" then content
|
102
|
+
when "PodTemplate" then content.fetch('template')
|
103
|
+
else content.dig('spec', 'template') || {}
|
104
|
+
end
|
97
105
|
end
|
98
106
|
|
99
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
|
+
version: 0.6.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:
|
11
|
+
date: 2022-05-20 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email: michael@grosser.it
|
@@ -31,14 +31,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
31
31
|
requirements:
|
32
32
|
- - ">="
|
33
33
|
- !ruby/object:Gem::Version
|
34
|
-
version: 2.
|
34
|
+
version: 2.6.0
|
35
35
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
36
36
|
requirements:
|
37
37
|
- - ">="
|
38
38
|
- !ruby/object:Gem::Version
|
39
39
|
version: '0'
|
40
40
|
requirements: []
|
41
|
-
rubygems_version: 3.1.
|
41
|
+
rubygems_version: 3.1.6
|
42
42
|
signing_key:
|
43
43
|
specification_version: 4
|
44
44
|
summary: Smart diff for kubernetes configs to ensure symmetric configuration
|