Skip to content

Commit

Permalink
[#1766] feat: enhance IngressController to support configurable servi…
Browse files Browse the repository at this point in the history
…ce protocol
  • Loading branch information
TheophileDiot committed Dec 9, 2024
1 parent 756daea commit b97257c
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/autoconf/IngressController.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def __init__(self):
super().__init__("kubernetes")
config.load_incluster_config()

Configuration._default.verify_ssl = getenv("KUBERNETES_VERIFY_SSL", "yes") == "yes"
Configuration._default.verify_ssl = getenv("KUBERNETES_VERIFY_SSL", "yes").lower().strip() == "yes"
self._logger.info(f"SSL verification is {'enabled' if Configuration._default.verify_ssl else 'disabled'}")

ssl_ca_cert = getenv("KUBERNETES_SSL_CA_CERT", "")
Expand All @@ -30,7 +30,7 @@ def __init__(self):
self.__corev1 = client.CoreV1Api()
self.__networkingv1 = client.NetworkingV1Api()

self.__use_fqdn = getenv("USE_KUBERNETES_FQDN", "yes").lower() == "yes"
self.__use_fqdn = getenv("USE_KUBERNETES_FQDN", "yes").lower().strip() == "yes"
self._logger.info(f"Using Pod {'FQDN' if self.__use_fqdn else 'IP'} as hostname")

self.__ingress_class = getenv("KUBERNETES_INGRESS_CLASS", "")
Expand All @@ -40,6 +40,12 @@ def __init__(self):
self.__domain_name = getenv("KUBERNETES_DOMAIN_NAME", "cluster.local")
self._logger.info(f"Using domain name: {self.__domain_name}")

self.__service_protocol = getenv("KUBERNETES_SERVICE_PROTOCOL", "http").lower().strip()
if self.__service_protocol not in ("http", "https"):
self._logger.warning(f"Unsupported service protocol {self.__service_protocol}")
self.__service_protocol = "http"
self._logger.info(f"Using service protocol: {self.__service_protocol}")

def _get_controller_instances(self) -> list:
instances = []
pods = self.__corev1.list_pod_for_all_namespaces(watch=False).items
Expand Down Expand Up @@ -162,7 +168,7 @@ def _to_services(self, controller_service) -> List[dict]:
else:
port = path.backend.service.port.number

reverse_proxy_host = f"http://{path.backend.service.name}.{namespace}.svc.{self.__domain_name}"
reverse_proxy_host = f"{self.__service_protocol}://{path.backend.service.name}.{namespace}.svc.{self.__domain_name}"
if port != 80:
reverse_proxy_host += f":{port}"

Expand Down

0 comments on commit b97257c

Please sign in to comment.