fluent-plugin-kubernetes_metadata_filter 2.3.0 → 2.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a221d8fa203e3a37486010781387ef2407e1cf68133530d029344981be45b51d
4
- data.tar.gz: 4e38e559dd5e9a98d8819778d7a293dfbc537bfaccab5fdae2fd19572b794ad2
3
+ metadata.gz: 575489bd872c75d8035fe86c3142e8286cbdcbda3bc282632f6965066bb0e683
4
+ data.tar.gz: f6d697e6294b206e85b6b4cfc3bc1f8d3393aa71f13ea4f6d6817b50da039174
5
5
  SHA512:
6
- metadata.gz: d205ea159f0a54edcc58a9e0794079c2aa5772269ed589156d587adf78b22380669d164013675227750cabca826cab29144ef2cfaa5bf0704eb72efb365d89e3
7
- data.tar.gz: d43b8aa7415ebda5df028e4a63113db79a928a202b110791b70c65dfae877d5a77465957326fb370c4e5bba1951a1338c0382572b1269b36d580ad0f377ed6f4
6
+ metadata.gz: a441fb799b3047fc6796a290572af3fdce3cba0bf37f41c2ebfc325b69ec0ba990c11b9c487acd2bf1b2349047be549da99a6b73ebbabc42059b88266fd8ed4c
7
+ data.tar.gz: fe9397d1a5e3c270650cf297a0fd1b566552df418ef6ae78b7e4633f09d466733c2d0ad98663d8fdb378e3b8192a493f2de6863fba5df2ae47c33855e7495a12
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |gem|
6
6
  gem.name = "fluent-plugin-kubernetes_metadata_filter"
7
- gem.version = "2.3.0"
7
+ gem.version = "2.4.0"
8
8
  gem.authors = ["Jimmi Dyson"]
9
9
  gem.email = ["jimmidyson@gmail.com"]
10
10
  gem.description = %q{Filter plugin to add Kubernetes metadata}
@@ -23,7 +23,7 @@ Gem::Specification.new do |gem|
23
23
  gem.add_runtime_dependency "lru_redux"
24
24
  gem.add_runtime_dependency "kubeclient", '< 5'
25
25
 
26
- gem.add_development_dependency "bundler", "~> 1.3"
26
+ gem.add_development_dependency "bundler", "~> 2.0.2"
27
27
  gem.add_development_dependency "rake"
28
28
  gem.add_development_dependency "minitest", "~> 4.0"
29
29
  gem.add_development_dependency "test-unit", "~> 3.0.2"
@@ -25,8 +25,20 @@ module KubernetesMetadata
25
25
 
26
26
  def start_pod_watch
27
27
  begin
28
- resource_version = @client.get_pods.resourceVersion
29
- watcher = @client.watch_pods(resource_version)
28
+ options = {
29
+ resource_version: '0' # Fetch from API server.
30
+ }
31
+ if ENV['K8S_NODE_NAME']
32
+ options[:field_selector] = 'spec.nodeName=' + ENV['K8S_NODE_NAME']
33
+ end
34
+ pods = @client.get_pods(options)
35
+ pods.each do |pod|
36
+ cache_key = pod.metadata['uid']
37
+ @cache[cache_key] = parse_pod_metadata(pod)
38
+ @stats.bump(:pod_cache_host_updates)
39
+ end
40
+ options[:resource_version] = pods.resourceVersion
41
+ watcher = @client.watch_pods(options)
30
42
  rescue Exception => e
31
43
  message = "Exception encountered fetching metadata from Kubernetes API endpoint: #{e.message}"
32
44
  message += " (#{e.response})" if e.respond_to?(:response)
@@ -25,6 +25,47 @@ class DefaultPodWatchStrategyTest < WatchTest
25
25
  include KubernetesMetadata::WatchPods
26
26
 
27
27
  setup do
