Fix resource cache not being used (#228)

Fix resource cache not being used

SUMMARY

This was some bad copy/paste from the openshift client. The resource
cache was never being used resulting in unnecessary HTTP requests.

ISSUE TYPE


Bugfix Pull Request

COMPONENT NAME

ADDITIONAL INFORMATION

Reviewed-by: None <None>
Reviewed-by: Gonéri Le Bouder <goneri@lebouder.net>
Reviewed-by: None <None>
This commit is contained in:
Mike Graves
2021-09-09 11:26:58 -04:00
committed by GitHub
parent 8bb455afb9
commit b397439972
2 changed files with 5 additions and 1 deletions

View File

@@ -0,0 +1,3 @@
---
bugfixes:
- fix resource cache not being used (https://github.com/ansible-collections/kubernetes.core/pull/228).

View File

@@ -18,6 +18,7 @@ import os
from collections import defaultdict
import hashlib
import tempfile
from functools import partial
import kubernetes.dynamic
import kubernetes.dynamic.discovery
@@ -74,7 +75,7 @@ class Discoverer(kubernetes.dynamic.discovery.Discoverer):
else:
try:
with open(self.__cache_file, 'r') as f:
self._cache = json.load(f, cls=CacheDecoder(self.client))
self._cache = json.load(f, cls=partial(CacheDecoder, self.client))
if self._cache.get('library_version') != __version__:
# Version mismatch, need to refresh cache
self.invalidate_cache()