{{ if .Values.authenticator.enabled }}
apiVersion: apps/v1
kind: Deployment
metadata:
  name: authenticator
spec:
  replicas: 1
  selector:
    matchLabels:
      app: authenticator
  template:
    metadata:
      name: authenticator
      labels:
        app: authenticator
    spec:
      terminationGracePeriodSeconds: 1
      containers:
      - name: authenticator
        image: goalprofit/access-control:{{.Values.authenticator.version}}
        imagePullPolicy: Always
        env:
        - name: COOKIE_SESSION_NAME
          value: {{.Values.cookie_session_name}}
        - name: COOKIE_SESSION_NO_EXPIRES
          value: {{.Values.cookie_session_no_expires | quote}}
        - name: COOKIE_SESSION_MAX_AGE
          value: {{.Values.cookie_session_max_age | quote}}
        - name: COOKIE_SESSION_HTTP_ONLY
          value: {{.Values.cookie_session_http_only | quote}}
        - name: COOKIE_SESSION_SECURE
          value: {{.Values.cookie_session_secure | quote}}
        - name: COOKIE_SESSION_DOMAIN
          value: {{.Values.cookie_session_domain}}
        - name: COOKIE_SESSION_KEY
          valueFrom:
            secretKeyRef:
              name: cookie-session
              key: key
        - name: SERVICE_LOGIN
          valueFrom:
            secretKeyRef:
              name: secret-service
              key: username
              optional: false
        - name: SERVICE_PASSWORD
          valueFrom:
            secretKeyRef:
              name: secret-service
              key: password
              optional: false
        - name: RESOURCE_ID
          value: authenticator
        - name: INTERNAL_PORT
          value: "8080"
        - name: EXTERNAL_PORT
          value: "80"

{{ 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 }}

        volumeMounts:
        - mountPath: /data
          name: customer
          subPath: data

      imagePullSecrets:
      - name: regcred
      volumes:
      - name: customer
        {{ include "app.customer_volume" . | nindent 8}}
      {{ include "app.affinity" . | nindent 6}}

---
apiVersion: v1
kind: Service
metadata:
  name: authenticator
spec:
  type: ClusterIP
  selector:
    app: authenticator
  ports:
    - name: http
      protocol: TCP
      port: 80
      targetPort: 8080

{{ end }}