apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: scylla
  labels:
    app: scylla
  namespace: subcord
spec:
  serviceName: scylla
  replicas: 2
  selector:
    matchLabels:
      app: scylla
  template:
    metadata:
      labels:
        app: scylla
      namespace: subcord
    spec:
      containers:
        - name: scylla
          image: scylladb/scylla:4.1.1
          imagePullPolicy: IfNotPresent
          args: ["--seeds", "scylla-0.scylla.subcord.svc.cluster.local", "--smp", "2", "--rpc-address", "0.0.0.0", "--broadcast-rpc-address", "$POD_IP"]
          ports:
            - containerPort: 7000
              name: intra-node
            - containerPort: 7001
              name: tls-intra-node
            - containerPort: 7199
              name: jmx
            - containerPort: 9042
              name: cql
          resources:
            limits:
              cpu: 500m
              memory: 1Gi
            requests:
              cpu: 500m
              memory: 1Gi
          securityContext:
            capabilities:
              add:
                - IPC_LOCK
          lifecycle:
            preStop:
              exec:
                command: ["/bin/sh", "-c", "PID=$(pidof scylla) && kill $PID && while ps -p $PID > /dev/null; do sleep 1; done"]
          env:
            - name: POD_IP
              valueFrom:
                fieldRef:
                  fieldPath: status.podIP
          readinessProbe:
            exec:
              command:
                - /bin/bash
                - -c
                - exec
                - /opt/ready-probe.sh
            initialDelaySeconds: 15
            timeoutSeconds: 5
          volumeMounts:
            - name: scylla-data
              mountPath: /var/lib/scylla
            - name: scylla-ready-probe
              mountPath: /opt/ready-probe.sh
              subPath: ready-probe.sh
      volumes:
        - name: scylla-ready-probe
          configMap:
            name: scylla
  volumeClaimTemplates:
  - metadata:
      name: scylla-data
    spec:
      accessModes: [ "ReadWriteOnce" ]
      storageClassName: scw-bssd-retain
      resources:
        requests:
          storage: 1Gi
