outposts: improve handling of recreate scenarios
Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
parent
92d38f62b5
commit
a1b3af401d
|
@ -1,5 +1,5 @@
|
|||
"""Base Kubernetes Reconciler"""
|
||||
from typing import TYPE_CHECKING, Generic, TypeVar
|
||||
from typing import TYPE_CHECKING, Generic, Optional, TypeVar
|
||||
|
||||
from django.utils.text import slugify
|
||||
from kubernetes.client import V1ObjectMeta
|
||||
|
@ -78,10 +78,17 @@ class KubernetesObjectReconciler(Generic[T]):
|
|||
# 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._recreate(current=current, reference=reference)
|
||||
return
|
||||
self.logger.debug("Other unhandled error", exc=exc)
|
||||
raise exc
|
||||
except NeedsRecreate:
|
||||
self._recreate(current=current, reference=reference)
|
||||
else:
|
||||
self.logger.debug("Object is up-to-date.")
|
||||
|
||||
def _recreate(self, reference: T, current: Optional[T] = None):
|
||||
"""Recreate object"""
|
||||
self.logger.debug("Recreate requested")
|
||||
if current:
|
||||
self.logger.debug("Deleted old")
|
||||
|
@ -90,8 +97,6 @@ class KubernetesObjectReconciler(Generic[T]):
|
|||
self.logger.debug("No old found, creating")
|
||||
self.logger.debug("Creating")
|
||||
self.create(reference)
|
||||
else:
|
||||
self.logger.debug("Object is up-to-date.")
|
||||
|
||||
def down(self):
|
||||
"""Delete object if found"""
|
||||
|
|
Reference in New Issue