{{- if .Values.adminrpc.enabled -}}
apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "gitdata.fullname" . }}-adminrpc
  namespace: {{ include "gitdata.namespace" . }}
  labels:
    app.kubernetes.io/name: {{ include "gitdata.fullname" . }}-adminrpc
    app.kubernetes.io/instance: {{ .Release.Name }}
    app.kubernetes.io/version: {{ .Chart.AppVersion }}
spec:
  replicas: 1
  selector:
    matchLabels:
      app.kubernetes.io/name: {{ include "gitdata.fullname" . }}-adminrpc
      app.kubernetes.io/instance: {{ .Release.Name }}
  template:
    metadata:
      labels:
        app.kubernetes.io/name: {{ include "gitdata.fullname" . }}-adminrpc
        app.kubernetes.io/instance: {{ .Release.Name }}
    spec:
      {{- if $.Values.image.pullSecrets }}
      imagePullSecrets:
        {{- range $.Values.image.pullSecrets }}
        - name: {{ . }}
        {{- end }}
      {{- end }}
      terminationGracePeriodSeconds: 10
      containers:
        - name: adminrpc
          image: "{{ .Values.image.registry }}/{{ .Values.adminrpc.image.repository }}:{{ .Values.adminrpc.image.tag }}"
          imagePullPolicy: {{ .Values.adminrpc.image.pullPolicy | default .Values.image.pullPolicy }}
          ports:
            - name: grpc
              containerPort: {{ .Values.adminrpc.service.port }}
              protocol: TCP
          args:
            - --bind
            - "0.0.0.0:{{ .Values.adminrpc.service.port }}"
          envFrom:
            - configMapRef:
                name: {{ include "gitdata.fullname" . }}-config
          livenessProbe:
            tcpSocket:
              port: {{ .Values.adminrpc.service.port }}
            initialDelaySeconds: 5
            periodSeconds: 10
          readinessProbe:
            tcpSocket:
              port: {{ .Values.adminrpc.service.port }}
            initialDelaySeconds: 5
            periodSeconds: 5
          {{- if .Values.adminrpc.resources }}
          resources:
            {{- toYaml .Values.adminrpc.resources | nindent 12 }}
          {{- end }}
      {{- with .Values.adminrpc.nodeSelector }}
      nodeSelector:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.adminrpc.tolerations }}
      tolerations:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.adminrpc.affinity }}
      affinity:
        {{- toYaml . | nindent 8 }}
      {{- end }}
---
apiVersion: v1
kind: Service
metadata:
  name: {{ include "gitdata.fullname" . }}-adminrpc
  namespace: {{ include "gitdata.namespace" . }}
  labels:
    app.kubernetes.io/name: {{ include "gitdata.fullname" . }}-adminrpc
    app.kubernetes.io/instance: {{ .Release.Name }}
spec:
  type: ClusterIP
  ports:
    - port: {{ .Values.adminrpc.service.port }}
      targetPort: grpc
      protocol: TCP
      name: grpc
  selector:
    app.kubernetes.io/name: {{ include "gitdata.fullname" . }}-adminrpc
    app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}
