From ef2eed0bdf32217cbfe3fb7ea451239d42b999f0 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Tue, 8 Feb 2022 17:40:49 +0100 Subject: [PATCH] outposts: fix compare_ports to support both service and container ports Signed-off-by: Jens Langhammer --- authentik/outposts/controllers/k8s/utils.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/authentik/outposts/controllers/k8s/utils.py b/authentik/outposts/controllers/k8s/utils.py index 2605d46b7..d1f01811f 100644 --- a/authentik/outposts/controllers/k8s/utils.py +++ b/authentik/outposts/controllers/k8s/utils.py @@ -1,6 +1,7 @@ """k8s utils""" from pathlib import Path +from kubernetes.client.models.v1_container_port import V1ContainerPort from kubernetes.client.models.v1_service_port import V1ServicePort from kubernetes.config.incluster_config import SERVICE_TOKEN_FILENAME @@ -16,19 +17,28 @@ def get_namespace() -> str: return "default" -def compare_port(current: V1ServicePort, reference: V1ServicePort) -> bool: +def compare_port( + current: V1ServicePort | V1ContainerPort, reference: V1ServicePort | V1ContainerPort +) -> bool: """Compare a single port""" if current.name != reference.name: return False - # We only care about the target port - if current.target_port != reference.target_port: - return False if current.protocol != reference.protocol: return False + if isinstance(current, V1ServicePort) and isinstance(reference, V1ServicePort): + # We only care about the target port + if current.target_port != reference.target_port: + return False + if isinstance(current, V1ContainerPort) and isinstance(reference, V1ContainerPort): + # We only care about the target port + if current.container_port != reference.container_port: + return False return True -def compare_ports(current: list[V1ServicePort], reference: list[V1ServicePort]): +def compare_ports( + current: list[V1ServicePort | V1ContainerPort], reference: list[V1ServicePort | V1ContainerPort] +): """Compare ports of a list""" if len(current) != len(reference): raise NeedsRecreate()