---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ tuple . "maint" | include "benji.fullname" }}
  annotations:
    checksum/config: {{ .Values.benji.configuration | toYaml | sha256sum }}
  labels:
    app.kubernetes.io/name: {{ include "benji.name" . }}
    helm.sh/chart: {{ include "benji.chart" . }}
    app.kubernetes.io/instance: {{ .Release.Name }}
    app.kubernetes.io/component: benji
    app.kubernetes.io/managed-by: {{ .Release.Service }}
spec:
  replicas: 1
  selector:
    matchLabels:
      app.kubernetes.io/name: {{ include "benji.name" . }}
      app.kubernetes.io/instance: {{ .Release.Name }}
      app.kubernetes.io/component: benji
  template:
    metadata:
      labels:
        app.kubernetes.io/name: {{ include "benji.name" . }}
        app.kubernetes.io/instance: {{ .Release.Name }}
        app.kubernetes.io/component: benji
    spec:
      serviceAccountName: {{ tuple . "" | include "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
            - name: PROM_PUSH_GATEWAY
              value: "{{- printf "%s-%s" .Release.Name .Values.pushgateway.nameOverride | trunc 63 | trimSuffix "-" -}}:9091"
          volumeMounts:
            - name: benji-config
              mountPath: /benji/etc
            - name: tz-config
              mountPath: /etc/localtime
            {{ toYaml .Values.benji.volumeMounts | nindent 12 }}
          resources:
            {{ toYaml .Values.benji.resources | nindent 12 }}
      hostNetwork: false
      volumes:
        - name: benji-config
          configMap:
            name: {{ tuple . "" | include "benji.fullname" }}
        - name: tz-config
          hostPath:
            path: /usr/share/zoneinfo/{{ .Values.timeZone }}
        {{ toYaml .Values.benji.volumes | nindent 8 }}
{{- with .Values.benji.nodeSelector }}
      nodeSelector:
        {{ toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.benji.affinity }}
      affinity:
        {{ toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.benji.tolerations }}
      tolerations:
        {{ toYaml . | nindent 8 }}
{{- end }}
