---
apiVersion: batch/v1
kind: Job
metadata:
  name: joinchannel
spec:
  backoffLimit: 1
  template:
    metadata:
      name: joinchannel
    spec:
      restartPolicy: "Never"
      volumes:
      - name: sharedvolume
        persistentVolumeClaim:
          claimName: shared-pvc
      containers:
      - name: joinevotingpeer0channeltype1
        image: hyperledger/fabric-peer:1.4.4
        imagePullPolicy: Always
        command: ["sh", "-c", "peer channel join --tls --cafile ${ORDERER_CA} -b /shared/${CHANNEL_NAME}.block "]
        env:
        - name: CHANNEL_NAME
          value: type1
        - name: CORE_PEER_NETWORKID
          value: nid1
        - name: ORDERER_URL
          value: blockchain-orderer0:31010
        - name: CORE_PEER_ADDRESS
          value: blockchain-evotingpeer0:30110
        - name: CORE_PEER_ADDRESSAUTODETECT
          value: "false"
        - name: CORE_PEER_LOCALMSPID
          value: CojEvotingMSP
        - name: CORE_PEER_MSPID
          value: CojEvotingMSP
        - name: FABRIC_LOGGING_SPECL
          value: debug
        - name: ORDERER_GENERAL_TLS_ENABLED
          value: "true"
        - name: ORDERER_GENERAL_TLS_PRIVATEKEY
          value: /shared/crypto-config/ordererOrganizations/coj.go.th/orderers/blockchain-orderer0.coj.go.th/tls/server.key
        - name: ORDERER_GENERAL_TLS_CERTIFICATE
          value: /shared/crypto-config/ordererOrganizations/coj.go.th/orderers/blockchain-orderer0.coj.go.th/tls/server.crt
        - name: ORDERER_GENERAL_TLS_ROOTCAS
          value: /shared/crypto-config/ordererOrganizations/coj.go.th/orderers/blockchain-orderer0.coj.go.th/tls/ca.crt
        - name: ORDERER_CA
          value: /shared/crypto-config/ordererOrganizations/coj.go.th/orderers/blockchain-orderer0.coj.go.th/msp/tlscacerts/tlsca.coj.go.th-cert.pem
        - name: CORE_PEER_MSPCONFIGPATH
          value: /shared/crypto-config/peerOrganizations/evoting.coj.go.th/users/Admin@evoting.coj.go.th/msp/
        - name: FABRIC_CFG_PATH
          value: /etc/hyperledger/fabric
        # - name: GODEBUG
        #   value: "netdns=go"
        volumeMounts:
        - mountPath: /shared
          name: sharedvolume

      - name: joinevotingpeer0channeltype2
        image: hyperledger/fabric-peer:1.4.4
        imagePullPolicy: Always
        command: ["sh", "-c", "peer channel join --tls --cafile ${ORDERER_CA} -b /shared/${CHANNEL_NAME}.block "]
        env:
        - name: CHANNEL_NAME
          value: type2
        - name: CORE_PEER_NETWORKID
          value: nid1
        - name: ORDERER_URL
          value: blockchain-orderer0:31010
        - name: CORE_PEER_ADDRESS
          value: blockchain-evotingpeer0:30110
        - name: CORE_PEER_ADDRESSAUTODETECT
          value: "false"
        - name: CORE_PEER_LOCALMSPID
          value: CojEvotingMSP
        - name: CORE_PEER_MSPID
          value: CojEvotingMSP
        - name: FABRIC_LOGGING_SPECL
          value: debug
        - name: ORDERER_GENERAL_TLS_ENABLED
          value: "true"
        - name: ORDERER_GENERAL_TLS_PRIVATEKEY
          value: /shared/crypto-config/ordererOrganizations/coj.go.th/orderers/blockchain-orderer0.coj.go.th/tls/server.key
        - name: ORDERER_GENERAL_TLS_CERTIFICATE
          value: /shared/crypto-config/ordererOrganizations/coj.go.th/orderers/blockchain-orderer0.coj.go.th/tls/server.crt
        - name: ORDERER_GENERAL_TLS_ROOTCAS
          value: /shared/crypto-config/ordererOrganizations/coj.go.th/orderers/blockchain-orderer0.coj.go.th/tls/ca.crt
        - name: ORDERER_CA
          value: /shared/crypto-config/ordererOrganizations/coj.go.th/orderers/blockchain-orderer0.coj.go.th/msp/tlscacerts/tlsca.coj.go.th-cert.pem
        - name: CORE_PEER_MSPCONFIGPATH
          value: /shared/crypto-config/peerOrganizations/evoting.coj.go.th/users/Admin@evoting.coj.go.th/msp/
        - name: FABRIC_CFG_PATH
          value: /etc/hyperledger/fabric
        # - name: GODEBUG
        #   value: "netdns=go"
        volumeMounts:
        - mountPath: /shared
          name: sharedvolume

      - name: joinevotingpeer0channeltype3
        image: hyperledger/fabric-peer:1.4.4
        imagePullPolicy: Always
        command: ["sh", "-c", "peer channel join --tls --cafile ${ORDERER_CA} -b /shared/${CHANNEL_NAME}.block "]
        env:
        - name: CHANNEL_NAME
          value: type3
        - name: CORE_PEER_NETWORKID
          value: nid1
        - name: ORDERER_URL
          value: blockchain-orderer0:31010
        - name: CORE_PEER_ADDRESS
          value: blockchain-evotingpeer0:30110
        - name: CORE_PEER_ADDRESSAUTODETECT
          value: "false"
        - name: CORE_PEER_LOCALMSPID
          value: CojEvotingMSP
        - name: CORE_PEER_MSPID
          value: CojEvotingMSP
        - name: FABRIC_LOGGING_SPECL
          value: debug
        - name: ORDERER_GENERAL_TLS_ENABLED
          value: "true"
        - name: ORDERER_GENERAL_TLS_PRIVATEKEY
          value: /shared/crypto-config/ordererOrganizations/coj.go.th/orderers/blockchain-orderer0.coj.go.th/tls/server.key
        - name: ORDERER_GENERAL_TLS_CERTIFICATE
          value: /shared/crypto-config/ordererOrganizations/coj.go.th/orderers/blockchain-orderer0.coj.go.th/tls/server.crt
        - name: ORDERER_GENERAL_TLS_ROOTCAS
          value: /shared/crypto-config/ordererOrganizations/coj.go.th/orderers/blockchain-orderer0.coj.go.th/tls/ca.crt
        - name: ORDERER_CA
          value: /shared/crypto-config/ordererOrganizations/coj.go.th/orderers/blockchain-orderer0.coj.go.th/msp/tlscacerts/tlsca.coj.go.th-cert.pem
        - name: CORE_PEER_MSPCONFIGPATH
          value: /shared/crypto-config/peerOrganizations/evoting.coj.go.th/users/Admin@evoting.coj.go.th/msp/
        - name: FABRIC_CFG_PATH
          value: /etc/hyperledger/fabric
        # - name: GODEBUG
        #   value: "netdns=go"
        volumeMounts:
        - mountPath: /shared
          name: sharedvolume

      - name: joinevotingpeer1channeltype1
        image: hyperledger/fabric-peer:1.4.4
        imagePullPolicy: Always
        command: ["sh", "-c", "peer channel join --tls --cafile ${ORDERER_CA} -b /shared/${CHANNEL_NAME}.block "]
        env:
        - name: CHANNEL_NAME
          value: type1
        - name: CORE_PEER_NETWORKID
          value: nid1
        - name: ORDERER_URL
          value: blockchain-orderer0:31010
        - name: CORE_PEER_ADDRESS
          value: blockchain-evotingpeer1:30120
        - name: CORE_PEER_ADDRESSAUTODETECT
          value: "false"
        - name: CORE_PEER_LOCALMSPID
          value: CojEvotingMSP
        - name: CORE_PEER_MSPID
          value: CojEvotingMSP
        - name: FABRIC_LOGGING_SPECL
          value: debug
        - name: ORDERER_GENERAL_TLS_ENABLED
          value: "true"
        - name: ORDERER_GENERAL_TLS_PRIVATEKEY
          value: /shared/crypto-config/ordererOrganizations/coj.go.th/orderers/blockchain-orderer0.coj.go.th/tls/server.key
        - name: ORDERER_GENERAL_TLS_CERTIFICATE
          value: /shared/crypto-config/ordererOrganizations/coj.go.th/orderers/blockchain-orderer0.coj.go.th/tls/server.crt
        - name: ORDERER_GENERAL_TLS_ROOTCAS
          value: /shared/crypto-config/ordererOrganizations/coj.go.th/orderers/blockchain-orderer0.coj.go.th/tls/ca.crt
        - name: ORDERER_CA
          value: /shared/crypto-config/ordererOrganizations/coj.go.th/orderers/blockchain-orderer0.coj.go.th/msp/tlscacerts/tlsca.coj.go.th-cert.pem
        - name: CORE_PEER_MSPCONFIGPATH
          value: /shared/crypto-config/peerOrganizations/evoting.coj.go.th/users/Admin@evoting.coj.go.th/msp/
        - name: FABRIC_CFG_PATH
          value: /etc/hyperledger/fabric
        # - name: GODEBUG
        #   value: "netdns=go"
        volumeMounts:
        - mountPath: /shared
          name: sharedvolume

      - name: joinevotingpeer1channeltype2
        image: hyperledger/fabric-peer:1.4.4
        imagePullPolicy: Always
        command: ["sh", "-c", "peer channel join --tls --cafile ${ORDERER_CA} -b /shared/${CHANNEL_NAME}.block "]
        env:
        - name: CHANNEL_NAME
          value: type2
        - name: CORE_PEER_NETWORKID
          value: nid1
        - name: ORDERER_URL
          value: blockchain-orderer0:31010
        - name: CORE_PEER_ADDRESS
          value: blockchain-evotingpeer1:30120
        - name: CORE_PEER_ADDRESSAUTODETECT
          value: "false"
        - name: CORE_PEER_LOCALMSPID
          value: CojEvotingMSP
        - name: CORE_PEER_MSPID
          value: CojEvotingMSP
        - name: FABRIC_LOGGING_SPECL
          value: debug
        - name: ORDERER_GENERAL_TLS_ENABLED
          value: "true"
        - name: ORDERER_GENERAL_TLS_PRIVATEKEY
          value: /shared/crypto-config/ordererOrganizations/coj.go.th/orderers/blockchain-orderer0.coj.go.th/tls/server.key
        - name: ORDERER_GENERAL_TLS_CERTIFICATE
          value: /shared/crypto-config/ordererOrganizations/coj.go.th/orderers/blockchain-orderer0.coj.go.th/tls/server.crt
        - name: ORDERER_GENERAL_TLS_ROOTCAS
          value: /shared/crypto-config/ordererOrganizations/coj.go.th/orderers/blockchain-orderer0.coj.go.th/tls/ca.crt
        - name: ORDERER_CA
          value: /shared/crypto-config/ordererOrganizations/coj.go.th/orderers/blockchain-orderer0.coj.go.th/msp/tlscacerts/tlsca.coj.go.th-cert.pem
        - name: CORE_PEER_MSPCONFIGPATH
          value: /shared/crypto-config/peerOrganizations/evoting.coj.go.th/users/Admin@evoting.coj.go.th/msp/
        - name: FABRIC_CFG_PATH
          value: /etc/hyperledger/fabric
        # - name: GODEBUG
        #   value: "netdns=go"
        volumeMounts:
        - mountPath: /shared
          name: sharedvolume

      - name: joinevotingpeer1channeltype3
        image: hyperledger/fabric-peer:1.4.4
        imagePullPolicy: Always
        command: ["sh", "-c", "peer channel join --tls --cafile ${ORDERER_CA} -b /shared/${CHANNEL_NAME}.block "]
        env:
        - name: CHANNEL_NAME
          value: type3
        - name: CORE_PEER_NETWORKID
          value: nid1
        - name: ORDERER_URL
          value: blockchain-orderer0:31010
        - name: CORE_PEER_ADDRESS
          value: blockchain-evotingpeer1:30120
        - name: CORE_PEER_ADDRESSAUTODETECT
          value: "false"
        - name: CORE_PEER_LOCALMSPID
          value: CojEvotingMSP
        - name: CORE_PEER_MSPID
          value: CojEvotingMSP
        - name: FABRIC_LOGGING_SPECL
          value: debug
        - name: ORDERER_GENERAL_TLS_ENABLED
          value: "true"
        - name: ORDERER_GENERAL_TLS_PRIVATEKEY
          value: /shared/crypto-config/ordererOrganizations/coj.go.th/orderers/blockchain-orderer0.coj.go.th/tls/server.key
        - name: ORDERER_GENERAL_TLS_CERTIFICATE
          value: /shared/crypto-config/ordererOrganizations/coj.go.th/orderers/blockchain-orderer0.coj.go.th/tls/server.crt
        - name: ORDERER_GENERAL_TLS_ROOTCAS
          value: /shared/crypto-config/ordererOrganizations/coj.go.th/orderers/blockchain-orderer0.coj.go.th/tls/ca.crt
        - name: ORDERER_CA
          value: /shared/crypto-config/ordererOrganizations/coj.go.th/orderers/blockchain-orderer0.coj.go.th/msp/tlscacerts/tlsca.coj.go.th-cert.pem
        - name: CORE_PEER_MSPCONFIGPATH
          value: /shared/crypto-config/peerOrganizations/evoting.coj.go.th/users/Admin@evoting.coj.go.th/msp/
        - name: FABRIC_CFG_PATH
          value: /etc/hyperledger/fabric
        # - name: GODEBUG
        #   value: "netdns=go"
        volumeMounts:
        - mountPath: /shared
          name: sharedvolume
      tolerations:
      - key: dedicated
        operator: Exists
        effect: NoSchedule