From 12ddee3bb680b5dcd4577f0dc7ed19f6b2b0f449 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Fri, 27 Aug 2021 19:26:27 +0200 Subject: [PATCH] outpost: add additional labels to docker container Signed-off-by: Jens Langhammer --- authentik/outposts/controllers/docker.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/authentik/outposts/controllers/docker.py b/authentik/outposts/controllers/docker.py index 51c579b28..25784cb6d 100644 --- a/authentik/outposts/controllers/docker.py +++ b/authentik/outposts/controllers/docker.py @@ -29,7 +29,9 @@ class DockerController(BaseController): raise ControllerException from exc def _get_labels(self) -> dict[str, str]: - return {} + return { + "io.goauthentik.outpost-uuid": self.outpost.pk.hex, + } def _get_env(self) -> dict[str, str]: return { @@ -49,6 +51,17 @@ class DockerController(BaseController): return True return False + def _comp_labels(self, container: Container) -> bool: + """Check if container's labels is equal to what we would set. Return true if container needs + to be rebuilt.""" + should_be = self._get_labels() + for key, expected_value in should_be.items(): + if key not in container.labels: + return True + if container.labels[key] != expected_value: + return True + return False + def _comp_ports(self, container: Container) -> bool: """Check that the container has the correct ports exposed. Return true if container needs to be rebuilt.""" @@ -135,6 +148,11 @@ class DockerController(BaseController): self.logger.info("Container has outdated config, re-creating...") self.down() return self.up(depth + 1) + # Check that container values match our values + if self._comp_labels(container): + self.logger.info("Container has outdated labels, re-creating...") + self.down() + return self.up(depth + 1) if ( container.attrs.get("HostConfig", {}) .get("RestartPolicy", {})