#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.
#

{{- if .Values.components.oxia }}
apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ template "pulsar.fullname" . }}-{{ .Values.oxia.component }}-coordinator
  namespace: {{ template "pulsar.namespace" . }}
  labels:
    {{- include "pulsar.standardLabels" . | nindent 4 }}
    component: {{ .Values.oxia.component }}-coordinator
  annotations: {{ .Values.oxia.coordinator.appAnnotations | toYaml | nindent 4 }}
spec:
  replicas: 1
  selector:
    matchLabels:
      {{- include "pulsar.matchLabels" . | nindent 6 }}
      component: {{ .Values.oxia.component }}-coordinator
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        {{- include "pulsar.template.labels" . | nindent 8 }}
        component: {{ .Values.oxia.component }}-coordinator
      annotations:
        {{- if not .Values.oxia.coordinator.podMonitor.enabled }}
        prometheus.io/scrape: "true"
        prometheus.io/port: "{{ .Values.oxia.coordinator.ports.metrics }}"
        {{- end }}
    spec:
    {{- if .Values.oxia.server.nodeSelector }}
      nodeSelector:
{{ toYaml .Values.oxia.server.nodeSelector | indent 8 }}
    {{- end }}
    {{- if .Values.oxia.server.tolerations }}
      tolerations:
{{ toYaml .Values.oxia.server.tolerations | indent 8 }}
    {{- end }}    
      serviceAccountName: {{ template "pulsar.fullname" . }}-{{ .Values.oxia.component }}-coordinator
      containers:
        - command:
            {{- include "oxia.coordinator.entrypoint" . | nindent 12 }}
          image: "{{ .Values.images.oxia.repository }}:{{ .Values.images.oxia.tag }}"
          imagePullPolicy: "{{ template "pulsar.imagePullPolicy" (dict "image" .Values.images.oxia "root" .) }}"
          name: coordinator
          ports:
            {{- range $key, $value := .Values.oxia.coordinator.ports }}
            - containerPort: {{ $value | int }}
              name: {{ $key }}
            {{- end}}
          resources:
            limits:
              cpu: {{ .Values.oxia.coordinator.cpuLimit }}
              memory: {{ .Values.oxia.coordinator.memoryLimit }}
          livenessProbe:
            {{- include "oxia-cluster.probe" .Values.oxia.coordinator.ports.internal | nindent 12 }}
          readinessProbe:
            {{- include "oxia-cluster.probe" .Values.oxia.coordinator.ports.internal | nindent 12 }}
{{- end }}