fluent-plugin-kubernetes_metadata_filter 2.5.2 → 2.6.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/.circleci/config.yml +6 -6
- data/Gemfile.lock +43 -43
- data/fluent-plugin-kubernetes_metadata_filter.gemspec +3 -6
- data/lib/fluent/plugin/filter_kubernetes_metadata.rb +38 -59
- data/lib/fluent/plugin/kubernetes_metadata_common.rb +20 -46
- data/lib/fluent/plugin/kubernetes_metadata_watch_namespaces.rb +17 -12
- data/lib/fluent/plugin/kubernetes_metadata_watch_pods.rb +33 -16
- data/test/helper.rb +17 -1
- data/test/plugin/test_cache_stats.rb +2 -5
- data/test/plugin/test_cache_strategy.rb +5 -8
- data/test/plugin/test_filter_kubernetes_metadata.rb +11 -10
- data/test/plugin/test_watch_namespaces.rb +90 -68
- data/test/plugin/test_watch_pods.rb +164 -135
- data/test/plugin/watch_test.rb +3 -10
- metadata +7 -28
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c891b663769f4927f2bc0a2524b8358d965c0962ec8d56e691e50a4011c4b6f4
|
4
|
+
data.tar.gz: cb8110159bd202df0fba96c477149f16836b54598be864bbb5bda9412d8ef563
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a974a260ab2b56e5e941711ae0216c6da574429a35e12cd622f76cea8423b66fa09b71a58f7627c5f940ad175b8c45cf8fb1b3993cb825197dab0ef4b4d28443
|
7
|
+
data.tar.gz: 5988e42558432f8e067b50230490c2a128661ef0f6f7294ee0e3e219eab764c11d4fc86b33b8c13a2c2753afc8416e14af8afff625afa64858d9a59c5802bb97
|
data/.circleci/config.yml
CHANGED
@@ -14,21 +14,21 @@ missingdeps: &missingdeps
|
|
14
14
|
sudo cp /tmp/sources.list /etc/apt/sources.list
|
15
15
|
sudo apt-get update
|
16
16
|
sudo apt-get install cmake libicu-dev libssl-dev
|
17
|
-
|
17
|
+
|
18
18
|
test: &test
|
19
19
|
name: Test bundle
|
20
20
|
command: bundle exec rake test
|
21
21
|
|
22
22
|
executors:
|
23
|
-
ruby-2-4:
|
24
|
-
docker:
|
25
|
-
- image: circleci/ruby:2.4.6
|
26
23
|
ruby-2-5:
|
27
24
|
docker:
|
28
25
|
- image: circleci/ruby:2.5.5
|
29
26
|
ruby-2-6:
|
30
27
|
docker:
|
31
28
|
- image: circleci/ruby:2.6.3
|
29
|
+
ruby-2-7:
|
30
|
+
docker:
|
31
|
+
- image: circleci/ruby:2.7.1
|
32
32
|
jobs:
|
33
33
|
"ruby-test":
|
34
34
|
parameters:
|
@@ -49,9 +49,9 @@ jobs:
|
|
49
49
|
workflows:
|
50
50
|
"test_multiple_ruby_versions":
|
51
51
|
jobs:
|
52
|
-
- ruby-test:
|
53
|
-
ruby-version: ruby-2-4
|
54
52
|
- ruby-test:
|
55
53
|
ruby-version: ruby-2-5
|
56
54
|
- ruby-test:
|
57
55
|
ruby-version: ruby-2-6
|
56
|
+
- ruby-test:
|
57
|
+
ruby-version: ruby-2-7
|
data/Gemfile.lock
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
fluent-plugin-kubernetes_metadata_filter (2.
|
5
|
-
fluentd (>= 0.14.0, < 1.
|
4
|
+
fluent-plugin-kubernetes_metadata_filter (2.6.0)
|
5
|
+
fluentd (>= 0.14.0, < 1.13)
|
6
6
|
kubeclient (< 5)
|
7
7
|
lru_redux
|
8
8
|
|
@@ -12,36 +12,37 @@ GEM
|
|
12
12
|
addressable (2.7.0)
|
13
13
|
public_suffix (>= 2.0.2, < 5.0)
|
14
14
|
ast (2.4.1)
|
15
|
-
bump (0.
|
15
|
+
bump (0.10.0)
|
16
16
|
charlock_holmes (0.7.7)
|
17
17
|
codeclimate-test-reporter (0.6.0)
|
18
18
|
simplecov (>= 0.7.1, < 1.0.0)
|
19
|
-
concurrent-ruby (1.1.
|
20
|
-
cool.io (1.
|
19
|
+
concurrent-ruby (1.1.8)
|
20
|
+
cool.io (1.7.0)
|
21
21
|
copyright-header (1.0.22)
|
22
22
|
github-linguist
|
23
|
-
crack (0.4.
|
24
|
-
|
25
|
-
docile (1.3.
|
23
|
+
crack (0.4.5)
|
24
|
+
rexml
|
25
|
+
docile (1.3.5)
|
26
26
|
domain_name (0.5.20190701)
|
27
27
|
unf (>= 0.0.5, < 1.0.0)
|
28
28
|
escape_utils (1.2.1)
|
29
|
-
ffi (1.
|
29
|
+
ffi (1.14.2)
|
30
30
|
ffi-compiler (1.0.1)
|
31
31
|
ffi (>= 1.0.0)
|
32
32
|
rake
|
33
|
-
fluentd (1.
|
33
|
+
fluentd (1.12.0)
|
34
|
+
bundler
|
34
35
|
cool.io (>= 1.4.5, < 2.0.0)
|
35
36
|
http_parser.rb (>= 0.5.1, < 0.7.0)
|
36
37
|
msgpack (>= 1.3.1, < 2.0.0)
|
37
|
-
serverengine (>= 2.
|
38
|
+
serverengine (>= 2.2.2, < 3.0.0)
|
38
39
|
sigdump (~> 0.2.2)
|
39
40
|
strptime (>= 0.2.2, < 1.0.0)
|
40
41
|
tzinfo (>= 1.0, < 3.0)
|
41
42
|
tzinfo-data (~> 1.0)
|
42
43
|
yajl-ruby (~> 1.0)
|
43
|
-
github-linguist (7.
|
44
|
-
charlock_holmes (~> 0.7.
|
44
|
+
github-linguist (7.12.2)
|
45
|
+
charlock_holmes (~> 0.7.7)
|
45
46
|
escape_utils (~> 1.2.0)
|
46
47
|
mini_mime (~> 1.0)
|
47
48
|
rugged (>= 0.25.1)
|
@@ -55,13 +56,12 @@ GEM
|
|
55
56
|
http-cookie (1.0.3)
|
56
57
|
domain_name (~> 0.5)
|
57
58
|
http-form_data (2.3.0)
|
58
|
-
http-parser (1.2.
|
59
|
+
http-parser (1.2.3)
|
59
60
|
ffi-compiler (>= 1.0, < 2.0)
|
60
61
|
http_parser.rb (0.6.0)
|
61
|
-
jsonpath (1.0
|
62
|
+
jsonpath (1.1.0)
|
62
63
|
multi_json
|
63
|
-
|
64
|
-
kubeclient (4.8.0)
|
64
|
+
kubeclient (4.9.1)
|
65
65
|
http (>= 3.0, < 5.0)
|
66
66
|
jsonpath (~> 1.0)
|
67
67
|
recursive-open-struct (~> 1.1, >= 1.1.1)
|
@@ -69,21 +69,21 @@ GEM
|
|
69
69
|
lru_redux (1.1.0)
|
70
70
|
mime-types (3.3.1)
|
71
71
|
mime-types-data (~> 3.2015)
|
72
|
-
mime-types-data (3.2020.
|
72
|
+
mime-types-data (3.2020.1104)
|
73
73
|
mini_mime (1.0.2)
|
74
74
|
minitest (4.7.5)
|
75
75
|
msgpack (1.3.3)
|
76
76
|
multi_json (1.15.0)
|
77
77
|
netrc (0.11.0)
|
78
|
-
parallel (1.
|
79
|
-
parser (
|
78
|
+
parallel (1.20.1)
|
79
|
+
parser (3.0.0.0)
|
80
80
|
ast (~> 2.4.1)
|
81
81
|
power_assert (1.2.0)
|
82
|
-
public_suffix (4.0.
|
82
|
+
public_suffix (4.0.6)
|
83
83
|
rainbow (3.0.0)
|
84
|
-
rake (13.0.
|
85
|
-
recursive-open-struct (1.1.
|
86
|
-
regexp_parser (
|
84
|
+
rake (13.0.3)
|
85
|
+
recursive-open-struct (1.1.3)
|
86
|
+
regexp_parser (2.0.3)
|
87
87
|
rest-client (2.1.0)
|
88
88
|
http-accept (>= 1.7.0, < 2.0)
|
89
89
|
http-cookie (>= 1.0.2, < 2.0)
|
@@ -91,44 +91,44 @@ GEM
|
|
91
91
|
netrc (~> 0.8)
|
92
92
|
rexml (3.2.4)
|
93
93
|
rr (1.2.1)
|
94
|
-
rubocop (
|
94
|
+
rubocop (1.8.1)
|
95
95
|
parallel (~> 1.10)
|
96
|
-
parser (>=
|
96
|
+
parser (>= 3.0.0.0)
|
97
97
|
rainbow (>= 2.2.2, < 4.0)
|
98
|
-
regexp_parser (>= 1.
|
98
|
+
regexp_parser (>= 1.8, < 3.0)
|
99
99
|
rexml
|
100
|
-
rubocop-ast (>=
|
100
|
+
rubocop-ast (>= 1.2.0, < 2.0)
|
101
101
|
ruby-progressbar (~> 1.7)
|
102
|
-
unicode-display_width (>= 1.4.0, <
|
103
|
-
rubocop-ast (
|
104
|
-
parser (>= 2.7.
|
105
|
-
ruby-progressbar (1.
|
106
|
-
rugged (1.0
|
107
|
-
|
108
|
-
serverengine (2.2.1)
|
102
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
103
|
+
rubocop-ast (1.4.0)
|
104
|
+
parser (>= 2.7.1.5)
|
105
|
+
ruby-progressbar (1.11.0)
|
106
|
+
rugged (1.1.0)
|
107
|
+
serverengine (2.2.2)
|
109
108
|
sigdump (~> 0.2.2)
|
110
109
|
sigdump (0.2.4)
|
111
|
-
simplecov (0.
|
110
|
+
simplecov (0.21.2)
|
112
111
|
docile (~> 1.1)
|
113
112
|
simplecov-html (~> 0.11)
|
114
|
-
|
115
|
-
|
113
|
+
simplecov_json_formatter (~> 0.1)
|
114
|
+
simplecov-html (0.12.3)
|
115
|
+
simplecov_json_formatter (0.1.2)
|
116
|
+
strptime (0.2.5)
|
116
117
|
test-unit (3.0.9)
|
117
118
|
power_assert
|
118
119
|
test-unit-rr (1.0.5)
|
119
120
|
rr (>= 1.1.1)
|
120
121
|
test-unit (>= 2.5.2)
|
121
|
-
|
122
|
-
tzinfo (2.0.2)
|
122
|
+
tzinfo (2.0.4)
|
123
123
|
concurrent-ruby (~> 1.0)
|
124
|
-
tzinfo-data (1.2020.
|
124
|
+
tzinfo-data (1.2020.6)
|
125
125
|
tzinfo (>= 1.0.0)
|
126
126
|
unf (0.1.4)
|
127
127
|
unf_ext
|
128
128
|
unf_ext (0.0.7.7)
|
129
|
-
unicode-display_width (
|
129
|
+
unicode-display_width (2.0.0)
|
130
130
|
vcr (6.0.0)
|
131
|
-
webmock (3.
|
131
|
+
webmock (3.11.1)
|
132
132
|
addressable (>= 2.3.6)
|
133
133
|
crack (>= 0.3.2)
|
134
134
|
hashdiff (>= 0.4.0, < 2.0.0)
|
@@ -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.
|
7
|
+
gem.version = "2.6.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}
|
@@ -13,13 +13,10 @@ Gem::Specification.new do |gem|
|
|
13
13
|
gem.license = "Apache-2.0"
|
14
14
|
|
15
15
|
gem.files = `git ls-files`.split($/)
|
16
|
-
gem.executables = gem.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
-
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
-
gem.require_paths = ["lib"]
|
19
16
|
|
20
|
-
gem.required_ruby_version = '>= 2.
|
17
|
+
gem.required_ruby_version = '>= 2.5.0'
|
21
18
|
|
22
|
-
gem.add_runtime_dependency 'fluentd', ['>= 0.14.0', '< 1.
|
19
|
+
gem.add_runtime_dependency 'fluentd', ['>= 0.14.0', '< 1.13']
|
23
20
|
gem.add_runtime_dependency "lru_redux"
|
24
21
|
gem.add_runtime_dependency "kubeclient", '< 5'
|
25
22
|
|
@@ -90,29 +90,15 @@ module Fluent::Plugin
|
|
90
90
|
|
91
91
|
def fetch_pod_metadata(namespace_name, pod_name)
|
92
92
|
log.trace("fetching pod metadata: #{namespace_name}/#{pod_name}") if log.trace?
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
@stats.bump(:pod_cache_api_updates)
|
103
|
-
log.trace("parsed metadata for #{namespace_name}/#{pod_name}: #{metadata}") if log.trace?
|
104
|
-
@cache[metadata['pod_id']] = metadata
|
105
|
-
return metadata
|
106
|
-
rescue Exception=>e
|
107
|
-
log.debug(e)
|
108
|
-
@stats.bump(:pod_cache_api_nil_bad_resp_payload)
|
109
|
-
log.trace("returning empty metadata for #{namespace_name}/#{pod_name} due to error '#{e}'") if log.trace?
|
110
|
-
end
|
111
|
-
end
|
112
|
-
rescue Exception=>e
|
113
|
-
@stats.bump(:pod_cache_api_nil_error)
|
114
|
-
log.debug "Exception '#{e}' encountered fetching pod metadata from Kubernetes API #{@apiVersion} endpoint #{@kubernetes_url}"
|
115
|
-
end
|
93
|
+
pod_object = @client.get_pod(pod_name, namespace_name)
|
94
|
+
log.trace("raw metadata for #{namespace_name}/#{pod_name}: #{pod_object}") if log.trace?
|
95
|
+
metadata = parse_pod_metadata(pod_object)
|
96
|
+
@stats.bump(:pod_cache_api_updates)
|
97
|
+
log.trace("parsed metadata for #{namespace_name}/#{pod_name}: #{metadata}") if log.trace?
|
98
|
+
@cache[metadata['pod_id']] = metadata
|
99
|
+
rescue => e
|
100
|
+
@stats.bump(:pod_cache_api_nil_error)
|
101
|
+
log.debug "Exception '#{e}' encountered fetching pod metadata from Kubernetes API #{@apiVersion} endpoint #{@kubernetes_url}"
|
116
102
|
{}
|
117
103
|
end
|
118
104
|
|
@@ -132,29 +118,15 @@ module Fluent::Plugin
|
|
132
118
|
|
133
119
|
def fetch_namespace_metadata(namespace_name)
|
134
120
|
log.trace("fetching namespace metadata: #{namespace_name}") if log.trace?
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
@stats.bump(:namespace_cache_api_updates)
|
145
|
-
log.trace("parsed metadata for #{namespace_name}: #{metadata}") if log.trace?
|
146
|
-
@namespace_cache[metadata['namespace_id']] = metadata
|
147
|
-
return metadata
|
148
|
-
rescue Exception => e
|
149
|
-
log.debug(e)
|
150
|
-
@stats.bump(:namespace_cache_api_nil_bad_resp_payload)
|
151
|
-
log.trace("returning empty metadata for #{namespace_name} due to error '#{e}'") if log.trace?
|
152
|
-
end
|
153
|
-
end
|
154
|
-
rescue Exception => kube_error
|
155
|
-
@stats.bump(:namespace_cache_api_nil_error)
|
156
|
-
log.debug "Exception '#{kube_error}' encountered fetching namespace metadata from Kubernetes API #{@apiVersion} endpoint #{@kubernetes_url}"
|
157
|
-
end
|
121
|
+
namespace_object = @client.get_namespace(namespace_name)
|
122
|
+
log.trace("raw metadata for #{namespace_name}: #{namespace_object}") if log.trace?
|
123
|
+
metadata = parse_namespace_metadata(namespace_object)
|
124
|
+
@stats.bump(:namespace_cache_api_updates)
|
125
|
+
log.trace("parsed metadata for #{namespace_name}: #{metadata}") if log.trace?
|
126
|
+
@namespace_cache[metadata['namespace_id']] = metadata
|
127
|
+
rescue => kube_error
|
128
|
+
@stats.bump(:namespace_cache_api_nil_error)
|
129
|
+
log.debug "Exception '#{kube_error}' encountered fetching namespace metadata from Kubernetes API #{@apiVersion} endpoint #{@kubernetes_url}"
|
158
130
|
{}
|
159
131
|
end
|
160
132
|
|
@@ -174,7 +146,7 @@ module Fluent::Plugin
|
|
174
146
|
require 'lru_redux'
|
175
147
|
@stats = KubernetesMetadata::Stats.new
|
176
148
|
|
177
|
-
if @de_dot &&
|
149
|
+
if @de_dot && @de_dot_separator.include?(".")
|
178
150
|
raise Fluent::ConfigError, "Invalid de_dot_separator: cannot be or contain '.'"
|
179
151
|
end
|
180
152
|
|
@@ -201,7 +173,7 @@ module Fluent::Plugin
|
|
201
173
|
|
202
174
|
env_host = ENV['KUBERNETES_SERVICE_HOST']
|
203
175
|
env_port = ENV['KUBERNETES_SERVICE_PORT']
|
204
|
-
if
|
176
|
+
if present?(env_host) && present?(env_port)
|
205
177
|
if env_host =~ Resolv::IPv6::Regex
|
206
178
|
# Brackets are needed around IPv6 addresses
|
207
179
|
env_host = "[#{env_host}]"
|
@@ -219,22 +191,21 @@ module Fluent::Plugin
|
|
219
191
|
ca_cert = File.join(@secret_dir, K8_POD_CA_CERT)
|
220
192
|
pod_token = File.join(@secret_dir, K8_POD_TOKEN)
|
221
193
|
|
222
|
-
if
|
194
|
+
if !present?(@ca_file) and File.exist?(ca_cert)
|
223
195
|
log.debug "Found CA certificate: #{ca_cert}"
|
224
196
|
@ca_file = ca_cert
|
225
197
|
end
|
226
198
|
|
227
|
-
if
|
199
|
+
if !present?(@bearer_token_file) and File.exist?(pod_token)
|
228
200
|
log.debug "Found pod token: #{pod_token}"
|
229
201
|
@bearer_token_file = pod_token
|
230
202
|
end
|
231
203
|
end
|
232
204
|
|
233
|
-
if @kubernetes_url
|
234
|
-
|
205
|
+
if present?(@kubernetes_url)
|
235
206
|
ssl_options = {
|
236
|
-
client_cert: @client_cert
|
237
|
-
client_key: @client_key
|
207
|
+
client_cert: present?(@client_cert) ? OpenSSL::X509::Certificate.new(File.read(@client_cert)) : nil,
|
208
|
+
client_key: present?(@client_key) ? OpenSSL::PKey::RSA.new(File.read(@client_key)) : nil,
|
238
209
|
ca_file: @ca_file,
|
239
210
|
verify_ssl: @verify_ssl ? OpenSSL::SSL::VERIFY_PEER : OpenSSL::SSL::VERIFY_NONE
|
240
211
|
}
|
@@ -256,15 +227,19 @@ module Fluent::Plugin
|
|
256
227
|
|
257
228
|
auth_options = {}
|
258
229
|
|
259
|
-
if @bearer_token_file
|
230
|
+
if present?(@bearer_token_file)
|
260
231
|
bearer_token = File.read(@bearer_token_file)
|
261
232
|
auth_options[:bearer_token] = bearer_token
|
262
233
|
end
|
263
234
|
|
264
235
|
log.debug "Creating K8S client"
|
265
|
-
@client = Kubeclient::Client.new
|
266
|
-
|
267
|
-
|
236
|
+
@client = Kubeclient::Client.new(
|
237
|
+
@kubernetes_url,
|
238
|
+
@apiVersion,
|
239
|
+
ssl_options: ssl_options,
|
240
|
+
auth_options: auth_options,
|
241
|
+
as: :parsed_symbolized
|
242
|
+
)
|
268
243
|
|
269
244
|
begin
|
270
245
|
@client.api_valid?
|
@@ -305,7 +280,7 @@ module Fluent::Plugin
|
|
305
280
|
'pod_name' => pod_name
|
306
281
|
}
|
307
282
|
}
|
308
|
-
if @kubernetes_url
|
283
|
+
if present?(@kubernetes_url)
|
309
284
|
pod_metadata = get_pod_metadata(container_id, namespace_name, pod_name, create_time, batch_miss_cache)
|
310
285
|
|
311
286
|
if (pod_metadata.include? 'containers') && (pod_metadata['containers'].include? container_id) && !@skip_container_metadata
|
@@ -396,5 +371,9 @@ module Fluent::Plugin
|
|
396
371
|
end
|
397
372
|
end
|
398
373
|
|
374
|
+
# copied from activesupport
|
375
|
+
def present?(object)
|
376
|
+
object.respond_to?(:empty?) ? !object.empty? : !!object
|
377
|
+
end
|
399
378
|
end
|
400
379
|
end
|
@@ -39,65 +39,65 @@ module KubernetesMetadata
|
|
39
39
|
|
40
40
|
def parse_namespace_metadata(namespace_object)
|
41
41
|
labels = String.new
|
42
|
-
labels = syms_to_strs(namespace_object[
|
42
|
+
labels = syms_to_strs(namespace_object[:metadata][:labels].to_h) unless @skip_labels
|
43
43
|
|
44
|
-
annotations = match_annotations(syms_to_strs(namespace_object[
|
44
|
+
annotations = match_annotations(syms_to_strs(namespace_object[:metadata][:annotations].to_h))
|
45
45
|
if @de_dot
|
46
46
|
self.de_dot!(labels) unless @skip_labels
|
47
47
|
self.de_dot!(annotations)
|
48
48
|
end
|
49
49
|
kubernetes_metadata = {
|
50
|
-
'namespace_id' => namespace_object[
|
51
|
-
'creation_timestamp' => namespace_object[
|
50
|
+
'namespace_id' => namespace_object[:metadata][:uid],
|
51
|
+
'creation_timestamp' => namespace_object[:metadata][:creationTimestamp]
|
52
52
|
}
|
53
53
|
kubernetes_metadata['namespace_labels'] = labels unless labels.empty?
|
54
54
|
kubernetes_metadata['namespace_annotations'] = annotations unless annotations.empty?
|
55
|
-
|
55
|
+
kubernetes_metadata
|
56
56
|
end
|
57
57
|
|
58
58
|
def parse_pod_metadata(pod_object)
|
59
59
|
labels = String.new
|
60
|
-
labels = syms_to_strs(pod_object[
|
60
|
+
labels = syms_to_strs(pod_object[:metadata][:labels].to_h) unless @skip_labels
|
61
61
|
|
62
|
-
annotations = match_annotations(syms_to_strs(pod_object[
|
62
|
+
annotations = match_annotations(syms_to_strs(pod_object[:metadata][:annotations].to_h))
|
63
63
|
if @de_dot
|
64
64
|
self.de_dot!(labels) unless @skip_labels
|
65
65
|
self.de_dot!(annotations)
|
66
66
|
end
|
67
67
|
|
68
|
-
# collect container
|
68
|
+
# collect container information
|
69
69
|
container_meta = {}
|
70
70
|
begin
|
71
|
-
pod_object[
|
71
|
+
pod_object[:status][:containerStatuses].each do|container_status|
|
72
72
|
# get plain container id (eg. docker://hash -> hash)
|
73
|
-
container_id = container_status[
|
73
|
+
container_id = container_status[:containerID].sub /^[-_a-zA-Z0-9]+:\/\//, ''
|
74
74
|
unless @skip_container_metadata
|
75
75
|
container_meta[container_id] = {
|
76
|
-
'name' => container_status[
|
77
|
-
'image' => container_status[
|
78
|
-
'image_id' => container_status[
|
76
|
+
'name' => container_status[:name],
|
77
|
+
'image' => container_status[:image],
|
78
|
+
'image_id' => container_status[:imageID]
|
79
79
|
}
|
80
80
|
else
|
81
81
|
container_meta[container_id] = {
|
82
|
-
'name' => container_status[
|
82
|
+
'name' => container_status[:name]
|
83
83
|
}
|
84
84
|
end
|
85
85
|
end
|
86
86
|
rescue
|
87
|
-
log.debug("parsing container meta information failed for: #{pod_object[
|
87
|
+
log.debug("parsing container meta information failed for: #{pod_object[:metadata][:namespace]}/#{pod_object[:metadata][:name]} ")
|
88
88
|
end
|
89
89
|
|
90
90
|
kubernetes_metadata = {
|
91
|
-
'namespace_name' => pod_object[
|
92
|
-
'pod_id' => pod_object[
|
93
|
-
'pod_name' => pod_object[
|
91
|
+
'namespace_name' => pod_object[:metadata][:namespace],
|
92
|
+
'pod_id' => pod_object[:metadata][:uid],
|
93
|
+
'pod_name' => pod_object[:metadata][:name],
|
94
94
|
'containers' => syms_to_strs(container_meta),
|
95
|
-
'host' => pod_object[
|
95
|
+
'host' => pod_object[:spec][:nodeName]
|
96
96
|
}
|
97
97
|
kubernetes_metadata['annotations'] = annotations unless annotations.empty?
|
98
98
|
kubernetes_metadata['labels'] = labels unless labels.empty?
|
99
99
|
kubernetes_metadata['master_url'] = @kubernetes_url unless @skip_master_url
|
100
|
-
|
100
|
+
kubernetes_metadata
|
101
101
|
end
|
102
102
|
|
103
103
|
def syms_to_strs(hsh)
|
@@ -117,29 +117,3 @@ module KubernetesMetadata
|
|
117
117
|
|
118
118
|
end
|
119
119
|
end
|
120
|
-
|
121
|
-
# copied from activesupport
|
122
|
-
class Object
|
123
|
-
# An object is blank if it's false, empty, or a whitespace string.
|
124
|
-
# For example, +nil+, '', ' ', [], {}, and +false+ are all blank.
|
125
|
-
#
|
126
|
-
# This simplifies
|
127
|
-
#
|
128
|
-
# !address || address.empty?
|
129
|
-
#
|
130
|
-
# to
|
131
|
-
#
|
132
|
-
# address.blank?
|
133
|
-
#
|
134
|
-
# @return [true, false]
|
135
|
-
def blank?
|
136
|
-
respond_to?(:empty?) ? !!empty? : !self
|
137
|
-
end
|
138
|
-
|
139
|
-
# An object is present if it's not blank.
|
140
|
-
#
|
141
|
-
# @return [true, false]
|
142
|
-
def present?
|
143
|
-
!blank?
|
144
|
-
end
|
145
|
-
end
|