{{- /*
Copyright Broadcom, Inc. All Rights Reserved.
SPDX-License-Identifier: APACHE-2.0
*/}}

{{- if and .Values.cache.enabled .Values.cache.useHeadlessServiceWithAppVersion }}
apiVersion: v1
kind: Service
metadata:
  name: {{ template "keycloak.headless.ispn.serviceName" . }}
  namespace: {{ include "common.names.namespace" . | quote }}
  labels: {{- include "common.labels.standard" (dict "customLabels" .Values.commonLabels "context" .) | nindent 4 }}
    app.kubernetes.io/component: keycloak
    app.kubernetes.io/part-of: keycloak
  {{- if or .Values.commonAnnotations .Values.service.headless.annotations }}
  {{- $annotations := include "common.tplvalues.merge" (dict "values" (list .Values.service.headless.annotations .Values.commonAnnotations) "context" .) }}
  annotations: {{- include "common.tplvalues.render" (dict "value" $annotations "context" .) | nindent 4 }}
  {{- end }}
spec:
  type: ClusterIP
  clusterIP: None
  ports:
    {{- if .Values.service.http.enabled }}
    - name: http
      port: {{ .Values.containerPorts.http }}
      protocol: TCP
      targetPort: http
    {{- end }}
    {{- if .Values.tls.enabled }}
    - name: https
      port: {{ .Values.containerPorts.https }}
      protocol: TCP
      targetPort: https
    {{- end }}
    {{- if .Values.service.headless.extraPorts }}
    {{- include "common.tplvalues.render" (dict "value" .Values.service.headless.extraPorts "context" .) | nindent 4 }}
    {{- end }}
  publishNotReadyAddresses: true
  {{- $podLabels := include "common.tplvalues.merge" (dict "values" (list .Values.podLabels .Values.commonLabels) "context" .) }}
  selector: {{- include "common.labels.matchLabels" (dict "customLabels" $podLabels "context" .) | nindent 4 }}
    app.kubernetes.io/component: keycloak
    app.kubernetes.io/part-of: keycloak
    app.kubernetes.io/app-version: {{ .Chart.AppVersion | quote }}
{{- end }}
