diff --git a/gateway-haproxy-config.py b/gateway-haproxy-config.py index 8d479a0..46db381 100644 --- a/gateway-haproxy-config.py +++ b/gateway-haproxy-config.py @@ -10,8 +10,6 @@ import jinja2 __location__ = os.path.realpath(os.path.join(os.getcwd(), os.path.dirname(__file__))) -KUBERNETES_MASTER_PORT_LISTEN = 7443 -# the next two constants come from openstack for one of the master nodes KUBERNETES_MASTER_PORT = 6443 KUBERNETES_MASTER_IP = "10.0.20.7" # update with the private IP of one of the master nodes KUBECTL_HOST = "https://%s:%d" % (KUBERNETES_MASTER_IP, KUBERNETES_MASTER_PORT) @@ -55,7 +53,7 @@ def get_endpoints_for_loadbalancers(): gateway_endpoint['mode'] = "%s" % port['protocol'].lower() gateway_endpoint['balance'] = 'leastconn' gateway_endpoint['servers'] = [] - server_number = 0 + server_number = 1 if 'addresses' in subset: for address in subset['addresses']: gateway_endpoint['servers'].append("server %s_%s %s:%d check cookie %s" % (service_name, server_number, address['ip'], port['targetPort']), server_number) @@ -65,7 +63,7 @@ def get_endpoints_for_loadbalancers(): def get_haproxy_config(): load_balanced_endpoints = get_endpoints_for_loadbalancers() - haproxy_config = get_haproxy_config_template().render(services=load_balanced_endpoints) + haproxy_config = get_haproxy_config_template().render(backends=load_balanced_endpoints) return haproxy_config def main(): diff --git a/haproxy.j2 b/haproxy.j2 index aa0dd2d..c795ac2 100644 --- a/haproxy.j2 +++ b/haproxy.j2 @@ -15,15 +15,15 @@ defaults timeout client 50000 timeout server 50000 -{% for service in services %} -backend {{ service.name }} - mode {{ service.mode }} - balance {{ service.balance }} - {% for key, value in service.labels %} +{% for backend in backends %} +backend {{ backend.name }} + mode {{ backend.mode }} + balance {{ backend.balance }} + {% for key, value in backend.labels %} option {{ value }} # {{ key }} {% endfor % - cookie {{ service.mode }} insert indirect nocache - {% for server in service.servers -%} + cookie {{ backend.mode }} insert indirect nocache + {% for server in backend.servers -%} {{ server }} {% endfor %} diff --git a/oroginal b/oroginal new file mode 100644 index 0000000..59938ff --- /dev/null +++ b/oroginal @@ -0,0 +1,29 @@ +backend be_open_event_manager + description default backend for open-event-manager + mode http + balance roundrobin + option httpchk GET /health/check + option forwardfor + cookie OEM_SERVERID insert indirect nocache + server DE-NUE-WEB01 10.106.10.11:8081 check cookie 1 + server DE-NUE-WEB02 10.106.10.12:8081 check cookie 2 + server DE-NUE-WEB04 10.106.10.14:8081 check cookie 3 + server DE-NUE-WEB05 10.106.10.5:8081 check cookie 4 + server DE-NUE-WEB06 10.106.10.6:8081 check cookie 5 + + + + +"metadata": { + "labels": { + "key1" : "value1", + "key2" : "value2" + } +} + + + + {% for key, value in dict_item.items() %} +

Key: {{key}}

+

Value: {{value}}

+ {% endfor %} \ No newline at end of file