Skip to content

Commit

Permalink
track library version, and refresh cache on version mismatch (#283)
Browse files Browse the repository at this point in the history
  • Loading branch information
fabianvf authored Apr 17, 2019
1 parent 1a84141 commit 8d59337
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions openshift/dynamic/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from kubernetes import watch
from kubernetes.client.rest import ApiException

from openshift import __version__
from openshift.dynamic.exceptions import ResourceNotFoundError, ResourceNotUniqueError, api_exception, KubernetesValidateMissing
from urllib3.exceptions import ProtocolError, MaxRetryError

Expand Down Expand Up @@ -596,17 +597,19 @@ def __init__(self, client, cache_file):

def __init_cache(self, refresh=False):
if refresh or not os.path.exists(self.__cache_file):
self._cache = {}
self._cache = {'library_version': __version__}
refresh = True
else:
try:
with open(self.__cache_file, 'r') as f:
self._cache = json.load(f, cls=cache_decoder(self.client))
if self._cache.get('library_version') != __version__:
# Version mismatch, need to refresh cache
self.invalidate_cache()
except Exception:
return self.__init_cache(refresh=True)
self.invalidate_cache()
self._load_server_info()
self.discover()

if refresh:
self._write_cache()

Expand Down

0 comments on commit 8d59337

Please sign in to comment.