---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: {{ template "benji.fullname" . }}
  labels:
    app: {{ template "benji.name" . }}
    chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
    release: {{ .Release.Name }}
    heritage: {{ .Release.Service }}
spec:
  replicas: 1
  template:
    metadata:
      name: {{ template "benji.fullname" . }}
      labels:
        app: {{ template "benji.name" . }}
        release: {{ .Release.Name }}
      annotations:
        prometheus.io/port: "{{ .Values.pushgateway.port }}"
        prometheus.io/scrape: "true"
    spec:
      serviceAccountName: {{ template "benji.fullname" . }}
      dnsPolicy: ClusterFirstWithHostNet
      containers:
        - name: benji
          image: "{{ .Values.benji.image.registry }}/{{ .Values.benji.image.repository }}:{{ .Values.benji.image.tag }}"
          imagePullPolicy: {{ .Values.benji.image.pullPolicy }}
          securityContext:
            privileged: true
          env:
            - name: POD_NAME
              valueFrom:
                fieldRef:
                  fieldPath: metadata.name
            - name: POD_NAMESPACE
              valueFrom:
                fieldRef:
                  fieldPath: metadata.namespace
          volumeMounts:
            - name: benji-config
              mountPath: /benji/etc
            - name: tz-config
              mountPath: /etc/localtime
            # Ceph volumes start
            - name: ceph-etc
              mountPath: /etc/ceph/ceph.conf
              subPath: ceph.conf
              readOnly: true
            - name: ceph-client-admin-keyring
              mountPath: /etc/ceph/ceph.client.admin.keyring
              subPath: ceph.client.admin.keyring
              readOnly: true
            # Ceph volumes end
          resources:
{{ toYaml .Values.benji.resources | indent 12 }}
        - name: pushgateway
          image: "{{ .Values.pushgateway.image.registry }}/{{ .Values.pushgateway.image.repository }}:{{ .Values.pushgateway.image.tag }}"
          imagePullPolicy: {{ .Values.pushgateway.image.pullPolicy }}
          args:
            - "--web.listen-address=:{{ .Values.pushgateway.port }}"
            - "--persistence.file=/var/lib/pushgateway/database.dat"
          ports:
            - containerPort: {{ .Values.pushgateway.port }}
          volumeMounts:
            - mountPath: /var/lib/pushgateway
              name: pushgateway
            - name: tz-config
              mountPath: /etc/localtime
      hostNetwork: false
      volumes:
        - name: benji-config
          configMap:
            name: {{ template "benji.fullname" . }}
        - name: pushgateway
          emptyDir: {}
        - name: tz-config
          hostPath:
            path: /usr/share/zoneinfo/{{ .Values.timeZone }}
        # Ceph volumes start
        - name: ceph-etc
          configMap:
            name: ceph-etc
            defaultMode: 0444
        - name: ceph-client-admin-keyring
          secret:
            secretName: ceph-client-admin-keyring
        # Ceph end
    {{- if .Values.nodeSelector }}
      nodeSelector:
{{ toYaml .Values.nodeSelector | indent 8 }}
    {{- end }}
