apiVersion: v1
kind: Service
metadata:
{{- if .Values.service.annotations }}
  annotations:
{{ toYaml .Values.service.annotations | indent 4 }}
{{- end }}
  labels:
    app.kubernetes.io/name: {{ include "inbucket.name" . }}
    app.kubernetes.io/instance: {{ .Release.Name }}
    app.kubernetes.io/managed-by: {{ .Release.Service }}
    helm.sh/chart: {{ include "inbucket.chart" . }}
  name: {{ include "inbucket.fullname" . }}
spec:
  type: "{{ .Values.service.type }}"
  clusterIP: "{{ .Values.service.clusterIP }}"
{{- if .Values.service.externalIPs }}
  externalIPs:
{{ toYaml .Values.service.externalIPs | indent 4 }}
{{- end }}
{{- if .Values.service.loadBalancerIP }}
  loadBalancerIP: "{{ .Values.service.loadBalancerIP }}"
{{- end }}
{{- if .Values.service.loadBalancerSourceRanges }}
  loadBalancerSourceRanges:
{{ toYaml .Values.service.loadBalancerSourceRanges | indent 4 }}
{{- end }}
  ports:
    - name: http
      port: {{ .Values.service.port.http }}
      protocol: TCP
      targetPort: http
      {{- if (and (eq .Values.service.type "NodePort") (not (empty .Values.service.nodePort.http))) }}
      nodePort: {{ .Values.service.nodePort.http }}
      {{- end }}
    - name: smtp
      port: {{ .Values.service.port.smtp }}
      protocol: TCP
      targetPort: smtp
      {{- if (and (eq .Values.service.type "NodePort") (not (empty .Values.service.nodePort.smtp))) }}
      nodePort: {{ .Values.service.nodePort.smtp }}
      {{- end }}
    - name: pop3
      port: {{ .Values.service.port.pop3 }}
      protocol: TCP
      targetPort: pop3
      {{- if (and (eq .Values.service.type "NodePort") (not (empty .Values.service.nodePort.pop3))) }}
      nodePort: {{ .Values.service.nodePort.pop3 }}
      {{- end }}
  selector:
    app.kubernetes.io/name: {{ include "inbucket.name" . }}
    app.kubernetes.io/instance: {{ .Release.Name }}
