{{ if .Values.mf_dengine_grid.enabled }}
apiVersion: apps/v1
kind: Deployment
metadata:
  name: mf-dengine-grid
spec:
  replicas: 1
  selector:
    matchLabels:
      app: mf-dengine-grid
  template:
    metadata:
      name: mf-dengine-grid
      labels:
        app: mf-dengine-grid
    spec:
      containers:
      - name: mf-dengine-grid
        image: docker.io/goalprofit/mf-dengine-grid:{{.Values.mf_dengine_grid.version}}
        imagePullPolicy: Always
        volumeMounts:
        - mountPath: /work
          name: work
          subPath: data/dist/

        env:
{{ if .Values.local_user_id }}
        - name: LOCAL_USER_ID
          value: "{{.Values.local_user_id}}"
{{ end }}
{{ if .Values.local_user_name }}
        - name: LOCAL_USER_NAME
          value: "{{.Values.local_user_name}}"
{{ end }}
      imagePullSecrets:
      - name: regcred

      volumes:
      - name: work
        {{ include "app.customer_volume" . | nindent 8}}
---
apiVersion: v1
kind: Service
metadata:
  name: mf-dengine-grid
spec:
  type: ClusterIP
  selector:
    app: mf-dengine-grid
  ports:
    - name: http
      protocol: TCP
      port: 80
      targetPort: 80
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: mf-dengine-grid
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /$1
    nginx.ingress.kubernetes.io/configuration-snippet: |
      auth_request /authenticator/check-basic;
      error_page 401 =302 /authenticator/login?redirect=$request_uri;
spec:
  ingressClassName: nginx
  rules:
    - host: {{ .Values.domain }}
      http:
        paths:
          - path: /mf-dengine-grid/?(.*)
            pathType: ImplementationSpecific
            backend:
              service:
                name: mf-dengine-grid
                port:
                  number: 80
{{ end }}