apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "helm-dashboard.fullname" . }}
  labels:
    {{- include "helm-dashboard.labels" . | nindent 4 }}
spec:
  {{- if not .Values.autoscaling.enabled }}
  replicas: {{ .Values.replicaCount }}
  {{- end }}
  selector:
    matchLabels:
      {{- include "helm-dashboard.selectorLabels" . | nindent 6 }}
  strategy: {{- toYaml .Values.updateStrategy | nindent 4 }}
  template:
    metadata:
      {{- with .Values.podAnnotations }}
      annotations:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      labels:
        {{- include "helm-dashboard.selectorLabels" . | nindent 8 }}
    spec:
      {{- with .Values.imagePullSecrets }}
      imagePullSecrets:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      serviceAccountName: {{ include "helm-dashboard.serviceAccountName" . }}
      securityContext:
        {{- toYaml .Values.podSecurityContext | nindent 8 }}
      containers:
        - name: {{ .Chart.Name }}
          command:
            - /bin/helm-dashboard
          args:
          {{- with .Values.extraArgs }}
            {{- toYaml . | nindent 12 }}
          {{- end }}
          securityContext:
            {{- toYaml .Values.securityContext | nindent 12 }}
          image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          env:
            - name: HELM_CACHE_HOME
              value: /opt/dashboard/helm/cache
            - name: HELM_CONFIG_HOME
              value: /opt/dashboard/helm/config
            - name: HELM_DATA_HOME
              value: /opt/dashboard/helm/data
            - name: DEBUG
              value: {{- ternary " 1" "" .Values.debug }}
            {{- if .Values.dashboard.namespace }}
            - name: HELM_NAMESPACE
              value: {{ .Values.dashboard.namespace }}
            {{end}}
          ports:
            - name: http
              containerPort: 8080
              protocol: TCP
          livenessProbe:
            httpGet:
              path: /status
              port: http
          readinessProbe:
            httpGet:
              path: /status
              port: http
          resources:
            {{- toYaml .Values.resources | nindent 12 }}
          volumeMounts:
            - name: data
              mountPath: /opt/dashboard/helm
      {{- with .Values.nodeSelector }}
      nodeSelector:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.affinity }}
      affinity:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.tolerations }}
      tolerations:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      volumes:
        - name: data
        {{- if .Values.dashboard.persistence.enabled }}
          persistentVolumeClaim:
            claimName: {{ include "helm-dashboard.fullname" . }}
        {{- else }}
          emptyDir: { }
        {{- end }}

