Fix slash handling in KubernetesConnector's get_request

The KubernetesConnector can generate URLs that contain '//' when
joining the API prefix with the endpoint. This causes errors in newer
versions of the Kubernetes API and breaks agent startup since it uses
the API to determine the node hostname.

This patch changes KubernetesConnector.get_request()'s behavior to
remove extraneous slashes when necessary.

Change-Id: Icd45b0eb4a9e5535c7c9d95bda209ec186036fab
This commit is contained in:
Tim Buckley 2017-08-01 16:29:06 -06:00
parent 9ff337881b
commit 5f849db6a3
1 changed files with 8 additions and 1 deletions

View File

@ -146,7 +146,14 @@ class KubernetesConnector(object):
"""Sends request to Kubernetes API with given endpoint.
Will retry the request once, with updated token/cert, if unauthorized.
"""
request_url = "{}/{}".format(self.api_url, request_endpoint)
api_url = self.api_url
if api_url[-1] == '/':
api_url = api_url[:-1]
if request_endpoint[0] == '/':
request_endpoint = request_endpoint[1:]
request_url = "{}/{}".format(api_url, request_endpoint)
result = requests.get(request_url,
timeout=self.connection_timeout,
headers=self.api_request_header,