diff --git a/kubernetes/base/config/kube_config.py b/kubernetes/base/config/kube_config.py index 09cda8bda0..4f68c94064 100644 --- a/kubernetes/base/config/kube_config.py +++ b/kubernetes/base/config/kube_config.py @@ -25,8 +25,6 @@ import time from collections import namedtuple -import google.auth -import google.auth.transport.requests import oauthlib.oauth2 import urllib3 import yaml @@ -44,6 +42,15 @@ except ImportError: pass +try: + import google.auth + import google.auth.transport.requests + google_auth_available = True +except ImportError: + google_auth_available = False + + + EXPIRY_SKEW_PREVENTION_DELAY = datetime.timedelta(minutes=5) KUBE_CONFIG_DEFAULT_LOCATION = os.environ.get('KUBECONFIG', '~/.kube/config') ENV_KUBECONFIG_PATH_SEPARATOR = ';' if platform.system() == 'Windows' else ':' @@ -239,15 +246,19 @@ def _refresh_credentials(): 'config' in self._user['auth-provider'] and 'cmd-path' in self._user['auth-provider']['config']): return _refresh_credentials_with_cmd_path() - - credentials, project_id = google.auth.default(scopes=[ - 'https://www.googleapis.com/auth/cloud-platform', - 'https://www.googleapis.com/auth/userinfo.email' - ]) - request = google.auth.transport.requests.Request() - credentials.refresh(request) - return credentials - + + # Make the Google auth block optional. + if google_auth_available: + credentials, project_id = google.auth.default(scopes=[ + 'https://www.googleapis.com/auth/cloud-platform', + 'https://www.googleapis.com/auth/userinfo.email' + ]) + request = google.auth.transport.requests.Request() + credentials.refresh(request) + return credentials + else: + return None + if get_google_credentials: self._get_google_credentials = get_google_credentials else: diff --git a/requirements.txt b/requirements.txt index bc6dc4dc00..da405abdc7 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,7 +3,6 @@ six>=1.9.0 # MIT python-dateutil>=2.5.3 # BSD setuptools>=21.0.0 # PSF/ZPL pyyaml>=5.4.1 # MIT -google-auth>=1.0.1 # Apache-2.0 websocket-client>=0.32.0,!=0.40.0,!=0.41.*,!=0.42.* # LGPLv2+ requests # Apache-2.0 requests-oauthlib # ISC diff --git a/setup.py b/setup.py index 74eb82d631..67eb782be5 100644 --- a/setup.py +++ b/setup.py @@ -28,7 +28,8 @@ # http://pypi.python.org/pypi/setuptools EXTRAS = { - 'adal': ['adal>=1.0.2'] + 'adal': ['adal>=1.0.2'], + 'google-auth': ['google-auth>=1.0.1'] } REQUIRES = [] with open('requirements.txt') as f: