{{- if .Values.service.read.enabled }}
---
apiVersion: v1
kind: Service
metadata:
  name: {{ include "keto.fullname" . }}-read
  {{- if .Release.Namespace }}
  namespace: {{ .Release.Namespace }}
  {{- end }}
  labels:
    app.kubernetes.io/component: read
    {{- include "keto.labels" . | nindent 4 }}
spec:
  type: {{ .Values.service.read.type }}
  {{- if eq .Values.service.read.type "LoadBalancer" }}
  {{- with .Values.service.read.loadBalancerIP }}
  loadBalancerIP: {{ . }}
  {{- end }}
  {{- end }}
  {{- if eq .Values.service.read.type "ClusterIP" }}
  {{- with .Values.service.read.clusterIP }}
  clusterIP: {{ . }}
  {{- end }}
  {{- end }}
  ports:
    - port: {{ .Values.service.read.port }}
      targetPort: {{ .Values.service.read.name }}
      protocol: TCP
      name: {{ .Values.service.read.name }}
      appProtocol: {{ .Values.service.read.appProtocol }}
  selector:
    app.kubernetes.io/name: {{ include "keto.name" . }}
    app.kubernetes.io/instance: {{ .Release.Name }}
{{- if .Values.service.read.headless.enabled }}
---
apiVersion: v1
kind: Service
metadata:
  name: {{ include "keto.fullname" . }}-read-headless
  {{- if .Release.Namespace }}
  namespace: {{ .Release.Namespace }}
  {{- end }}
  labels:
    service.ory.sh/type: headless
    app.kubernetes.io/component: read
    {{- include "keto.labels" . | nindent 4 }}
spec:
  type: "ClusterIP"
  clusterIP: "None"
  ports:
    - port: {{ .Values.keto.config.serve.read.port }}
      targetPort: {{ .Values.service.read.name }}
      protocol: TCP
      name: {{ .Values.service.read.name }}
      appProtocol: {{ .Values.service.read.appProtocol }}
  selector:
    app.kubernetes.io/name: {{ include "keto.name" . }}
    app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}
{{- end }}