feat: Add new USE_KUBERNETES_FQDN environment variable to allow using the full qualified domain name of the services in Kubernetes instead of the ip address for the hostname of instances (default is yes)

This commit is contained in:
Théophile Diot 2024-08-07 14:05:26 +01:00
parent e1bd4a6313
commit 8a323582cf
No known key found for this signature in database
GPG key ID: FA995104A0BA376A
2 changed files with 13 additions and 5 deletions

View file

@ -11,6 +11,7 @@
- [FEATURE] Add new templating feature to allow to quickly override the default values of settings and custom configurations. You can also precise steps to follow in the UI to help the user configure services.
- [SCHEDULER] Refactor the scheduler to use the `BUNKERWEB_INSTANCES` (previously known as `OVERRIDE_INSTANCES`) environment variable instead of an integration specific system
- [AUTOCONF] Add new `NAMESPACES` environment variable to allow setting the namespaces to watch for the autoconf feature which makes it possible to use multiple autoconf instances in the same cluster while keeping the configuration separated
- [AUTOCONF] Add new `USE_KUBERNETES_FQDN` environment variable to allow using the full qualified domain name of the services in Kubernetes instead of the ip address for the hostname of instances (default is yes)
- [UI] Start refactoring the UI to make it more modular and easier to maintain with migration from Jinja to Vue.js
- [UI] Add a `remember me` feature to the login page so that the user can stay logged in for a longer period of time (expires after 31 days)
- [UI] Add new `TOTP_SECRETS` setting to encrypt the TOTP secrets in the database (if not set, we generate a random amount of secrets via passlib.totp) - ⚠ We highly recommend setting this setting to a custom value to prevent the secrets from being erased when the volumes are deleted

View file

@ -1,6 +1,7 @@
#!/usr/bin/env python3
from contextlib import suppress
from os import getenv
from time import sleep
from traceback import format_exc
from typing import List
@ -18,6 +19,8 @@ class IngressController(Controller):
config.load_incluster_config()
self.__corev1 = client.CoreV1Api()
self.__networkingv1 = client.NetworkingV1Api()
self.__use_fqdn = getenv("USE_KUBERNETES_FQDN", "yes").lower() == "yes"
self._logger.info(f"Using Pod {'FQDN' if self.__use_fqdn else 'IP'} as hostname")
def _get_controller_instances(self) -> list:
instances = []
@ -42,33 +45,37 @@ class IngressController(Controller):
def _to_instances(self, controller_instance) -> List[dict]:
instance = {
"name": controller_instance.metadata.name,
"hostname": controller_instance.metadata.name,
"hostname": controller_instance.metadata.name if self.__use_fqdn else controller_instance.status.pod_ip,
"health": False,
"type": "pod",
"env": {},
}
health = False
if controller_instance.status.conditions:
for condition in controller_instance.status.conditions:
if condition.type == "Ready" and condition.status == "True":
health = True
instance["health"] = True
break
instance["health"] = health
instance["env"] = {}
pod = None
for container in controller_instance.spec.containers:
if container.name == "bunkerweb":
pod = container
break
if not pod:
self._logger.warning(f"Missing container bunkerweb in pod {controller_instance.metadata.name}")
else:
for env in pod.env:
instance["env"][env.name] = env.value or ""
for controller_service in self._get_controller_services():
if controller_service.metadata.annotations:
for annotation, value in controller_service.metadata.annotations.items():
if not annotation.startswith("bunkerweb.io/"):
continue
instance["env"][annotation.replace("bunkerweb.io/", "", 1)] = value
return [instance]
def _to_services(self, controller_service) -> List[dict]: