apiVersion: apps/v1
kind: Deployment
metadata:
  name: orion
spec:
  selector:
    matchLabels:
      app: orion
  replicas: 1
  template:
    metadata:
      labels:
        app: orion
    spec:
      serviceAccountName: default-service-account
      nodeSelector:
        cloud.google.com/gke-spot: "true"
      terminationGracePeriodSeconds: 15
      containers:
      - name: orion
        image: "orion"
        ports:
        - containerPort: 8080
        resources:
          requests:
            memory: "52Mi"
            cpu: 50m
          limits:
            memory: "52Mi"
            cpu: 50m
        env:
        - name: "GCP_PROJECT"
          value: "flowy-dev-440017"
        - name: "PORT"
          value: "8080"
        - name: "AERO_ADDR"
          value: "aero:50051"
        - name: "GCS_BUCKET"
          value: "flowy-llink-bucket"
        - name: "LLINK_POSTGRES_CONNECTION_URL"
          valueFrom:
            secretKeyRef:
              name: shared-secrets
              key: LLINK_POSTGRES_CONNECTION_URL
        - name: "GOOGLE_SERVICE_ACCOUNT_EMAIL"
          value: "iam-for-gke-sa@flowy-dev-440017.iam.gserviceaccount.com"
        - name: "REDIS_HOST"
          value: "10.138.57.187"
        - name: "LIVEKIT_API_KEY"
          valueFrom:
            secretKeyRef:
              name: shared-secrets
              key: LIVEKIT_API_KEY
        - name: "LIVEKIT_API_SECRET"
          valueFrom:
            secretKeyRef:
              name: shared-secrets
              key: LIVEKIT_API_SECRET
        - name: "LIVEKIT_URL"
          valueFrom:
            secretKeyRef:
              name: shared-secrets
              key: LIVEKIT_URL
        - name: "STRIPE_SECRET_KEY"
          valueFrom:
            secretKeyRef:
              name: shared-secrets
              key: STRIPE_SECRET_KEY
        - name: "STRIPE_WEBHOOK_SECRET"
          valueFrom:
            secretKeyRef:
              name: shared-secrets
              key: STRIPE_WEBHOOK_SECRET
        - name: "STRIPE_PRICE_PRO_MONTHLY"
          value: "price_1TM9abF9Z3lE6HEQJQmVsWES"
        - name: "STRIPE_PRICE_PRO_ANNUAL"
          value: "price_1TM9abF9Z3lE6HEQsToXflbq"
        - name: "BILLING_SUCCESS_URL"
          value: "llink://billing/success"
        - name: "BILLING_CANCEL_URL"
          value: "llink://billing/cancel"
        # Web client origins
        - name: "CORS_ALLOWED_ORIGINS"
          value: "http://localhost:5173,http://localhost:5174,http://localhost:5175,https://llink.dev.flowy.live"

---

apiVersion: v1
kind: Service
metadata:
  name: orion
spec:
  selector:
    app: orion
  ports:
  - port: 8080
    targetPort: 8080
    protocol: TCP

---

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

---

apiVersion: networking.gke.io/v1
kind: HealthCheckPolicy
metadata:
  name: orion-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: orion
