From 622f2eb2ac0d4d69ba2b99496e6a3d8f78448059 Mon Sep 17 00:00:00 2001 From: florian Date: Tue, 4 Apr 2023 21:13:22 +0200 Subject: [PATCH] autoconf - check if service exists before adding config --- src/autoconf/Controller.py | 8 ++++++++ src/autoconf/IngressController.py | 5 +++++ src/autoconf/SwarmController.py | 5 +++++ 3 files changed, 18 insertions(+) diff --git a/src/autoconf/Controller.py b/src/autoconf/Controller.py index 39cd17804..57aa42ee7 100644 --- a/src/autoconf/Controller.py +++ b/src/autoconf/Controller.py @@ -103,3 +103,11 @@ class Controller(ABC): @abstractmethod def process_events(self): pass + + def _is_service_present(self, server_name) : + for service in self._services : + if not "SERVER_NAME" in service or service["SERVER_NAME"] == "" : + continue + if server_name == service["SERVER_NAME"].split(" ")[0] : + return True + return False diff --git a/src/autoconf/IngressController.py b/src/autoconf/IngressController.py index f614adce7..4936dda66 100644 --- a/src/autoconf/IngressController.py +++ b/src/autoconf/IngressController.py @@ -197,6 +197,11 @@ class IngressController(Controller, ConfigCaller): continue config_site = "" if "bunkerweb.io/CONFIG_SITE" in configmap.metadata.annotations: + if not self._is_service_present(configmap.metadata.annotations['bunkerweb.io/CONFIG_SITE']) : + self.__logger.warning( + f"Ignoring config {configmap.metadata.name} because {configmap.metadata.annotations['bunkerweb.io/CONFIG_SITE']} doesn't exist", + ) + continue config_site = ( f"{configmap.metadata.annotations['bunkerweb.io/CONFIG_SITE']}/" ) diff --git a/src/autoconf/SwarmController.py b/src/autoconf/SwarmController.py index 791a2add0..4527f24f1 100644 --- a/src/autoconf/SwarmController.py +++ b/src/autoconf/SwarmController.py @@ -112,6 +112,11 @@ class SwarmController(Controller, ConfigCaller): continue config_site = "" if "bunkerweb.CONFIG_SITE" in config.attrs["Spec"]["Labels"]: + if not self._is_service_present(config.attrs['Spec']['Labels']['bunkerweb.CONFIG_SITE']) : + self.__logger.warning( + f"Ignoring config {config_name} because {config.attrs['Spec']['Labels']['bunkerweb.CONFIG_SITE']} doesn't exist", + ) + continue config_site = ( f"{config.attrs['Spec']['Labels']['bunkerweb.CONFIG_SITE']}/" )