autoconf - let's encrypt support for ingress controller

This commit is contained in:
florian
2021-08-03 22:38:00 +02:00
parent 4e178b474c
commit b6809266af
9 changed files with 31 additions and 23 deletions

View File

@@ -8,10 +8,11 @@ from logger import log
class Config :
def __init__(self, type, api_uri, lock=None) :
def __init__(self, type, api_uri, lock=None, http_port="8080") :
self.__type = type
self.__api_uri = api_uri
self.__lock = lock
self.__http_port = http_port
def __jobs(self) :
log("config", "INFO", "starting jobs ...")
@@ -145,16 +146,16 @@ class Config :
try :
dns_result = dns.resolver.query("tasks." + name)
for ip in dns_result :
urls.append("http://" + ip.to_text() + ":8080" + self.__api_uri + path)
urls.append("http://" + ip.to_text() + ":" + self.__http_port + self.__api_uri + path)
except :
ret = False
elif self.__type == Controller.Type.KUBERNETES :
for instance in instances :
name = instance.metadata.name
try :
dns_result = dns.resolver.query(name + ".default.svc.cluster.local")
dns_result = dns.resolver.query(name + "." + instance.metadata.namespace + ".svc.cluster.local")
for ip in dns_result :
urls.append("http://" + ip.to_text() + ":8080" + self.__api_uri + path)
urls.append("http://" + ip.to_text() + ":" + self.__http_port + self.__api_uri + path)
except :
ret = False

View File

@@ -10,8 +10,8 @@ class Type(Enum) :
class Controller(ABC) :
def __init__(self, type, api_uri=None, lock=None) :
self._config = Config(type, api_uri, lock)
def __init__(self, type, api_uri=None, lock=None, http_port="8080") :
self._config = Config(type, api_uri, lock=lock, http_port=http_port)
self.lock = lock
@abstractmethod

View File

@@ -8,8 +8,8 @@ from logger import log
class IngressController(Controller.Controller) :
def __init__(self, api_uri) :
super().__init__(Controller.Type.KUBERNETES, api_uri=api_uri, lock=Lock())
def __init__(self, api_uri, http_port) :
super().__init__(Controller.Type.KUBERNETES, api_uri=api_uri, lock=Lock(), http_port=http_port)
config.load_incluster_config()
self.__api = client.CoreV1Api()
self.__extensions_api = client.ExtensionsV1beta1Api()
@@ -78,6 +78,10 @@ class IngressController(Controller.Controller) :
first_servers.extend(env["SERVER_NAME"].split(" "))
for ingress in ingresses :
env.update(self.__rules_to_env(ingress.spec.rules))
if ingress.spec.tls :
for tls_entry in ingress.spec.tls :
for host in tls_entry.hosts :
env[host + "_AUTO_LETS_ENCRYPT"] = "yes"
if "SERVER_NAME" in env and env["SERVER_NAME"] != "" :
first_servers.extend(env["SERVER_NAME"].split(" "))
for service in services :

View File

@@ -7,8 +7,8 @@ import Controller
class SwarmController(Controller.Controller) :
def __init__(self, docker_host, api_uri) :
super().__init__(Controller.Type.SWARM, api_uri=api_uri, lock=Lock())
def __init__(self, docker_host, api_uri, http_port) :
super().__init__(Controller.Type.SWARM, api_uri=api_uri, lock=Lock(), http_port=http_port)
self.__client = docker.DockerClient(base_url=docker_host)
def __get_instances(self) :

View File

@@ -15,14 +15,15 @@ swarm = os.getenv("SWARM_MODE", "no") == "yes"
kubernetes = os.getenv("KUBERNETES_MODE", "no") == "yes"
api_uri = os.getenv("API_URI", "")
docker_host = os.getenv("DOCKER_HOST", "unix:///var/run/docker.sock")
http_port = os.getenv("HTTP_PORT", "8080")
# Instantiate the controller
if swarm :
log("autoconf", "INFO", "swarm mode detected")
controller = SwarmController(docker_host, api_uri)
controller = SwarmController(docker_host, api_uri, http_port)
elif kubernetes :
log("autoconf", "INFO", "kubernetes mode detected")
controller = IngressController(api_uri)
controller = IngressController(api_uri, http_port)
else :
log("autoconf", "INFO", "docker mode detected")
controller = DockerController(docker_host)