Skip to content

Commit

Permalink
feat: Add new USE_KUBERNETES_FQDN environment variable to allow usi…
Browse files Browse the repository at this point in the history
…ng the full qualified domain name of the services in Kubernetes instead of the ip address for the hostname of instances (default is yes)
  • Loading branch information
TheophileDiot committed Aug 7, 2024
1 parent e1bd4a6 commit 8a32358
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 12 additions & 5 deletions src/autoconf/IngressController.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -18,6 +19,8 @@ def __init__(self):
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 = []
Expand All @@ -42,33 +45,37 @@ def _get_controller_services(self) -> list:
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]:
Expand Down

0 comments on commit 8a32358

Please sign in to comment.