{{- include "common.values.setup" . -}}
{{- range $namespace := append .Values.routed_namespaces .Release.Namespace }}
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ include "pod-gateway.configmap" $ | quote }}
  namespace: {{ $namespace }}
  labels:
    {{- include "common.labels" $ | nindent 4 }}
data:
  settings.sh: |
    #!/bin/sh
    # Generated by {{ include "common.names.fullname" $ }}
    {{- range $key, $value := $.Values.settings }}
    {{ $key }}={{ $value | quote }}
    {{- end }}
  nat.conf: |
    # Generated by {{ include "common.names.fullname" $ }}
    {{- range $entry := $.Values.publicPorts }}
    {{ $entry.hostname | required "Missing hostname" }} {{ $entry.IP | required "Missing IP" }}
      {{- range $index, $port := $entry.ports -}}
        {{- if eq $index 0 -}}
          {{- print " " -}}
        {{- else -}}
          {{- print "," -}}
        {{- end -}}
        {{- $port.type | required "Missing port type" }}:{{ $port.port | required "Missing port number" -}}
      {{- end }}
    {{- end }}
{{- end -}}
