apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "server.fullname" . }}
  namespace: {{ include "server.fullname" . }}
  labels:
    {{- include "server.labels" . | nindent 4 }}
spec:
  {{- if not .Values.autoscaling.enabled }}
  replicas: {{ .Values.replicaCount }}
  {{- end }}
  selector:
    matchLabels:
      {{- include "server.selectorLabels" . | nindent 6 }}
  template:
    metadata:
      {{- with .Values.podAnnotations }}
      annotations:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      labels:
        {{- include "server.selectorLabels" . | nindent 8 }}
    spec:
      {{- with .Values.imagePullSecrets }}
      imagePullSecrets:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      serviceAccountName: {{ include "server.serviceAccountName" . }}
      securityContext:
        {{- toYaml .Values.podSecurityContext | nindent 8 }}
      containers:
        - name: {{ include "server.fullname" . }}
          securityContext:
            {{- toYaml .Values.securityContext | nindent 12 }}
          image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          command:
            {{- toYaml .Values.command | nindent 12 }}
          args:
            {{- toYaml .Values.args | nindent 12 }}
          ports:
            - containerPort: {{ .Values.service.port }}
          resources:
            {{- toYaml .Values.resources | nindent 12 }}
          {{- if eq (include "server.fullname" .) .Values.service.serverName }}
          livenessProbe:
            grpc:
              port: {{ .Values.service.port }}
            initialDelaySeconds: {{ .Values.service.livenessInitialDelaySeconds }}
            periodSeconds: {{ .Values.service.livenessPeriodSeconds }}
          readinessProbe:
            grpc:
              port: {{ .Values.service.port }}
            initialDelaySeconds: {{ .Values.service.readinessInitialDelaySeconds }}
            periodSeconds: {{ .Values.service.readinessPeriodSeconds }}
          {{- end }}
      {{- with .Values.nodeSelector }}
      nodeSelector:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.affinity }}
      affinity:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.tolerations }}
      tolerations:
        {{- toYaml . | nindent 8 }}
      {{- end }}
