# helm_charts_stun-svc.yaml
{{ if not .Values.unifiedService.enabled }}
apiVersion: v1
kind: Service
metadata:
  name: {{ template "unifi.fullname" . }}-stun
  labels:
    app.kubernetes.io/name: {{ include "unifi.name" . }}
    helm.sh/chart: {{ include "unifi.chart" . }}
    app.kubernetes.io/instance: {{ .Release.Name }}
    app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- if .Values.stunService.labels }}
{{ toYaml .Values.stunService.labels | indent 4 }}
{{- end }}
{{- with .Values.stunService.annotations }}
  annotations:
{{ toYaml . | indent 4 }}
{{- end }}
spec:
{{- if (or (eq .Values.stunService.type "ClusterIP") (empty .Values.stunService.type)) }}
  type: ClusterIP
  {{- if .Values.stunService.clusterIP }}
  clusterIP: {{ .Values.stunService.clusterIP }}
  {{end}}
{{- else if eq .Values.stunService.type "LoadBalancer" }}
  type: {{ .Values.stunService.type }}
  {{- if .Values.stunService.loadBalancerIP }}
  loadBalancerIP: {{ .Values.stunService.loadBalancerIP }}
  {{- end }}
  {{- if .Values.stunService.loadBalancerSourceRanges }}
  loadBalancerSourceRanges:
{{ toYaml .Values.stunService.loadBalancerSourceRanges | indent 4 }}
  {{- end -}}
{{- else }}
  type: {{ .Values.stunService.type }}
{{- end }}
{{- if .Values.stunService.externalIPs }}
  externalIPs:
{{ toYaml .Values.stunService.externalIPs | indent 4 }}
{{- end }}
  {{- if .Values.stunService.externalTrafficPolicy }}
  externalTrafficPolicy: {{ .Values.stunService.externalTrafficPolicy }}
  {{- end }}
  ports:
    - port: {{ .Values.stunService.port }}
      targetPort: stun
      protocol: UDP
      name: stun
{{ if (and (eq .Values.stunService.type "NodePort") (not (empty .Values.stunService.nodePort))) }}
      nodePort: {{.Values.stunService.nodePort}}
{{ end }}
  selector:
    app.kubernetes.io/name: {{ include "unifi.name" . }}
    app.kubernetes.io/instance: {{ .Release.Name }}
{{ end }}