{{- if .Values.imageRenderer.enabled }}
apiVersion: {{ include "common.capabilities.deployment.apiVersion" . }}
kind: Deployment
metadata:
  name: {{ include "common.names.fullname" . }}-image-renderer
  namespace: {{ .Release.Namespace | quote }}
  labels: {{- include "common.labels.standard" . | nindent 4 }}
    {{- if .Values.commonLabels }}
    {{- include "common.tplvalues.render" ( dict "value" .Values.commonLabels "context" $ ) | nindent 4 }}
    {{- end }}
    app.kubernetes.io/component: image-renderer
  {{- if .Values.commonAnnotations }}
  annotations: {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }}
  {{- end }}
spec:
  replicas: {{ .Values.imageRenderer.replicaCount }}
  {{- if .Values.imageRenderer.updateStrategy }}
  strategy: {{- toYaml .Values.imageRenderer.updateStrategy | nindent 4 }}
  {{- end }}
  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.podLabels }}
        {{- include "common.tplvalues.render" (dict "value" .Values.imageRenderer.podLabels "context" $) | nindent 8 }}
        {{- end }}
      {{- if .Values.imageRenderer.podAnnotations }}
      annotations: {{- toYaml .Values.imageRenderer.podAnnotations | nindent 8 }}
      {{- end }}
    spec:
      {{- include "grafana.imagePullSecrets" . | nindent 6 }}
      serviceAccountName: {{ template "grafana.serviceAccountName" . }}
      {{- if .Values.imageRenderer.hostAliases }}
      hostAliases: {{- include "common.tplvalues.render" (dict "value" .Values.imageRenderer.hostAliases "context" $) | nindent 8 }}
      {{- end }}
      {{- if .Values.imageRenderer.affinity }}
      affinity: {{- include "common.tplvalues.render" (dict "value" .Values.imageRenderer.affinity "context" $) | nindent 8 }}
      {{- else }}
      affinity:
        podAffinity: {{- include "common.affinities.pods" (dict "type" .Values.imageRenderer.podAffinityPreset "component" "image-renderer" "context" $) | nindent 10 }}
        podAntiAffinity: {{- include "common.affinities.pods" (dict "type" .Values.imageRenderer.podAntiAffinityPreset "component" "image-renderer" "context" $) | nindent 10 }}
        nodeAffinity: {{- include "common.affinities.nodes" (dict "type" .Values.imageRenderer.nodeAffinityPreset.type "key" .Values.imageRenderer.nodeAffinityPreset.key "values" .Values.imageRenderer.nodeAffinityPreset.values) | nindent 10 }}
      {{- 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.priorityClassName }}
      priorityClassName: {{ .Values.imageRenderer.priorityClassName | quote }}
      {{- end }}
      {{- if .Values.imageRenderer.schedulerName }}
      schedulerName: {{ .Values.imageRenderer.schedulerName | quote }}
      {{- end }}
      {{- if .Values.imageRenderer.topologySpreadConstraints }}
      topologySpreadConstraints: {{- include "common.tplvalues.render" (dict "value" .Values.imageRenderer.topologySpreadConstraints "context" $) | nindent 8 }}
      {{- end }}
      {{- if .Values.imageRenderer.podSecurityContext.enabled }}
      securityContext: {{- omit .Values.imageRenderer.podSecurityContext "enabled" | toYaml | nindent 8 }}
      {{- end }}
      {{- if .Values.imageRenderer.terminationGracePeriodSeconds }}
      terminationGracePeriodSeconds: {{ .Values.imageRenderer.terminationGracePeriodSeconds }}
      {{- end }}
      initContainers:
        {{- if .Values.imageRenderer.initContainers }}
        {{- include "common.tplvalues.render" (dict "value" .Values.imageRenderer.initContainers "context" $) | nindent 8 }}
        {{- end }}
      containers:
        - name: grafana-image-renderer
          image: {{ template "grafana.imageRenderer.image" . }}
          imagePullPolicy: {{ .Values.imageRenderer.image.pullPolicy }}
          {{- if .Values.imageRenderer.containerSecurityContext.enabled }}
          securityContext: {{- omit .Values.imageRenderer.containerSecurityContext "enabled" | toYaml | nindent 12 }}
          {{- end }}
          {{- if .Values.diagnosticMode.enabled }}
          command: {{- include "common.tplvalues.render" (dict "value" .Values.diagnosticMode.command "context" $) | nindent 12 }}
          {{- else if .Values.imageRenderer.command }}
          command: {{- include "common.tplvalues.render" (dict "value" .Values.imageRenderer.command "context" $) | nindent 12 }}
          {{- end }}
          {{- if .Values.diagnosticMode.enabled }}
          args: {{- include "common.tplvalues.render" (dict "value" .Values.diagnosticMode.args "context" $) | nindent 12 }}
          {{- else if .Values.imageRenderer.args }}
          args: {{- include "common.tplvalues.render" (dict "value" .Values.imageRenderer.args "context" $) | nindent 12 }}
          {{- end }}
          {{- if .Values.imageRenderer.lifecycleHooks }}
          lifecycle: {{- include "common.tplvalues.render" (dict "value" .Values.imageRenderer.lifecycleHooks "context" $) | nindent 12 }}
          {{- end }}
          envFrom:
            {{- if .Values.imageRenderer.extraEnvVarsCM }}
            - configMapRef:
                name: {{ include "common.tplvalues.render" (dict "value" .Values.imageRenderer.extraEnvVarsCM "context" $) }}
            {{- end }}
            {{- if .Values.imageRenderer.extraEnvVarsSecret }}
            - secretRef:
                name: {{ include "common.tplvalues.render" (dict "value" .Values.imageRenderer.extraEnvVarsSecret "context" $) }}
            {{- end }}
          env:
            - name: HTTP_PORT
              value: "8080"
            - name: HTTP_HOST
              value: "::"
            - name: ENABLE_METRICS
              value: {{ ternary "true" "false" .Values.imageRenderer.metrics.enabled | quote }}
            {{- if .Values.imageRenderer.extraEnvVars }}
            {{- include "common.tplvalues.render" (dict "value" .Values.imageRenderer.extraEnvVars "context" $) | nindent 12 }}
            {{- end }}
          ports:
            - name: http
              containerPort: 8080
              protocol: TCP
          {{- if .Values.imageRenderer.resources }}
          resources: {{- toYaml .Values.imageRenderer.resources | nindent 12 }}
          {{- end }}
          {{- if .Values.imageRenderer.extraVolumeMounts }}
          volumeMounts: {{- include "common.tplvalues.render" (dict "value" .Values.imageRenderer.extraVolumeMounts "context" $) | nindent 12 }}
          {{- end }}
        {{- if .Values.imageRenderer.sidecars }}
        {{- include "common.tplvalues.render" ( dict "value" .Values.imageRenderer.sidecars "context" $) | nindent 8 }}
        {{- end }}
      {{- if .Values.imageRenderer.extraVolumes }}
      volumes: {{- include "common.tplvalues.render" (dict "value" .Values.imageRenderer.extraVolumes "context" $) | nindent 8 }}
      {{- end }}
{{- end }}
