apiVersion: v1
kind: Secret
metadata:
  name: mattermost-secrets
  namespace: nextgen
type: Opaque
stringData:
  # DB Format: postgres://<user>:<password>@<host>:<port>/<db>?sslmode=disable&connect_timeout=10
  MM_SQLSETTINGS_DATASOURCE: "postgres://mmuser:mattermost-db-password-change-me@postgres:5432/mattermost?sslmode=disable&connect_timeout=10"
  MM_FILESETTINGS_AMAZONS3ACCESSKEYID: "minioadmin"
  MM_FILESETTINGS_AMAZONS3SECRETACCESSKEY: "minioadmin123"
---
apiVersion: v1
kind: Service
metadata:
  name: mattermost
  namespace: nextgen
spec:
  selector:
    app: mattermost
  ports:
    - name: http
      port: 8065
      targetPort: 8065
    - name: calls
      port: 8443
      targetPort: 8443
      protocol: UDP
  type: ClusterIP
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: mattermost-plugins-pvc
  namespace: nextgen
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: mattermost
  namespace: nextgen
  annotations:
    kubernetes.io/ingress.class: nginx
    cert-manager.io/cluster-issuer: letsencrypt-prod
    nginx.ingress.kubernetes.io/proxy-body-size: "50m"
spec:
  tls:
    - hosts:
        - chat.techarvest.co.zw
      secretName: chat-techarvest-tls
  rules:
    - host: chat.techarvest.co.zw
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: mattermost
                port:
                  number: 8065
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: mattermost
  namespace: nextgen
spec:
  replicas: 1
  strategy:
    type: Recreate
  selector:
    matchLabels:
      app: mattermost
  template:
    metadata:
      labels:
        app: mattermost
    spec:
      containers:
        - name: mattermost
          image: mattermost/mattermost-team-edition:9.11
          env:
            - name: MM_SQLSETTINGS_DRIVERNAME
              value: postgres
            - name: MM_SQLSETTINGS_DATASOURCE
              valueFrom:
                secretKeyRef:
                  name: mattermost-secrets
                  key: MM_SQLSETTINGS_DATASOURCE
            - name: MM_FILESETTINGS_DRIVERNAME
              value: amazons3
            - name: MM_FILESETTINGS_AMAZONS3ENDPOINT
              value: "minio.geocrop.svc.cluster.local:9000"
            - name: MM_FILESETTINGS_AMAZONS3ACCESSKEYID
              valueFrom:
                secretKeyRef:
                  name: mattermost-secrets
                  key: MM_FILESETTINGS_AMAZONS3ACCESSKEYID
            - name: MM_FILESETTINGS_AMAZONS3SECRETACCESSKEY
              valueFrom:
                secretKeyRef:
                  name: mattermost-secrets
                  key: MM_FILESETTINGS_AMAZONS3SECRETACCESSKEY
            - name: MM_FILESETTINGS_AMAZONS3BUCKET
              value: "mattermost"
            - name: MM_FILESETTINGS_AMAZONS3SSL
              value: "false"
            - name: MM_SERVICESETTINGS_SITEURL
              value: "https://chat.techarvest.co.zw"
            - name: MM_PLUGINSETTINGS_ENABLEUPLOADS
              value: "true"
            - name: MM_PLUGINSETTINGS_PLUGINSTATES
              value: '{"com.mattermost.calls":{"Enable":true}}'
            - name: MM_PLUGINSETTINGS_PLUGINS_COM.MATTERMOST.CALLS_UDPLISTENADDRESS
              value: ":8443"
            - name: MM_PLUGINSETTINGS_PLUGINS_COM.MATTERMOST.CALLS_ICEHOSTOVERRIDE
              value: "167.86.68.48"
            - name: MM_PLUGINSETTINGS_PLUGINS_COM.MATTERMOST.CALLS_ALLOWSESSIONNATIVE
              value: "true"
          ports:
            - containerPort: 8065
            - containerPort: 8443
              protocol: UDP
              hostPort: 8443
          volumeMounts:
            - name: mattermost-plugins
              mountPath: /mattermost/plugins
      volumes:
        - name: mattermost-plugins
          persistentVolumeClaim:
            claimName: mattermost-plugins-pvc
