# helm_charts_controller-svc.yaml
{{ if not .Values.unifiedService.enabled }}
apiVersion: v1
kind: Service
metadata:
  name: {{ template "unifi.fullname" . }}-controller
  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.controllerService.labels }}
{{ toYaml .Values.controllerService.labels | indent 4 }}
{{- end }}
{{- with .Values.controllerService.annotations }}
  annotations:
{{ toYaml . | indent 4 }}
{{- end }}
spec:
{{- if (or (eq .Values.controllerService.type "ClusterIP") (empty .Values.controllerService.type)) }}
  type: ClusterIP
  {{- if .Values.controllerService.clusterIP }}
  clusterIP: {{ .Values.controllerService.clusterIP }}
  {{end}}
{{- else if eq .Values.controllerService.type "LoadBalancer" }}
  type: {{ .Values.controllerService.type }}
  {{- if .Values.controllerService.loadBalancerIP }}
  loadBalancerIP: {{ .Values.controllerService.loadBalancerIP }}
  {{- end }}
  {{- if .Values.controllerService.loadBalancerSourceRanges }}
  loadBalancerSourceRanges:
{{ toYaml .Values.controllerService.loadBalancerSourceRanges | indent 4 }}
  {{- end -}}
{{- else }}
  type: {{ .Values.controllerService.type }}
{{- end }}
{{- if .Values.controllerService.externalIPs }}
  externalIPs:
{{ toYaml .Values.controllerService.externalIPs | indent 4 }}
{{- end }}
  {{- if .Values.controllerService.externalTrafficPolicy }}
  externalTrafficPolicy: {{ .Values.controllerService.externalTrafficPolicy }}
  {{- end }}
  ports:
    - port: {{ .Values.controllerService.port }}
      targetPort: controller
      protocol: TCP
      name: controller
{{ if (and (eq .Values.controllerService.type "NodePort") (not (empty .Values.controllerService.nodePort))) }}
      nodePort: {{.Values.controllerService.nodePort}}
{{ end }}
  selector:
    app.kubernetes.io/name: {{ include "unifi.name" . }}
    app.kubernetes.io/instance: {{ .Release.Name }}
{{ end }}