kucodiff 0.2.1 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/kucodiff/version.rb +1 -1
- data/lib/kucodiff.rb +48 -34
- metadata +4 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 626cbfd398f264adaf284a4842ea250babe4d8bcb506f1700cb1629c2cfb3e3e
|
4
|
+
data.tar.gz: d3d33300480d745da896131cb1dba9881358b3d478e91ff516a3446661e33313
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2a87916da814015b02fcb1e5fa9b8027702eeab15a6104e3c9af2bb682daf98763d4260416962b70dda6b5b23f5e97bdfb7bc0877fb3989c1acf871f72b0c9fd
|
7
|
+
data.tar.gz: a4f29440331c0eae9a2447751e6c3b6653019d1f3f0198e591915ea8888495bf8667aa961097c5b23bd3a31c63c9f3b69a4313677c837376d8b1098f16b36256
|
data/lib/kucodiff/version.rb
CHANGED
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
|
-
|
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
|
@@ -31,26 +27,39 @@ module Kucodiff
|
|
31
27
|
private
|
32
28
|
|
33
29
|
def read(file)
|
34
|
-
content =
|
35
|
-
|
36
|
-
|
37
|
-
|
30
|
+
content =
|
31
|
+
if file.end_with?('.yml', '.yaml')
|
32
|
+
if RUBY_VERSION >= "2.6.0"
|
33
|
+
YAML.load_stream(File.read(file), filename: file) # uncovered
|
34
|
+
else
|
35
|
+
YAML.load_stream(File.read(file), file) # uncovered
|
36
|
+
end
|
37
|
+
else
|
38
|
+
raise ArgumentError, "unknown file format in #{file}"
|
39
|
+
end.first
|
38
40
|
|
39
|
-
|
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)
|
40
47
|
hashify_required_env!(content)
|
41
48
|
|
42
49
|
flat_hash(content)
|
43
50
|
end
|
44
51
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
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]
|
54
63
|
end
|
55
64
|
end
|
56
65
|
|
@@ -60,22 +69,23 @@ module Kucodiff
|
|
60
69
|
annotations[key] = Hash[annotations[key].strip.split(/[\s,]/).map { |k| [k, true] }] if annotations[key]
|
61
70
|
end
|
62
71
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
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.", "") }
|
71
84
|
else
|
72
|
-
template
|
85
|
+
template.select! { |k, _| k.start_with?("spec.template.") }
|
86
|
+
template.transform_keys! { |k| k.sub("spec.template.", "") }
|
73
87
|
end
|
74
88
|
end
|
75
|
-
|
76
|
-
diff = different_keys(*templates)
|
77
|
-
diff.select! { |k| k.start_with?(prefix) } if ignore_unindented
|
78
|
-
diff
|
79
89
|
end
|
80
90
|
|
81
91
|
def different_keys(a, b)
|
@@ -87,7 +97,11 @@ module Kucodiff
|
|
87
97
|
end
|
88
98
|
|
89
99
|
def template(content)
|
90
|
-
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
|
91
105
|
end
|
92
106
|
|
93
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.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:
|
11
|
+
date: 2022-05-20 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email: michael@grosser.it
|
@@ -31,15 +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
|
-
|
42
|
-
rubygems_version: 2.5.1
|
41
|
+
rubygems_version: 3.1.6
|
43
42
|
signing_key:
|
44
43
|
specification_version: 4
|
45
44
|
summary: Smart diff for kubernetes configs to ensure symmetric configuration
|