{{ if .Values.chat_mgmt.enabled }}
apiVersion: apps/v1
kind: Deployment
metadata:
  name: chat-mgmt
spec:
  replicas: 1
  selector:
    matchLabels:
      app: chat-mgmt
  template:
    metadata:
      name: chat-mgmt
      labels:
        app: chat-mgmt
    spec:
      terminationGracePeriodSeconds: 1
      containers:
      - name: chat-mgmt
        image: docker.io/goalprofit/chat-mgmt:{{.Values.chat_mgmt.version}}
        imagePullPolicy: Always
        livenessProbe:
          httpGet:
            path: /health
            port: 8080
        env:
          - name: LOG_LEVEL
            value: debug
          - name: API_PORT
            value: "8080"
          - name: CHAT_SERVICE_EMAIL
            value: chat_service_account@digitalwavetechnology.com
          - name: PLATFORM_HOST
            value: {{.Values.domain}}
            
          - name: COOKIE_SESSION_NAME
            value: {{.Values.cookie_session_name}}
          - name: COOKIE_SESSION_KEY
            valueFrom:
              secretKeyRef:
                name: cookie-session
                key: key

          - name: OLAP_URL
            value: http://server:8080/graphql

          - name: SERVER_API_HOST
            value: http://server-api:8080
          - name: ROCKET_API_HOST
            value: http://rocketchat-rocketchat
          - 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: MONGO_URI
            valueFrom:
              secretKeyRef:
                name: rocketchat-rocketchat
                key: mongo-uri
                optional: false

          
        volumeMounts:
        - mountPath: /app/data
          name: customer
          subPath: data/chat-mgmt
      imagePullSecrets:
      - name: regcred
        
      volumes:
      - name: customer
        {{ include "app.customer_volume" . | nindent 8}}
      
      {{ include "app.affinity" . | nindent 6}}
---
apiVersion: v1
kind: Service
metadata:
  name: chat-mgmt
spec:
  type: ClusterIP
  selector:
    app: chat-mgmt
  ports:
    - name: http
      protocol: TCP
      port: 8080
      targetPort: 8080
{{ end }}