k8s-client 0.4.0 → 0.4.1

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
  SHA256:
3
- metadata.gz: ac23332f18be9e1b95502a9526eab9ed5e4f31a379540387c452802be09b61dc
4
- data.tar.gz: 673e7eb930084bb9dd49353d87de7dc54631e8b4a8a85f3bb707c28573ca8441
3
+ metadata.gz: 7ffb8d5ea84ea9155cf1edabd3658712e419d61caf2381c7c9e00a450d7b5c52
4
+ data.tar.gz: d97128fc9858a09d41585a5b9879deb2920cda848fcf1b01661c5bf23c2b1c10
5
5
  SHA512:
6
- metadata.gz: f19573347f0f74af1e6eb9da2d8aa61d469aa6de69b2deef3938a39f74758191e5edc0f931d33e3953c3f3a96accb0463cfda704dec16d731b700a10e6f8fe7c
7
- data.tar.gz: 426356558b0772b51324624ad06ee4ed3b6bef519fd78d845df5f020cf515f81ae1a4bc11febcae3609b425d46ca804645b17e53d891c52e26f9215d4586b4a4
6
+ metadata.gz: c79481cc31f515777ab46d942aa5f941c4525fee62497dd93137ea33e075d32cd25ec1a4a26c3422b6a7c5ef533432b58e36a6cd10b2cd392deffa0dc66e9c91
7
+ data.tar.gz: 34694c8c5985f51ff701853cd7d34a307c9e3a414570e0817760df5200edc9b47b92b8b7a087d094c5863e2ef5d0133447905f576b09491fd5b2c9fa002e9a42
@@ -12,7 +12,7 @@ deploy:
12
12
  provider: rubygems
13
13
  gem: k8s-client
14
14
  api_key:
15
- secure: ArI9RehHbuJIZklO3FA0cGp4WOc2QYkO26BsKZDWLkTOpRo0GSQRt4WMeOmVpdYfR7yNRgyV8eaGnEYr6ZNS8ejjmwWUnRhBaoEzEC4e9RxaDPTVJDpFOPi38eAtUyAZ7bMeJzhgPev7Y7ofrymuVmsXq/48mJZtSHJckii0UYjaveiH8aGeXxCVFY1csexN36AYr3NCkCqQp9ICXAhQI+UXftVKoN/uXMJC2l8VgjRuxn61x68/XCAxoPr44kYY4PSDAF9eYX/2UTDx4V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fZdh7gb/szfmeDDZ66eAolzrImU="
16
16
  on:
17
17
  tags: true
18
18
  rvm: '2.4'
@@ -1,6 +1,6 @@
1
1
  module K8s
2
2
  class Client
3
3
  # Updated on releases using semver.
4
- VERSION = "0.4.0"
4
+ VERSION = "0.4.1"
5
5
  end
6
6
  end
@@ -27,7 +27,7 @@ module K8s
27
27
 
28
28
  if stat.directory?
29
29
  # recurse
30
- Dir.glob("#{path}/*.{yml,yaml}").sort.map{|path| self.from_files(path) }.flatten
30
+ Dir.glob("#{path}/*.{yml,yaml}").sort.map { |dir| self.from_files(dir) }.flatten
31
31
  else
32
32
  ::YAML.load_stream(File.read(path), path).map{|doc| new(doc) }
33
33
  end
@@ -79,10 +79,13 @@ module K8s
79
79
  # @return [Hash]
80
80
  def current_config(config_annotation)
81
81
  current_cfg = self.metadata.annotations&.dig(config_annotation)
82
+ return {} unless current_cfg
82
83
 
83
- return JSON.parse(current_cfg) if current_cfg
84
+ current_hash = JSON.parse(current_cfg)
85
+ # kubectl adds empty metadata.namespace, let's fix it
86
+ current_hash['metadata'].delete('namespace') if current_hash.dig('metadata', 'namespace').to_s.empty?
84
87
 
85
- {}
88
+ current_hash
86
89
  end
87
90
 
88
91
  def can_patch?(config_annotation)
@@ -1,6 +1,9 @@
1
1
  module K8s
2
2
  # Miscellaneous helpers
3
3
  module Util
4
+ PATH_TR_MAP={ '~' => '~0', '/' => '~1' }.freeze
5
+ PATH_REGEX=%r{(/|~(?!1))}.freeze
6
+
4
7
  # Yield with all non-nil args, returning matching array with corresponding return values or nils.
5
8
  #
6
9
  # Args must be usable as hash keys. Duplicate args will all map to the same return value.
@@ -29,13 +32,17 @@ module K8s
29
32
  def self.json_patch(a, b)
30
33
  diffs = HashDiff.diff(a, b, array_path: true)
31
34
  ops = []
32
- # Each diff is like ["+", "spec.selector.aziz", "kebab"]
33
- # or ["-", "spec.selector.aziz", "kebab"]
35
+ # Each diff is like:
36
+ # ["+", ["spec", "selector", "food"], "kebab"]
37
+ # ["-", ["spec", "selector", "drink"], "pepsi"]
38
+ # or
39
+ # ["~", ["spec", "selector", "drink"], "old value", "new value"]
40
+ # the path elements can be symbols too, depending on the input hashes
34
41
  diffs.each do |diff|
35
42
  operator = diff[0]
36
43
  # substitute '/' with '~1' and '~' with '~0'
37
44
  # according to RFC 6901
38
- path = diff[1].map {|p| p.to_s.gsub('/', '~1')}.map {|p| p.to_s.gsub('~', '~0')}
45
+ path = diff[1].map {|p| p.to_s.gsub(PATH_REGEX, PATH_TR_MAP) }
39
46
  if operator == '-'
40
47
  ops << {
41
48
  op: "remove",
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: k8s-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kontena, Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-09-11 00:00:00.000000000 Z
11
+ date: 2018-09-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: excon