apiVersion: apps/v1
kind: Deployment
metadata:
  name: cassandra-proxy
spec:
  replicas: 1
  selector:
    matchLabels:
      app: cassandra-proxy
  strategy:
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 0
    type: RollingUpdate
  template:
    metadata:
      labels:
        app: cassandra-proxy
      annotations:
        prometheus.io/path: /metrics
        prometheus.io/port: "6060"
        prometheus.io/scrape: "true"
    spec:
      terminationGracePeriodSeconds: 300
      securityContext:
        runAsUser: 65532
        runAsGroup: 65532
        fsGroup: 65532
        fsGroupChangePolicy: OnRootMismatch
      affinity:
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
            - matchExpressions:
              - key: serverless.tidbcloud.com/node
                operator: In
                values:
                - critical-services
      tolerations:
      - key: serverless.tidbcloud.com/node
        operator: Equal
        value: critical-services
        effect: NoSchedule
      topologySpreadConstraints:
      - maxSkew: 1
        topologyKey: topology.kubernetes.io/zone
        whenUnsatisfiable: DoNotSchedule
        labelSelector:
          matchLabels:
            app: cassandra-proxy
      containers:
      - name: cassandra-proxy
        image: 385595570414.dkr.ecr.us-west-2.amazonaws.com/tidbcloud/serverless/cassandra-proxy:latest
        imagePullPolicy: IfNotPresent
        command:
          - /cassandra-on-mysql-proxy
        args:
          - -config
          - /config.yaml
        lifecycle:
          preStop:
            httpGet:
              path: /drain
              port: 6060
              scheme: HTTP
        ports:
          - containerPort: 9042
          - containerPort: 9142
          - containerPort: 6060
        livenessProbe:
          failureThreshold: 3
          httpGet:
            path: /healthz
            port: 6060
            scheme: HTTP
          initialDelaySeconds: 5
          periodSeconds: 10
          successThreshold: 1
          timeoutSeconds: 2
        readinessProbe:
          failureThreshold: 1
          httpGet:
            path: /ready
            port: 6060
            scheme: HTTP
          initialDelaySeconds: 5
          periodSeconds: 3
          successThreshold: 1
          timeoutSeconds: 2
        resources:
          limits:
            cpu: "4"
            memory: 4Gi
          requests:
            cpu: "4"
            memory: 4Gi
        volumeMounts:
          - name: cassandra-proxy-config
            mountPath: /config.yaml
            subPath: config.yaml
          - name: server-cert
            mountPath: /server-cert
            readOnly: true
      volumes:
        - name: cassandra-proxy-config
          configMap:
            name: cassandra-proxy-config
            items:
              - key: config.yaml
                path: config.yaml
        - name: server-cert
          secret:
            secretName: cassandra-proxy-cluster-secret
