apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "layer0_describo.fullname" . }}
  namespace: {{ .Release.Namespace  }}
  labels:
{{ include "layer0_describo.labels" . | indent 4 }}
spec:
  replicas: {{ .Values.replicaCount }}
  selector:
    matchLabels:
{{ include "layer0_describo.labels" . | indent 6 }}
  template:
    metadata:
      labels:
{{ include "layer0_describo.labels" . | indent 8 }}
    spec:
      volumes:
        - name: describo-configuration
          configMap:
            name: describo-configuration-file
            items:
            - key: configuration.json
              path: configuration.json
            - key: type-definitions-lookup.json
              path: type-definitions-lookup.json
            - key: type-definitions.json
              path: type-definitions.json
            - key: nginx.conf
              path: nginx.conf
    {{- with .Values.imagePullSecrets }}
      imagePullSecrets:
        {{- toYaml . | nindent 8 }}
    {{- end }}
      containers:
        - name: "api"
          image: {{ template "layer0_describo.apiImage" . }}
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          volumeMounts:
            - name: describo-configuration
              mountPath: /srv/api/configuration.json
              subPath: configuration.json
              readOnly: true
            - name: describo-configuration
              mountPath: /srv/profiles/type-definitions-lookup.json
              subPath: type-definitions-lookup.json
              readOnly: true
            - name: describo-configuration
              mountPath: /srv/profiles/type-definitions.json
              subPath: type-definitions.json
              readOnly: true
          env:
          - name: DB_PASSWORD
            valueFrom:
              secretKeyRef:
                name: describo-pg-passwd
                key: postgresql-password
          - name: ADMIN_PASSWORD
            valueFrom:
              secretKeyRef:
                name: admin-passwd
                key: passwd
          envFrom:
          - configMapRef:
              name: mservice
          - configMapRef:
              name: proxy
          - configMapRef:
              name: globalenvvar
          - configMapRef:
              name: describoconfig
          resources:
            {{- toYaml .Values.resources | nindent 12 }}
        - name: "ui"
          image: {{ template "layer0_describo.uiImage" . }}
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          volumeMounts:
            - name: describo-configuration
              mountPath: /etc/nginx/conf.d/default.conf
              subPath: nginx.conf
              readOnly: true
          env:
          - name: "VUE_APP_BASE_URL"
            value: "{{ .Values.ingress.path }}"
          - name: "NODE_ENV"
            value: "production"
          envFrom:
          - configMapRef:
              name: mservice
          - configMapRef:
              name: proxy
          - configMapRef:
              name: globalenvvar
          ports:
            - name: http
              containerPort: {{ .Values.service.targetPort }}
              protocol: TCP
          livenessProbe:
            httpGet:
              path: /
              port: http
            periodSeconds: 10
          readinessProbe:
            httpGet:
              path: /
              port: http
            periodSeconds: 10
          resources:
            {{- toYaml .Values.resources | nindent 12 }}
      {{- with .Values.nodeSelector }}
      nodeSelector:
        {{- toYaml . | nindent 8 }}
      {{- end }}
    {{- with .Values.affinity }}
      affinity:
        {{- toYaml . | nindent 8 }}
    {{- end }}
    {{- with .Values.tolerations }}
      tolerations:
        {{- toYaml . | nindent 8 }}
    {{- end }}
