# helm_charts_rethinkdb-proxy-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: "{{ template "rethinkdb.fullname" . }}-proxy"
  labels:
    app: "{{ template "rethinkdb.name" . }}-proxy"
    chart: {{ template "rethinkdb.chart" . }}
    heritage: {{ .Release.Service | quote }}
    release: {{ .Release.Name | quote }}
spec:
  replicas: {{ .Values.proxy.replicas }}
  selector:
    matchLabels:
      app: {{ template "rethinkdb.name" . }}-proxy
      heritage: {{ .Release.Service | quote }}
      release: {{ .Release.Name | quote }}
      chart: {{ template "rethinkdb.chart" . }}
  template:
    metadata:
      name: {{ template "rethinkdb.fullname" . }}-proxy
      labels:
        app: {{ template "rethinkdb.name" . }}-proxy
        heritage: {{ .Release.Service | quote }}
        release: {{ .Release.Name | quote }}
        chart: {{ template "rethinkdb.chart" . }}
      annotations:
      {{- if .Values.proxy.podAnnotations }}
{{ toYaml .Values.proxy.podAnnotations | indent 8 }}
      {{- end }}
    spec:
      serviceAccountName: {{ template "rethinkdb.serviceAccountName" . }}
      containers:
        - name: {{ template "rethinkdb.name" . }}-proxy
          image: "{{ .Values.image.name }}:{{ .Values.image.tag }}"
          imagePullPolicy: "{{ .Values.image.pullPolicy }}"
          ports:
            - name: cluster
              containerPort: {{ .Values.ports.cluster }}
            - name: driver
              containerPort: {{ .Values.ports.driver }}
            - name: admin
              containerPort: {{ .Values.ports.admin }}
          args:
            - "--bind"
            - "all"
            {{- if .Values.proxy.driverTLS.enabled }}
            - "--driver-tls-key"
            - "/secrets/driver-key.pem"
            - "--driver-tls-cert"
            - "/secrets/driver-cert.pem"
            {{- end }}
          volumeMounts:
            - name: "secrets"
              mountPath: "/secrets"
          env:
            - name: PROXY
              value: "true"
            - name: RETHINK_CLUSTER_SERVICE
              value: "{{ template "rethinkdb.fullname" . }}-cluster"
            - name: RETHINKDB_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: {{ template "rethinkdb.fullname" . }}
                  key: rethinkdb-password
            - name: POD_IP
              valueFrom:
                fieldRef:
                  apiVersion: v1
                  fieldPath: status.podIP
            - name: POD_NAMESPACE
              valueFrom:
                fieldRef:
                  fieldPath: metadata.namespace
            - name: POD_NAME
              valueFrom:
                fieldRef:
                  fieldPath: metadata.name
          resources:
{{ toYaml .Values.proxy.resources | indent 12 }}
      volumes:
        - name: secrets
          projected:
            sources:
            - secret:
                name: {{ template "rethinkdb.fullname" . }}