apiVersion: v1
kind: Service
metadata:
  name: {{ include "home-assistant.fullname" . }}
  labels:
    {{- include "home-assistant.labels" . | nindent 4 }}
  {{- with .Values.service.annotations }}
  annotations:
    {{- toYaml . | nindent 4 }}
  {{ end }}
spec:
  type: {{ .Values.service.type }}
  ports:
    - port: {{ .Values.service.port }}
      targetPort: http
      protocol: TCP
      name: http
  selector:
    {{- include "home-assistant.selectorLabels" . | nindent 4 }}

{{- if .Values.additionalServices }}
{{- range .Values.additionalServices }}
---
apiVersion: v1
kind: Service
metadata:
  name: {{ include "home-assistant.fullname" $ }}-{{ .name }}
  labels:
    {{- include "home-assistant.labels" $ | nindent 4 }}
  {{- with .labels }}
    {{- toYaml . | nindent 4 }}
  {{- end }}
  {{- with .annotations }}
  annotations:
    {{- toYaml . | nindent 4 }}
  {{ end }}
spec:
  type: {{ .type }}
  {{- if .loadBalancerClass}}
  loadBalancerClass: {{.loadBalancerClass}}
  {{- end}}
  ports:
    - port: {{ .port }}
      targetPort: {{ .targetPort }}
      protocol: {{ .protocol }}
      name: {{ .name }}
      {{- if .nodePort }}
      nodePort: {{ .nodePort }}
      {{- end }}
  selector:
    {{- include "home-assistant.selectorLabels" $ | nindent 4 }}
{{- end }}
{{- end}}
