Return consistent info in discovery if the whole group-version is absent
from typing import Dict, Optional, cast
+import aiohttp
+
from kopf.clients import auth
from kopf.structs import resources
@@ -17,6 +19,7 @@ async def discover(
async with session._discovery_lock:
if resource not in session._discovered_resources:
+ try:
response = await session.get(
url=resource.get_version_url(server=session.server),
)
@@ -27,6 +30,13 @@ async def discover(
resources.Resource(resource.group, resource.version, info['name']): info
for info in respdata['resources']
})
+
+ except aiohttp.ClientResponseError as e:
+ if e.status in [403, 404]:
+ session._discovered_resources[resource] = None
+ else:
+ raise
+
return session._discovered_resources.get(resource, None)
