|
| 1 | +{{/* vim: set filetype=mustache: */}} |
| 2 | +{{/* |
| 3 | +Expand the name of the chart. |
| 4 | +*/}} |
| 5 | +{{- define "coredns.name" -}} |
| 6 | +{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}} |
| 7 | +{{- end -}} |
| 8 | + |
| 9 | +{{/* |
| 10 | +Create a default fully qualified app name. |
| 11 | +We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). |
| 12 | +*/}} |
| 13 | +{{- define "coredns.fullname" -}} |
| 14 | +{{- if .Values.fullnameOverride -}} |
| 15 | +{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}} |
| 16 | +{{- else -}} |
| 17 | +{{- $name := default .Chart.Name .Values.nameOverride -}} |
| 18 | +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}} |
| 19 | +{{- end -}} |
| 20 | +{{- end -}} |
| 21 | + |
| 22 | +{{/* |
| 23 | +Generate the list of ports automatically from the server definitions |
| 24 | +*/}} |
| 25 | +{{- define "coredns.servicePorts" -}} |
| 26 | + {{/* Set ports to be an empty dict */}} |
| 27 | + {{- $ports := dict -}} |
| 28 | + {{/* Iterate through each of the server blocks */}} |
| 29 | + {{- range .Values.servers -}} |
| 30 | + {{/* Capture port to avoid scoping awkwardness */}} |
| 31 | + {{- $port := toString .port -}} |
| 32 | + |
| 33 | + {{/* If none of the server blocks has mentioned this port yet take note of it */}} |
| 34 | + {{- if not (hasKey $ports $port) -}} |
| 35 | + {{- $ports := set $ports $port (dict "istcp" false "isudp" false) -}} |
| 36 | + {{- end -}} |
| 37 | + {{/* Retrieve the inner dict that holds the protocols for a given port */}} |
| 38 | + {{- $innerdict := index $ports $port -}} |
| 39 | + |
| 40 | + {{/* |
| 41 | + Look at each of the zones and check which protocol they serve |
| 42 | + At the moment the following are supported by CoreDNS: |
| 43 | + UDP: dns:// |
| 44 | + TCP: tls://, grpc:// |
| 45 | + */}} |
| 46 | + {{- range .zones -}} |
| 47 | + {{- if has (default "" .scheme) (list "dns://") -}} |
| 48 | + {{/* Optionally enable tcp for this service as well */}} |
| 49 | + {{- if eq (default false .use_tcp) true }} |
| 50 | + {{- $innerdict := set $innerdict "istcp" true -}} |
| 51 | + {{- end }} |
| 52 | + {{- $innerdict := set $innerdict "isudp" true -}} |
| 53 | + {{- end -}} |
| 54 | + |
| 55 | + {{- if has (default "" .scheme) (list "tls://" "grpc://") -}} |
| 56 | + {{- $innerdict := set $innerdict "istcp" true -}} |
| 57 | + {{- end -}} |
| 58 | + {{- end -}} |
| 59 | + |
| 60 | + {{/* If none of the zones specify scheme, default to dns:// on both tcp & udp */}} |
| 61 | + {{- if and (not (index $innerdict "istcp")) (not (index $innerdict "isudp")) -}} |
| 62 | + {{- $innerdict := set $innerdict "isudp" true -}} |
| 63 | + {{- $innerdict := set $innerdict "istcp" true -}} |
| 64 | + {{- end -}} |
| 65 | + |
| 66 | + {{/* Write the dict back into the outer dict */}} |
| 67 | + {{- $ports := set $ports $port $innerdict -}} |
| 68 | + {{- end -}} |
| 69 | + |
| 70 | + {{/* Write out the ports according to the info collected above */}} |
| 71 | + {{- range $port, $innerdict := $ports -}} |
| 72 | + {{- if index $innerdict "isudp" -}} |
| 73 | + {{- printf "- {port: %v, protocol: UDP, name: udp-%s}\n" $port $port -}} |
| 74 | + {{- end -}} |
| 75 | + {{- if index $innerdict "istcp" -}} |
| 76 | + {{- printf "- {port: %v, protocol: TCP, name: tcp-%s}\n" $port $port -}} |
| 77 | + {{- end -}} |
| 78 | + {{- end -}} |
| 79 | +{{- end -}} |
| 80 | + |
| 81 | +{{/* |
| 82 | +Generate the list of ports automatically from the server definitions |
| 83 | +*/}} |
| 84 | +{{- define "coredns.containerPorts" -}} |
| 85 | + {{/* Set ports to be an empty dict */}} |
| 86 | + {{- $ports := dict -}} |
| 87 | + {{/* Iterate through each of the server blocks */}} |
| 88 | + {{- range .Values.servers -}} |
| 89 | + {{/* Capture port to avoid scoping awkwardness */}} |
| 90 | + {{- $port := toString .port -}} |
| 91 | + |
| 92 | + {{/* If none of the server blocks has mentioned this port yet take note of it */}} |
| 93 | + {{- if not (hasKey $ports $port) -}} |
| 94 | + {{- $ports := set $ports $port (dict "istcp" false "isudp" false) -}} |
| 95 | + {{- end -}} |
| 96 | + {{/* Retrieve the inner dict that holds the protocols for a given port */}} |
| 97 | + {{- $innerdict := index $ports $port -}} |
| 98 | + |
| 99 | + {{/* |
| 100 | + Look at each of the zones and check which protocol they serve |
| 101 | + At the moment the following are supported by CoreDNS: |
| 102 | + UDP: dns:// |
| 103 | + TCP: tls://, grpc:// |
| 104 | + */}} |
| 105 | + {{- range .zones -}} |
| 106 | + {{- if has (default "" .scheme) (list "dns://") -}} |
| 107 | + {{/* Optionally enable tcp for this service as well */}} |
| 108 | + {{- if eq (default false .use_tcp) true }} |
| 109 | + {{- $innerdict := set $innerdict "istcp" true -}} |
| 110 | + {{- end }} |
| 111 | + {{- $innerdict := set $innerdict "isudp" true -}} |
| 112 | + {{- end -}} |
| 113 | + |
| 114 | + {{- if has (default "" .scheme) (list "tls://" "grpc://") -}} |
| 115 | + {{- $innerdict := set $innerdict "istcp" true -}} |
| 116 | + {{- end -}} |
| 117 | + {{- end -}} |
| 118 | + |
| 119 | + {{/* If none of the zones specify scheme, default to dns:// on both tcp & udp */}} |
| 120 | + {{- if and (not (index $innerdict "istcp")) (not (index $innerdict "isudp")) -}} |
| 121 | + {{- $innerdict := set $innerdict "isudp" true -}} |
| 122 | + {{- $innerdict := set $innerdict "istcp" true -}} |
| 123 | + {{- end -}} |
| 124 | + |
| 125 | + {{/* Write the dict back into the outer dict */}} |
| 126 | + {{- $ports := set $ports $port $innerdict -}} |
| 127 | + {{- end -}} |
| 128 | + |
| 129 | + {{/* Write out the ports according to the info collected above */}} |
| 130 | + {{- range $port, $innerdict := $ports -}} |
| 131 | + {{- if index $innerdict "isudp" -}} |
| 132 | + {{- printf "- {containerPort: %v, protocol: UDP, name: udp-%s}\n" $port $port -}} |
| 133 | + {{- end -}} |
| 134 | + {{- if index $innerdict "istcp" -}} |
| 135 | + {{- printf "- {containerPort: %v, protocol: TCP, name: tcp-%s}\n" $port $port -}} |
| 136 | + {{- end -}} |
| 137 | + {{- end -}} |
| 138 | +{{- end -}} |
| 139 | + |
| 140 | +{{/* |
| 141 | +Create the name of the service account to use |
| 142 | +*/}} |
| 143 | +{{- define "coredns.serviceAccountName" -}} |
| 144 | +{{- if .Values.serviceAccount.create -}} |
| 145 | + {{ default (include "coredns.fullname" .) .Values.serviceAccount.name }} |
| 146 | +{{- else -}} |
| 147 | + {{ default "default" .Values.serviceAccount.name }} |
| 148 | +{{- end -}} |
| 149 | +{{- end -}} |
0 commit comments