outposts: handle k8s 422 response code by recreating objects

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2021-10-18 10:23:11 +02:00
parent 98a56c77e3
commit 92d38f62b5
1 changed files with 11 additions and 3 deletions

View File

@ -70,6 +70,17 @@ class KubernetesObjectReconciler(Generic[T]):
raise exc
else:
self.reconcile(current, reference)
except NeedsUpdate:
try:
self.update(current, reference)
self.logger.debug("Updating")
except (OpenApiException, HTTPError) as exc:
# pylint: disable=no-member
if isinstance(exc, ApiException) and exc.status == 422:
self.logger.debug("Failed to update current, triggering re-create")
raise NeedsRecreate from exc
self.logger.debug("Other unhandled error", exc=exc)
raise exc
except NeedsRecreate:
self.logger.debug("Recreate requested")
if current:
@ -79,9 +90,6 @@ class KubernetesObjectReconciler(Generic[T]):
self.logger.debug("No old found, creating")
self.logger.debug("Creating")
self.create(reference)
except NeedsUpdate:
self.logger.debug("Updating")
self.update(current, reference)
else:
self.logger.debug("Object is up-to-date.")