global
    log                 127.0.0.1 local2 debug
    user haproxy
    group haproxy
    maxconn             {{ config_options['global']['maxconn'] }}

defaults
    log                 global
    option              dontlognull
    timeout connect     {{ config_options['defaults']['timeout_connect'] }}
    timeout client      {{ config_options['defaults']['timeout_client'] }}
    timeout server      {{ config_options['defaults']['timeout_server'] }}
    timeout tunnel      {{ config_options['defaults']['timeout_tunnel'] }}
    timeout client-fin  {{ config_options['defaults']['timeout_client_fin'] }}
    maxconn             {{ config_options['defaults']['maxconn'] }}

frontend http
{%- for binding in bindings %}
    bind                {{ binding }}:80
{%- endfor %}
    option              tcplog
    mode                tcp
    default_backend     http_backend

backend http_backend
    mode                tcp
    balance             source
    option              tcp-check
    default-server      inter 2s fall 2 rise 3
{%- for node in nodes -%}
{% if 'worker' in node['roles'] %}
    server {{ node['name'] }} {{ node['internal_address'] }}:{{ target_ports.http }} check port {{ target_ports.http }} send-proxy
{%- endif %}
{%- endfor %}

frontend https
{%- for binding in bindings %}
    bind                {{ binding }}:443
{%- endfor %}
    option              tcplog
    mode                tcp
    default_backend     https_backend

backend https_backend
    mode                tcp
    balance             source
    option              tcp-check
    default-server      inter 2s fall 2 rise 3
{%- for node in nodes -%}
{% if 'worker' in node['roles'] %}
    server {{ node['name'] }} {{ node['internal_address'] }}:{{ target_ports.https }} check port {{ target_ports.https }} send-proxy
{%- endif %}
{%- endfor %}

frontend kubernetes_api
{%- for binding in bindings %}
    bind                {{ binding }}:6443
{%- endfor %}
    option              tcplog
    mode                tcp
    default_backend     kubernetes_control_plane_nodes

backend kubernetes_control_plane_nodes
    mode                tcp
    balance             roundrobin
    option              tcp-check
    default-server      inter 2s fall 2 rise 3
{%- for node in nodes -%}
{% if 'control-plane' in node['roles'] %}
    server {{ node['name'] }} {{ node['internal_address'] }}:6443 check port 6443
{%- endif %}
{%- endfor %}

