From 2ef8dfecb9dafbe99c31cb788fd4d64b2ac6371c Mon Sep 17 00:00:00 2001 From: Joao M Date: Thu, 11 Aug 2022 17:00:38 -0500 Subject: [PATCH] Added lookup_label parameter --- README.md | 3 +++ assets/scripts/swarm.py | 4 ++++ easymapping/__init__.py | 2 +- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d5b82b1..59655bd 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,7 @@ The environment variables will setup the HAProxy. | Environment Variable | Description | |----------------------|-------------------------------------------------------------------------------| | DISCOVER | How `haproxy.cfg` will be created: `static`, `docker` or `swarm` | +| LOOKUP_LABEL | (Optional) The key will search to match resources. Default: `easyhaproxy`. | | HAPROXY_USERNAME | (Optional) The HAProxy username to the statistics. Default: `admin` | | HAPROXY_PASSWORD | The HAProxy password to the statistics. If not set disable stats. | | HAPROXY_STATS_PORT | (Optional) The HAProxy port to the statistics. Default: `1936` | @@ -169,6 +170,8 @@ stats: password: password port: 1936 # Optional (default 1936) +lookup_label: easyhaproxy # The key the system will try to find in the docker labels. + customerrors: true # Optional (default false) easymapping: diff --git a/assets/scripts/swarm.py b/assets/scripts/swarm.py index c7741ec..e8bfb53 100644 --- a/assets/scripts/swarm.py +++ b/assets/scripts/swarm.py @@ -16,6 +16,10 @@ if os.getenv("HAPROXY_PASSWORD"): "port": os.getenv("HAPROXY_STATS_PORT") if os.getenv("HAPROXY_STATS_PORT") else "1936", } +result["metadata"] = { + "lookup_label": os.getenv("LOOKUP_LABEL") if os.getenv("LOOKUP_LABEL") else "easyhaproxy", +} + cfg = HaproxyConfigGenerator(result) print(cfg.generate(lineList)) diff --git a/easymapping/__init__.py b/easymapping/__init__.py index ead2cea..7a00b43 100644 --- a/easymapping/__init__.py +++ b/easymapping/__init__.py @@ -35,7 +35,7 @@ class DockerLabelHandler: class HaproxyConfigGenerator: def __init__(self, mapping, ssl_cert_folder="/etc/haproxy/certs"): self.mapping = mapping - self.label = DockerLabelHandler("easyhaproxy") + self.label = DockerLabelHandler(mapping['lookup_label'] if 'lookup_label' in mapping else "easyhaproxy") self.ssl_cert_folder = ssl_cert_folder self.ssl_cert_increment = 0 os.makedirs(self.ssl_cert_folder, exist_ok=True)