apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: replication-worker
spec:
  persistentVolumeClaimRetentionPolicy:
    whenDeleted: Delete
    whenScaled: Retain
  serviceName: "replication-worker"
  selector:
    matchLabels:
      app.kubernetes.io/name: replication-worker
  template:
    metadata:
      annotations:
        cluster-autoscaler.kubernetes.io/safe-to-evict: "false"
        prometheus.io/path: /metrics
        prometheus.io/port: "19000"
        prometheus.io/scrape: "true"
      labels:
        app: replication-worker
        app.kubernetes.io/name: replication-worker
        app.kubernetes.io/component: replication-worker
    spec:
      containers:
        - name: replication-worker
          command:
            - /bin/sh
            - /usr/local/bin/replication_worker_start_script.sh
          env:
            - name: DFS_PREFIX
              value: S3_PREFIX
            - name: DFS_S3_BUCKET
              value: S3_BUCKET
            - name: DFS_S3_REGION
              value: S3_REGION
            - name: CSE_MASTER_KEY_ID
              value: CSE_MASTER_KEY_ID
            - name: CSE_MASTER_KEY_CIPHER_TEXT
              value: CSE_MASTER_KEY_CIPHER_TEXT
            - name: CSE_MASTER_KEY_VENDOR
              value: CSE_MASTER_KEY_VENDOR
            - name: CONTAINER_NAME
              valueFrom:
                fieldRef:
                  fieldPath: metadata.name
            - name: MALLOC_CONF
              value: prof:true
          ports:
            - containerPort: 19160
              name: grpc
            - containerPort: 19000
              name: http
          resources:
            limits:
              cpu: "4"
              memory: 16Gi
            requests:
              cpu: 1000m
              memory: 4Gi
          volumeMounts:
            - mountPath: /data
              name: data
            - mountPath: /etc/config
              name: config-volume
            - mountPath: /etc/podinfo
              name: podinfo
              readOnly: true
            - mountPath: /usr/local/bin
              name: startup-script
              readOnly: true
      volumes:
        - name: config-volume
          configMap:
            items:
              - key: replication-worker.toml
                path: replication-worker.toml
            name: replication-worker-config
        - name: podinfo
          downwardAPI:
            items:
              - path: annotations
                fieldRef:
                  fieldPath: metadata.annotations
        - name: startup-script
          configMap:
            defaultMode: 420
            items:
              - key: replication-worker-startup-script
                path: replication_worker_start_script.sh
            name: rep-scripts
      serviceAccountName: serverless-controller
  volumeClaimTemplates:
    - metadata:
        name: data
      spec:
        accessModes:
          - ReadWriteOnce
        resources:
          requests:
            storage: 250Gi
        storageClassName: gp3-500
        volumeMode: Filesystem
