{{- if and .Values.query.enabled .Values.query.service.additionalHeadless }}
apiVersion: v1
kind: Service
metadata:
  name: {{ include "common.names.fullname" . }}-query-headless
  namespace: {{ .Release.Namespace | quote }}
  labels: {{- include "common.labels.standard" . | nindent 4 }}
    app.kubernetes.io/component: query
    {{- if .Values.commonLabels }}
    {{- include "common.tplvalues.render" ( dict "value" .Values.commonLabels "context" $ ) | nindent 4 }}
    {{- end }}
  annotations:
    {{- if .Values.commonAnnotations }}
    {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }}
    {{- end }}
    {{- if .Values.query.service.annotations }}
    {{- include "common.tplvalues.render" (dict "value" .Values.query.service.annotations "context" $) | nindent 4 }}
    {{- end }}
spec:
  type: ClusterIP
  clusterIP: None
  ports:
    - port: {{ if .Values.query.service.http }}{{ coalesce .Values.query.service.ports.http .Values.query.service.http.port }}{{ else }}{{ .Values.query.service.ports.http }}{{ end }}
      targetPort: http
      protocol: TCP
      name: http
    {{- if .Values.query.service.extraPorts }}
    {{- include "common.tplvalues.render" (dict "value" .Values.query.service.extraPorts "context" $) | nindent 4 }}
    {{- end }}
  selector:
    {{- if .Values.query.service.labelSelectorsOverride }}
    {{- include "common.tplvalues.render" (dict "value" .Values.query.service.labelSelectorsOverride "context" $) | nindent 4 }}
    {{- else }}
    {{- include "common.labels.matchLabels" . | nindent 4 }}
    app.kubernetes.io/component: query
    {{- end }}
{{- end }}
