#
# Copyright IBM Corp. All Rights Reserved.
#
# SPDX-License-Identifier: Apache-2.0
#
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: org2-admin-cli
spec:
  replicas: 1
  selector:
    matchLabels:
      app: org2-admin-cli
  template:
    metadata:
      labels:
        app: org2-admin-cli
    spec:
      containers:
        - name: main
          image: hyperledger/fabric-tools:{{FABRIC_VERSION}}
          imagePullPolicy: IfNotPresent
          env:
            - name: FABRIC_CFG_PATH
              value: /var/hyperledger/fabric/config
            - name: CORE_PEER_MSPCONFIGPATH
              value: /var/hyperledger/fabric/organizations/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp
            - name: CORE_PEER_TLS_ROOTCERT_FILE
              value: /var/hyperledger/fabric/organizations/peerOrganizations/org2.example.com/msp/tlscacerts/org2-tls-ca.pem
          args:
            - sleep
            - "2147483647"
          workingDir: /root
          volumeMounts:
            - name: fabric-volume
              mountPath: /var/hyperledger
            - name: fabric-config
              mountPath: /var/hyperledger/fabric/config

      # This init container will unfurl all of the MSP archives listed in the msp-config config map.
      initContainers:
        - name: msp-unfurl
          image: busybox
          command:
            - sh
            - -c
            - "for msp in $(ls /msp/msp-*.tgz); do echo $msp && tar zxvf $msp -C /var/hyperledger/fabric; done"
          volumeMounts:
            - name: msp-config
              mountPath: /msp
            - name: fabric-volume
              mountPath: /var/hyperledger

      volumes:
        - name: fabric-volume
          persistentVolumeClaim:
            claimName: fabric-org2
        - name: fabric-config
          configMap:
            name: org2-config
        - name: msp-config
          configMap:
            name: msp-config
