apiVersion: v1
kind: ConfigMap
metadata:
  name: kube-proxy
data:
  kube-proxy.yaml: |
    apiVersion: kubeproxy.config.k8s.io/v1alpha1
    kind: KubeProxyConfiguration
    mode: ipvs
    ipvs:
      scheduler: rr
      tcpFinTimeout: 30s
      strictARP: true
    clientConnection:
      kubeconfig: /etc/kubernetes/kubeconfig
    clusterCIDR: {{ required "podCIDR must be specified!" .Values.podCIDR }}
    metricsBindAddress: HOST_IP
    healthzBindAddress: HOST_IP
    hostnameOverride: NODE_NAME
    {{- if gt (len .Values.nodePortAddresses) 0 }}
    nodePortAddresses:
    {{- range $index, $address := .Values.nodePortAddresses }}
    - {{ $address }}
    {{- end }}
    {{- end }}
  kubeconfig: |
    apiVersion: v1
    clusters:
    - name: local
      cluster:
        {{- if gt (len .Values.apiServers) 1 }}
        server: https://127.0.0.1:9443
        {{- else }}
        server: https://{{- index .Values.apiServers 0 }}
        {{- end }}
        certificate-authority: /var/run/secrets/kubernetes.io/serviceaccount/ca.crt
    users:
    - name: service-account
      user:
        # Use service account token
        tokenFile: /var/run/secrets/kubernetes.io/serviceaccount/token
    contexts:
    - context:
        cluster: local
        user: service-account
  haproxy.cfg: |
    defaults
      # Do TLS passthrough
      mode tcp
      # Required values for both frontend and backend
      timeout connect 5s
      timeout client 30s
      timeout client-fin 30s
      timeout server 30s
      timeout tunnel 21d

    {{- if gt (len .Values.apiServers) 1 }}
    frontend kube-apiserver
      bind 127.0.0.1:9443
      default_backend kube-apiserver

    backend kube-apiserver
      option httpchk
      http-check send meth GET uri /healthz ver HTTP/1.1 hdr host kube-proxy
      {{- range $index, $server := .Values.apiServers }}
      server {{ $index }} {{ $server }} verify none check check-ssl
      {{- end }}
    {{- end }}

    frontend kube-proxy
      bind 127.0.0.1:10249
      default_backend kube-proxy

    backend kube-proxy
      option httpchk
      http-check send meth GET uri /healthz ver HTTP/1.1 hdr host kube-proxy
      server 1 HOST_IP:10249

    frontend stats
      bind HOST_IP:9080
      mode http
      http-request use-service prometheus-exporter if { path /metrics }
      stats enable
      stats uri /metrics
      stats refresh 10s
