Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 92 additions & 0 deletions charts/gateway/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,95 @@ Scheme to use while connecting etcd
{{- "http" }}
{{- end }}
{{- end }}

{{/*
Expand a port value (which may contain a port range) into a list of individual
port numbers for K8s resource definitions.
Input: a string like "2000-2100" or "127.0.0.1:2000-2100" or "9100"
Output: JSON {"ports": [2000, 2001, ..., 2100]}
*/}}
{{- define "gateway.expandPorts" -}}
{{- $result := list -}}
{{- $s := . | toString -}}
{{- $portPart := splitList ":" $s | last -}}
{{- if contains "-" $portPart -}}
{{- $bounds := splitList "-" $portPart -}}
{{- $start := index $bounds 0 | trim | int -}}
{{- $end := index $bounds 1 | trim | int -}}
{{- if gt $start $end -}}
{{- $tmp := $start -}}
{{- $start = $end -}}
{{- $end = $tmp -}}
{{- end -}}
{{- $count := add1 (sub $end $start) | int -}}
{{- range $i := until $count -}}
{{- $result = append $result (add $start $i | int) -}}
{{- end -}}
{{- else -}}
{{- $result = append $result ($portPart | trim | int) -}}
{{- end -}}
{{- dict "ports" $result | toJson -}}
{{- end -}}

{{/*
Normalize a TCP port list into expanded individual port entries for K8s resources.
Handles integers, strings (with ranges), and map entries (with addr ranges).
Input: the .tcp array from values
Output: JSON {"entries": [{"port": 9100, "nodePort": ""}, ...]}
*/}}
{{- define "gateway.normalizedTcpPorts" -}}
{{- $result := list -}}
{{- range $item := . -}}
{{- $addrStr := "" -}}
{{- $nodePort := "" -}}
{{- if kindIs "map" $item -}}
{{- $addrStr = $item.addr | toString -}}
{{- if hasKey $item "nodePort" -}}
{{- $nodePort = $item.nodePort | toString -}}
{{- end -}}
{{- else -}}
{{- $addrStr = $item | toString -}}
{{- end -}}
{{- $portPart := splitList ":" $addrStr | last -}}
{{- if or (contains "," $addrStr) (contains "-" $portPart) -}}
{{- $expanded := include "gateway.expandPorts" $addrStr | fromJson -}}
{{- range $port := $expanded.ports -}}
{{- $result = append $result (dict "port" $port "nodePort" "") -}}
{{- end -}}
{{- else -}}
{{- $result = append $result (dict "port" ($portPart | int) "nodePort" $nodePort) -}}
{{- end -}}
{{- end -}}
{{- dict "entries" $result | toJson -}}
{{- end -}}

