|
| 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 | +Common labels |
| 24 | +*/}} |
| 25 | +{{- define "coredns.labels" -}} |
| 26 | +app.kubernetes.io/managed-by: {{ .Release.Service | quote }} |
| 27 | +app.kubernetes.io/instance: {{ .Release.Name | quote }} |
| 28 | +helm.sh/chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}" |
| 29 | +{{- if .Values.isClusterService }} |
| 30 | +k8s-app: {{ template "coredns.k8sapplabel" . }} |
| 31 | +kubernetes.io/cluster-service: "true" |
| 32 | +kubernetes.io/name: "CoreDNS" |
| 33 | +{{- end }} |
| 34 | +app.kubernetes.io/name: {{ template "coredns.name" . }} |
| 35 | +{{- end -}} |
| 36 | + |
| 37 | +{{/* |
| 38 | +Common labels with autoscaler |
| 39 | +*/}} |
| 40 | +{{- define "coredns.labels.autoscaler" -}} |
| 41 | +app.kubernetes.io/managed-by: {{ .Release.Service | quote }} |
| 42 | +app.kubernetes.io/instance: {{ .Release.Name | quote }} |
| 43 | +helm.sh/chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}" |
| 44 | +{{- if .Values.isClusterService }} |
| 45 | +k8s-app: {{ template "coredns.k8sapplabel" . }}-autoscaler |
| 46 | +kubernetes.io/cluster-service: "true" |
| 47 | +kubernetes.io/name: "CoreDNS" |
| 48 | +{{- end }} |
| 49 | +app.kubernetes.io/name: {{ template "coredns.name" . }}-autoscaler |
| 50 | +{{- end -}} |
| 51 | + |
| 52 | +{{/* |
| 53 | +Allow k8s-app label to be overridden |
| 54 | +*/}} |
| 55 | +{{- define "coredns.k8sapplabel" -}} |
| 56 | +{{- coalesce .Values.k8sApp .Values.k8sAppLabelOverride .Chart.Name | trunc 63 | trimSuffix "-" -}} |
| 57 | +{{- end -}} |
| 58 | + |
| 59 | +{{/* |
| 60 | +Generate the list of ports automatically from the server definitions |
| 61 | +*/}} |
| 62 | +{{- define "coredns.servicePorts" -}} |
| 63 | + {{/* Set ports to be an empty dict */}} |
| 64 | + {{- $ports := dict -}} |
| 65 | + {{/* Iterate through each of the server blocks */}} |
| 66 | + {{- range .Values.servers -}} |
| 67 | + {{/* Capture port to avoid scoping awkwardness */}} |
| 68 | + {{- $port := toString .port -}} |
| 69 | + {{- $serviceport := default .port .servicePort -}} |
| 70 | + |
| 71 | + {{/* If none of the server blocks has mentioned this port yet take note of it */}} |
| 72 | + {{- if not (hasKey $ports $port) -}} |
| 73 | + {{- $ports := set $ports $port (dict "istcp" false "isudp" false "serviceport" $serviceport) -}} |
| 74 | + {{- end -}} |
| 75 | + {{/* Retrieve the inner dict that holds the protocols for a given port */}} |
| 76 | + {{- $innerdict := index $ports $port -}} |
| 77 | + |
| 78 | + {{/* |
| 79 | + Look at each of the zones and check which protocol they serve |
| 80 | + At the moment the following are supported by CoreDNS: |
| 81 | + UDP: dns:// |
| 82 | + TCP: tls://, grpc://, https:// |
| 83 | + */}} |
| 84 | + {{- range .zones -}} |
| 85 | + {{- if has (default "" .scheme) (list "dns://" "") -}} |
| 86 | + {{/* Optionally enable tcp for this service as well */}} |
| 87 | + {{- if eq (default false .use_tcp) true }} |
| 88 | + {{- $innerdict := set $innerdict "istcp" true -}} |
| 89 | + {{- end }} |
| 90 | + {{- $innerdict := set $innerdict "isudp" true -}} |
| 91 | + {{- end -}} |
| 92 | + |
| 93 | + {{- if has (default "" .scheme) (list "tls://" "grpc://" "https://") -}} |
| 94 | + {{- $innerdict := set $innerdict "istcp" true -}} |
| 95 | + {{- end -}} |
| 96 | + {{- end -}} |
| 97 | + |
| 98 | + {{/* If none of the zones specify scheme, default to dns:// on both tcp & udp */}} |
| 99 | + {{- if and (not (index $innerdict "istcp")) (not (index $innerdict "isudp")) -}} |
| 100 | + {{- $innerdict := set $innerdict "isudp" true -}} |
| 101 | + {{- $innerdict := set $innerdict "istcp" true -}} |
| 102 | + {{- end -}} |
| 103 | + |
| 104 | + {{- if .nodePort -}} |
| 105 | + {{- $innerdict := set $innerdict "nodePort" .nodePort -}} |
| 106 | + {{- end -}} |
| 107 | + |
| 108 | + {{/* Write the dict back into the outer dict */}} |
| 109 | + {{- $ports := set $ports $port $innerdict -}} |
| 110 | + {{- end -}} |
| 111 | + |
| 112 | + {{/* Write out the ports according to the info collected above */}} |
| 113 | + {{- range $port, $innerdict := $ports -}} |
| 114 | + {{- $portList := list -}} |
| 115 | + {{- if index $innerdict "isudp" -}} |
| 116 | + {{- $portList = append $portList (dict "port" (get $innerdict "serviceport") "protocol" "UDP" "name" (printf "udp-%s" $port) "targetPort" ($port | int)) -}} |
| 117 | + {{- end -}} |
| 118 | + {{- if index $innerdict "istcp" -}} |
| 119 | + {{- $portList = append $portList (dict "port" (get $innerdict "serviceport") "protocol" "TCP" "name" (printf "tcp-%s" $port) "targetPort" ($port | int)) -}} |
| 120 | + {{- end -}} |
| 121 | + |
| 122 | + {{- range $portDict := $portList -}} |
| 123 | + {{- if index $innerdict "nodePort" -}} |
| 124 | + {{- $portDict := set $portDict "nodePort" (get $innerdict "nodePort" | int) -}} |
| 125 | + {{- end -}} |
| 126 | + |
| 127 | + {{- printf "- %s\n" (toJson $portDict) -}} |
| 128 | + {{- end -}} |
| 129 | + {{- end -}} |
| 130 | +{{- end -}} |
| 131 | + |
| 132 | +{{/* |
| 133 | +Generate the list of ports automatically from the server definitions |
| 134 | +*/}} |
| 135 | +{{- define "coredns.containerPorts" -}} |
| 136 | + {{/* Set ports to be an empty dict */}} |
| 137 | + {{- $ports := dict -}} |
| 138 | + {{/* Iterate through each of the server blocks */}} |
| 139 | + {{- range .Values.servers -}} |
| 140 | + {{/* Capture port to avoid scoping awkwardness */}} |
| 141 | + {{- $port := toString .port -}} |
| 142 | + |
| 143 | + {{/* If none of the server blocks has mentioned this port yet take note of it */}} |
| 144 | + {{- if not (hasKey $ports $port) -}} |
| 145 | + {{- $ports := set $ports $port (dict "istcp" false "isudp" false) -}} |
| 146 | + {{- end -}} |
| 147 | + {{/* Retrieve the inner dict that holds the protocols for a given port */}} |
| 148 | + {{- $innerdict := index $ports $port -}} |
| 149 | + |
| 150 | + {{/* |
| 151 | + Look at each of the zones and check which protocol they serve |
| 152 | + At the moment the following are supported by CoreDNS: |
| 153 | + UDP: dns:// |
| 154 | + TCP: tls://, grpc://, https:// |
| 155 | + */}} |
| 156 | + {{- range .zones -}} |
| 157 | + {{- if has (default "" .scheme) (list "dns://" "") -}} |
| 158 | + {{/* Optionally enable tcp for this service as well */}} |
| 159 | + {{- if eq (default false .use_tcp) true }} |
| 160 | + {{- $innerdict := set $innerdict "istcp" true -}} |
| 161 | + {{- end }} |
| 162 | + {{- $innerdict := set $innerdict "isudp" true -}} |
| 163 | + {{- end -}} |
| 164 | + |
| 165 | + {{- if has (default "" .scheme) (list "tls://" "grpc://" "https://") -}} |
| 166 | + {{- $innerdict := set $innerdict "istcp" true -}} |
| 167 | + {{- end -}} |
| 168 | + {{- end -}} |
| 169 | + |
| 170 | + {{/* If none of the zones specify scheme, default to dns:// on both tcp & udp */}} |
| 171 | + {{- if and (not (index $innerdict "istcp")) (not (index $innerdict "isudp")) -}} |
| 172 | + {{- $innerdict := set $innerdict "isudp" true -}} |
| 173 | + {{- $innerdict := set $innerdict "istcp" true -}} |
| 174 | + {{- end -}} |
| 175 | + |
| 176 | + {{- if .hostPort -}} |
| 177 | + {{- $innerdict := set $innerdict "hostPort" .hostPort -}} |
| 178 | + {{- end -}} |
| 179 | + |
| 180 | + {{/* Write the dict back into the outer dict */}} |
| 181 | + {{- $ports := set $ports $port $innerdict -}} |
| 182 | + |
| 183 | + {{/* Fetch port from the configuration if the prometheus section exists */}} |
| 184 | + {{- range .plugins -}} |
| 185 | + {{- if eq .name "prometheus" -}} |
| 186 | + {{- $prometheus_addr := toString .parameters -}} |
| 187 | + {{- $prometheus_addr_list := regexSplit ":" $prometheus_addr -1 -}} |
| 188 | + {{- $prometheus_port := index $prometheus_addr_list 1 -}} |
| 189 | + {{- $ports := set $ports $prometheus_port (dict "istcp" true "isudp" false) -}} |
| 190 | + {{- end -}} |
| 191 | + {{- end -}} |
| 192 | + {{- end -}} |
| 193 | + |
| 194 | + {{/* Write out the ports according to the info collected above */}} |
| 195 | + {{- range $port, $innerdict := $ports -}} |
| 196 | + {{- $portList := list -}} |
| 197 | + {{- if index $innerdict "isudp" -}} |
| 198 | + {{- $portList = append $portList (dict "containerPort" ($port | int) "protocol" "UDP" "name" (printf "udp-%s" $port)) -}} |
| 199 | + {{- end -}} |
| 200 | + {{- if index $innerdict "istcp" -}} |
| 201 | + {{- $portList = append $portList (dict "containerPort" ($port | int) "protocol" "TCP" "name" (printf "tcp-%s" $port)) -}} |
| 202 | + {{- end -}} |
| 203 | + |
| 204 | + {{- range $portDict := $portList -}} |
| 205 | + {{- if index $innerdict "hostPort" -}} |
| 206 | + {{- $portDict := set $portDict "hostPort" (get $innerdict "hostPort" | int) -}} |
| 207 | + {{- end -}} |
| 208 | + |
| 209 | + {{- printf "- %s\n" (toJson $portDict) -}} |
| 210 | + {{- end -}} |
| 211 | + {{- end -}} |
| 212 | +{{- end -}} |
| 213 | + |
| 214 | +{{/* |
| 215 | +Create the name of the service account to use |
| 216 | +*/}} |
| 217 | +{{- define "coredns.serviceAccountName" -}} |
| 218 | +{{- if .Values.serviceAccount.create -}} |
| 219 | + {{ default (include "coredns.fullname" .) .Values.serviceAccount.name }} |
| 220 | +{{- else -}} |
| 221 | + {{ default "default" .Values.serviceAccount.name }} |
| 222 | +{{- end -}} |
| 223 | +{{- end -}} |
| 224 | + |
| 225 | +{{/* |
| 226 | +Create the name of the service account to use |
| 227 | +*/}} |
| 228 | +{{- define "coredns.clusterRoleName" -}} |
| 229 | +{{- if and .Values.clusterRole .Values.clusterRole.nameOverride -}} |
| 230 | + {{ .Values.clusterRole.nameOverride }} |
| 231 | +{{- else -}} |
| 232 | + {{ template "coredns.fullname" . }} |
| 233 | +{{- end -}} |
| 234 | +{{- end -}} |
| 235 | + |
| 236 | +{{- define "system_default_registry" -}} |
| 237 | +{{- if .Values.global.systemDefaultRegistry -}} |
| 238 | +{{- printf "%s/" .Values.global.systemDefaultRegistry -}} |
| 239 | +{{- else -}} |
| 240 | +{{- "" -}} |
| 241 | +{{- end -}} |
| 242 | +{{- end -}} |
| 243 | + |
| 244 | +{{/* |
| 245 | +Set the clusterDNS service IP |
| 246 | +*/}} |
| 247 | +{{- define "clusterDNSServerIP" -}} |
| 248 | +{{- if .Values.service.clusterIP }} |
| 249 | + {{- .Values.service.clusterIP }} |
| 250 | +{{ else }} |
| 251 | + {{- $dnsIPs := split "," .Values.global.clusterDNS }} |
| 252 | + {{- $dnsCount := len $dnsIPs }} |
| 253 | + {{- if eq $dnsCount 1 }} |
| 254 | + {{- .Values.global.clusterDNS -}} |
| 255 | + {{- else }} |
| 256 | + {{- if gt $dnsCount 1 }} |
| 257 | + {{- $dnsIPs._0 -}} |
| 258 | + {{ else }} |
| 259 | + {{- "10.43.0.10" }} |
| 260 | + {{- end }} |
| 261 | + {{- end }} |
| 262 | +{{- end }} |
| 263 | +{{- end }} |
| 264 | + |
| 265 | +{{/* |
| 266 | +Pass the clusterDNS service IP for the nodelocal config |
| 267 | +*/}} |
| 268 | +{{- define "nodelocalUpstreamDNSServerIP" -}} |
| 269 | +{{- if .Values.nodelocal.ipvs }} |
| 270 | +{{- "" -}} |
| 271 | +{{ else }} |
| 272 | +{{- (include "clusterDNSServerIP" .) -}} |
| 273 | +{{- end }} |
| 274 | +{{- end }} |
| 275 | + |
| 276 | +{{/* |
| 277 | +Fill the localip flag in the nodelocal CLI |
| 278 | +*/}} |
| 279 | +{{- define "nodelocalLocalIPFlag" -}} |
| 280 | +{{- if .Values.nodelocal.ipvs }} |
| 281 | +{{- "" -}} |
| 282 | +{{ else }} |
| 283 | +{{- printf ",%s" (include "clusterDNSServerIP" .) -}} |
| 284 | +{{- end }} |
| 285 | +{{- end }} |
| 286 | + |
| 287 | +{{/* |
| 288 | +Fill the ipFamily correctly |
| 289 | +*/}} |
| 290 | +{{- define "ipFamilyPolicy" -}} |
| 291 | +{{- if .Values.service.ipFamilyPolicy }} |
| 292 | + {{- .Values.service.ipFamilyPolicy }} |
| 293 | +{{ else }} |
| 294 | + {{- $dnsIPs := split "," .Values.global.clusterDNS }} |
| 295 | + {{- $dnsCount := len $dnsIPs }} |
| 296 | + {{- if gt $dnsCount 1 }} |
| 297 | + {{- "PreferDualStack" }} |
| 298 | + {{ else }} |
| 299 | + {{- "SingleStack" }} |
| 300 | + {{- end }} |
| 301 | +{{- end }} |
| 302 | +{{- end }} |
0 commit comments