kucodiff 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/kucodiff/version.rb +1 -1
- data/lib/kucodiff.rb +33 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 59e1b9b9b4ac8a580ad3f6d8cc5d67b81fdd18de
|
4
|
+
data.tar.gz: 98be6f305b643cd96c419bf2287dc18f67a97e48
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 34ada378819ea565b3a14ff9a3229072e45bd18a7c26d860b1cb274dc8ce5414a11e1623167dbd794ce0e44a67fab82479473b6027d682802b7d129d5f77038e
|
7
|
+
data.tar.gz: 233c20efb8dc84254cd1b049d1dfb9764dca5cec5d55c9694de42d252382586481a866dd46d92d922b42140b1dfdeff0f1d29b9affd26d5e1a6a57eea641df06
|
data/lib/kucodiff/version.rb
CHANGED
data/lib/kucodiff.rb
CHANGED
@@ -2,13 +2,20 @@ require 'yaml'
|
|
2
2
|
|
3
3
|
module Kucodiff
|
4
4
|
class << self
|
5
|
-
def diff(files, ignore: false, expected: {})
|
5
|
+
def diff(files, ignore: false, indent_pod: false, expected: {})
|
6
6
|
raise ArgumentError, "Need 2+ files" if files.size < 2
|
7
7
|
|
8
8
|
base = files.shift
|
9
9
|
base_template = read(base)
|
10
|
+
|
10
11
|
diff = files.each_with_object({}) do |other, all|
|
11
|
-
|
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
|
12
19
|
result.reject! { |k| k =~ ignore } if ignore
|
13
20
|
all["#{base}-#{other}"] = result.sort
|
14
21
|
end
|
@@ -37,7 +44,7 @@ module Kucodiff
|
|
37
44
|
|
38
45
|
# make env comparable
|
39
46
|
def hashify_container_env!(content)
|
40
|
-
containers = content
|
47
|
+
containers = template(content).fetch('spec', {}).fetch('containers', [])
|
41
48
|
containers.each do |container|
|
42
49
|
next unless container['env']
|
43
50
|
container['env'] = container['env'].each_with_object({}) do |v, h|
|
@@ -49,10 +56,28 @@ module Kucodiff
|
|
49
56
|
|
50
57
|
def hashify_required_env!(content)
|
51
58
|
key = 'samson/required_env'
|
52
|
-
annotations = content
|
59
|
+
annotations = template(content).fetch('metadata', {}).fetch('annotations', {})
|
53
60
|
annotations[key] = Hash[annotations[key].strip.split(/[\s,]/).map { |k| [k, true] }] if annotations[key]
|
54
61
|
end
|
55
62
|
|
63
|
+
def different_keys_pod_indented(*templates)
|
64
|
+
ignore_unindented = false
|
65
|
+
prefix = "spec.template."
|
66
|
+
|
67
|
+
templates.map! do |template|
|
68
|
+
if template["kind"] == "Pod"
|
69
|
+
ignore_unindented = true
|
70
|
+
Hash[template.map { |k,v| [prefix + k, v] }]
|
71
|
+
else
|
72
|
+
template
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
diff = different_keys(*templates)
|
77
|
+
diff.select! { |k| k.start_with?(prefix) } if ignore_unindented
|
78
|
+
diff
|
79
|
+
end
|
80
|
+
|
56
81
|
def different_keys(a, b)
|
57
82
|
(a.keys + b.keys).uniq.select { |k| a[k] != b[k] }
|
58
83
|
end
|
@@ -61,6 +86,10 @@ module Kucodiff
|
|
61
86
|
a + b - (a & b)
|
62
87
|
end
|
63
88
|
|
89
|
+
def template(content)
|
90
|
+
content['kind'] == "Pod" ? content : content.fetch('spec', {}).fetch('template', {})
|
91
|
+
end
|
92
|
+
|
64
93
|
# http://stackoverflow.com/questions/9647997/converting-a-nested-hash-into-a-flat-hash
|
65
94
|
def flat_hash(input, base = nil, all = {})
|
66
95
|
if input.is_a?(Array)
|
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.2.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: 2017-
|
11
|
+
date: 2017-04-01 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email: michael@grosser.it
|