Skip to content
This repository was archived by the owner on Sep 26, 2025. It is now read-only.

Commit 80f9702

Browse files
authored
Merge pull request #129 from splunk/refresh_token
Add support for refreshing bearer token
2 parents 9449d66 + 3ed5e86 commit 80f9702

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

docker/Gemfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ source 'https://rubygems.org'
66
gem "fluentd", ">=1.14.2"
77
gem "fluent-plugin-prometheus", ">=2.0"
88
gem "fluent-plugin-record-modifier", "=2.1.0"
9-
gem "fluent-plugin-kubernetes_metadata_filter", ">=2.5.3"
109
gem "fluent-plugin-jq", "=0.5.1"
1110
gem "oj", "=3.10.18"
1211
gem 'multi_json', '=1.14.1'

docker/Gemfile.lock

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,6 @@ GEM
3535
fluent-plugin-jq (0.5.1)
3636
fluentd (>= 0.14.10, < 2)
3737
multi_json (~> 1.13)
38-
fluent-plugin-kubernetes_metadata_filter (2.9.3)
39-
fluentd (>= 0.14.0, < 1.15)
40-
kubeclient (>= 4.0.0, < 5.0.0)
41-
lru_redux
4238
fluent-plugin-prometheus (2.0.2)
4339
fluentd (>= 1.9.1, < 2)
4440
prometheus-client (>= 2.1.0)
@@ -88,7 +84,6 @@ GEM
8884
jsonpath (~> 1.0)
8985
recursive-open-struct (~> 1.1, >= 1.1.1)
9086
rest-client (~> 2.0)
91-
lru_redux (1.1.0)
9287
mail (2.7.1)
9388
mini_mime (>= 0.1.1)
9489
mime-types (3.4.1)
@@ -162,7 +157,6 @@ DEPENDENCIES
162157
bigdecimal (= 3.0.0)
163158
fluent-plugin-jq (= 0.5.1)
164159
fluent-plugin-kubernetes-metrics!
165-
fluent-plugin-kubernetes_metadata_filter (>= 2.5.3)
166160
fluent-plugin-prometheus (>= 2.0)
167161
fluent-plugin-record-modifier (= 2.1.0)
168162
fluent-plugin-splunk-hec (>= 1.2.5)

lib/fluent/plugin/in_kubernetes_metrics.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ def init_without_kubeconfig(_options = {})
166166
}
167167

168168
auth_options = {}
169-
auth_options[:bearer_token] = File.read(@bearer_token_file) if @bearer_token_file
169+
auth_options[:bearer_token_file] = @bearer_token_file if @bearer_token_file
170170

171171
@client = Kubeclient::Client.new(
172172
@kubernetes_url, 'v1',
@@ -244,6 +244,11 @@ def set_ssl_options
244244
ssl_options
245245
end
246246

247+
# This method is used to refresh the authorization token for kubeclient
248+
def update_kubeclient_header
249+
@client.headers[:Authorization] = 'Bearer ' + File.read(@bearer_token_file) if @bearer_token_file
250+
end
251+
247252
# This method is used to set the options for sending a request to the kubelet api
248253
def request_options
249254
options = { method: 'get', url: @kubelet_url }
@@ -677,6 +682,7 @@ def scrape_metrics
677682
response = RestClient::Request.execute request_options
678683
handle_response(response)
679684
else
685+
update_kubeclient_header
680686
@node_names.each do |node|
681687
response = summary_proxy_api(node).get(@client.headers)
682688
handle_response(response)
@@ -688,6 +694,7 @@ def is_stats_endpoint_available?
688694
if @use_rest_client
689695
response_stats = RestClient::Request.execute request_options_stats
690696
else
697+
update_kubeclient_header
691698
@node_names.each do |node|
692699
@node_name = node
693700
response_stats = stats_proxy_api(node).get(@client.headers)
@@ -703,6 +710,7 @@ def scrape_stats_metrics
703710
response_stats = RestClient::Request.execute request_options_stats
704711
handle_stats_response(response_stats)
705712
else
713+
update_kubeclient_header
706714
@node_names.each do |node|
707715
@node_name = node
708716
response_stats = stats_proxy_api(node).get(@client.headers)
@@ -716,6 +724,7 @@ def scrape_cadvisor_metrics
716724
response_cadvisor = RestClient::Request.execute cadvisor_request_options
717725
handle_cadvisor_response(response_cadvisor)
718726
else
727+
update_kubeclient_header
719728
@node_names.each do |node|
720729
response_cadvisor = cadvisor_proxy_api(node).get(@client.headers)
721730
handle_cadvisor_response(response_cadvisor)

0 commit comments

Comments
 (0)