apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ template "dialCore.names.fullname" . }}
  namespace: {{ include "common.names.namespace" . | quote }}
  labels: {{ include "dialCore.labels.standard" . | nindent 4 }}
    {{- if .Values.commonLabels }}
    {{- include "common.tplvalues.render" ( dict "value" .Values.commonLabels "context" $ ) | nindent 4 }}
    {{- end }}
    {{- if .Values.labels }}
    {{- include "common.tplvalues.render" ( dict "value" .Values.labels "context" $ ) | nindent 4 }}
    {{- end }}
  {{- if or .Values.annotations .Values.commonAnnotations }}
  annotations:
    {{- if .Values.annotations }}
    {{- include "common.tplvalues.render" ( dict "value" .Values.annotations "context" $ ) | nindent 4 }}
    {{- end }}
    {{- if .Values.commonAnnotations }}
    {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }}
    {{- end }}
  {{- end }}
spec:
  {{- if not .Values.autoscaling.hpa.enabled }}
  replicas: {{ .Values.replicaCount }}
  {{- end }}
  {{- if .Values.updateStrategy }}
  strategy: {{- toYaml .Values.updateStrategy | nindent 4 }}
  {{- end }}
  selector:
    matchLabels: {{- include "dialCore.labels.matchLabels" . | nindent 6 }}
  template:
    metadata:
      {{- if .Values.podAnnotations }}
      annotations: {{- include "common.tplvalues.render" (dict "value" .Values.podAnnotations "context" $) | nindent 8 }}
      {{- end }}
      labels: {{ include "dialCore.labels.matchLabels" . | nindent 8 }}
        {{- if .Values.podLabels }}
        {{- include "common.tplvalues.render" (dict "value" .Values.podLabels "context" $) | nindent 8 }}
        {{- end }}
        {{- if .Values.commonLabels }}
        {{- include "common.tplvalues.render" ( dict "value" .Values.commonLabels "context" $ ) | nindent 8 }}
        {{- end }}
    spec:
      serviceAccountName: {{ template "dialCore.serviceAccountName" . }}
      {{- include "common.images.renderPullSecrets" (dict "images" (list .Values.image) "context" $) | nindent 6 }}
      {{- if .Values.hostAliases }}
      hostAliases: {{- include "common.tplvalues.render" (dict "value" .Values.hostAliases "context" $) | nindent 8 }}
      {{- end }}
      {{- if .Values.affinity }}
      affinity: {{- include "common.tplvalues.render" ( dict "value" .Values.affinity "context" $) | nindent 8 }}
      {{- end }}
      {{- if .Values.nodeSelector }}
      nodeSelector: {{- include "common.tplvalues.render" ( dict "value" .Values.nodeSelector "context" $) | nindent 8 }}
      {{- end }}
      {{- if .Values.tolerations }}
      tolerations: {{- include "common.tplvalues.render" (dict "value" .Values.tolerations "context" .) | nindent 8 }}
      {{- end }}
      {{- if .Values.priorityClassName }}
      priorityClassName: {{ .Values.priorityClassName | quote }}
      {{- end }}
      {{- if .Values.schedulerName }}
      schedulerName: {{ .Values.schedulerName | quote }}
      {{- end }}
      {{- if .Values.topologySpreadConstraints }}
      topologySpreadConstraints: {{- include "common.tplvalues.render" (dict "value" .Values.topologySpreadConstraints "context" .) | nindent 8 }}
      {{- end }}
      {{- if .Values.podSecurityContext.enabled }}
      securityContext: {{- omit .Values.podSecurityContext "enabled" | toYaml | nindent 8 }}
      {{- end }}
      {{- if .Values.terminationGracePeriodSeconds }}
      terminationGracePeriodSeconds: {{ .Values.terminationGracePeriodSeconds }}
      {{- end }}
      {{- if .Values.initContainers }}
      initContainers: {{- include "common.tplvalues.render" (dict "value" .Values.initContainers "context" $) | nindent 8 }}
      {{- end }}
      {{- if .Values.hostNetwork }}
      hostNetwork: true
      dnsPolicy: ClusterFirstWithHostNet
      {{- end }}
      containers:
        - name: application
          image: {{ include "common.images.image" (dict "imageRoot" .Values.image "global" .Values.global) | quote }}
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          {{- if .Values.containerSecurityContext.enabled }}
          securityContext: {{- omit .Values.containerSecurityContext "enabled" | toYaml | nindent 12 }}
          {{- end }}
          {{- if .Values.command }}
          command: {{- include "common.tplvalues.render" (dict "value" .Values.command "context" $) | nindent 12 }}
          {{- end }}
          {{- if .Values.args }}
          args: {{- include "common.tplvalues.render" (dict "value" .Values.args "context" $) | nindent 12 }}
          {{- end }}
          {{- if or .Values.env .Values.redis.enabled }}
          env:
            {{- include "dialCore.redisSettings" . | nindent 12 }}
            {{- range $key, $value := .Values.env }}
            - name: {{ $key }}
              value: {{ tpl $value $ | quote }}
            {{- end }}
          {{- end }}
          envFrom:
            {{- if .Values.secrets }}
            - secretRef:
                name: {{ template "dialCore.names.fullname" . }}
            {{- end }}
            {{- if .Values.configuration.encryption.existingSecret }}
            - secretRef:
                name: {{ .Values.configuration.encryption.existingSecret }}
            {{- else }}
            - secretRef:
                name: {{ template "dialCore.encryptionSecretName" . }}
            {{- end }}
            {{- if .Values.extraEnvVarsSecret }}
            - secretRef:
                name: {{ include "common.tplvalues.render" (dict "value" .Values.extraEnvVarsSecret "context" $) }}
            {{- end }}
          {{- if .Values.resources }}
          resources: {{- toYaml .Values.resources | nindent 12 }}
          {{- end }}
          ports:
            - name: http
              containerPort: {{ .Values.containerPorts.http }}
            {{- if .Values.metrics.enabled }}
            - name: http-metrics
              containerPort: {{ .Values.containerPorts.metrics }}
            {{- end }}
          {{- if not .Values.diagnosticMode.enabled }}
          {{- if .Values.customLivenessProbe }}
          livenessProbe: {{- include "common.tplvalues.render" (dict "value" .Values.customLivenessProbe "context" $) | nindent 12 }}
          {{- else if .Values.livenessProbe.enabled }}
          livenessProbe: {{- include "common.tplvalues.render" (dict "value" (omit .Values.livenessProbe "enabled") "context" $) | nindent 12 }}
          {{- end }}
          {{- if .Values.customReadinessProbe }}
          readinessProbe: {{- include "common.tplvalues.render" (dict "value" .Values.customReadinessProbe "context" $) | nindent 12 }}
          {{- else if .Values.readinessProbe.enabled }}
          readinessProbe: {{- include "common.tplvalues.render" (dict "value" (omit .Values.readinessProbe "enabled") "context" $) | nindent 12 }}
          {{- end }}
          {{- if .Values.customStartupProbe }}
          startupProbe: {{- include "common.tplvalues.render" (dict "value" .Values.customStartupProbe "context" $) | nindent 12 }}
          {{- else if .Values.startupProbe.enabled }}
          startupProbe: {{- include "common.tplvalues.render" (dict "value" (omit .Values.startupProbe "enabled") "context" $) | nindent 12 }}
          {{- end }}
          {{- end }}
          {{- if .Values.lifecycleHooks }}
          lifecycle: {{- include "common.tplvalues.render" (dict "value" .Values.lifecycleHooks "context" $) | nindent 12 }}
          {{- end }}
        {{- if or .Values.logger.enabled .Values.extraVolumeMounts }}
          volumeMounts:
          {{- if .Values.logger.enabled }}
            - name: logs
              mountPath: /app/log
          {{- end }}
          {{- if .Values.extraVolumeMounts }}
          {{- include "common.tplvalues.render" (dict "value" .Values.extraVolumeMounts "context" $) | nindent 12 }}
          {{- end }}
        {{- end }}
        {{- if .Values.logger.enabled }}
        - name: logger
          image: {{ include "common.images.image" (dict "imageRoot" .Values.logger.image "global" .Values.global) | quote }}
          imagePullPolicy: {{ .Values.logger.image.pullPolicy | quote }}
          {{- if .Values.logger.command }}
          command: {{- include "common.tplvalues.render" (dict "value" .Values.logger.command "context" $) | nindent 12 }}
          {{- end }}
          {{- if .Values.logger.args }}
          args: {{- include "common.tplvalues.render" (dict "value" .Values.logger.args "context" $) | nindent 12 }}
          {{- end }}
          {{- if .Values.logger.containerSecurityContext.enabled }}
          securityContext: {{- omit .Values.logger.containerSecurityContext "enabled" | toYaml | nindent 12 }}
          {{- end }}
          resources: {{ toYaml .Values.logger.resources | nindent 12 }}
          {{ if .Values.logger.env }}
          env:
            {{- range $key, $value := .Values.logger.env }}
            - name: {{ $key }}
              value: {{ tpl $value $ | quote }}
            {{- end }}
          {{- end }}
          {{- if or .Values.logger.secrets .Values.logger.extraEnvVarsSecret }}
          envFrom:
            {{- if .Values.logger.secrets }}
            - secretRef:
                name: {{ template "dialCoreLogger.names.fullname" . }}
            {{- end }}
            {{- if .Values.logger.extraEnvVarsSecret }}
            - secretRef:
                name: {{ include "common.tplvalues.render" (dict "value" .Values.logger.extraEnvVarsSecret "context" $) }}
            {{- end }}
          {{- end }}
          volumeMounts:
            - name: logs
              mountPath: /app/log/
            - name: logger-config
              mountPath: /etc/vector/vector.yaml
              subPath: vector.yaml
          {{- if .Values.logger.extraVolumeMounts }}
            {{- include "common.tplvalues.render" (dict "value" .Values.logger.extraVolumeMounts "context" $) | nindent 12 }}
          {{- end }}
        {{- end }}
        {{- if .Values.sidecars }}
        {{- include "common.tplvalues.render" ( dict "value" .Values.sidecars "context" $) | nindent 8 }}
        {{- end }}
      {{- if or .Values.logger.enabled .Values.extraVolumes }}
      volumes:
        {{- if .Values.logger.enabled }}
        - name: logs
          emptyDir: {}
        {{- end }}
        {{- if and .Values.logger.enabled .Values.logger.config }}
        - name: logger-config
          configMap:
            name: {{ template "dialCoreLogger.names.fullname" . }}
            items:
              - key: vector.yaml
                path: vector.yaml
                mode: 292 # 0444
        {{- end }}
        {{- if .Values.extraVolumes }}
        {{- include "common.tplvalues.render" (dict "value" .Values.extraVolumes "context" $) | nindent 8 }}
        {{- end }}
        {{- end }}