
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: quorum-node2-deployment

spec:
  strategy:
    type: RollingUpdate
  replicas: 1
  selector:
    matchLabels:
      name: quorum-node2-deployment
  template:
    metadata:
      name:  quorum-node2-deployment
      labels:
        app: qubernetes
        tier: backend
        name: quorum-node2-deployment
    spec:
      initContainers:
        - name: quorum-genesis-init-container
          image: quorumengineering/quorum:21.7.1
          command: [ "sh" ]
          args:
            - "-cx"
            - "if [ ! -f $QUORUM_DATA_DIR/genesis_created ]; then
              /usr/local/bin/geth --datadir $QUORUM_DATA_DIR init /etc/quorum/genesis/genesis-geth.json;
              date > $QUORUM_DATA_DIR/genesis_created;
           fi;
          "
          env:
            - name: QUORUM_DATA_DIR
              value: /etc/quorum/qdata/dd
            - name: QHOME
              value: /etc/quorum/qdata
          volumeMounts:
            - name: quorum-persistent-storage
              mountPath:  /etc/quorum/qdata
              subPath: quorum-node2
            - name: genesis-config-persistent-storage
              mountPath: /etc/quorum/genesis/genesis-geth.json
              subPath: genesis-geth.json

      containers:
        - name: quorum
          image: quorumengineering/quorum:21.7.1
          readinessProbe:
            exec:
              command:
                - ls
                - $(QHOME)/dd/geth.ipc
            initialDelaySeconds: 20
            periodSeconds: 3
          command: [ "sh" ]
          args:
            - "-cx"
            - "
           apk add jq;

           ln -s $QUORUM_HOME/permission-nodes/permissioned-nodes.json $QUORUM_DATA_DIR/permissioned-nodes.json;
           ln -s $QUORUM_HOME/permission-nodes/permissioned-nodes.json $QUORUM_DATA_DIR/static-nodes.json;

           cat /etc/quorum/genesis/genesis-geth.json;

           touch $QUORUM_DATA_DIR/password.txt;
           NETWORK_ID=10
           RPC_APIS=admin,db,eth,debug,miner,net,shh,txpool,personal,web3,quorum
           args=\" --gcmode archive --istanbul.blockperiod 3 --syncmode full --mine --miner.threads 1 \";
           RPC_APIS=\"$RPC_APIS,istanbul\";
           /usr/local/bin/geth \
           --datadir $QUORUM_DATA_DIR \
           $args \
           --permissioned \
           --nodiscover \
           --nat=none \
           --verbosity 3 \
           --networkid $NETWORK_ID \
           --emitcheckpoints \
           --port 30303 \
           --rpc \
           --rpcaddr 0.0.0.0 \
           --rpcport 8545 \
           --rpcapi $RPC_APIS \
           --rpccorsdomain=\"*\" \
           --rpcvhosts=quorum-node2-rpc \
            2>&1 | tee -a /etc/quorum/qdata/logs/quorum.log;"
          ports:
            - containerPort: 8545
            - containerPort: 30303

          env:
            - name: PRIVATE_CONFIG
              value: "ignore"
            - name: QUORUM_DATA_DIR
              value: /etc/quorum/qdata/dd
            - name: QUORUM_HOME
              value: /etc/quorum/qdata
            - name: QHOME
              value: /etc/quorum/qdata
            - name: THIS_NODE_ID
              value: quorum-node2
            - name: THIS_ENODE
              value: 246f5003d339c5adc754137e5084d891e15854f548971c2177a3331ed9911cd03a054111ed0ada7c2f2b9585f4ababb9332fe9f2301100ca326f59035adbf621
          volumeMounts:
            - name: quorum-persistent-storage
              mountPath: /etc/quorum/qdata
              subPath: quorum-node2
            - name: quorum-persistent-storage-logs
              mountPath: /etc/quorum/qdata/logs
              subPath: quorum-node2-logs
            - name: genesis-config-persistent-storage
              mountPath: /etc/quorum/genesis/genesis-geth.json
              subPath: genesis-geth.json
            - name: quorum-nodekey
              mountPath: /etc/quorum/qdata/dd/geth/nodekey
              subPath: nodekey
            - name: quorum-enode
              mountPath: /etc/quorum/qdata/dd/geth/enode
              subPath: enode
            - name: quorum-permissioned-config
              mountPath: /etc/quorum/qdata/permission-nodes
            - name: geth-helpers
              mountPath: /geth-helpers
            - name: istanbul-validator-config
              mountPath: /etc/quorum/qdata/istanbul-validator-config.toml
            - name: node-management
              mountPath: /etc/quorum/qdata/node-management/ibft_propose.sh
              subPath: ibft_propose.sh
            - name: node-management
              mountPath: /etc/quorum/qdata/node-management/ibft_propose_all.sh
              subPath: ibft_propose_all.sh
      volumes:
        - name: quorum-permissioned-config
          configMap:
            name: quorum-permissioned-config
            items:
              - key: permissioned-nodes.json
                path: permissioned-nodes.json
        - name: genesis-config-persistent-storage
          configMap:
            name: genesis-config
            items:
              - key: genesis-geth.json
                path: genesis-geth.json
        - name: quorum-nodekey
          configMap:
            name: quorum-node2-nodekey-config
            items:
              - key: nodekey
                path: nodekey
        - name: quorum-enode
          configMap:
            name: quorum-node2-enode-config
            items:
              - key: enode
                path: enode
        - name: geth-helpers
          configMap:
            name: geth-helpers
            items:
              - key: geth-attach.sh
                path: geth-attach.sh
              - key: geth-exec.sh
                path: geth-exec.sh
            defaultMode: 0777
        - name: istanbul-validator-config
          configMap:
            name: istanbul-validator-config.toml
        - name: node-management
          configMap:
            name: node-management
            items:
              - key: ibft_propose.sh
                path: ibft_propose.sh
              - key: ibft_propose_all.sh
                path: ibft_propose_all.sh
            defaultMode: 0777
        # PVC (configurable) https://kubernetes.io/docs/concepts/storage/persistent-volumes/#claims-as-volumes
        - name: quorum-persistent-storage
          persistentVolumeClaim:
            claimName: quorum-node2-pvc
        - name: quorum-persistent-storage-logs
          persistentVolumeClaim:
            claimName: quorum-node2-logs-pvc
