{{ if .Values.access_control.enabled }}
apiVersion: apps/v1
kind: Deployment
metadata:
  name: access-control
spec:
  replicas: 1
  selector:
    matchLabels:
      app: access-control
  template:
    metadata:
      name: access-control
      labels:
        app: access-control
    spec:
      terminationGracePeriodSeconds: 1
      containers:
      - name: access-control
        image: goalprofit/access-control:{{.Values.access_control.version}}
        imagePullPolicy: Always
        env:
        - name: COOKIE_SESSION_NAME
          value: {{.Values.cookie_session_name}}
        - 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
{{ 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
      {{ include "app.affinity" . | nindent 6}}

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

{{ end }}