# Mattermost Team Edition — self-hosted Slack alternative for foxhunt.
# Runs on platform nodes. PostgreSQL is the shared foxhunt instance.
# Access: https://chat.fxhnt.ai (Tailscale only)
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: mattermost-data
  namespace: foxhunt
  labels:
    app.kubernetes.io/name: mattermost
    app.kubernetes.io/part-of: foxhunt
spec:
  accessModes: [ReadWriteOnce]
  storageClassName: scw-bssd
  resources:
    requests:
      storage: 5Gi
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: mattermost
  namespace: foxhunt
  labels:
    app.kubernetes.io/name: mattermost
    app.kubernetes.io/part-of: foxhunt
spec:
  replicas: 1
  selector:
    matchLabels:
      app.kubernetes.io/name: mattermost
  strategy:
    type: Recreate  # RWO PVC
  template:
    metadata:
      labels:
        app.kubernetes.io/name: mattermost
        app.kubernetes.io/part-of: foxhunt
    spec:
      nodeSelector:
        k8s.scaleway.com/pool-name: platform
      containers:
        - name: mattermost
          image: mattermost/mattermost-team-edition:10.5
          ports:
            - containerPort: 8065
              name: http
          env:
            - name: DB_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: db-credentials
                  key: password
            - name: MM_SQLSETTINGS_DRIVERNAME
              value: postgres
            - name: MM_SQLSETTINGS_DATASOURCE
              value: "postgres://foxhunt:$(DB_PASSWORD)@postgres.foxhunt.svc.cluster.local:5432/mattermost?sslmode=disable"
            - name: MM_SERVICESETTINGS_SITEURL
              value: "https://chat.fxhnt.ai"
            - name: MM_SERVICESETTINGS_LISTENADDRESS
              value: ":8065"
            - name: MM_SERVICESETTINGS_ENABLEINCOMINGWEBHOOKS
              value: "true"
            - name: MM_SERVICESETTINGS_ENABLEPOSTUSERNAMEOVERRIDE
              value: "true"
            - name: MM_SERVICESETTINGS_ENABLEPOSTICONOVERRIDE
              value: "true"
            - name: MM_LOGSETTINGS_ENABLECONSOLE
              value: "true"
            - name: MM_LOGSETTINGS_CONSOLELEVEL
              value: INFO
            - name: MM_LOGSETTINGS_ENABLEFILE
              value: "false"
            - name: MM_FILESETTINGS_DRIVERNAME
              value: local
            - name: MM_FILESETTINGS_DIRECTORY
              value: /mattermost/data
            # Email via Stalwart — uncomment after Stalwart is deployed:
            # - name: MM_EMAILSETTINGS_SMTPSERVER
            #   value: stalwart.foxhunt.svc.cluster.local
            # - name: MM_EMAILSETTINGS_SMTPPORT
            #   value: "25"
            # - name: MM_EMAILSETTINGS_SENDEMAILNOTIFICATIONS
            #   value: "true"
          volumeMounts:
            - name: mattermost-data
              mountPath: /mattermost/data
          readinessProbe:
            httpGet:
              path: /api/v4/system/ping
              port: 8065
            initialDelaySeconds: 15
            periodSeconds: 10
          resources:
            requests:
              cpu: 200m
              memory: 512Mi
            limits:
              cpu: "1"
              memory: 1Gi
      volumes:
        - name: mattermost-data
          persistentVolumeClaim:
            claimName: mattermost-data
---
apiVersion: v1
kind: Service
metadata:
  name: mattermost
  namespace: foxhunt
  labels:
    app.kubernetes.io/name: mattermost
    app.kubernetes.io/part-of: foxhunt
spec:
  selector:
    app.kubernetes.io/name: mattermost
  ports:
    - port: 8065
      targetPort: 8065
      name: http
