---
apiVersion: batch/v1
kind: Job
metadata:
  name: joinchannel
  namespace: blockchain
spec:
  backoffLimit: 1
  template:
    metadata:
      name: joinchannel
    spec:
      restartPolicy: "Never"
      volumes:
      - name: sharedvolume
        persistentVolumeClaim:
          claimName: shared-pvc
      containers:
      - name: joinchannel1
        image: hyperledger/fabric-peer:1.4
        imagePullPolicy: Always
        command: ["sh", "-c", "peer channel fetch newest -o ${ORDERER_URL} -c ${CHANNEL_NAME} --tls --cafile ${CA_FILE} && peer channel join -b ${CHANNEL_NAME}_newest.block"]
        env:
        - name: CHANNEL_NAME
          value: channel1
        - name: CORE_PEER_TLS_ENABLED
          value: "true"
        - name: CORE_PEER_TLS_KEY_FILE
          value: /shared/crypto-config/peerOrganizations/org1.example.com/peers/blockchain-org1peer1/tls/server.key
        - name: CORE_PEER_TLS_CERT_FILE
          value: /shared/crypto-config/peerOrganizations/org1.example.com/peers/blockchain-org1peer1/tls/server.crt
        - name: CORE_PEER_TLS_ROOTCERT_FILE
          value: /shared/crypto-config/peerOrganizations/org1.example.com/peers/blockchain-org1peer1/tls/ca.crt
        - name: CA_FILE
          value: /shared/crypto-config/ordererOrganizations/blockchain-orderer/orderers/blockchain-orderer/tls/ca.crt
        - name: CORE_PEER_NETWORKID
          value: nid1
        - name: ORDERER_URL
          value: blockchain-orderer:31010
        - name: CORE_PEER_ADDRESS
          value: blockchain-org1peer1:30110
        - name: CORE_PEER_LOCALMSPID
          value: Org1MSP
        - name: CORE_PEER_MSPID
          value: Org1MSP
        - name: FABRIC_LOGGING_SPECL
          value: debug
        - name: CORE_PEER_MSPCONFIGPATH
          value: /shared/crypto-config/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
        - name: FABRIC_CFG_PATH
          value: /etc/hyperledger/fabric
        - name: GODEBUG
          value: "netdns=go"
        volumeMounts:
        - mountPath: /shared
          name: sharedvolume

      - name: joinchannel2
        image: hyperledger/fabric-peer:1.4
        imagePullPolicy: Always
        command: ["sh", "-c", "peer channel fetch newest -o ${ORDERER_URL} -c ${CHANNEL_NAME} --tls --cafile ${CA_FILE} && peer channel join -b ${CHANNEL_NAME}_newest.block "]
        env:
        - name: CHANNEL_NAME
          value: channel1
        - name: CORE_PEER_TLS_ENABLED
          value: "true"
        - name: CORE_PEER_TLS_KEY_FILE
          value: /shared/crypto-config/peerOrganizations/org2.example.com/peers/blockchain-org2peer1/tls/server.key
        - name: CORE_PEER_TLS_CERT_FILE
          value: /shared/crypto-config/peerOrganizations/org2.example.com/peers/blockchain-org2peer1/tls/server.crt
        - name: CORE_PEER_TLS_ROOTCERT_FILE
          value: /shared/crypto-config/peerOrganizations/org2.example.com/peers/blockchain-org2peer1/tls/ca.crt
        - name: CA_FILE
          value: /shared/crypto-config/ordererOrganizations/blockchain-orderer/orderers/blockchain-orderer/tls/ca.crt
        - name: CORE_PEER_NETWORKID
          value: nid1
        - name: ORDERER_URL
          value: blockchain-orderer:31010
        - name: CORE_PEER_ADDRESS
          value: blockchain-org2peer1:30210
        - name: CORE_PEER_LOCALMSPID
          value: Org2MSP
        - name: CORE_PEER_MSPID
          value: Org2MSP
        - name: FABRIC_LOGGING_SPEC
          value: debug
        - name: CORE_PEER_MSPCONFIGPATH
          value: /shared/crypto-config/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp
        - name: FABRIC_CFG_PATH
          value: /etc/hyperledger/fabric
        - name: GODEBUG
          value: "netdns=go"
        volumeMounts:
        - mountPath: /shared
          name: sharedvolume

      - name: joinchannel3
        image: hyperledger/fabric-peer:1.4
        imagePullPolicy: Always
        command: ["sh", "-c", "peer channel fetch newest -o ${ORDERER_URL} -c ${CHANNEL_NAME} --tls --cafile ${CA_FILE} && peer channel join -b ${CHANNEL_NAME}_newest.block "]
        env:
        - name: CHANNEL_NAME
          value: channel1
        - name: CORE_PEER_TLS_ENABLED
          value: "true"
        - name: CORE_PEER_TLS_KEY_FILE
          value: /shared/crypto-config/peerOrganizations/org3.example.com/peers/blockchain-org3peer1/tls/server.key
        - name: CORE_PEER_TLS_CERT_FILE
          value: /shared/crypto-config/peerOrganizations/org3.example.com/peers/blockchain-org3peer1/tls/server.crt
        - name: CORE_PEER_TLS_ROOTCERT_FILE
          value: /shared/crypto-config/peerOrganizations/org3.example.com/peers/blockchain-org3peer1/tls/ca.crt
        - name: CA_FILE
          value: /shared/crypto-config/ordererOrganizations/blockchain-orderer/orderers/blockchain-orderer/tls/ca.crt
        - name: CORE_PEER_NETWORKID
          value: nid1
        - name: ORDERER_URL
          value: blockchain-orderer:31010
        - name: CORE_PEER_ADDRESS
          value: blockchain-org3peer1:30310
        - name: CORE_PEER_LOCALMSPID
          value: Org3MSP
        - name: CORE_PEER_MSPID
          value: Org3MSP
        - name: FABRIC_LOGGING_SPEC
          value: debug
        - name: CORE_PEER_MSPCONFIGPATH
          value: /shared/crypto-config/peerOrganizations/org3.example.com/users/Admin@org3.example.com/msp
        - name: FABRIC_CFG_PATH
          value: /etc/hyperledger/fabric
        - name: GODEBUG
          value: "netdns=go"
        volumeMounts:
        - mountPath: /shared
          name: sharedvolume

      - name: joinchannel4
        image: hyperledger/fabric-peer:1.4
        imagePullPolicy: Always
        command: ["sh", "-c", "peer channel fetch newest -o ${ORDERER_URL} -c ${CHANNEL_NAME} --tls --cafile ${CA_FILE} && peer channel join -b ${CHANNEL_NAME}_newest.block "]
        env:
        - name: CHANNEL_NAME
          value: channel1
        - name: CORE_PEER_TLS_ENABLED
          value: "true"
        - name: CORE_PEER_TLS_KEY_FILE
          value: /shared/crypto-config/peerOrganizations/org4.example.com/peers/blockchain-org4peer1/tls/server.key
        - name: CORE_PEER_TLS_CERT_FILE
          value: /shared/crypto-config/peerOrganizations/org4.example.com/peers/blockchain-org4peer1/tls/server.crt
        - name: CORE_PEER_TLS_ROOTCERT_FILE
          value: /shared/crypto-config/peerOrganizations/org4.example.com/peers/blockchain-org4peer1/tls/ca.crt
        - name: CA_FILE
          value: /shared/crypto-config/ordererOrganizations/blockchain-orderer/orderers/blockchain-orderer/tls/ca.crt
        - name: CORE_PEER_NETWORKID
          value: nid1
        - name: ORDERER_URL
          value: blockchain-orderer:31010
        - name: CORE_PEER_ADDRESS
          value: blockchain-org4peer1:30410
        - name: CORE_PEER_LOCALMSPID
          value: Org4MSP
        - name: CORE_PEER_MSPID
          value: Org4MSP
        - name: FABRIC_LOGGING_SPEC
          value: debug
        - name: CORE_PEER_MSPCONFIGPATH
          value: /shared/crypto-config/peerOrganizations/org4.example.com/users/Admin@org4.example.com/msp
        - name: FABRIC_CFG_PATH
          value: /etc/hyperledger/fabric
        - name: GODEBUG
          value: "netdns=go"
        volumeMounts:
        - mountPath: /shared
          name: sharedvolume
      nodeSelector:
        kops.k8s.io/instancegroup: blockchain-nodes
