apiVersion: batch/v1
kind: Job
metadata:
  name: generate-key
spec:
  template:
    spec:
      initContainers:
        - name: cleanup-identity
          image: busybox:1.28
          args:
            - /bin/sh
            - -c
            - >
              set -x;
              rm -rf /config/server-identity.json
          volumeMounts:
            - mountPath: /config
              name: root-identity

      containers:
        - name: create-root-identity
          image: iotaledger/integration-services:latest
          imagePullPolicy: IfNotPresent
          command: ["node", "dist/index.js", "keygen"]
          env:
            - name: "SERVER_IDENTITY_FILE"
              value: "/config/server-identity.json"
            - name: "DATABASE_NAME"
              valueFrom:
                configMapKeyRef:
                  name: integration-service-api-config
                  key: DATABASE_NAME
            - name: "NETWORK"
              valueFrom:
                configMapKeyRef:
                  name: integration-service-api-config
                  key: NETWORK
            - name: "DATABASE_URL"
              valueFrom:
                configMapKeyRef:
                  name: integration-service-api-config
                  key: DATABASE_URL
            - name: "IOTA_HORNET_NODE"
              valueFrom:
                configMapKeyRef:
                  name: integration-service-api-config
                  key: IOTA_HORNET_NODE
            - name: "IOTA_PERMA_NODE"
              valueFrom:
                configMapKeyRef:
                  name: integration-service-api-config
                  key: IOTA_PERMA_NODE

            - name: "SERVER_SECRET"
              valueFrom:
                secretKeyRef:
                  name: integration-service-api-secrets
                  key: SERVER_SECRET

          volumeMounts:
            - mountPath: /config
              name: root-identity

      volumes:
        - name: root-identity
          persistentVolumeClaim:
            claimName: root-identity-pvc
      restartPolicy: OnFailure
  backoffLimit: 4
