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