28
+ @initial = Kubeclient::Common::EntityList.new(
29
+ 'PodList',
30
+ '123',
31
+ [
32
+ Kubeclient::Resource.new({
33
+ 'metadata' => {
34
+ 'name' => 'initial',
35
+ 'namespace' => 'initial_ns',
36
+ 'uid' => 'initial_uid',
37
+ 'labels' => {},
38
+ },
39
+ 'spec' => {
40
+ 'nodeName' => 'aNodeName',
41
+ 'containers' => [{
42
+ 'name' => 'foo',
43
+ 'image' => 'bar',
44
+ }, {
45
+ 'name' => 'bar',
46
+ 'image' => 'foo',
47
+ }]
48
+ }
49
+ }),
50
+ Kubeclient::Resource.new({
51
+ 'metadata' => {
52
+ 'name' => 'modified',
53
+ 'namespace' => 'create',
54
+ 'uid' => 'modified_uid',
55
+ 'labels' => {},
56
+ },
57
+ 'spec' => {
58
+ 'nodeName' => 'aNodeName',
59
+ 'containers' => [{
60
+ 'name' => 'foo',
61
+ 'image' => 'bar',
62
+ }, {
63
+ 'name' => 'bar',
64
+ 'image' => 'foo',
65
+ }]
66
+ }
67
+ }),
68
+ ])
28
69
  @created = OpenStruct.new(
29
70
  type: 'CREATED',
30
71
  object: {
@@ -97,11 +138,38 @@ class DefaultPodWatchStrategyTest < WatchTest
97
138
  )
98
139
  end
99
140
 
141
+ test 'pod list caches pods' do
142
+ orig_env_val = ENV['K8S_NODE_NAME']
143
+ ENV['K8S_NODE_NAME'] = 'aNodeName'
144
+ @client.stub :get_pods, @initial do
145
+ start_pod_watch
146
+ assert_equal(true, @cache.key?('initial_uid'))
147
+ assert_equal(true, @cache.key?('modified_uid'))
148
+ assert_equal(2, @stats[:pod_cache_host_updates])
149
+ end
150
+ ENV['K8S_NODE_NAME'] = orig_env_val
151
+ end
152
+
153
+ test 'pod list caches pods and watch updates' do
154
+ orig_env_val = ENV['K8S_NODE_NAME']
155
+ ENV['K8S_NODE_NAME'] = 'aNodeName'
156
+ @client.stub :get_pods, @initial do
157
+ @client.stub :watch_pods, [@modified] do
158
+ start_pod_watch
159
+ assert_equal(2, @stats[:pod_cache_host_updates])
160
+ assert_equal(1, @stats[:pod_cache_watch_updates])
161
+ end
162
+ end
163
+ ENV['K8S_NODE_NAME'] = orig_env_val
164
+ end
165
+
100
166
  test 'pod watch notice ignores CREATED' do
101
- @client.stub :watch_pods, [@created] do
102
- start_pod_watch
103
- assert_equal(false, @cache.key?('created_uid'))
104
- assert_equal(1, @stats[:pod_cache_watch_ignored])
167
+ @client.stub :get_pods, @initial do
168
+ @client.stub :watch_pods, [@created] do
169
+ start_pod_watch
170
+ assert_equal(false, @cache.key?('created_uid'))
171
+ assert_equal(1, @stats[:pod_cache_watch_ignored])
172
+ end
105
173
  end
106
174
  end
107
175
 
@@ -30,16 +30,16 @@ class WatchTest < Test::Unit::TestCase
30
30
  def @client.resourceVersion
31
31
  '12345'
32
32
  end
33
- def @client.watch_pods(value)
33
+ def @client.watch_pods(options = {})
34
34
  []
35
35
  end
36
- def @client.watch_namespaces(value)
36
+ def @client.watch_namespaces(options = {})
37
37
  []
38
38
  end
39
- def @client.get_namespaces
39
+ def @client.get_namespaces(options = {})
40
40
  self
41
41
  end
42
- def @client.get_pods
42
+ def @client.get_pods(options = {})
43
43
  self
44
44
  end
45
45
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-kubernetes_metadata_filter
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.0
4
+ version: 2.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jimmi Dyson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-08-26 00:00:00.000000000 Z
11
+ date: 2019-09-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fluentd
@@ -64,14 +64,14 @@ dependencies:
64
64
  requirements:
65
65
  - - "~>"
66
66
  - !ruby/object:Gem::Version
67
- version: '1.3'
67
+ version: 2.0.2
68
68
  type: :development
69
69
  prerelease: false
70
70
  version_requirements: !ruby/object:Gem::Requirement
71
71
  requirements:
72
72
  - - "~>"
73
73
  - !ruby/object:Gem::Version
74
- version: '1.3'
74
+ version: 2.0.2
75
75
  - !ruby/object:Gem::Dependency
76
76
  name: rake
77
77
  requirement: !ruby/object:Gem::Requirement
@@ -258,7 +258,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
258
258
  - !ruby/object:Gem::Version
259
259
  version: '0'
260
260
  requirements: []
261
- rubygems_version: 3.0.3
261
+ rubygems_version: 3.0.6
262
262
  signing_key:
263
263
  specification_version: 4
264
264
  summary: Fluentd filter plugin to add Kubernetes metadata