apiVersion: v1
kind: Service
metadata:
  name: {{ template "external-dns.fullname" . }}
  labels: {{ include "external-dns.labels" . | nindent 4 }}
  {{- if .Values.service.annotations }}
  annotations: {{ toYaml .Values.service.annotations | nindent 4 }}
  {{- end }}
spec:
  {{- if .Values.service.clusterIP }}
  clusterIP: {{ .Values.service.clusterIP }}
  {{- end }}
  {{- if .Values.service.externalIPs }}
  externalIPs: {{ toYaml .Values.service.externalIPs | nindent 4 }}
  {{- end }}
  {{- if .Values.service.loadBalancerIP }}
  loadBalancerIP: {{ .Values.service.loadBalancerIP }}
  {{- end }}
  {{- if .Values.service.loadBalancerSourceRanges }}
  loadBalancerSourceRanges: {{ toYaml .Values.service.loadBalancerSourceRanges | nindent 4 }}
  {{- end }}
  ports:
  - name: http
    port: {{ .Values.service.port }}
    protocol: TCP
    targetPort: http
    {{- if and (eq .Values.service.type "NodePort") (not (empty .Values.service.nodePort)) }}
    nodePort: {{ .Values.service.nodePort  }}
    {{- end }}
  selector: {{ include "external-dns.matchLabels" . | nindent 6 }}
  type: {{ .Values.service.type }}
