diff --git a/authentik/outposts/controllers/k8s/base.py b/authentik/outposts/controllers/k8s/base.py index a298ad325..d9f8a3c98 100644 --- a/authentik/outposts/controllers/k8s/base.py +++ b/authentik/outposts/controllers/k8s/base.py @@ -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,21 +78,26 @@ 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.logger.debug("Recreate requested") - if current: - self.logger.debug("Deleted old") - self.delete(current) - else: - self.logger.debug("No old found, creating") - self.logger.debug("Creating") - self.create(reference) + 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") + self.delete(current) + else: + self.logger.debug("No old found, creating") + self.logger.debug("Creating") + self.create(reference) + def down(self): """Delete object if found""" if self.noop: