Skip to content

Commit 2d4d6f3

Browse files
committed
All resources to be found through exception deferral
There are situations where a given api service unrelated to the requested resource is unavailable and an ServiceUnavailableError exception is thrown. The change in this PR will allow resources to be found if the resource being requested is unrelated to an api service that is unavailable. Resolves openshift#349
1 parent 29851d0 commit 2d4d6f3

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

openshift/dynamic/discovery.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from urllib3.exceptions import ProtocolError, MaxRetryError
1010

1111
from openshift import __version__
12-
from .exceptions import ResourceNotFoundError, ResourceNotUniqueError, ApiException
12+
from .exceptions import ResourceNotFoundError, ResourceNotUniqueError, ApiException, ServiceUnavailableError
1313
from .resource import Resource, ResourceList
1414

1515

@@ -29,6 +29,7 @@ def __init__(self, client, cache_file):
2929
default_cachefile_name = 'osrcp-{0}.json'.format(hashlib.sha1(self.__get_default_cache_id()).hexdigest())
3030
self.__cache_file = cache_file or os.path.join(tempfile.gettempdir(), default_cachefile_name)
3131
self.__init_cache()
32+
self.__deferred_exception = None
3233

3334
def __get_default_cache_id(self):
3435
user = self.__get_user()
@@ -182,7 +183,11 @@ def get_resources_for_api_version(self, prefix, group, version, preferred):
182183
subresources = {}
183184

184185
path = '/'.join(filter(None, [prefix, group, version]))
185-
resources_response = self.client.request('GET', path).resources or []
186+
try:
187+
resources_response = self.client.request('GET', path).resources or []
188+
except ServiceUnavailableError as e:
189+
self.__deferred_exception = e
190+
resources_response = []
186191

187192
resources_raw = list(filter(lambda resource: '/' not in resource['name'], resources_response))
188193
subresources_raw = list(filter(lambda resource: '/' in resource['name'], resources_response))
@@ -240,7 +245,7 @@ def get(self, **kwargs):
240245
if len(results) == 1:
241246
return results[0]
242247
elif not results:
243-
raise ResourceNotFoundError('No matches found for {}'.format(kwargs))
248+
raise self.__deferred_exception or ResourceNotFoundError('No matches found for {}'.format(kwargs))
244249
else:
245250
raise ResourceNotUniqueError('Multiple matches found for {}: {}'.format(kwargs, results))
246251

0 commit comments

Comments
 (0)