kucodiff 0.1.1 → 0.2.0

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
  SHA1:
3
- metadata.gz: 4f0bc5d52a96c4780c31fbea4a698abcc7d68a1e
4
- data.tar.gz: da7a31d7540bec7f8acb108d0cede6d417d6f359
3
+ metadata.gz: 59e1b9b9b4ac8a580ad3f6d8cc5d67b81fdd18de
4
+ data.tar.gz: 98be6f305b643cd96c419bf2287dc18f67a97e48
5
5
  SHA512:
6
- metadata.gz: 5ce396f5b2f5c7617a045d53768c9bc5ce9d4dd7ffaee09f4c56fc5464884d96793eaa95cd7db3fc0a88502c14ff7da578815e35ca87a582419b63e61e10ff7e
7
- data.tar.gz: 0438ca56fa8b57dbf8bf0530a1d5dd456f43f6b3f11a2054518bd121fc597df9cce3577da7eecdaf55bb1cf54583d601338f7b7f76379010952214f2993fa397
6
+ metadata.gz: 34ada378819ea565b3a14ff9a3229072e45bd18a7c26d860b1cb274dc8ce5414a11e1623167dbd794ce0e44a67fab82479473b6027d682802b7d129d5f77038e
7
+ data.tar.gz: 233c20efb8dc84254cd1b049d1dfb9764dca5cec5d55c9694de42d252382586481a866dd46d92d922b42140b1dfdeff0f1d29b9affd26d5e1a6a57eea641df06
@@ -1,3 +1,3 @@
1
1
  module Kucodiff
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  end
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
- result = different_keys(base_template, read(other))
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.fetch('spec', {}).fetch('template', {}).fetch('spec', {}).fetch('containers', [])
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.fetch('spec', {}).fetch('template', {}).fetch('metadata', {}).fetch('annotations', {})
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.1.1
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-03-20 00:00:00.000000000 Z
11
+ date: 2017-04-01 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: michael@grosser.it