Skip to content

Commit

Permalink
Support different service and container ports
Browse files Browse the repository at this point in the history
Signed-off-by: Andre Baptista Aguas <[email protected]>
  • Loading branch information
abaguas authored and aba_osag committed Oct 1, 2024
1 parent c04e952 commit c93148a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
4 changes: 2 additions & 2 deletions charts/coredns/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
apiVersion: v2
name: coredns
version: 1.33.0
version: 1.34.0
appVersion: 1.11.3
home: https://coredns.io
icon: https://coredns.io/images/CoreDNS_Colour_Horizontal.png
Expand All @@ -20,4 +20,4 @@ type: application
annotations:
artifacthub.io/changes: |
- kind: added
description: Add support for specifying the service loadBalancerClass.
description: Support different service and container ports
9 changes: 5 additions & 4 deletions charts/coredns/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,11 @@ Generate the list of ports automatically from the server definitions
{{- range .Values.servers -}}
{{/* Capture port to avoid scoping awkwardness */}}
{{- $port := toString .port -}}
{{- $serviceport := default .port .servicePort -}}

{{/* If none of the server blocks has mentioned this port yet take note of it */}}
{{- if not (hasKey $ports $port) -}}
{{- $ports := set $ports $port (dict "istcp" false "isudp" false) -}}
{{- $ports := set $ports $port (dict "istcp" false "isudp" false "serviceport" $serviceport) -}}
{{- end -}}
{{/* Retrieve the inner dict that holds the protocols for a given port */}}
{{- $innerdict := index $ports $port -}}
Expand Down Expand Up @@ -116,10 +117,10 @@ Generate the list of ports automatically from the server definitions
{{- range $port, $innerdict := $ports -}}
{{- $portList := list -}}
{{- if index $innerdict "isudp" -}}
{{- $portList = append $portList (dict "port" ($port | int) "protocol" "UDP" "name" (printf "udp-%s" $port)) -}}
{{- $portList = append $portList (dict "port" (get $innerdict "serviceport") "protocol" "UDP" "name" (printf "udp-%s" $port) "targetPort" ($port | int)) -}}
{{- end -}}
{{- if index $innerdict "istcp" -}}
{{- $portList = append $portList (dict "port" ($port | int) "protocol" "TCP" "name" (printf "tcp-%s" $port)) -}}
{{- $portList = append $portList (dict "port" (get $innerdict "serviceport") "protocol" "TCP" "name" (printf "tcp-%s" $port) "targetPort" ($port | int)) -}}
{{- end -}}

{{- range $portDict := $portList -}}
Expand Down Expand Up @@ -234,4 +235,4 @@ Create the name of the service account to use
{{- else -}}
{{ template "coredns.fullname" . }}
{{- end -}}
{{- end -}}
{{- end -}}
2 changes: 2 additions & 0 deletions charts/coredns/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ servers:
- zones:
- zone: .
port: 53
# -- expose the service on a different port
# servicePort: 5353
# If serviceType is nodePort you can specify nodePort here
# nodePort: 30053
# hostPort: 53
Expand Down

0 comments on commit c93148a

Please sign in to comment.