@@ -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