{{- if .Values.imageRenderer.enabled }}
apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "common.names.fullname" . }}-image-renderer
  namespace: {{ .Release.Namespace }}
  labels: {{- include "common.labels.standard" . | nindent 4 }}
    app.kubernetes.io/component: image-renderer
spec:
  replicas: {{ .Values.imageRenderer.replicaCount }}
  selector:
    matchLabels: {{- include "common.labels.matchLabels" . | nindent 6 }}
      app.kubernetes.io/component: image-renderer
  template:
    metadata:
      labels: {{- include "common.labels.standard" . | nindent 8 }}
        app.kubernetes.io/component: image-renderer
      {{- if .Values.imageRenderer.podAnnotations }}
      annotations: {{- toYaml .Values.imageRenderer.podAnnotations | nindent 8 }}
      {{- end }}
    spec:
      {{- include "grafana.imagePullSecrets" . | nindent 6 }}
      serviceAccountName: {{ template "grafana.serviceAccountName" . }}
      {{- if .Values.schedulerName }}
      schedulerName: {{ .Values.schedulerName | quote }}
      {{- end }}
      {{- if .Values.imageRenderer.affinity }}
      affinity: {{- include "common.tplvalues.render" (dict "value" .Values.imageRenderer.affinity "context" $) | nindent 8 }}
      {{- end }}
      {{- if .Values.imageRenderer.nodeSelector }}
      nodeSelector: {{- include "common.tplvalues.render" (dict "value" .Values.imageRenderer.nodeSelector "context" $) | nindent 8 }}
      {{- end }}
      {{- if .Values.imageRenderer.tolerations }}
      tolerations: {{- include "common.tplvalues.render" (dict "value" .Values.imageRenderer.tolerations "context" $) | nindent 8 }}
      {{- end }}
      {{- if .Values.imageRenderer.securityContext.enabled }}
      securityContext:
        runAsUser: {{ .Values.imageRenderer.securityContext.runAsUser }}
        fsGroup: {{ .Values.imageRenderer.securityContext.fsGroup }}
        runAsNonRoot: {{ .Values.imageRenderer.securityContext.runAsNonRoot }}
      {{- end }}
      containers:
        - name: grafana-image-renderer
          image: {{ template "grafana.imageRenderer.image" . }}
          imagePullPolicy: {{ .Values.imageRenderer.image.pullPolicy }}
          env:
            - name: HTTP_PORT
              value: "8080"
            - name: HTTP_HOST
              value: "0.0.0.0"
            - name: ENABLE_METRICS
              value: {{ ternary "true" "false" .Values.imageRenderer.metrics.enabled | quote }}
          ports:
            - name: http
              containerPort: 8080
              protocol: TCP
{{- end }}
