# services/comms/matrix-ingress.yaml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: matrix-routing
  annotations:
    kubernetes.io/ingress.class: traefik
    traefik.ingress.kubernetes.io/router.entrypoints: websecure
    traefik.ingress.kubernetes.io/router.tls: "true"
    cert-manager.io/cluster-issuer: letsencrypt
spec:
  ingressClassName: traefik
  tls:
    - hosts:
        - matrix.live.bstein.dev
      secretName: matrix-live-tls
    - hosts:
        - live.bstein.dev
      secretName: live-othrys-tls
  # Consolidated Matrix routing: MAS for auth/UI, Synapse for Matrix APIs, guest-register for guest joins.
  rules:
    - host: matrix.live.bstein.dev
      http:
        paths:
          - path: /_matrix/client/v3/register
            pathType: Prefix
            backend:
              service:
                name: matrix-guest-register
                port:
                  number: 8080
          - path: /_matrix/client/r0/register
            pathType: Prefix
            backend:
              service:
                name: matrix-guest-register
                port:
                  number: 8080
          - path: /_matrix/client/v3/login
            pathType: Prefix
            backend:
              service:
                name: matrix-authentication-service
                port:
                  number: 8080
          - path: /_matrix/client/v3/logout
            pathType: Exact
            backend:
              service:
                name: matrix-authentication-service
                port:
                  number: 8080
          - path: /_matrix/client/v3/refresh
            pathType: Exact
            backend:
              service:
                name: matrix-authentication-service
                port:
                  number: 8080
          - path: /_matrix
            pathType: Prefix
            backend:
              service:
                name: othrys-synapse-matrix-synapse
                port:
                  number: 8008
          - path: /_synapse
            pathType: Prefix
            backend:
              service:
                name: othrys-synapse-matrix-synapse
                port:
                  number: 8008
          - path: /
            pathType: Prefix
            backend:
              service:
                name: matrix-authentication-service
                port:
                  number: 8080
    - host: live.bstein.dev
      http:
        paths:
          - path: /_matrix/client/v3/register
            pathType: Prefix
            backend:
              service:
                name: matrix-guest-register
                port:
                  number: 8080
          - path: /_matrix/client/r0/register
            pathType: Prefix
            backend:
              service:
                name: matrix-guest-register
                port:
                  number: 8080
          - path: /_matrix/client/v3/login
            pathType: Prefix
            backend:
              service:
                name: matrix-authentication-service
                port:
                  number: 8080
          - path: /_matrix/client/v3/logout
            pathType: Exact
            backend:
              service:
                name: matrix-authentication-service
                port:
                  number: 8080
          - path: /_matrix/client/v3/refresh
            pathType: Exact
            backend:
              service:
                name: matrix-authentication-service
                port:
                  number: 8080
          - path: /_matrix
            pathType: Prefix
            backend:
              service:
                name: othrys-synapse-matrix-synapse
                port:
                  number: 8008
