---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: l2geth-replica
spec:
  replicas: 1
  serviceName: l2geth-replica
  template:
    spec:
      terminationGracePeriodSeconds: 10
      restartPolicy: Always
      initContainers:
        - name: geth-init
          image: ethereumoptimism/l2geth
          command:
            - sh
            - -c
            - /geth-scripts/check-for-chaindata.sh
          envFrom:
            - configMapRef:
                name: l2geth-replica
            - configMapRef:
                name: l2geth-replica-sync-source
          volumeMounts:
            - name: geth-scripts
              mountPath: /geth-scripts
            - name: l2geth-replica-data
              mountPath: /geth
        - name: wait-for-dtl
          image: nicolaka/netshoot
          command: ['bash', '-c', '/script/wait/wait-for-dtl.sh']
          envFrom:
            - configMapRef:
                name: l2geth-replica
            - configMapRef:
                name: l2geth-replica-sync-source
          volumeMounts:
          - name: wait-scripts
            mountPath: /script/wait
      containers:
      - name: l2geth-replica
        image: ethereumoptimism/l2geth
        command:
          - geth
          - --datadir=$(DATADIR)
          - --password=$(DATADIR)/password
          - --allow-insecure-unlock
          - --unlock=$(BLOCK_SIGNER_ADDRESS)
          - --mine
          - --miner.etherbase=$(BLOCK_SIGNER_ADDRESS)
          - --metrics
          - --metrics.influxdb
          - --metrics.influxdb.endpoint=http://influxdb.monitoring:8086
          - --metrics.influxdb.database=$(NAMESPACE)
        imagePullPolicy: IfNotPresent
        ports:
          - containerPort: 8545
            protocol: TCP
          - containerPort: 8546
            protocol: TCP
        resources: {}
        env:
          - name: NAMESPACE
            valueFrom:
              fieldRef:
                fieldPath: metadata.namespace
        envFrom:
          - configMapRef:
              name: l2geth-replica
          - configMapRef:
              name: l2geth-replica-sync-source
        volumeMounts:
          - name: liveliness-script
            mountPath: /script/liveliness
          - name: l2geth-replica-data
            mountPath: /geth
          - name: l2geth-config
            mountPath: /l2geth-config
        livenessProbe:
          exec:
            command:
              - /script/liveliness/test.sh
              - geth
          initialDelaySeconds: 15
          periodSeconds: 10
      volumes:
        - name: l2geth-replica-data
          emptyDir: {}
        - name: liveliness-script
          configMap:
            name: liveliness-script
            defaultMode: 0777
        - name: wait-scripts
          configMap:
            name: wait-scripts
            defaultMode: 0777
        - name: geth-scripts
          configMap:
            name: geth-scripts
            defaultMode: 0777
        - name: l2geth-config
          configMap:
            name: l2geth-config
