apiVersion: apps/v1
kind: Deployment
metadata:
  name: pusher
spec:
  selector:
    matchLabels:
      app: pusher
  replicas: 1
  template:
    metadata:
      labels:
        app: pusher
    spec:
      serviceAccountName: default-service-account
      containers:
      - name: pusher
        image: "pusher"
        ports:
        - containerPort: 8080
        - containerPort: 50051
        resources:
          requests:
            memory: "52Mi"
            cpu: 50m
          limits:
            memory: "52Mi"
            cpu: 50m
        env:
        - name: "PORT"
          value: "8080"
        - name: "GRPC_PORT"
          value: "50051"
        - name: "REDIS_HOST"
          value: "10.204.2.99"
        - name: "LLINK_POSTGRES_CONNECTION_URL"
          valueFrom:
            secretKeyRef:
              name: shared-secrets
              key: LLINK_POSTGRES_CONNECTION_URL

---

apiVersion: v1
kind: Service
metadata:
  name: pusher
spec:
  selector:
    app: pusher
  ports:
  - name: http
    port: 8080
    targetPort: 8080
    protocol: TCP
  - name: grpc
    port: 50051
    targetPort: 50051
    protocol: TCP

---

kind: HTTPRoute
apiVersion: gateway.networking.k8s.io/v1beta1
metadata:
  name: pusher
spec:
  parentRefs:
  - kind: Gateway
    name: external-gateway
  hostnames:
  - pusher.flowy.live
  rules:
  - backendRefs:
    - name: pusher
      port: 8080

---

# WebSocket connections need a much longer timeout than the default 30s.
# Without this, GKE terminates idle WS connections after 30 seconds.
apiVersion: networking.gke.io/v1
kind: GCPBackendPolicy
metadata:
  name: pusher-backend-policy
spec:
  default:
    timeoutSec: 3600
    connectionDraining:
      drainingTimeoutSec: 30
  targetRef:
    group: ""
    kind: Service
    name: pusher

---

apiVersion: networking.gke.io/v1
kind: HealthCheckPolicy
metadata:
  name: pusher-service-health-check
spec:
  default:
    checkIntervalSec: 15
    timeoutSec: 15
    healthyThreshold: 1
    unhealthyThreshold: 2
    logConfig:
      enabled: true
    config:
      type: HTTP
      httpHealthCheck:
        portSpecification: USE_FIXED_PORT
        port: 8080
        requestPath: /health
  targetRef:
    group: ""
    kind: Service
    name: pusher
