apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: hraftd
  namespace: hraft
  labels:
    app: hraftd
spec:
  serviceName: hraftd
  podManagementPolicy: "Parallel"
  replicas: 3
  selector:
    matchLabels:
      app: hraftd
  template:
    metadata:
      labels:
        app: hraftd
    spec:
      terminationGracePeriodSeconds: 30
      containers:
      - name: hraftd
        image: 1xyz/hraftd
        imagePullPolicy: Always
        env:
          - name: HTTP_PORT
            valueFrom:
              configMapKeyRef:
                name: hraftd-config
                key: HTTP_PORT
          - name: RAFT_PORT
            valueFrom:
              configMapKeyRef:
                name: hraftd-config
                key: RAFT_PORT
          - name: BOOTSTRAP_NODE_ID
            valueFrom:
              configMapKeyRef:
                name: hraftd-config
                key: BOOTSTRAP_NODE_ID
          - name: DATA_DIR
            valueFrom:
              configMapKeyRef:
                name: hraftd-config
                key: DATA_DIR
          - name: CLUSTER_DNS_SUFFIX
            valueFrom:
              configMapKeyRef:
                name: hraftd-config
                key: CLUSTER_DNS_SUFFIX
          - name: NODE_ID
            valueFrom:
              fieldRef:
                fieldPath: metadata.name
        # command: ["sleep", "1000"]
        command:  ["/root/hraftd",
          "-bootstrap-id", "$(BOOTSTRAP_NODE_ID)",
          "-data-dir", "$(DATA_DIR)",
          "-id", "$(NODE_ID)",
          "-join", "$(BOOTSTRAP_NODE_ID).$(CLUSTER_DNS_SUFFIX):$(HTTP_PORT)",
          "-raddr", "$(NODE_ID).$(CLUSTER_DNS_SUFFIX):$(RAFT_PORT)",
          "-haddr", ":$(HTTP_PORT)"
        ]
        ports:
        - containerPort: 11000
          name: http
        - containerPort: 12000
          name: raft-tcp
        resources:
          limits:
            cpu: "2000m"
            memory: 2Gi
          requests:
            cpu: "500m"
            memory: 1Gi