autoconf - check if service exists before adding config

This commit is contained in:
florian 2023-04-04 21:13:22 +02:00
parent 9f70605643
commit 622f2eb2ac
No known key found for this signature in database
GPG key ID: 3D80806F12602A7C
3 changed files with 18 additions and 0 deletions

View file

@ -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

View file

@ -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']}/"
)

View file

@ -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']}/"
)