apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    control-plane: ai-gateway
  name: ai-gateway
  namespace: tidb-admin
spec:
  replicas: 2
  selector:
    matchLabels:
      app.kubernetes.io/component: ai-gateway
  strategy:
    rollingUpdate:
      maxSurge: 100%
      maxUnavailable: 0
    type: RollingUpdate
  template:
    metadata:
      labels:
        app.kubernetes.io/component: ai-gateway
        app.kubernetes.io/name: gateway
      annotations:
        prometheus.io/path: /metrics
        prometheus.io/port: "10080"
        prometheus.io/scrape: "true"
    spec:
      affinity:
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
            - matchExpressions:
              - key: serverless.tidbcloud.com/node
                operator: In
                values:
                - general
          preferredDuringSchedulingIgnoredDuringExecution:
          - weight: 100
            preference:
              matchExpressions:
              - key: serverless.tidbcloud.com/zone
                operator: In
                values:
                - primary
        podAntiAffinity:
          preferredDuringSchedulingIgnoredDuringExecution:
            - weight: 100
              podAffinityTerm:
                labelSelector:
                  matchExpressions:
                    - key: app.kubernetes.io/component
                      operator: In
                      values:
                        - ai-gateway
                topologyKey: kubernetes.io/hostname
      containers:
        - name: qdrant-api
          command:
            - /qdrant-on-tidb/qdrant-api
          args:
            - --cert=/qdrant-gateway-tls/tls.crt
            - --key=/qdrant-gateway-tls/tls.key
            - --database=ai
          env:
            - name: MAX_LIFETIME
              value: "300"
            - name: IDLE_TIMEOUT
              value: "60"
            - name: MIN_CONNECTIONS
              value: "0"
            - name: TENANTS_DB_CACHE_SIZE
              value: "100"
          image: 385595570414.dkr.ecr.us-east-1.amazonaws.com/tidbcloud/serverless/qdrant-on-tidb:4720ac1019a8ddd5ab91bb68d506a040712db9e0
          imagePullPolicy: IfNotPresent
          livenessProbe:
            failureThreshold: 3
            successThreshold: 1
            httpGet:
              path: /healthz
              port: 6333
              scheme: HTTPS
            initialDelaySeconds: 5
          readinessProbe:
            httpGet:
              path: /healthz
              port: 6333
              scheme: HTTPS
            initialDelaySeconds: 5
          resources:
            limits:
              cpu: "2"
              memory: 8Gi
            requests:
              cpu: 200m
              memory: 512Mi
          volumeMounts:
          - mountPath: /qdrant-gateway-tls
            name: tls-certs
      serviceAccount: fts-server
      serviceAccountName: fts-server
      volumes:
      - name: tls-certs
        secret:
          defaultMode: 288
          secretName: gateway-letsencrypt-secret
      tolerations:
      - effect: NoSchedule
        key: serverless.tidbcloud.com/node
        operator: Equal
        value: general
