fluent-plugin-kubernetes-objects 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +91 -0
- data/LICENSE +233 -0
- data/README.md +169 -0
- data/Rakefile +10 -0
- data/fluent-plugin-kubernetes-objects.gemspec +43 -0
- data/lib/fluent/plugin/in_kubernetes_objects.rb +237 -0
- data/test/fluent/plugin/in_kubernetes_objects_test.rb +134 -0
- data/test/lib/no_webmock/http_lib_adapters/curb_adapter.rb +0 -0
- data/test/lib/no_webmock/http_lib_adapters/em_http_request_adapter.rb +0 -0
- data/test/lib/no_webmock/http_lib_adapters/excon_adapter.rb +0 -0
- data/test/lib/no_webmock/http_lib_adapters/httpclient_adapter.rb +0 -0
- data/test/lib/no_webmock/http_lib_adapters/manticore_adapter.rb +0 -0
- data/test/lib/no_webmock/http_lib_adapters/patron_adapter.rb +0 -0
- data/test/lib/no_webmock/http_lib_adapters/typhoeus_hydra_adapter.rb +0 -0
- data/test/test_helper.rb +95 -0
- metadata +169 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: d39161509a5767c7b3bb242c99b750af77fd3d5999b37afc58fc8a450f9f68be
|
4
|
+
data.tar.gz: c87dd9f4fe3c9003cc56f5033d0492eb0f4c558ad2fefe00cb312c7ed8896910
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 030e4ff7c8ed1a20fd6b27b10a8324e07e0e0d47c4ee36438c199a919ff8c71fadb728bd3c50ba91bf23db801acdd0873704d71201ad4c7321db94ee4e98cd79
|
7
|
+
data.tar.gz: 2eaa921a968b667d146b195239e8ed2661d7662116abc6c1388d8a1248abb1c75043dfa4bb3e3cafd431039867e7fb018219cfabc047358fd56ecade3622fbec
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at zliang@splunk.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
fluent-plugin-kubernetes-objects (1.0.0)
|
5
|
+
fluentd (~> 1.0)
|
6
|
+
kubeclient (~> 3.0)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
addressable (2.5.2)
|
12
|
+
public_suffix (>= 2.0.2, < 4.0)
|
13
|
+
cool.io (1.5.3)
|
14
|
+
crack (0.4.3)
|
15
|
+
safe_yaml (~> 1.0.0)
|
16
|
+
dig_rb (1.0.1)
|
17
|
+
domain_name (0.5.20170404)
|
18
|
+
unf (>= 0.0.5, < 1.0.0)
|
19
|
+
fluentd (1.1.0)
|
20
|
+
cool.io (>= 1.4.5, < 2.0.0)
|
21
|
+
dig_rb (~> 1.0.0)
|
22
|
+
http_parser.rb (>= 0.5.1, < 0.7.0)
|
23
|
+
msgpack (>= 0.7.0, < 2.0.0)
|
24
|
+
serverengine (>= 2.0.4, < 3.0.0)
|
25
|
+
sigdump (~> 0.2.2)
|
26
|
+
strptime (>= 0.2.2, < 1.0.0)
|
27
|
+
tzinfo (~> 1.0)
|
28
|
+
tzinfo-data (~> 1.0)
|
29
|
+
yajl-ruby (~> 1.0)
|
30
|
+
hashdiff (0.3.7)
|
31
|
+
http (2.2.2)
|
32
|
+
addressable (~> 2.3)
|
33
|
+
http-cookie (~> 1.0)
|
34
|
+
http-form_data (~> 1.0.1)
|
35
|
+
http_parser.rb (~> 0.6.0)
|
36
|
+
http-cookie (1.0.3)
|
37
|
+
domain_name (~> 0.5)
|
38
|
+
http-form_data (1.0.3)
|
39
|
+
http_parser.rb (0.6.0)
|
40
|
+
kubeclient (3.0.0)
|
41
|
+
http (~> 2.2.2)
|
42
|
+
recursive-open-struct (~> 1.0.4)
|
43
|
+
rest-client (~> 2.0)
|
44
|
+
mime-types (3.1)
|
45
|
+
mime-types-data (~> 3.2015)
|
46
|
+
mime-types-data (3.2016.0521)
|
47
|
+
minitest (5.11.3)
|
48
|
+
msgpack (1.2.4)
|
49
|
+
netrc (0.11.0)
|
50
|
+
power_assert (1.1.1)
|
51
|
+
public_suffix (3.0.2)
|
52
|
+
rake (10.5.0)
|
53
|
+
recursive-open-struct (1.0.5)
|
54
|
+
rest-client (2.0.2)
|
55
|
+
http-cookie (>= 1.0.2, < 2.0)
|
56
|
+
mime-types (>= 1.16, < 4.0)
|
57
|
+
netrc (~> 0.8)
|
58
|
+
safe_yaml (1.0.4)
|
59
|
+
serverengine (2.0.6)
|
60
|
+
sigdump (~> 0.2.2)
|
61
|
+
sigdump (0.2.4)
|
62
|
+
strptime (0.2.3)
|
63
|
+
test-unit (3.2.7)
|
64
|
+
power_assert
|
65
|
+
thread_safe (0.3.6)
|
66
|
+
tzinfo (1.2.5)
|
67
|
+
thread_safe (~> 0.1)
|
68
|
+
tzinfo-data (1.2018.3)
|
69
|
+
tzinfo (>= 1.0.0)
|
70
|
+
unf (0.1.4)
|
71
|
+
unf_ext
|
72
|
+
unf_ext (0.0.7.5)
|
73
|
+
webmock (3.3.0)
|
74
|
+
addressable (>= 2.3.6)
|
75
|
+
crack (>= 0.3.2)
|
76
|
+
hashdiff
|
77
|
+
yajl-ruby (1.3.1)
|
78
|
+
|
79
|
+
PLATFORMS
|
80
|
+
ruby
|
81
|
+
|
82
|
+
DEPENDENCIES
|
83
|
+
bundler (~> 1.16)
|
84
|
+
fluent-plugin-kubernetes-objects!
|
85
|
+
minitest (~> 5.0)
|
86
|
+
rake (~> 10.0)
|
87
|
+
test-unit (~> 3.0)
|
88
|
+
webmock (~> 3.2)
|
89
|
+
|
90
|
+
BUNDLED WITH
|
91
|
+
1.16.1
|
data/LICENSE
ADDED
@@ -0,0 +1,233 @@
|
|
1
|
+
Apache License
|
2
|
+
Version 2.0, January 2004
|
3
|
+
http://www.apache.org/licenses/
|
4
|
+
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
6
|
+
|
7
|
+
1. Definitions.
|
8
|
+
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
11
|
+
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
13
|
+
the copyright owner that is granting the License.
|
14
|
+
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
16
|
+
other entities that control, are controlled by, or are under common
|
17
|
+
control with that entity. For the purposes of this definition,
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
19
|
+
direction or management of such entity, whether by contract or
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
22
|
+
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
24
|
+
exercising permissions granted by this License.
|
25
|
+
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
27
|
+
including but not limited to software source code, documentation
|
28
|
+
source, and configuration files.
|
29
|
+
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
31
|
+
transformation or translation of a Source form, including but
|
32
|
+
not limited to compiled object code, generated documentation,
|
33
|
+
and conversions to other media types.
|
34
|
+
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
36
|
+
Object form, made available under the License, as indicated by a
|
37
|
+
copyright notice that is included in or attached to the work
|
38
|
+
(an example is provided in the Appendix below).
|
39
|
+
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
46
|
+
the Work and Derivative Works thereof.
|
47
|
+
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
49
|
+
the original version of the Work and any modifications or additions
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
61
|
+
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
64
|
+
subsequently incorporated within the Work.
|
65
|
+
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
72
|
+
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
78
|
+
where such license applies only to those patent claims licensable
|
79
|
+
by such Contributor that are necessarily infringed by their
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
82
|
+
institute patent litigation against any entity (including a
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
85
|
+
or contributory patent infringement, then any patent licenses
|
86
|
+
granted to You under this License for that Work shall terminate
|
87
|
+
as of the date such litigation is filed.
|
88
|
+
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
91
|
+
modifications, and in Source or Object form, provided that You
|
92
|
+
meet the following conditions:
|
93
|
+
|
94
|
+
(a) You must give any other recipients of the Work or
|
95
|
+
Derivative Works a copy of this License; and
|
96
|
+
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
98
|
+
stating that You changed the files; and
|
99
|
+
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
102
|
+
attribution notices from the Source form of the Work,
|
103
|
+
excluding those notices that do not pertain to any part of
|
104
|
+
the Derivative Works; and
|
105
|
+
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
108
|
+
include a readable copy of the attribution notices contained
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
111
|
+
of the following places: within a NOTICE text file distributed
|
112
|
+
as part of the Derivative Works; within the Source form or
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
114
|
+
within a display generated by the Derivative Works, if and
|
115
|
+
wherever such third-party notices normally appear. The contents
|
116
|
+
of the NOTICE file are for informational purposes only and
|
117
|
+
do not modify the License. You may add Your own attribution
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
120
|
+
that such additional attribution notices cannot be construed
|
121
|
+
as modifying the License.
|
122
|
+
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
124
|
+
may provide additional or different license terms and conditions
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
128
|
+
the conditions stated in this License.
|
129
|
+
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
133
|
+
this License, without any additional terms or conditions.
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
135
|
+
the terms of any separate license agreement you may have executed
|
136
|
+
with Licensor regarding such Contributions.
|
137
|
+
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
140
|
+
except as required for reasonable and customary use in describing the
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
142
|
+
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
152
|
+
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
158
|
+
incidental, or consequential damages of any character arising as a
|
159
|
+
result of this License or out of the use or inability to use the
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
162
|
+
other commercial damages or losses), even if such Contributor
|
163
|
+
has been advised of the possibility of such damages.
|
164
|
+
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
168
|
+
or other liability obligations and/or rights consistent with this
|
169
|
+
License. However, in accepting such obligations, You may act only
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
174
|
+
of your accepting any such warranty or additional liability.
|
175
|
+
|
176
|
+
END OF TERMS AND CONDITIONS
|
177
|
+
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
179
|
+
|
180
|
+
To apply the Apache License to your work, attach the following
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "{}"
|
182
|
+
replaced with your own identifying information. (Don't include
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
184
|
+
comment syntax for the file format. We also recommend that a
|
185
|
+
file or class name and description of purpose be included on the
|
186
|
+
same "printed page" as the copyright notice for easier
|
187
|
+
identification within third-party archives.
|
188
|
+
|
189
|
+
Copyright 2018 Splunk Inc.
|
190
|
+
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
192
|
+
you may not use this file except in compliance with the License.
|
193
|
+
You may obtain a copy of the License at
|
194
|
+
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
196
|
+
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
200
|
+
See the License for the specific language governing permissions and
|
201
|
+
limitations under the License.
|
202
|
+
|
203
|
+
=======================================================================
|
204
|
+
Fluentd Plugin for Kubernetes Objects:
|
205
|
+
|
206
|
+
The Fluentd Plugin for Kubernetes Objects project contains
|
207
|
+
subcomponents with separate copyright notices and license terms.
|
208
|
+
Your use of the source code for the these subcomponents is subject
|
209
|
+
to the terms and conditions of the following licenses.
|
210
|
+
|
211
|
+
========================================================================
|
212
|
+
Apache License 2.0
|
213
|
+
========================================================================
|
214
|
+
The following components are provided under the Apache License 2.0. See project link for details.
|
215
|
+
|
216
|
+
(Apache License 2.0) fluentd (https://github.com/fluent/fluentd/blob/master/LICENSE)
|
217
|
+
|
218
|
+
========================================================================
|
219
|
+
MIT licenses
|
220
|
+
========================================================================
|
221
|
+
The following components are provided under the MIT License. See project link for details.
|
222
|
+
|
223
|
+
(MIT License) kubeclient (https://github.com/abonas/kubeclient/blob/master/LICENSE.txt)
|
224
|
+
(MIT License) bundler (https://github.com/bundler/bundler/blob/master/LICENSE.md)
|
225
|
+
(MIT License) rake (https://github.com/ruby/rake/blob/master/MIT-LICENSE)
|
226
|
+
(MIT License) webmock (https://github.com/bblimke/webmock/blob/master/LICENSE)
|
227
|
+
(MIT License) minitest (https://github.com/seattlerb/minitest/blob/master/README.rdoc#license)
|
228
|
+
|
229
|
+
========================================================================
|
230
|
+
For test-unit:
|
231
|
+
========================================================================
|
232
|
+
|
233
|
+
See https://github.com/test-unit/test-unit/blob/master/COPYING
|
data/README.md
ADDED
@@ -0,0 +1,169 @@
|
|
1
|
+
[ ![Codeship Status for splunk/fluent-plugin-kubernetes-objects](https://app.codeship.com/projects/8ae91f00-261e-0136-02ab-6e830b67b562/status?branch=master)](https://app.codeship.com/projects/286766)
|
2
|
+
# fluent-plugin-kubernetes-objects
|
3
|
+
|
4
|
+
[Fluentd](https://fluentd.org/) input plugin to collect [objects](https://kubernetes.io/docs/concepts/overview/working-with-objects/kubernetes-objects/) in a kubernetes cluster.
|
5
|
+
|
6
|
+
This input plugin can collects data in two ways:
|
7
|
+
* pull: it collects all available objects at a interval by calling the list APIs.
|
8
|
+
* watch: it collects only the new objects when they show up by calling the watch APIs.
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
See also: [Plugin Management](https://docs.fluentd.org/v1.0/articles/plugin-management).
|
13
|
+
|
14
|
+
### RubyGems
|
15
|
+
|
16
|
+
```
|
17
|
+
$ gem install fluent-plugin-kubernetes-objects
|
18
|
+
```
|
19
|
+
|
20
|
+
### Bundler
|
21
|
+
|
22
|
+
Add following line to your Gemfile:
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
gem "fluent-plugin-kubernetes-objects"
|
26
|
+
```
|
27
|
+
|
28
|
+
And then execute:
|
29
|
+
|
30
|
+
```
|
31
|
+
$ bundle
|
32
|
+
```
|
33
|
+
|
34
|
+
## Configuration
|
35
|
+
|
36
|
+
### Example
|
37
|
+
|
38
|
+
```
|
39
|
+
<source>
|
40
|
+
@type kubernetes_objects
|
41
|
+
tag k8s.*
|
42
|
+
|
43
|
+
<pull>
|
44
|
+
resource_name nodes
|
45
|
+
</pull>
|
46
|
+
|
47
|
+
<pull>
|
48
|
+
resource_name pods
|
49
|
+
namespace default
|
50
|
+
</pull>
|
51
|
+
|
52
|
+
<watch>
|
53
|
+
resource_name events
|
54
|
+
</watch>
|
55
|
+
```
|
56
|
+
|
57
|
+
In this example, it will pull all the `nodes` , and all the `pods` in `default` namespace, and also watch `events`. And all those data will be tagged with prefix `"k8s."`.
|
58
|
+
|
59
|
+
### Parameters
|
60
|
+
|
61
|
+
#### @type (string) (required)
|
62
|
+
|
63
|
+
This must be `kubernetes_objects`.
|
64
|
+
|
65
|
+
#### tag (string) (optional)
|
66
|
+
|
67
|
+
The tag of the event.
|
68
|
+
|
69
|
+
`*` can be used as a placeholder that expands to the actual resource name (watch objects will have `.watch` suffix). For example, if you set
|
70
|
+
|
71
|
+
```
|
72
|
+
tag k8s.*
|
73
|
+
<pull>
|
74
|
+
resource_name pods
|
75
|
+
</pull>
|
76
|
+
<watch>
|
77
|
+
resource_name events
|
78
|
+
</watch>
|
79
|
+
```
|
80
|
+
|
81
|
+
The tag for `pods` data will be `k8s.pods`, while the tag for `events` will be `k8s.events.watch`.
|
82
|
+
|
83
|
+
Default value: `kubernetes.*`.
|
84
|
+
|
85
|
+
#### kubernetes_url (string) (optional)
|
86
|
+
|
87
|
+
The URL to the kubernetes API endpoint. By default, it will read from environment variables `KUBERNETES_SERVICE_HOST` and `KUBERNETES_SERVICE_PORT`. If those environment variables are not available, and this parameter is not set, error will be raised.
|
88
|
+
|
89
|
+
#### api_version (string) (optional)
|
90
|
+
|
91
|
+
Kubernetes API version, it includes the API group name and the version, just like the `apiVersion` in a Kubernetes manifests YAML file. E.g. `v1`, `rbac.authorization.k8s.io/v1`, etc.
|
92
|
+
|
93
|
+
Default value: `v1`.
|
94
|
+
|
95
|
+
#### client_cert (string) (optional)
|
96
|
+
|
97
|
+
Path to the certificate file for this client.
|
98
|
+
|
99
|
+
#### client_key (string) (optional)
|
100
|
+
|
101
|
+
Path to the private key file for this client.
|
102
|
+
|
103
|
+
#### ca_file (string) (optional)
|
104
|
+
|
105
|
+
Path to the CA file.
|
106
|
+
|
107
|
+
#### insecure_ssl (bool) (optional)
|
108
|
+
|
109
|
+
When set to `true`, it will ignore inscure `HTTPS` connections (i.e. it ignores server SSL certificate verification errors).
|
110
|
+
|
111
|
+
Default value: `false`.
|
112
|
+
|
113
|
+
#### secret_dir (string) (optional)
|
114
|
+
|
115
|
+
Path of the location where pod's service account's credentials are stored.th of the location where pod's service account's credentials are stored.
|
116
|
+
|
117
|
+
Default value: `/var/run/secrets/kubernetes.io/serviceaccount`.
|
118
|
+
|
119
|
+
#### bearer_token_file (string) (optional)
|
120
|
+
|
121
|
+
Path to the file contains the API token. By default it reads from the file "token" in the `secret_dir`.
|
122
|
+
|
123
|
+
#### <pull> Section (optional) (multiple)
|
124
|
+
|
125
|
+
Ths <pull> section is used to define which object to pull from the cluster. One section defines one object.
|
126
|
+
|
127
|
+
##### resource_name (string) (required)
|
128
|
+
|
129
|
+
The name of the object to pull. E.g. `pods`, `nodes`. This must match `api_version`.
|
130
|
+
The `resource_name` is not exactly the same as the name in Kubernetes API.
|
131
|
+
If a name contains multiple words, e.g. `daemonsets` and `replicasets`,
|
132
|
+
you will need use underscore `_` to separate the words.
|
133
|
+
So `daemonsets` becomes `daemon_sets`, and `replicasets` becomes `replica_sets`, and so on.
|
134
|
+
|
135
|
+
##### namespace (string) (optional)
|
136
|
+
|
137
|
+
Only the objects belong to the namespace specified in this parameter will be pulled. When it's not set, it will pull from all name spaces.
|
138
|
+
|
139
|
+
#### label_selector (string) (optional)
|
140
|
+
|
141
|
+
A selector to restrict the list of returned objects by labels.
|
142
|
+
|
143
|
+
#### field_selector (string) (optional)
|
144
|
+
|
145
|
+
A selector to restrict the list of returned objects by fields.
|
146
|
+
|
147
|
+
#### interval (time) (optional)
|
148
|
+
|
149
|
+
The interval at which the objects will be pulled.
|
150
|
+
|
151
|
+
Default value: `15m`.
|
152
|
+
|
153
|
+
#### <watch> Section (optional) (multiple)
|
154
|
+
|
155
|
+
Ths <watch> section is used to define which object to watch from the cluster. One section defines one object.
|
156
|
+
|
157
|
+
This section has exactly the same parameters except `interval` as the <pull> section does. Check the <pull> section above for details.
|
158
|
+
|
159
|
+
#### <storage> Section (optional) (single)
|
160
|
+
|
161
|
+
Defines where to storage checkpoints for `watch`. Each object the plugin watches, it will record the latest `resoruce_version` of that object. And when the fluentd restarts, the plugin will send the previously recorded `resource_version` to the kubernetes watch API.
|
162
|
+
|
163
|
+
By default, it uses the memory storage.
|
164
|
+
|
165
|
+
See also [Storage section configurations](https://docs.fluentd.org/v1.0/articles/storage-section) and [Storage Plugin Overview](https://docs.fluentd.org/v1.0/articles/storage-plugin-overview).
|
166
|
+
|
167
|
+
## License
|
168
|
+
|
169
|
+
See [License](LICENSE).
|
data/Rakefile
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
Gem::Specification.new do |spec|
|
2
|
+
spec.name = "fluent-plugin-kubernetes-objects"
|
3
|
+
spec.version = "1.0.0"
|
4
|
+
spec.authors = ["Gimi Liang"]
|
5
|
+
spec.email = ["zliang@splunk.com"]
|
6
|
+
|
7
|
+
spec.summary = %q{Fluentd Plugin for Kubernetes Objects.}
|
8
|
+
spec.description = %q{A Fluentd input plugin for collecting Kubernetes objects, e.g. pods, namespaces, events, etc. by pulling or watching.}
|
9
|
+
spec.homepage = "https://github.com/splunk/fluent-plugin-kubernetes-objects"
|
10
|
+
spec.license = "Apache-2.0"
|
11
|
+
|
12
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
13
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
14
|
+
# if spec.respond_to?(:metadata)
|
15
|
+
# spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
|
16
|
+
# else
|
17
|
+
# raise "RubyGems 2.0 or newer is required to protect against " \
|
18
|
+
# "public gem pushes."
|
19
|
+
# end
|
20
|
+
|
21
|
+
spec.require_paths = ["lib"]
|
22
|
+
spec.test_files = Dir.glob('test/**/**.rb')
|
23
|
+
spec.files = %w[
|
24
|
+
CODE_OF_CONDUCT.md README.md LICENSE
|
25
|
+
fluent-plugin-kubernetes-objects.gemspec
|
26
|
+
Gemfile Gemfile.lock
|
27
|
+
Rakefile
|
28
|
+
] + Dir.glob('lib/**/**').reject(&File.method(:directory?))
|
29
|
+
|
30
|
+
spec.bindir = "exe"
|
31
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
32
|
+
|
33
|
+
spec.required_ruby_version = '>= 2.3.0'
|
34
|
+
|
35
|
+
spec.add_runtime_dependency "fluentd", "~> 1.0"
|
36
|
+
spec.add_runtime_dependency "kubeclient", "~> 3.0"
|
37
|
+
|
38
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
39
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
40
|
+
spec.add_development_dependency "test-unit", "~> 3.0" # required by fluent/test.rb
|
41
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
42
|
+
spec.add_development_dependency "webmock", "~> 3.2"
|
43
|
+
end
|
@@ -0,0 +1,237 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "fluent/plugin/input"
|
4
|
+
require 'kubeclient'
|
5
|
+
|
6
|
+
module Fluent::Plugin
|
7
|
+
class KubernetesObjectsInput < Fluent::Plugin::Input
|
8
|
+
VERSION = "1.0.0"
|
9
|
+
|
10
|
+
Fluent::Plugin.register_input('kubernetes_objects', self)
|
11
|
+
|
12
|
+
helpers :storage, :thread
|
13
|
+
|
14
|
+
desc 'The tag of the event.'
|
15
|
+
config_param :tag, :string, default: 'kubernetes.*'
|
16
|
+
|
17
|
+
desc 'URL of the kubernetes API.'
|
18
|
+
config_param :kubernetes_url, :string, default: nil
|
19
|
+
|
20
|
+
desc 'Kubernetes API version.'
|
21
|
+
config_param :api_version, :string, default: 'v1'
|
22
|
+
|
23
|
+
desc 'Path to the certificate file for this client.'
|
24
|
+
config_param :client_cert, :string, default: nil
|
25
|
+
|
26
|
+
desc 'Path to the private key file for this client.'
|
27
|
+
config_param :client_key, :string, default: nil
|
28
|
+
|
29
|
+
desc 'Path to the CA file.'
|
30
|
+
config_param :ca_file, :string, default: nil
|
31
|
+
|
32
|
+
desc "If `insecure_ssl` is set to `true`, it won't verify apiserver's certificate."
|
33
|
+
config_param :insecure_ssl, :bool, default: false
|
34
|
+
|
35
|
+
desc 'Path to the file contains the API token. By default it reads from the file "token" in the `secret_dir`.'
|
36
|
+
config_param :bearer_token_file, :string, default: nil
|
37
|
+
|
38
|
+
desc "Path of the location where pod's service account's credentials are stored."
|
39
|
+
config_param :secret_dir, :string, default: '/var/run/secrets/kubernetes.io/serviceaccount'
|
40
|
+
|
41
|
+
desc 'Define a resource to pull.'
|
42
|
+
config_section :pull, required: false, init: false, multi: true, param_name: :pull_objects do
|
43
|
+
desc 'The name of the resource, e.g. "nodes".'
|
44
|
+
config_param :resource_name, :string
|
45
|
+
|
46
|
+
desc 'The namespace of the resource, it pulls from all namespaces if not set.'
|
47
|
+
config_param :namespace, :string, default: nil
|
48
|
+
|
49
|
+
desc 'A selector to restrict the list of returned objects by labels.'
|
50
|
+
config_param :label_selector, :string, default: nil
|
51
|
+
|
52
|
+
desc 'A selector to restrict the list of returned objects by fields.'
|
53
|
+
config_param :field_selector, :string, default: nil
|
54
|
+
|
55
|
+
desc 'The interval at which the objects will be pulled.'
|
56
|
+
config_param :interval, :time, default: 15 * 60
|
57
|
+
end
|
58
|
+
|
59
|
+
desc 'Define a resource to watch.'
|
60
|
+
config_section :watch, required: false, init: false, multi: true, param_name: :watch_objects do
|
61
|
+
desc 'The name of the resource, e.g. "events".'
|
62
|
+
config_param :resource_name, :string
|
63
|
+
|
64
|
+
desc 'The namespace of the resource, it watches all namespaces if not set.'
|
65
|
+
config_param :namespace, :string, default: nil
|
66
|
+
|
67
|
+
desc 'The name of the entity to watch, use this to watch only one entity.'
|
68
|
+
config_param :entity_name, :string, default: nil
|
69
|
+
|
70
|
+
desc 'A selector to restrict the list of returned objects by labels.'
|
71
|
+
config_param :label_selector, :string, default: nil
|
72
|
+
|
73
|
+
desc 'A selector to restrict the list of returned objects by fields.'
|
74
|
+
config_param :field_selector, :string, default: nil
|
75
|
+
end
|
76
|
+
|
77
|
+
config_section :storage do
|
78
|
+
# use memory by default
|
79
|
+
config_set_default :usage, "checkpoints"
|
80
|
+
config_set_default :@type, "local"
|
81
|
+
config_set_default :persistent, false
|
82
|
+
end
|
83
|
+
|
84
|
+
def configure(conf)
|
85
|
+
super
|
86
|
+
|
87
|
+
raise Fluent::ConfigError, "At least one <pull> or <watch> is required, but found none." if @pull_objects.empty? && @watch_objects.empty?
|
88
|
+
|
89
|
+
@storage = storage_create usage: "checkpoints"
|
90
|
+
|
91
|
+
parse_tag
|
92
|
+
initialize_client
|
93
|
+
end
|
94
|
+
|
95
|
+
def start
|
96
|
+
super
|
97
|
+
start_pullers
|
98
|
+
start_watchers
|
99
|
+
end
|
100
|
+
|
101
|
+
def close
|
102
|
+
@watchers.each &:finish if @watchers
|
103
|
+
super
|
104
|
+
end
|
105
|
+
|
106
|
+
private
|
107
|
+
|
108
|
+
def parse_tag
|
109
|
+
@tag_prefix, @tag_suffix = @tag.split('*') if @tag.include?('*')
|
110
|
+
end
|
111
|
+
|
112
|
+
def generate_tag(item_name)
|
113
|
+
return @tag unless @tag_prefix
|
114
|
+
|
115
|
+
[@tag_prefix, item_name, @tag_suffix].join
|
116
|
+
end
|
117
|
+
|
118
|
+
def initialize_client
|
119
|
+
# mostly borrowed from Fluentd Kubernetes Metadata Filter Plugin
|
120
|
+
if @kubernetes_url.nil?
|
121
|
+
# Use Kubernetes default service account if we're in a pod.
|
122
|
+
env_host = ENV['KUBERNETES_SERVICE_HOST']
|
123
|
+
env_port = ENV['KUBERNETES_SERVICE_PORT']
|
124
|
+
if env_host && env_port
|
125
|
+
@kubernetes_url = "https://#{env_host}:#{env_port}/#{@api_version == 'v1' ? 'api' : 'apis'}"
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
raise Fluent::ConfigError, "kubernetes url is not set" unless @kubernetes_url
|
130
|
+
|
131
|
+
# Use SSL certificate and bearer token from Kubernetes service account.
|
132
|
+
if Dir.exist?(@secret_dir)
|
133
|
+
secret_ca_file = File.join(@secret_dir, 'ca.cert')
|
134
|
+
secret_token_file = File.join(@secret_dir, 'token')
|
135
|
+
|
136
|
+
if @ca_file.nil? and File.exist?(secret_ca_file)
|
137
|
+
@ca_file = secret_ca_file
|
138
|
+
end
|
139
|
+
|
140
|
+
if @bearer_token_file.nil? and File.exist?(secret_token_file)
|
141
|
+
@bearer_token_file = secret_token_file
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
ssl_options = {
|
146
|
+
client_cert: @client_cert && OpenSSL::X509::Certificate.new(File.read(@client_cert)),
|
147
|
+
client_key: @client_key && OpenSSL::PKey::RSA.new(File.read(@client_key)),
|
148
|
+
ca_file: @ca_file,
|
149
|
+
verify_ssl: @insecure_ssl ? OpenSSL::SSL::VERIFY_NONE : OpenSSL::SSL::VERIFY_PEER
|
150
|
+
}
|
151
|
+
|
152
|
+
auth_options = {}
|
153
|
+
auth_options[:bearer_token] = File.read(@bearer_token_file) if @bearer_token_file
|
154
|
+
|
155
|
+
@client = Kubeclient::Client.new(
|
156
|
+
@kubernetes_url, @api_version,
|
157
|
+
ssl_options: ssl_options,
|
158
|
+
auth_options: auth_options
|
159
|
+
)
|
160
|
+
|
161
|
+
begin
|
162
|
+
@client.api_valid?
|
163
|
+
rescue KubeException => kube_error
|
164
|
+
raise Fluent::ConfigError, "Invalid Kubernetes API #{@api_version} endpoint #{@kubernetes_url}: #{kube_error.message}"
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
def start_pullers
|
169
|
+
@pull_objects.each(&method(:create_pull_thread))
|
170
|
+
end
|
171
|
+
|
172
|
+
def start_watchers
|
173
|
+
@watchers = @watch_objects.map do |o|
|
174
|
+
o = o.to_h.dup
|
175
|
+
o[:as] = :raw
|
176
|
+
resource_name = o.delete(:resource_name)
|
177
|
+
version = @storage.get(resource_name)
|
178
|
+
o[:resource_version] = version if version
|
179
|
+
@client.public_send("watch_#{resource_name}", o).tap { |watcher|
|
180
|
+
create_watcher_thread resource_name, watcher
|
181
|
+
}
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
def create_pull_thread(conf)
|
186
|
+
options = conf.to_h.dup
|
187
|
+
options[:as] = :raw
|
188
|
+
resource_name = options.delete :resource_name
|
189
|
+
pull_interval = options.delete :interval
|
190
|
+
|
191
|
+
thread_create :"pull_#{resource_name}" do
|
192
|
+
tag = generate_tag resource_name
|
193
|
+
while thread_current_running?
|
194
|
+
log.debug "Going to pull #{resource_name}"
|
195
|
+
response = @client.public_send "get_#{resource_name}", options
|
196
|
+
now = Fluent::Engine.now
|
197
|
+
es = Fluent::MultiEventStream.new
|
198
|
+
|
199
|
+
# code copied from kubeclient
|
200
|
+
# kubeclient will create one open struct object for each item in the response,
|
201
|
+
# but this is totally unecessary in this plugin, thus we use as: :raw.
|
202
|
+
result = JSON.parse(response)
|
203
|
+
|
204
|
+
resource_version = result.fetch('resourceVersion') {
|
205
|
+
result.fetch('metadata', {})['resourceVersion']
|
206
|
+
}
|
207
|
+
|
208
|
+
update_op = if resource_version
|
209
|
+
->(item) { item['metadata'].update requestResourceVersion: resource_version }
|
210
|
+
else
|
211
|
+
->(item) {}
|
212
|
+
end
|
213
|
+
|
214
|
+
# result['items'] might be nil due to https://github.com/kubernetes/kubernetes/issues/13096
|
215
|
+
items = result['items'].to_a
|
216
|
+
log.debug { "Received #{items.size} #{resource_name}" }
|
217
|
+
items.each { |item| es.add now, item.tap(&update_op) }
|
218
|
+
router.emit_stream(tag, es)
|
219
|
+
|
220
|
+
sleep(pull_interval)
|
221
|
+
end
|
222
|
+
end
|
223
|
+
end
|
224
|
+
|
225
|
+
def create_watcher_thread(object_name, watcher)
|
226
|
+
thread_create(:"watch_#{object_name}") {
|
227
|
+
tag = generate_tag "#{object_name}.watch"
|
228
|
+
watcher.each { |entity|
|
229
|
+
log.trace { "Received new object from watching #{object_name}"}
|
230
|
+
entity = JSON.parse(entity)
|
231
|
+
router.emit tag, Fluent::Engine.now, entity
|
232
|
+
@storage.put object_name, entity['object']['metadata']['resourceVersion']
|
233
|
+
}
|
234
|
+
}
|
235
|
+
end
|
236
|
+
end
|
237
|
+
end
|
@@ -0,0 +1,134 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
describe Fluent::Plugin::KubernetesObjectsInput do
|
4
|
+
include Fluent::Test::Helpers
|
5
|
+
include PluginTestHelper
|
6
|
+
|
7
|
+
before {
|
8
|
+
Fluent::Test.setup # setup router and others
|
9
|
+
stub_k8s_requests
|
10
|
+
}
|
11
|
+
|
12
|
+
it { expect(::Fluent::Plugin::KubernetesObjectsInput::VERSION).wont_be_nil }
|
13
|
+
|
14
|
+
it "should require at least one <pull> or <watch> section" do
|
15
|
+
expect{create_input_driver("kubernetes_url #{k8s_url}")}.must_raise Fluent::ConfigError
|
16
|
+
expect(create_input_driver(<<~CONF)).wont_be_nil
|
17
|
+
kubernetes_url #{k8s_url}
|
18
|
+
<pull>
|
19
|
+
resource_name nodes
|
20
|
+
</pull>
|
21
|
+
CONF
|
22
|
+
expect(create_input_driver(<<~CONF)).wont_be_nil
|
23
|
+
kubernetes_url #{k8s_url}
|
24
|
+
<watch>
|
25
|
+
resource_name nodes
|
26
|
+
</watch>
|
27
|
+
CONF
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "config: kubernetes_url" do
|
31
|
+
it "should read from environment variables by default" do
|
32
|
+
ENV['KUBERNETES_SERVICE_HOST'] = k8s_host
|
33
|
+
ENV['KUBERNETES_SERVICE_PORT'] = k8s_port
|
34
|
+
expect(create_input_driver(<<~CONF).instance.kubernetes_url).must_equal k8s_url
|
35
|
+
<pull>
|
36
|
+
resource_name nodes
|
37
|
+
</pull>
|
38
|
+
CONF
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should panic if not set" do
|
42
|
+
ENV['KUBERNETES_SERVICE_HOST'] = nil
|
43
|
+
ENV['KUBERNETES_SERVICE_PORT'] = nil
|
44
|
+
expect{ create_input_driver(<<~CONF) }.must_raise Fluent::ConfigError
|
45
|
+
<pull>
|
46
|
+
resource_name nodes
|
47
|
+
</pull>
|
48
|
+
CONF
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should use pick the right path" do
|
52
|
+
ENV['KUBERNETES_SERVICE_HOST'] = k8s_host
|
53
|
+
ENV['KUBERNETES_SERVICE_PORT'] = k8s_port
|
54
|
+
expect(create_input_driver(<<~CONF).instance.kubernetes_url).must_equal k8s_url('apis')
|
55
|
+
api_version apps/v1
|
56
|
+
<pull>
|
57
|
+
resource_name deployments
|
58
|
+
</pull>
|
59
|
+
CONF
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe "emit events" do
|
64
|
+
it "can pull one resource" do
|
65
|
+
d = create_input_driver(<<~CONF)
|
66
|
+
kubernetes_url #{k8s_url}
|
67
|
+
<pull>
|
68
|
+
resource_name nodes
|
69
|
+
</pull>
|
70
|
+
CONF
|
71
|
+
|
72
|
+
d.run expect_emits: 1, timeout: 3
|
73
|
+
events = d.events
|
74
|
+
|
75
|
+
expect(events[0][0]).must_equal 'kubernetes.nodes'
|
76
|
+
end
|
77
|
+
|
78
|
+
it "can pull multiple resources" do
|
79
|
+
d = create_input_driver(<<~CONF)
|
80
|
+
kubernetes_url #{k8s_url}
|
81
|
+
<pull>
|
82
|
+
resource_name namespaces
|
83
|
+
</pull>
|
84
|
+
<pull>
|
85
|
+
resource_name pods
|
86
|
+
</pull>
|
87
|
+
CONF
|
88
|
+
|
89
|
+
d.run expect_emits: 2, timeout: 3
|
90
|
+
events = d.events
|
91
|
+
|
92
|
+
expect(events.any? { |e| e[0] == 'kubernetes.pods'}).must_equal true
|
93
|
+
expect(events.any? { |e| e[0] == 'kubernetes.namespaces'}).must_equal true
|
94
|
+
end
|
95
|
+
|
96
|
+
it "can watch resources" do
|
97
|
+
d = create_input_driver(<<~CONF)
|
98
|
+
kubernetes_url #{k8s_url}
|
99
|
+
<watch>
|
100
|
+
resource_name events
|
101
|
+
</watch>
|
102
|
+
CONF
|
103
|
+
|
104
|
+
d.run expect_emits: 1, timeout: 3
|
105
|
+
events = d.events
|
106
|
+
expect(events.all? { |e| e[0] == 'kubernetes.events.watch'}).must_equal true
|
107
|
+
end
|
108
|
+
|
109
|
+
it "should use checkpoints for watching" do
|
110
|
+
begin
|
111
|
+
require 'tempfile'
|
112
|
+
f = Tempfile.new("fluentd-k8s-objects-test", encoding: 'utf-8')
|
113
|
+
f.write('{"events": "123456"}')
|
114
|
+
f.close
|
115
|
+
|
116
|
+
d = create_input_driver(<<~CONF)
|
117
|
+
kubernetes_url #{k8s_url}
|
118
|
+
<storage>
|
119
|
+
path #{f.path}
|
120
|
+
</storage>
|
121
|
+
<watch>
|
122
|
+
resource_name events
|
123
|
+
</watch>
|
124
|
+
CONF
|
125
|
+
|
126
|
+
stub_k8s_events params: {resourceVersion: "123456"}
|
127
|
+
|
128
|
+
d.run expect_emits: 1, timeout: 3
|
129
|
+
ensure
|
130
|
+
f.unlink
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
$LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
|
2
|
+
#$LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
|
3
|
+
|
4
|
+
# suppress warning, when require the 'http' library, it shows circle require warnning,
|
5
|
+
# which is pretty annoying (kubeclient depends on http for watch_stream)
|
6
|
+
_verbose = $VERBOSE
|
7
|
+
$VERBOSE = nil
|
8
|
+
require "fluent/plugin/in_kubernetes_objects"
|
9
|
+
$VERBOSE = _verbose
|
10
|
+
|
11
|
+
require "fluent/test"
|
12
|
+
require "fluent/test/driver/input"
|
13
|
+
require "fluent/test/helpers"
|
14
|
+
require "minitest/autorun"
|
15
|
+
require "webmock/minitest"
|
16
|
+
|
17
|
+
# make assertions from webmock available in minitest/spec
|
18
|
+
module Minitest::Expectations
|
19
|
+
infect_an_assertion :assert_requested, :must_be_requested, :reverse
|
20
|
+
infect_an_assertion :assert_not_requested, :wont_be_requested, :reverse
|
21
|
+
end
|
22
|
+
|
23
|
+
module PluginTestHelper
|
24
|
+
def k8s_host() "127.0.0.1" end
|
25
|
+
def k8s_port() "8001" end
|
26
|
+
def k8s_url(path='api') "https://#{k8s_host}:#{k8s_port}/#{path}" end
|
27
|
+
|
28
|
+
def fluentd_conf_for(*lines)
|
29
|
+
basic_config = [
|
30
|
+
]
|
31
|
+
(basic_config + lines).join("\n")
|
32
|
+
end
|
33
|
+
|
34
|
+
def create_input_driver(*configs)
|
35
|
+
Fluent::Test::Driver::Input.new(Fluent::Plugin::KubernetesObjectsInput).tap { |d|
|
36
|
+
d.configure(fluentd_conf_for(*configs))
|
37
|
+
}
|
38
|
+
end
|
39
|
+
|
40
|
+
def stub_k8s_requests
|
41
|
+
# all stub response bodies are from real k8s 1.8 API calls
|
42
|
+
stub_k8s_api
|
43
|
+
stub_k8s_apis
|
44
|
+
stub_k8s_v1
|
45
|
+
stub_k8s_namespaces
|
46
|
+
stub_k8s_nodes
|
47
|
+
stub_k8s_pods
|
48
|
+
stub_k8s_events
|
49
|
+
end
|
50
|
+
|
51
|
+
def stub_k8s_api
|
52
|
+
open(File.expand_path('../api.json', __FILE__)).tap { |f|
|
53
|
+
stub_request(:get, k8s_url).to_return(body: f.read)
|
54
|
+
}.close
|
55
|
+
end
|
56
|
+
|
57
|
+
def stub_k8s_apis
|
58
|
+
open(File.expand_path('../apis.json', __FILE__)).tap { |f|
|
59
|
+
stub_request(:get, k8s_url('apis')).to_return(body: f.read)
|
60
|
+
}.close
|
61
|
+
end
|
62
|
+
|
63
|
+
def stub_k8s_v1
|
64
|
+
open(File.expand_path('../v1.json', __FILE__)).tap { |f|
|
65
|
+
stub_request(:get, "#{k8s_url}/v1").to_return(body: f.read)
|
66
|
+
}.close
|
67
|
+
end
|
68
|
+
|
69
|
+
def stub_k8s_namespaces
|
70
|
+
open(File.expand_path('../namespaces.json', __FILE__)).tap { |f|
|
71
|
+
stub_request(:get, "#{k8s_url}/v1/namespaces").to_return(body: f.read())
|
72
|
+
}.close
|
73
|
+
end
|
74
|
+
|
75
|
+
def stub_k8s_nodes
|
76
|
+
open(File.expand_path('../nodes.json', __FILE__)).tap { |f|
|
77
|
+
stub_request(:get, "#{k8s_url}/v1/nodes").to_return(body: f.read())
|
78
|
+
}.close
|
79
|
+
end
|
80
|
+
|
81
|
+
def stub_k8s_pods
|
82
|
+
open(File.expand_path('../pods.json', __FILE__)).tap { |f|
|
83
|
+
stub_request(:get, "#{k8s_url}/v1/pods").to_return(body: f.read())
|
84
|
+
}.close
|
85
|
+
end
|
86
|
+
|
87
|
+
def stub_k8s_events(params: nil)
|
88
|
+
open(File.expand_path('../events.json', __FILE__)).tap { |f|
|
89
|
+
url = "#{k8s_url}/v1/watch/events"
|
90
|
+
url << '?' << params.map { |k, v| "#{k}=#{v}" }.join('&') if params
|
91
|
+
stub_request(:get, url).
|
92
|
+
to_return(body: f.read(), headers: {"Content-Type" => "application/json", "Transfer-Encoding" => "chunked"})
|
93
|
+
}.close
|
94
|
+
end
|
95
|
+
end
|
metadata
ADDED
@@ -0,0 +1,169 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fluent-plugin-kubernetes-objects
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Gimi Liang
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-05-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: fluentd
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: kubeclient
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.16'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.16'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: test-unit
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: minitest
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '5.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '5.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: webmock
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '3.2'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '3.2'
|
111
|
+
description: A Fluentd input plugin for collecting Kubernetes objects, e.g. pods,
|
112
|
+
namespaces, events, etc. by pulling or watching.
|
113
|
+
email:
|
114
|
+
- zliang@splunk.com
|
115
|
+
executables: []
|
116
|
+
extensions: []
|
117
|
+
extra_rdoc_files: []
|
118
|
+
files:
|
119
|
+
- CODE_OF_CONDUCT.md
|
120
|
+
- Gemfile
|
121
|
+
- Gemfile.lock
|
122
|
+
- LICENSE
|
123
|
+
- README.md
|
124
|
+
- Rakefile
|
125
|
+
- fluent-plugin-kubernetes-objects.gemspec
|
126
|
+
- lib/fluent/plugin/in_kubernetes_objects.rb
|
127
|
+
- test/fluent/plugin/in_kubernetes_objects_test.rb
|
128
|
+
- test/lib/no_webmock/http_lib_adapters/curb_adapter.rb
|
129
|
+
- test/lib/no_webmock/http_lib_adapters/em_http_request_adapter.rb
|
130
|
+
- test/lib/no_webmock/http_lib_adapters/excon_adapter.rb
|
131
|
+
- test/lib/no_webmock/http_lib_adapters/httpclient_adapter.rb
|
132
|
+
- test/lib/no_webmock/http_lib_adapters/manticore_adapter.rb
|
133
|
+
- test/lib/no_webmock/http_lib_adapters/patron_adapter.rb
|
134
|
+
- test/lib/no_webmock/http_lib_adapters/typhoeus_hydra_adapter.rb
|
135
|
+
- test/test_helper.rb
|
136
|
+
homepage: https://github.com/splunk/fluent-plugin-kubernetes-objects
|
137
|
+
licenses:
|
138
|
+
- Apache-2.0
|
139
|
+
metadata: {}
|
140
|
+
post_install_message:
|
141
|
+
rdoc_options: []
|
142
|
+
require_paths:
|
143
|
+
- lib
|
144
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
145
|
+
requirements:
|
146
|
+
- - ">="
|
147
|
+
- !ruby/object:Gem::Version
|
148
|
+
version: 2.3.0
|
149
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
150
|
+
requirements:
|
151
|
+
- - ">="
|
152
|
+
- !ruby/object:Gem::Version
|
153
|
+
version: '0'
|
154
|
+
requirements: []
|
155
|
+
rubyforge_project:
|
156
|
+
rubygems_version: 2.7.6
|
157
|
+
signing_key:
|
158
|
+
specification_version: 4
|
159
|
+
summary: Fluentd Plugin for Kubernetes Objects.
|
160
|
+
test_files:
|
161
|
+
- test/fluent/plugin/in_kubernetes_objects_test.rb
|
162
|
+
- test/lib/no_webmock/http_lib_adapters/patron_adapter.rb
|
163
|
+
- test/lib/no_webmock/http_lib_adapters/manticore_adapter.rb
|
164
|
+
- test/lib/no_webmock/http_lib_adapters/em_http_request_adapter.rb
|
165
|
+
- test/lib/no_webmock/http_lib_adapters/typhoeus_hydra_adapter.rb
|
166
|
+
- test/lib/no_webmock/http_lib_adapters/curb_adapter.rb
|
167
|
+
- test/lib/no_webmock/http_lib_adapters/httpclient_adapter.rb
|
168
|
+
- test/lib/no_webmock/http_lib_adapters/excon_adapter.rb
|
169
|
+
- test/test_helper.rb
|