{{/*
Normalize a UDP port list into expanded individual port entries for K8s resources.
Input: the .udp array from values
Output: JSON {"entries": [{"port": 9200, "nodePort": ""}, ...]}
*/}}
{{- define "gateway.normalizedUdpPorts" -}}
{{- $result := list -}}
{{- range $item := . -}}
{{- $addrStr := "" -}}
{{- $nodePort := "" -}}
{{- if kindIs "map" $item -}}
{{- $addrStr = $item.addr | toString -}}
{{- if hasKey $item "nodePort" -}}
{{- $nodePort = $item.nodePort | toString -}}
{{- end -}}
{{- else -}}
{{- $addrStr = $item | toString -}}
{{- end -}}
{{- $portPart := splitList ":" $addrStr | last -}}
{{- if or (contains "," $addrStr) (contains "-" $portPart) -}}
{{- $expanded := include "gateway.expandPorts" $addrStr | fromJson -}}
{{- range $port := $expanded.ports -}}
{{- $result = append $result (dict "port" $port "nodePort" "") -}}
{{- end -}}
{{- else -}}
{{- $result = append $result (dict "port" ($portPart | int) "nodePort" $nodePort) -}}
{{- end -}}
{{- end -}}
{{- dict "entries" $result | toJson -}}
{{- end -}}
24 changes: 8 additions & 16 deletions charts/gateway/templates/_pod.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -130,31 +130,23 @@ spec:
protocol: TCP
{{- end }}
{{- if and .Values.gateway.stream.enabled (or (gt (len .Values.gateway.stream.tcp) 0) (gt (len .Values.gateway.stream.udp) 0)) }}
{{- with .Values.gateway.stream }}
{{- if (gt (len .tcp) 0) }}
{{- range $index, $port := .tcp }}
{{- if (gt (len .Values.gateway.stream.tcp) 0) }}
{{- $normalized := include "gateway.normalizedTcpPorts" .Values.gateway.stream.tcp | fromJson }}
{{- range $index, $entry := $normalized.entries }}
- name: proxy-tcp-{{ $index | toString }}
{{- if kindIs "map" $port }}
containerPort: {{ splitList ":" ($port.addr | toString) | last }}
{{- else }}
containerPort: {{ $port }}
{{- end }}
containerPort: {{ $entry.port | int }}
protocol: TCP
{{- end }}
{{- end }}
{{- if (gt (len .udp) 0) }}
{{- range $index, $port := .udp }}
{{- if (gt (len .Values.gateway.stream.udp) 0) }}
{{- $normalized := include "gateway.normalizedUdpPorts" .Values.gateway.stream.udp | fromJson }}
{{- range $index, $entry := $normalized.entries }}
- name: proxy-udp-{{ $index | toString }}
{{- if kindIs "map" $port }}
containerPort: {{ splitList ":" ($port.addr | toString) | last }}
{{- else }}
containerPort: {{ $port }}
{{- end }}
containerPort: {{ $entry.port | int }}
protocol: UDP
{{- end }}
{{- end }}
{{- end }}
{{- end }}
{{- if and .Values.deployment.fallback_cp.mode (eq .Values.deployment.fallback_cp.mode "write") }}
{{- /* Disable probes when fallback_cp mode is set to write */ -}}
{{- else }}
Expand Down
8 changes: 6 additions & 2 deletions charts/gateway/templates/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,12 @@ data:
tcp: # TCP proxy port list
{{- range .Values.gateway.stream.tcp }}
{{- if kindIs "map" . }}
- addr: {{ .addr }}
- addr: {{ .addr | quote }}
{{- if hasKey . "tls" }}
tls: {{ .tls }}
{{- end }}
{{- else if kindIs "string" . }}
- {{ . | quote }}
{{- else }}
- {{ . }}
{{- end }}
Expand All @@ -98,7 +100,9 @@ data:
udp: # UDP proxy port list
{{- range .Values.gateway.stream.udp }}
{{- if kindIs "map" . }}
- addr: {{ .addr }}
- addr: {{ .addr | quote }}
{{- else if kindIs "string" . }}
- {{ . | quote }}
{{- else }}
- {{ . }}
{{- end }}
Expand Down
56 changes: 16 additions & 40 deletions charts/gateway/templates/service-gateway.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -89,60 +89,36 @@ spec:
protocol: TCP
{{- end }}
{{- if and .Values.gateway.stream.enabled (or (gt (len .Values.gateway.stream.tcp) 0) (gt (len .Values.gateway.stream.udp) 0)) }}
{{- with .Values.gateway.stream }}
{{- if (gt (len .tcp) 0) }}
{{- range $index, $port := .tcp }}
{{- if (gt (len .Values.gateway.stream.tcp) 0) }}
{{- $normalized := include "gateway.normalizedTcpPorts" .Values.gateway.stream.tcp | fromJson }}
{{- range $index, $entry := $normalized.entries }}
- name: proxy-tcp-{{ $index | toString }}
protocol: TCP
{{- if kindIs "map" $port }}
port: {{ splitList ":" ($port.addr | toString) | last }}
targetPort: {{ splitList ":" ($port.addr | toString) | last }}
port: {{ $entry.port | int }}
targetPort: {{ $entry.port | int }}
{{- if eq $global.Values.gateway.type "NodePort" }}
{{- if $global.Values.gateway.stream.autoAssignNodePort }}
nodePort: {{ splitList ":" ($port.addr | toString) | last }}
{{- else }}
{{- if not (empty $port.nodePort) }}
nodePort: {{ $port.nodePort }}
nodePort: {{ $entry.port | int }}
{{- else if ne ($entry.nodePort | toString) "" }}
nodePort: {{ $entry.nodePort }}
{{- end }}
{{- end }}
{{- end }}
{{- else }}
port: {{ $port }}
targetPort: {{ $port }}
{{- if eq $global.Values.gateway.type "NodePort" }}
{{- if $global.Values.gateway.stream.autoAssignNodePort }}
nodePort: {{ $port }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
{{- if (gt (len .udp) 0) }}
{{- range $index, $port := .udp }}
{{- if (gt (len .Values.gateway.stream.udp) 0) }}
{{- $normalized := include "gateway.normalizedUdpPorts" .Values.gateway.stream.udp | fromJson }}
{{- range $index, $entry := $normalized.entries }}
- name: proxy-udp-{{ $index | toString }}
protocol: UDP
{{- if kindIs "map" $port }}
port: {{ splitList ":" ($port.addr | toString) | last }}
targetPort: {{ splitList ":" ($port.addr | toString) | last }}
port: {{ $entry.port | int }}
targetPort: {{ $entry.port | int }}
{{- if eq $global.Values.gateway.type "NodePort" }}
{{- if $global.Values.gateway.stream.autoAssignNodePort }}
nodePort: {{ splitList ":" ($port.addr | toString) | last }}
{{- else }}
{{- if not (empty $port.nodePort) }}
nodePort: {{ $port.nodePort }}
{{- end }}
nodePort: {{ $entry.port | int }}
{{- else if ne ($entry.nodePort | toString) "" }}
nodePort: {{ $entry.nodePort }}
{{- end }}
{{- end }}
{{- else }}
port: {{ $port }}
targetPort: {{ $port }}
{{- if eq $global.Values.gateway.type "NodePort" }}
{{- if $global.Values.gateway.stream.autoAssignNodePort }}
nodePort: {{ $port }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
Expand Down
5 changes: 5 additions & 0 deletions charts/gateway/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -364,10 +364,15 @@ gateway:
# - addr: 192.168.31.10:5432
# - addr: 3302
# nodePort: 31302
# - "2000-2100" # port range (nginx native support)
# - addr: "3000-3100" # port range in table form
# - addr: "127.0.0.1:4000-4100" # address with port range
# tls: true
udp: []
# - addr: 192.168.31.10:53
# - addr: 5353
# nodePort: 31353
# - "9300-9310" # port range
# -- Using ingress access API7 Gateway service
ingress:
enabled: false
Expand Down
Loading