Skip to content

Commit

Permalink
[#173] Support for multiple user-defined ports in interactive services
Browse files Browse the repository at this point in the history
  • Loading branch information
Gaspi committed Nov 12, 2024
1 parent c3525cc commit 157bb1a
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 23 deletions.
2 changes: 1 addition & 1 deletion charts/library-chart/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: v2
name: library-chart
version: 1.5.30
version: 1.5.31
type: library
37 changes: 28 additions & 9 deletions charts/library-chart/templates/_ingress.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,21 @@ spec:
backend:
service:
name: {{ $fullName }}
port:
port:
number: {{ $svcPort }}
{{- end }}
{{- end }}

{{/* Template to generate a custom Ingress */}}
{{- define "library-chart.ingressUser" -}}
{{- if .Values.ingress.enabled -}}
{{ if .Values.networking.user.enabled }}
{{- if and .Values.networking.user .Values.networking.user.enabled -}}
{{- $userPorts := list -}}
{{- if or .Values.networking.user.ports .Values.networking.user.port -}}
{{- $userPorts = .Values.networking.user.ports | default (list .Values.networking.user.port) -}}
{{- end -}}
{{- if $userPorts -}}
{{- $fullName := include "library-chart.fullname" . -}}
{{- $svcPort := .Values.networking.user.port -}}
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
Expand All @@ -96,22 +100,37 @@ spec:
{{- if .Values.ingress.tls }}
tls:
- hosts:
- {{ .Values.ingress.userHostname | quote }}
{{- if or .Values.ingress.useCertManager .Values.ingress.useTlsSecret}}
{{- range $userPort := $userPorts }}
{{- if eq (len $userPorts) 1 }}
- {{ $.Values.ingress.userHostname | quote }}
{{- else }}
- {{ regexReplaceAll "([^\\.]+)\\.(.*)" $.Values.ingress.userHostname (printf "${1}-%d.${2}" (int $userPort)) | quote }}
{{- end }}
{{- end }}
{{- if or .Values.ingress.useCertManager .Values.ingress.useTlsSecret }}
secretName: tls-cert-{{ include "library-chart.fullname" . }}
{{- end }}
{{- end }}
{{- end }}
rules:
{{- range $userPort := $userPorts }}
{{- with $ }}
{{- if eq (len $userPorts) 1 }}
- host: {{ .Values.ingress.userHostname | quote }}
{{- else }}
- host: {{ regexReplaceAll "([^\\.]+)\\.(.*)" .Values.ingress.userHostname (printf "${1}-%d.${2}" (int $userPort)) | quote }}
{{- end }}
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: {{ $fullName }}
port:
number: {{ $svcPort }}
port:
number: {{ $userPort }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
Expand Down Expand Up @@ -151,7 +170,7 @@ spec:
backend:
service:
name: {{ $fullName }}
port:
port:
number: {{ $svcPort }}
{{- end }}
{{- end }}
Expand Down
23 changes: 16 additions & 7 deletions charts/library-chart/templates/_route.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ spec:
to:
kind: Service
name: {{ $fullName }}
port:
port:
targetPort: {{ $svcPort }}
tls:
termination: {{ .Values.route.tls.termination }}
Expand All @@ -61,9 +61,11 @@ spec:
{{/* Template to generate a custom Route */}}
{{- define "library-chart.routeUser" -}}
{{- if .Values.route.enabled -}}
{{ if .Values.networking.user.enabled }}
{{- if and .Values.networking.user .Values.networking.user.enabled (or .Values.networking.user.ports .Values.networking.user.port) -}}
{{- $fullName := include "library-chart.fullname" . -}}
{{- $svcPort := .Values.networking.user.port -}}
{{- $userPorts := .Values.networking.user.ports | default (list .Values.networking.user.port) -}}
{{- range $userPort := $userPorts -}}
{{- with $ -}}
apiVersion: route.openshift.io/v1
kind: Route
metadata:
Expand All @@ -73,13 +75,17 @@ metadata:
annotations:
{{- include "library-chart.route.annotations" . | nindent 4 }}
spec:
{{- if eq (len $userPorts) 1 }}
host: {{ .Values.route.userHostname | quote }}
{{- else }}
host: {{ regexReplaceAll "([^\\.]+)\\.(.*)" .Values.route.userHostname (printf "${1}-d.${2}" $userPort) | quote }}
{{- end }}
path: /
to:
kind: Service
name: {{ $fullName }}
port:
targetPort: {{ $svcPort }}
port:
targetPort: {{ $userPort }}
tls:
termination: {{ .Values.route.tls.termination }}
{{- if .Values.route.tls.key }}
Expand All @@ -92,9 +98,12 @@ spec:
caCertificate: {{- .Values.route.tls.caCertificate }}
{{- end }}
{{- if .Values.route.tls.destinationCACertificate }}
destinationCACertificate: {{- .Values.route.tls.destinationCACertificate }}
destinationCACertificate: {{ .Values.route.tls.destinationCACertificate }}
{{- end }}
wildcardPolicy: {{ .Values.route.wildcardPolicy }}
---
{{- end }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
Expand All @@ -119,7 +128,7 @@ spec:
to:
kind: Service
name: {{ $fullName }}
port:
port:
targetPort: {{ $svcPort }}
tls:
termination: {{ .Values.route.tls.termination }}
Expand Down
14 changes: 8 additions & 6 deletions charts/library-chart/templates/_service.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

{{/* Template to generate a Service */}}
{{- define "library-chart.service" -}}
{{- $userPorts := list -}}
{{- if and .Values.networking.user .Values.networking.user.enabled (or .Values.networking.user.ports .Values.networking.user.port) -}}
{{- $userPorts = .Values.networking.user.ports | default (list .Values.networking.user.port) -}}
{{- end -}}
apiVersion: v1
kind: Service
metadata:
Expand All @@ -18,13 +22,11 @@ spec:
targetPort: {{ default .Values.networking.service.port .Values.networking.service.targetPort }}
protocol: TCP
name: main
{{ if .Values.networking.user }}
{{ if .Values.networking.user.enabled }}
- port: {{ .Values.networking.user.port }}
targetPort: {{ .Values.networking.user.port }}
{{- range $userPort := $userPorts }}
- port: {{ $userPort }}
targetPort: {{ $userPort }}
protocol: TCP
name: user
{{- end }}
name: {{ printf "user-%d" (int $userPort) | quote }}
{{- end }}
{{ if .Values.spark }}
{{ if .Values.spark.sparkui }}
Expand Down

0 comments on commit 157bb1a

Please sign in to comment.