apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: starcoin
  namespace: starcoin-barnard
  labels:
    app: starcoin
    network: barnard
spec:
  selector:
    matchLabels:
      app: starcoin
  serviceName: starcoin-svc
  replicas: 3
  template:
    metadata:
      name: starcoin
      labels:
        app: starcoin
        network: barnard
    spec:
      nodeSelector:
        starcoin/node-pool: seed-pool
      containers:
      - name: starcoin
        image: starcoin/starcoin:v1.6.0
        imagePullPolicy: Always
        command:
          - bash
          - -c
        args:
          -
            rm -rf /sc-data/barnard/starcoin.ipc /sc-data/barnard/starcoindb/db/starcoindb/LOCK;
            id=$(echo -e $POD_NAME|awk -F'-' '{print $2}') && IFS='; ' read -r -a node_keys <<< $NODE_KEYS &&
            node_key=${node_keys[$id]};
            if [ ! -z $node_key ]; then
              node_key_flag="--node-key ${node_key}";
            fi;
            /starcoin/starcoin -n barnard --discover-local true --min-peers-to-propagate 512 --max-peers-to-propagate 1024 --max-outgoing-peers 512 --max-incoming-peers 512 --slog-separate-store true -d /sc-data $node_key_flag;
        ports:
          - containerPort: 9840
            hostPort: 9840
        volumeMounts:
        - name: starcoin-volume
          mountPath: /sc-data
        env:
          - name: POD_NAME
            valueFrom:
              fieldRef:
                fieldPath: metadata.name
          - name: NODE_KEYS
            valueFrom:
              secretKeyRef:
                name: node-keys
                key: node-keys
      - name: filebeat
        image: docker.elastic.co/beats/filebeat:7.10.2
        args: [
            "-c", "/etc/filebeat.yml",
            "-e",
        ]
        env:
          - name: ELASTICSEARCH_HOST
            value: "search-starcoin-es2-47avtmhexhbg7qtynzebcnnu64.ap-northeast-1.es.amazonaws.com"
          - name: ELASTICSEARCH_PORT
            value: ""
          - name: ELASTICSEARCH_USERNAME
            value: elastic
          - name: ELASTICSEARCH_PASSWORD
            valueFrom:
              secretKeyRef:
                name: elasticsearch-pw-elastic
                key: password
          - name: NODE_NAME
            valueFrom:
              fieldRef:
                fieldPath: spec.nodeName
        securityContext:
          runAsUser: 0
        resources:
          limits:
            memory: 200Mi
          requests:
            cpu: 100m
            memory: 100Mi
        volumeMounts:
          - name: config
            mountPath: /etc/filebeat.yml
            readOnly: true
            subPath: filebeat.yml
          - mountPath: /sc-data
            readOnly: true
            name: starcoin-volume
      volumes:
        - name: config
          configMap:
            defaultMode: 0640
            name: filebeat-config
  volumeClaimTemplates:
  - metadata:
      name: starcoin-volume
      namespace: starcoin-barnard
    spec:
      accessModes: [ "ReadWriteOnce" ]
      resources:
        requests:
          storage: 50Gi
