Skip to content

Commit

Permalink
Combine all of advertiseIp handling to the helper
Browse files Browse the repository at this point in the history
While this might look more complex, it breaks down to a set of providers for hostnames which then combine into a comma separated list. So it should be much easier to extend in future.
  • Loading branch information
ressu committed Jan 18, 2024
1 parent 827fd73 commit e309894
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 17 deletions.
28 changes: 20 additions & 8 deletions charts/kube-plex/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,26 @@ Create a list of values for ADVERTISE_IP
*/}}
{{- define "advertiseIp" -}}
{{- $hosts := list -}}
{{- range .Values.ingress.hosts -}}
{{- if kindIs "string" . }}
{{- $hosts = printf "https://%s" . | append $hosts -}}
{{- $hosts = printf "https://%s:443" . | append $hosts -}}
{{- else }}
{{- $hosts = printf "https://%s" .host | append $hosts -}}
{{- $hosts = printf "https://%s:443" .host | append $hosts -}}
{{- end }}
{{- if (or (eq .Values.service.type "ClusterIP") (eq .Values.service.type "LoadBalancer") (empty .Values.service.type)) -}}
{{- if .Values.service.loadBalancerIP -}}{{- $hosts = printf "https://%s:32400" .Values.service.loadBalancerIP | append $hosts -}}{{- end -}}
{{- if index .Values.service.annotations "dns.pfsense.org/hostname" -}}
{{- range splitList "," (index .Values.service.annotations "dns.pfsense.org/hostname") -}}
{{- $hosts = printf "https://%s:32400" . | append $hosts -}}
{{- end -}}
{{- end -}}
{{- range .Values.ingress.hosts -}}
{{- if kindIs "string" . }}
{{- if not (eq (lower .) "chart-example.local") -}}
{{- $hosts = printf "https://%s" . | append $hosts -}}
{{- $hosts = printf "https://%s:443" . | append $hosts -}}
{{- end -}}
{{- else }}
{{- if not (eq (lower .host) "chart-example.local") -}}
{{- $hosts = printf "https://%s" .host | append $hosts -}}
{{- $hosts = printf "https://%s:443" .host | append $hosts -}}
{{- end -}}
{{- end }}
{{- end -}}
{{- end -}}
{{ join "," $hosts }}
{{- end -}}
10 changes: 1 addition & 9 deletions charts/kube-plex/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -137,18 +137,10 @@ spec:
{{- with .Values.extraEnv }}
{{- get (fromYaml (include "env_vars" $)) "env" | toYaml | nindent 8 -}}
{{- end }}
{{- if not (empty (include "advertiseIp" .)) }}
# Fill ADVERTISE_IP section in plex automatically
{{- if (or (eq .Values.service.type "ClusterIP") (empty .Values.service.type)) }}
- name: ADVERTISE_IP
value: {{ include "advertiseIp" . }}
{{- else if eq .Values.service.type "LoadBalancer" }}
{{- if (or .Values.service.loadBalancerIP .Values.ingress.hosts (index .Values.service.annotations "dns.pfsense.org/hostname")) }}
- name: ADVERTISE_IP
value: |
{{ if .Values.service.loadBalancerIP }}https://{{ .Values.service.loadBalancerIP }}:32400{{ end }}
{{ if index .Values.service.annotations "dns.pfsense.org/hostname" }},https://{{ join ",https://" (splitList "," (index .Values.service.annotations "dns.pfsense.org/hostname")) }}:32400{{ end }}
{{ if .Values.ingress.hosts }},{{ include "advertiseIp" . }}{{ end }}
{{- end }}
{{- end }}
volumeMounts:
- name: data
Expand Down

0 comments on commit e309894

Please sign in to comment.