apiVersion: pingcap.com/v1alpha1
kind: TidbCluster
metadata:
  name: {{ template "cluster.name" . }}
  namespace: {{ .Release.Namespace }}
{{- if .Values.enableConfigMapRollout }}
  annotations:
    pingcap.com/pd.{{ template "cluster.name" . }}-pd.sha: {{ include "pd-configmap.data-digest" . | quote }}
    pingcap.com/tikv.{{ template "cluster.name" . }}-tikv.sha: {{ include "tikv-configmap.data-digest" . | quote }}
    pingcap.com/tidb.{{ template "cluster.name" . }}-tidb.sha: {{ include "tidb-configmap.data-digest" . | quote }}
    pingcap.com/ha-topology-key: {{ .Values.haTopologyKey | default "kubernetes.io/hostname" }}
{{- end }}
  labels:
    app.kubernetes.io/name: {{ template "chart.name" . }}
    app.kubernetes.io/managed-by: {{ .Release.Service }}
    app.kubernetes.io/instance: {{ .Release.Name }}
    app.kubernetes.io/component: tidb-cluster
    helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+"  "_" }}
    {{- if .Values.extraLabels }}
{{ toYaml .Values.extraLabels | indent 4 }}
    {{- end }}
spec:
  pvReclaimPolicy: {{ .Values.pvReclaimPolicy }}
  enablePVReclaim: {{ .Values.enablePVReclaim }}
  timezone: {{ .Values.timezone | default "UTC" }}
{{- if .Values.tlsCluster }}
  tlsCluster:
{{ toYaml .Values.tlsCluster | indent 4 }}
{{- end }}
  services:
{{ toYaml .Values.services | indent 4 }}
  schedulerName: {{ .Values.schedulerName | default "default-scheduler" }}
  helper:
    image: {{ .Values.helper.image }}
  pd:
    replicas: {{ .Values.pd.replicas }}
    image: {{ .Values.pd.image }}
    imagePullPolicy: {{ .Values.pd.imagePullPolicy | default "IfNotPresent" }}
  {{- if .Values.pd.storageClassName }}
    storageClassName: {{ .Values.pd.storageClassName }}
  {{- end }}
  {{- if .Values.pd.resources }}
{{ toYaml .Values.pd.resources | indent 4 }}
  {{- end }}
    affinity:
{{ toYaml .Values.pd.affinity | indent 6 }}
    nodeSelector:
{{ toYaml .Values.pd.nodeSelector | indent 6 }}
  {{- if .Values.pd.tolerations }}
    tolerations:
{{ toYaml .Values.pd.tolerations | indent 4 }}
  {{- end }}
  {{- if .Values.pd.annotations }}
    annotations:
{{ toYaml .Values.pd.annotations | indent 6 }}
  {{- end }}
    hostNetwork: {{ .Values.pd.hostNetwork }}

  {{- if .Values.pd.podSecurityContext }}
    podSecurityContext:
{{ toYaml .Values.pd.podSecurityContext | indent 6}}
  {{- end }}
  {{- if .Values.pd.priorityClassName }}
    priorityClassName: {{ .Values.pd.priorityClassName }}
  {{- end }}
  {{- if .Values.pd.service }}
    service:
  {{ toYaml .Values.pd.service | indent 4 }}
  {{- end }}
  tikv:
    replicas: {{ .Values.tikv.replicas }}
    image: {{ .Values.tikv.image }}
    imagePullPolicy: {{ .Values.tikv.imagePullPolicy | default "IfNotPresent" }}
  {{- if .Values.tikv.storageClassName }}
    storageClassName: {{ .Values.tikv.storageClassName }}
  {{- end }}
  {{- if .Values.tikv.resources }}
{{ toYaml .Values.tikv.resources | indent 4 }}
  {{- end }}
    affinity:
{{ toYaml .Values.tikv.affinity | indent 6 }}
    nodeSelector:
{{ toYaml .Values.tikv.nodeSelector | indent 6 }}
  {{- if .Values.tikv.tolerations }}
    tolerations:
{{ toYaml .Values.tikv.tolerations | indent 4 }}
  {{- end }}
  {{- if .Values.tikv.annotations }}
    annotations:
{{ toYaml .Values.tikv.annotations | indent 6 }}
  {{- end }}
    hostNetwork: {{ .Values.tikv.hostNetwork }}
  {{- if .Values.tikv.podSecurityContext }}
    podSecurityContext:
{{ toYaml .Values.tikv.podSecurityContext | indent 6}}
  {{- end }}
  {{- if .Values.tikv.priorityClassName }}
    priorityClassName: {{ .Values.tikv.priorityClassName }}
  {{- end }}
    maxFailoverCount: {{ .Values.tikv.maxFailoverCount | default 3 }}
  tidb:
  {{- if .Values.tidb.tlsClient }}
    tlsClient:
{{ toYaml .Values.tidb.tlsClient | indent 6 }}
  {{- end }}
    replicas: {{ .Values.tidb.replicas }}
    image: {{ .Values.tidb.image }}
    imagePullPolicy: {{ .Values.tidb.imagePullPolicy | default "IfNotPresent" }}
  {{- if .Values.tidb.resources }}
{{ toYaml .Values.tidb.resources | indent 4 }}
  {{- end }}
    affinity:
{{ toYaml .Values.tidb.affinity | indent 6 }}
    nodeSelector:
{{ toYaml .Values.tidb.nodeSelector | indent 6 }}
  {{- if .Values.tidb.tolerations }}
    tolerations:
{{ toYaml .Values.tidb.tolerations | indent 4 }}
  {{- end }}
  {{- if .Values.tidb.annotations }}
    annotations:
{{ toYaml .Values.tidb.annotations | indent 6 }}
  {{- end }}
    hostNetwork: {{ .Values.tidb.hostNetwork }}
  {{- if .Values.tidb.podSecurityContext }}
    podSecurityContext:
{{ toYaml .Values.tidb.podSecurityContext | indent 6}}
  {{- end }}
  {{- if .Values.tidb.priorityClassName }}
    priorityClassName: {{ .Values.tidb.priorityClassName }}
  {{- end }}
    binlogEnabled: {{ .Values.binlog.pump.create | default false }}
    maxFailoverCount: {{ .Values.tidb.maxFailoverCount | default 3 }}
    separateSlowLog: {{ .Values.tidb.separateSlowLog | default false }}
    slowLogTailer:
      image: {{ .Values.tidb.slowLogTailer.image }}
      imagePullPolicy: {{ .Values.tidb.slowLogTailer.imagePullPolicy | default "IfNotPresent" }}
      {{- if .Values.tidb.slowLogTailer.resources }}
{{ toYaml .Values.tidb.slowLogTailer.resources | indent 6 }}
      {{- end }}
  tiproxy:
    replicas: {{ .Values.tiproxy.replicas }}
    baseImage: {{ .Values.tiproxy.baseImage }}
    version: {{ .Values.tiproxy.version }}
    imagePullPolicy: {{ .Values.tiproxy.imagePullPolicy }}
  {{- if .Values.tiproxy.storageClassName }}
    storageClassName: {{ .Values.tiproxy.storageClassName }}
  {{- end }}
  {{- if .Values.tiproxy.resources }}
{{ toYaml .Values.tiproxy.resources | indent 4 }}
  {{- end }}
