Skip to content

Commit

Permalink
Merge pull request google#107 from rimey/develop-with-proxy
Browse files Browse the repository at this point in the history
Enable connecting to the Kubernetes API through kubectl proxy.
  • Loading branch information
supriyagarg committed Aug 25, 2015
2 parents 951c0f2 + 1b1c8ea commit 65b3c8c
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion collector/kubernetes.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,21 @@ def get_kubernetes_base_url():
Uses the environment variables for the kubernetes service.
Additionally, the environment variable KUBERNETES_API can be used
to override the returned URL.
Returns:
The base URL for the Kubernetes master, including the API prefix.
Raises:
CollectorError: if the environment variable KUBERNETES_SERVICE_HOST
or KUBERNETES_SERVICE_PORT is not defined or empty.
"""
try:
return os.environ['KUBERNETES_API']
except KeyError:
pass

service_host = os.environ.get('KUBERNETES_SERVICE_HOST')
if not service_host:
raise collector_error.CollectorError(
Expand Down Expand Up @@ -99,7 +107,10 @@ def get_kubernetes_bearer_token():


def get_kubernetes_headers():
return {'Authorization': 'Bearer %s' % (get_kubernetes_bearer_token())}
try:
return {'Authorization': 'Bearer %s' % (get_kubernetes_bearer_token())}
except IOError:
return {}


@utilities.global_state_string_args
Expand Down

0 comments on commit 65b3c8c

Please sign in to comment.