From 45f99fbaf0b11e32a1d1dd995816c4480d54a907 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Sun, 3 Oct 2021 19:25:18 +0200 Subject: [PATCH] outposts: fix circular import in kubernetes controller Signed-off-by: Jens Langhammer --- authentik/outposts/controllers/k8s/base.py | 14 +------------- authentik/outposts/controllers/k8s/deployment.py | 3 ++- authentik/outposts/controllers/k8s/secret.py | 3 ++- authentik/outposts/controllers/k8s/triggers.py | 14 ++++++++++++++ authentik/outposts/controllers/k8s/utils.py | 2 +- .../providers/proxy/controllers/k8s/ingress.py | 7 ++----- .../providers/proxy/controllers/k8s/traefik.py | 3 ++- tests/integration/test_outpost_kubernetes.py | 2 +- 8 files changed, 25 insertions(+), 23 deletions(-) create mode 100644 authentik/outposts/controllers/k8s/triggers.py diff --git a/authentik/outposts/controllers/k8s/base.py b/authentik/outposts/controllers/k8s/base.py index d06a72b53..de7c244a2 100644 --- a/authentik/outposts/controllers/k8s/base.py +++ b/authentik/outposts/controllers/k8s/base.py @@ -10,7 +10,7 @@ from structlog.stdlib import get_logger from urllib3.exceptions import HTTPError from authentik import __version__ -from authentik.lib.sentry import SentryIgnoredException +from authentik.outposts.controllers.k8s.triggers import NeedsRecreate, NeedsUpdate from authentik.outposts.managed import MANAGED_OUTPOST if TYPE_CHECKING: @@ -20,18 +20,6 @@ if TYPE_CHECKING: T = TypeVar("T", V1Pod, V1Deployment) -class ReconcileTrigger(SentryIgnoredException): - """Base trigger raised by child classes to notify us""" - - -class NeedsRecreate(ReconcileTrigger): - """Exception to trigger a complete recreate of the Kubernetes Object""" - - -class NeedsUpdate(ReconcileTrigger): - """Exception to trigger an update to the Kubernetes Object""" - - class KubernetesObjectReconciler(Generic[T]): """Base Kubernetes Reconciler, handles the basic logic.""" diff --git a/authentik/outposts/controllers/k8s/deployment.py b/authentik/outposts/controllers/k8s/deployment.py index 47353f94c..5d3d1a74c 100644 --- a/authentik/outposts/controllers/k8s/deployment.py +++ b/authentik/outposts/controllers/k8s/deployment.py @@ -17,7 +17,8 @@ from kubernetes.client import ( ) from authentik.outposts.controllers.base import FIELD_MANAGER -from authentik.outposts.controllers.k8s.base import KubernetesObjectReconciler, NeedsUpdate +from authentik.outposts.controllers.k8s.base import KubernetesObjectReconciler +from authentik.outposts.controllers.k8s.triggers import NeedsUpdate from authentik.outposts.controllers.k8s.utils import compare_ports from authentik.outposts.models import Outpost diff --git a/authentik/outposts/controllers/k8s/secret.py b/authentik/outposts/controllers/k8s/secret.py index d7cb8c03c..fc8dc8296 100644 --- a/authentik/outposts/controllers/k8s/secret.py +++ b/authentik/outposts/controllers/k8s/secret.py @@ -5,7 +5,8 @@ from typing import TYPE_CHECKING from kubernetes.client import CoreV1Api, V1Secret from authentik.outposts.controllers.base import FIELD_MANAGER -from authentik.outposts.controllers.k8s.base import KubernetesObjectReconciler, NeedsUpdate +from authentik.outposts.controllers.k8s.base import KubernetesObjectReconciler +from authentik.outposts.controllers.k8s.triggers import NeedsUpdate if TYPE_CHECKING: from authentik.outposts.controllers.kubernetes import KubernetesController diff --git a/authentik/outposts/controllers/k8s/triggers.py b/authentik/outposts/controllers/k8s/triggers.py new file mode 100644 index 000000000..284acd3bc --- /dev/null +++ b/authentik/outposts/controllers/k8s/triggers.py @@ -0,0 +1,14 @@ +"""exceptions used by the kubernetes reconciler to trigger updates""" +from authentik.lib.sentry import SentryIgnoredException + + +class ReconcileTrigger(SentryIgnoredException): + """Base trigger raised by child classes to notify us""" + + +class NeedsRecreate(ReconcileTrigger): + """Exception to trigger a complete recreate of the Kubernetes Object""" + + +class NeedsUpdate(ReconcileTrigger): + """Exception to trigger an update to the Kubernetes Object""" diff --git a/authentik/outposts/controllers/k8s/utils.py b/authentik/outposts/controllers/k8s/utils.py index ad158e7e8..c44200555 100644 --- a/authentik/outposts/controllers/k8s/utils.py +++ b/authentik/outposts/controllers/k8s/utils.py @@ -4,7 +4,7 @@ from pathlib import Path from kubernetes.client.models.v1_container_port import V1ContainerPort from kubernetes.config.incluster_config import SERVICE_TOKEN_FILENAME -from authentik.outposts.controllers.k8s.base import NeedsRecreate +from authentik.outposts.controllers.k8s.triggers import NeedsRecreate def get_namespace() -> str: diff --git a/authentik/providers/proxy/controllers/k8s/ingress.py b/authentik/providers/proxy/controllers/k8s/ingress.py index 601cf9c1b..14eaa0d6e 100644 --- a/authentik/providers/proxy/controllers/k8s/ingress.py +++ b/authentik/providers/proxy/controllers/k8s/ingress.py @@ -14,11 +14,8 @@ from kubernetes.client import ( from kubernetes.client.models.networking_v1beta1_ingress_rule import NetworkingV1beta1IngressRule from authentik.outposts.controllers.base import FIELD_MANAGER -from authentik.outposts.controllers.k8s.base import ( - KubernetesObjectReconciler, - NeedsRecreate, - NeedsUpdate, -) +from authentik.outposts.controllers.k8s.base import KubernetesObjectReconciler +from authentik.outposts.controllers.k8s.triggers import NeedsRecreate, NeedsUpdate from authentik.providers.proxy.models import ProxyMode, ProxyProvider if TYPE_CHECKING: diff --git a/authentik/providers/proxy/controllers/k8s/traefik.py b/authentik/providers/proxy/controllers/k8s/traefik.py index 8f3cb816a..623c343a8 100644 --- a/authentik/providers/proxy/controllers/k8s/traefik.py +++ b/authentik/providers/proxy/controllers/k8s/traefik.py @@ -6,7 +6,8 @@ from dacite import from_dict from kubernetes.client import ApiextensionsV1Api, CustomObjectsApi from authentik.outposts.controllers.base import FIELD_MANAGER -from authentik.outposts.controllers.k8s.base import KubernetesObjectReconciler, NeedsUpdate +from authentik.outposts.controllers.k8s.base import KubernetesObjectReconciler +from authentik.outposts.controllers.k8s.triggers import NeedsUpdate from authentik.providers.proxy.models import ProxyMode, ProxyProvider if TYPE_CHECKING: diff --git a/tests/integration/test_outpost_kubernetes.py b/tests/integration/test_outpost_kubernetes.py index a82261854..40d96e833 100644 --- a/tests/integration/test_outpost_kubernetes.py +++ b/tests/integration/test_outpost_kubernetes.py @@ -3,8 +3,8 @@ from django.test import TestCase from authentik.flows.models import Flow from authentik.lib.config import CONFIG -from authentik.outposts.controllers.k8s.base import NeedsUpdate from authentik.outposts.controllers.k8s.deployment import DeploymentReconciler +from authentik.outposts.controllers.k8s.triggers import NeedsUpdate from authentik.outposts.controllers.kubernetes import KubernetesController from authentik.outposts.models import KubernetesServiceConnection, Outpost, OutpostType from authentik.outposts.tasks import outpost_local_connection