Skip to content

Add support for refreshing bearer token #129

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion docker/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ source 'https://rubygems.org'
gem "fluentd", ">=1.14.2"
gem "fluent-plugin-prometheus", ">=2.0"
gem "fluent-plugin-record-modifier", "=2.1.0"
gem "fluent-plugin-kubernetes_metadata_filter", ">=2.5.3"
gem "fluent-plugin-jq", "=0.5.1"
gem "oj", "=3.10.18"
gem 'multi_json', '=1.14.1'
Expand Down
6 changes: 0 additions & 6 deletions docker/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ GEM
fluent-plugin-jq (0.5.1)
fluentd (>= 0.14.10, < 2)
multi_json (~> 1.13)
fluent-plugin-kubernetes_metadata_filter (2.9.3)
fluentd (>= 0.14.0, < 1.15)
kubeclient (>= 4.0.0, < 5.0.0)
lru_redux
fluent-plugin-prometheus (2.0.2)
fluentd (>= 1.9.1, < 2)
prometheus-client (>= 2.1.0)
Expand Down Expand Up @@ -88,7 +84,6 @@ GEM
jsonpath (~> 1.0)
recursive-open-struct (~> 1.1, >= 1.1.1)
rest-client (~> 2.0)
lru_redux (1.1.0)
mail (2.7.1)
mini_mime (>= 0.1.1)
mime-types (3.4.1)
Expand Down Expand Up @@ -162,7 +157,6 @@ DEPENDENCIES
bigdecimal (= 3.0.0)
fluent-plugin-jq (= 0.5.1)
fluent-plugin-kubernetes-metrics!
fluent-plugin-kubernetes_metadata_filter (>= 2.5.3)
fluent-plugin-prometheus (>= 2.0)
fluent-plugin-record-modifier (= 2.1.0)
fluent-plugin-splunk-hec (>= 1.2.5)
Expand Down
11 changes: 10 additions & 1 deletion lib/fluent/plugin/in_kubernetes_metrics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def init_without_kubeconfig(_options = {})
}

auth_options = {}
auth_options[:bearer_token] = File.read(@bearer_token_file) if @bearer_token_file
auth_options[:bearer_token_file] = @bearer_token_file if @bearer_token_file

@client = Kubeclient::Client.new(
@kubernetes_url, 'v1',
Expand Down Expand Up @@ -244,6 +244,11 @@ def set_ssl_options
ssl_options
end

# This method is used to refresh the authorization token for kubeclient
def update_kubeclient_header
@client.headers[:Authorization] = 'Bearer ' + File.read(@bearer_token_file) if @bearer_token_file
end

# This method is used to set the options for sending a request to the kubelet api
def request_options
options = { method: 'get', url: @kubelet_url }
Expand Down Expand Up @@ -677,6 +682,7 @@ def scrape_metrics
response = RestClient::Request.execute request_options
handle_response(response)
else
update_kubeclient_header
@node_names.each do |node|
response = summary_proxy_api(node).get(@client.headers)
handle_response(response)
Expand All @@ -688,6 +694,7 @@ def is_stats_endpoint_available?
if @use_rest_client
response_stats = RestClient::Request.execute request_options_stats
else
update_kubeclient_header
@node_names.each do |node|
@node_name = node
response_stats = stats_proxy_api(node).get(@client.headers)
Expand All @@ -703,6 +710,7 @@ def scrape_stats_metrics
response_stats = RestClient::Request.execute request_options_stats
handle_stats_response(response_stats)
else
update_kubeclient_header
@node_names.each do |node|
@node_name = node
response_stats = stats_proxy_api(node).get(@client.headers)
Expand All @@ -716,6 +724,7 @@ def scrape_cadvisor_metrics
response_cadvisor = RestClient::Request.execute cadvisor_request_options
handle_cadvisor_response(response_cadvisor)
else
update_kubeclient_header
@node_names.each do |node|
response_cadvisor = cadvisor_proxy_api(node).get(@client.headers)
handle_cadvisor_response(response_cadvisor)
Expand Down