apiVersion: apps/v1
kind: StatefulSet
metadata:
  labels:
    io.kompose.service: cardano-db-sync
  name: cardano-db-sync
spec:
  replicas: 1
  updateStrategy:
    type: OnDelete
  selector:
    matchLabels:
      io.kompose.service: cardano-db-sync
  serviceName: cardano-db-sync
  updateStrategy:
    type: OnDelete
  template:
    metadata:
      labels:
        io.kompose.service: cardano-db-sync
    spec:
      containers:
      - name: cardano-db-sync
        env:
        - name: EXTENDED
          value: "true"
        - name: NETWORK
          value: mainnet
        - name: POSTGRES_HOST
          valueFrom:
            configMapKeyRef:
              name: common-env
              key: POSTGRES_HOST_RW
        - name: POSTGRES_PORT
          valueFrom:
            configMapKeyRef:
              name: common-env
              key: POSTGRES_PORT
        - name: POSTGRES_DB
          valueFrom:
            configMapKeyRef:
              name: common-env
              key: POSTGRES_DB
        - name: POSTGRES_USER
          valueFrom:
            configMapKeyRef:
              name: common-env
              key: POSTGRES_USER
        - name: POSTGRES_PASSWORD
          valueFrom:
            secretKeyRef:
              name: init0-postgresql-ha-postgresql
              key: postgresql-password
        image: repsistance/cardano-db-sync:8.0.0
        #command: ["sh", "-c", "while true; do sleep 6969; done"]
        imagePullPolicy: Always
        resources: {}
        volumeMounts:
        - name: node-ipc
          mountPath: /node-ipc
        - name: common-env
          mountPath: /run/secrets/common-env
          readOnly: true
        - name: postgres-password
          mountPath: /run/secrets/postgres-password
          readOnly: true
        - name: dbsync-statedir
          mountPath: /var/lib/cdbsync
      - name: socat-socket-server
        image: alpine/socat
        env:
        - name: CARDANO_NODE_SOCKET_TCP_HOST
          value: "cardano-node-headless"
        - name: CARDANO_NODE_SOCKET_TCP_PORT
          value: "30000"
        - name: SOCAT_TIMEOUT
          value: "3600"
        command: ["sh", "-c", "socat UNIX-LISTEN:/ipc/node.socket,fork TCP:${CARDANO_NODE_SOCKET_TCP_HOST}:${CARDANO_NODE_SOCKET_TCP_PORT},ignoreeof"]
        #command: ["sh", "-c", "socat -d -d -d -d -v UNIX-LISTEN:/ipc/node.socket TCP:${CARDANO_NODE_SOCKET_TCP_HOST}:${CARDANO_NODE_SOCKET_TCP_PORT},ignoreeof,keepalive,keepidle=10,keepintvl=10,keepcnt=100"]
        volumeMounts:
        - mountPath: /ipc
          name: node-ipc
      restartPolicy: Always
      serviceAccountName: ""
      volumes:
      - name: node-ipc
        emptyDir: {}
      - name: common-env
        configMap:
          name: common-env
      - name: postgres-password
        secret:
          secretName: init0-postgresql-ha-postgresql
          items:
          - key: postgresql-password
            path: POSTGRES_PASSWORD
      - name: dbsync-statedir
        persistentVolumeClaim:
          claimName: dbsync-statedir

  volumeClaimTemplates:
  - metadata:
      name: dbsync-statedir
    spec:
      accessModes: [ "ReadWriteOnce" ]
      resources:
        requests:
          storage: 1Gi
