# Service for Consul DNS.
{{- if (or (and (ne (.Values.dns.enabled | toString) "-") .Values.dns.enabled) (and (eq (.Values.dns.enabled | toString) "-") .Values.global.enabled)) }}
apiVersion: v1
kind: Service
metadata:
  name: {{ template "consul.fullname" . }}-dns
  namespace: {{ .Release.Namespace }}
  labels:
    app: {{ template "consul.name" . }}
    chart: {{ template "consul.chart" . }}
    heritage: {{ .Release.Service }}
    release: {{ .Release.Name }}
  {{- if .Values.dns.annotations }}
  annotations:
    {{ tpl .Values.dns.annotations . | nindent 4 | trim }}
  {{- end }}
spec:
{{- if .Values.dns.clusterIP }}
  clusterIP: {{ .Values.dns.clusterIP }}
{{- end }}
  ports:
    - name: dns-tcp
      port: 53
      protocol: "TCP"
      targetPort: dns-tcp
    - name: dns-udp
      port: 53
      protocol: "UDP"
      targetPort: dns-udp
  selector:
    app: {{ template "consul.name" . }}
    release: "{{ .Release.Name }}"
    hasDNS: "true"
{{- end }}
