apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "paidiverpy-gui.fullname" . }}
  labels:
    {{- include "paidiverpy-gui.labels" . | nindent 4 }}
  namespace: {{ .Release.Namespace }}
spec:
  replicas: {{ .Values.replicaCount }}
  selector:
    matchLabels:
      {{- include "paidiverpy-gui.selectorLabels" . | nindent 6 }}
  template:
    metadata:
      labels:
        {{- include "paidiverpy-gui.selectorLabels" . | nindent 8 }}
    spec:
      securityContext:
        {{- toYaml .Values.podSecurityContext | nindent 8 }}
      containers:
        - name: {{ .Chart.Name }}
          image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          command: [ {{ .Values.image.command }} ]
          args: [ {{- range $arg := .Values.image.args }}
            {{- $arg | quote }},
            {{- end }}
          ]
          securityContext:
            {{- toYaml .Values.securityContext | nindent 12 }}
          env:
          {{- range $key, $val := .Values.env }}
            - name: {{ $key }}
              value: {{ $val | quote }}
          {{- end }}
          {{- if .Values.netrc }}
            - name: NETRC
              value: /config/netrc
            - name: CURLOPT_NETRC
              value: CURL_NETRC_OPTIONAL
            - name: CURLOPT_NETRC_FILE
              value: /config/netrc
          {{- end }}
          {{- if .Values.envFromSecret }}
          envFrom:
            - secretRef:
                name: {{ .Values.existingSecret }}
          {{- end }}
          ports:
            - name: http
              containerPort: 5006
              protocol: TCP
          {{- if .Values.readinessProbe }}
          readinessProbe:
            {{- toYaml .Values.readinessProbe | nindent 12 }}
          {{- end }}

          {{- if .Values.livenessProbe }}
          livenessProbe:
            {{- toYaml .Values.livenessProbe | nindent 12 }}
          {{- end }}
          resources:
            {{- toYaml .Values.resources | nindent 12 }}
          volumeMounts:
            - mountPath: /config
              name: config
              readOnly: true
          {{- range .Values.extraHostPathMounts }}
            - name: {{ .name }}
              mountPath: {{ .mountPath }}
              readOnly: {{ .readOnly }}
            {{- if .mountPropagation }}
              mountPropagation: {{ .mountPropagation }}
            {{- end }}
          {{- end }}
      terminationGracePeriodSeconds: {{ .Values.env.terminationGracePeriodSeconds }}
      volumes:
        - name: config
          configMap:
            name: {{ include "paidiverpy-gui.fullname" . }}-configmap
      {{- range .Values.extraHostPathMounts }}
        - name: {{ .name }}
          hostPath:
            path: {{ .hostPath }}
            type: Directory
      {{- end }}
      {{- with .Values.imagePullSecrets }}
      imagePullSecrets:
        {{- range . }}
      - name: {{ .name }}
        {{- end }}
      {{- end }}
      {{- with .Values.serviceAccountName }}
      serviceAccountName: {{ . | quote }}
      {{- end }}
      {{- with .Values.nodeSelector }}
      nodeSelector:
        {{- toYaml . | nindent 8 }}
      {{- end }}
    {{- with .Values.affinity }}
      affinity:
        {{- toYaml . | nindent 8 }}
    {{- end }}
    {{- with .Values.tolerations }}
      tolerations:
        {{- toYaml . | nindent 8 }}
    {{- end }}
