Skip to content

Commit 8d59337

Browse files
authored
track library version, and refresh cache on version mismatch (#283)
1 parent 1a84141 commit 8d59337

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

openshift/dynamic/client.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from kubernetes import watch
1515
from kubernetes.client.rest import ApiException
1616

17+
from openshift import __version__
1718
from openshift.dynamic.exceptions import ResourceNotFoundError, ResourceNotUniqueError, api_exception, KubernetesValidateMissing
1819
from urllib3.exceptions import ProtocolError, MaxRetryError
1920

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

597598
def __init_cache(self, refresh=False):
598599
if refresh or not os.path.exists(self.__cache_file):
599-
self._cache = {}
600+
self._cache = {'library_version': __version__}
600601
refresh = True
601602
else:
602603
try:
603604
with open(self.__cache_file, 'r') as f:
604605
self._cache = json.load(f, cls=cache_decoder(self.client))
606+
if self._cache.get('library_version') != __version__:
607+
# Version mismatch, need to refresh cache
608+
self.invalidate_cache()
605609
except Exception:
606-
return self.__init_cache(refresh=True)
610+
self.invalidate_cache()
607611
self._load_server_info()
608612
self.discover()
609-
610613
if refresh:
611614
self._write_cache()
612615

0 commit comments

Comments
 (0)