Skip to content

Commit

Permalink
[fabric] Update add_peer and add_orderer to 2.5.4 (#2431)
Browse files Browse the repository at this point in the history
Primary Changes
--------------
1.add_peer updated for version 2.5.4
2.add_orderer updated for version 2.5.4

Modifications
-----------------------
platforms/hyperledger-fabric/charts/fabric-orderernode
platforms/hyperledger-fabric/charts/fabric-osnadmin-channel-create
platforms/hyperledger-fabric/configuration/add-orderer.yaml
platforms/hyperledger-fabric/configuration/add-peer.yaml
platforms/hyperledger-fabric/configuration/roles/create/new_orderer/create_appchannel_block/templates/update_channel_script.tpl
platforms/hyperledger-fabric/configuration/roles/create/orderers/tasks/main.yaml
platforms/hyperledger-fabric/configuration/roles/create/osnchannels/tasks/valuefile.yaml
platforms/hyperledger-fabric/configuration/roles/create/peers/tasks/main.yaml
platforms/hyperledger-fabric/configuration/roles/create/peers/tasks/nested_main.yaml
platforms/hyperledger-fabric/configuration/roles/helm_component/templates/orderernode.tpl
platforms/hyperledger-fabric/configuration/roles/helm_component/templates/osn_create_channel_job.tpl

fixes #2430

Signed-off-by: mgCepeda <[email protected]>
  • Loading branch information
mgCepeda authored Nov 30, 2023
1 parent df83b25 commit 2c1f343
Show file tree
Hide file tree
Showing 13 changed files with 196 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ data:
{{ end }}

---
{{- if ne $.Values.metadata.network.version "2.5.4" }}
apiVersion: v1
kind: ConfigMap
metadata:
Expand All @@ -62,4 +63,5 @@ metadata:
app.kubernetes.io/instance: {{ .Release.Name }}
{{- include "labels.custom" . | nindent 2 }}
data:
genesis.block.base64: {{ .Values.genesis | quote }}
genesis.block.base64: {{ .Values.genesis | quote }}
{{ end }}
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,14 @@ spec:
- key: ca.crt.pem
path: ca-certificates.crt # curl expects certs to be in /etc/ssl/certs/ca-certificates.crt
{{ end }}
{{- if ne $.Values.metadata.network.version "2.5.4" }}
- name: {{ $.Values.orderer.name }}-genesis-volume
configMap:
name: genesis-block-{{ $.Values.orderer.name }}
items:
- key: genesis.block.base64
path: genesis.block.base64
{{ end }}
- name: scripts-volume
configMap:
name: bevel-vault-script
Expand Down Expand Up @@ -207,9 +209,11 @@ spec:
volumeMounts:
- name: datadir
mountPath: /var/hyperledger/production/orderer
{{- if ne $.Values.metadata.network.version "2.5.4" }}
- name: {{ $.Values.orderer.name }}-genesis-volume
mountPath: /var/hyperledger/orderer/genesis
readOnly: true
{{- end }}
- name: certificates
mountPath: /var/hyperledger/orderer/crypto
readOnly: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,16 @@ data:
CHANNEL_NAME: {{ $.Values.channel.name }}
ADMIN_TLS_CERTS: /opt/gopath/src/github.com/hyperledger/fabric/crypto
GENESIS_FILE: /opt/gopath/src/github.com/hyperledger/fabric/orderer/genesis
{{- if $.Values.add_orderer }}
CORE_PEER_LOCALMSPID: {{ $.Values.orderer.localmspid }}
CORE_PEER_TLS_ROOTCERT_FILE: /opt/gopath/src/github.com/hyperledger/fabric/crypto/admin/msp/tlscacerts/tlsca.crt
CORE_PEER_MSPCONFIGPATH: /opt/gopath/src/github.com/hyperledger/fabric/crypto/admin/msp
CORE_PEER_ADDRESS: {{ $.Values.orderer.address }}
ORDERER_CA: /opt/gopath/src/github.com/hyperledger/fabric/crypto/{{ $.Values.orderer.name }}/tls/ca.crt
{{ end }}

---
{{- if not $.Values.add_orderer }}
apiVersion: v1
kind: ConfigMap
metadata:
Expand All @@ -38,3 +46,4 @@ metadata:
{{- include "labels.custom" . | nindent 2 }}
data:
genesis.block.base64: {{ $.Values.genesis | quote }}
{{ end }}
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,14 @@ spec:
- key: ca.crt.pem
path: ca-certificates.crt
{{ end }}
{{- if not $.Values.add_orderer }}
- name: genesis
configMap:
name: genesis-block
items:
- key: genesis.block.base64
path: genesis.block.base64
{{ end }}
- name: certificates
emptyDir:
medium: Memory
Expand All @@ -68,6 +70,8 @@ spec:
value: {{ $.Values.vault.authpath }}
- name: VAULT_APP_ROLE
value: {{ $.Values.vault.role }}
- name: VAULT_ADMIN_SECRET_PREFIX
value: "{{ $.Values.vault.adminsecretprefix }}"
- name: VAULT_ORDERER_SECRET_PREFIX
value: "{{ $.Values.vault.orderersecretprefix }}"
- name: ORDERERS_NAMES
Expand Down Expand Up @@ -127,6 +131,29 @@ spec:
echo "${CLIENTKEY}" >> ${OUTPUT_PATH}/server.key
done
###############################################################################
echo "Getting MSP certificates from Vault using key $vault_secret_key"
vaultBevelFunc "readJson" "${VAULT_ADMIN_SECRET_PREFIX}/msp"
ADMINCERT=$(echo ${VAULT_SECRET} | jq -r '.["admincerts"]')
CACERTS=$(echo ${VAULT_SECRET} | jq -r '.["cacerts"]')
KEYSTORE=$(echo ${VAULT_SECRET} | jq -r '.["keystore"]')
SIGNCERTS=$(echo ${VAULT_SECRET} | jq -r '.["signcerts"]')
TLSCACERTS=$(echo ${VAULT_SECRET} | jq -r '.["tlscacerts"]')
OUTPUT_PATH="${MOUNT_PATH}/admin/msp"
mkdir -p ${OUTPUT_PATH}/admincerts
mkdir -p ${OUTPUT_PATH}/cacerts
mkdir -p ${OUTPUT_PATH}/keystore
mkdir -p ${OUTPUT_PATH}/signcerts
mkdir -p ${OUTPUT_PATH}/tlscacerts
echo "${ADMINCERT}" >> ${OUTPUT_PATH}/admincerts/admin.crt
echo "${CACERTS}" >> ${OUTPUT_PATH}/cacerts/ca.crt
echo "${KEYSTORE}" >> ${OUTPUT_PATH}/keystore/server.key
echo "${SIGNCERTS}" >> ${OUTPUT_PATH}/signcerts/server.crt
echo "${TLSCACERTS}" >> ${OUTPUT_PATH}/tlscacerts/tlsca.crt
volumeMounts:
{{ if .Values.vault.tls }}
- name: vaultca
Expand All @@ -149,12 +176,19 @@ spec:
value: "{{ $.Values.orderers.orderer_info }}"
- name: NAMESPACE
value: "{{ $.Values.metadata.namespace }}"
- name: ADD_ORDERER
value: "{{ $.Values.add_orderer }}"
command: ["sh", "-c"]
args:
- |-
#!/usr/bin/env sh
echo "Fetch genesis file..."
cat ./genesis/genesis.block.base64 | base64 -d > orderer.genesis.block
if [ $ADD_ORDERER = false ]
then
cat ./genesis/genesis.block.base64 | base64 -d > orderer.genesis.block
else
peer channel fetch config ${CHANNEL_NAME}_config_block.pb -o ${CORE_PEER_ADDRESS} -c ${CHANNEL_NAME} --tls --cafile ${ORDERER_CA}
fi
list=$(echo "$ORDERERS_INFO" | tr "*" "\n")
for ORDERER_NAME in $list
Expand All @@ -167,10 +201,16 @@ spec:
CHANNEL_LIST_QUERY_RESPONSE=$(osnadmin channel list --channelID ${CHANNEL_NAME} -o "${ORDERER_URL}" --ca-file "${OSN_TLS_CA_ROOT_CERT}" --client-cert "${ADMIN_TLS_SIGN_CERT}" --client-key "${ADMIN_TLS_PRIVATE_KEY}")
if echo "$CHANNEL_LIST_QUERY_RESPONSE" | grep '404'; then
echo "Creating channel....."
osnadmin channel join --channelID "${CHANNEL_NAME}" --config-block orderer.genesis.block -o "${ORDERER_URL}" --ca-file "${OSN_TLS_CA_ROOT_CERT}" --client-cert "${ADMIN_TLS_SIGN_CERT}" --client-key "${ADMIN_TLS_PRIVATE_KEY}"
if [ $ADD_ORDERER = false ]
then
osnadmin channel join --channelID "${CHANNEL_NAME}" --config-block orderer.genesis.block -o "${ORDERER_URL}" --ca-file "${OSN_TLS_CA_ROOT_CERT}" --client-cert "${ADMIN_TLS_SIGN_CERT}" --client-key "${ADMIN_TLS_PRIVATE_KEY}"
else
osnadmin channel join --channelID "${CHANNEL_NAME}" --config-block ${CHANNEL_NAME}_config_block.pb -o "${ORDERER_URL}" --ca-file "${OSN_TLS_CA_ROOT_CERT}" --client-cert "${ADMIN_TLS_SIGN_CERT}" --client-key "${ADMIN_TLS_PRIVATE_KEY}"
fi
osnadmin channel list -o "${ORDERER_URL}" --ca-file "${OSN_TLS_CA_ROOT_CERT}" --client-cert "${ADMIN_TLS_SIGN_CERT}" --client-key "${ADMIN_TLS_PRIVATE_KEY}"
elif echo "$CHANNEL_LIST_QUERY_RESPONSE" | grep '200\|201'; then
echo "Channel ${CHANNEL_NAME}, is already created for url: ${ORDERER_URL}"
osnadmin channel list --channelID ${CHANNEL_NAME} -o "${ORDERER_URL}" --ca-file "${OSN_TLS_CA_ROOT_CERT}" --client-cert "${ADMIN_TLS_SIGN_CERT}" --client-key "${ADMIN_TLS_PRIVATE_KEY}"
else
echo $CHANNEL_LIST_QUERY_RESPONSE
fi
Expand All @@ -183,6 +223,8 @@ spec:
- name: certificates
mountPath: /opt/gopath/src/github.com/hyperledger/fabric/crypto
readOnly: true
{{- if not $.Values.add_orderer }}
- name: genesis
mountPath: /opt/gopath/src/github.com/hyperledger/fabric/orderer/genesis
readOnly: true
{{ end }}
15 changes: 13 additions & 2 deletions platforms/hyperledger-fabric/configuration/add-orderer.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
loop: "{{ network.organizations }}"
loop_control:
loop_var: org
when: org.type == 'orderer'
when: org.type == 'orderer' and '2.5.' not in network.version

# This role creates value file new orderer
- name: "create new orderer"
Expand Down Expand Up @@ -92,7 +92,18 @@
loop: "{{ network.organizations }}"
loop_control:
loop_var: org
when: org.type == 'orderer'
when: org.type == 'orderer' and '2.5.' not in network.version

# This role creates the value file for creating channel from creator organization
# to the vault.
- name: Create all create-channel jobs
include_role:
name: "create/osnchannels"
vars:
build_path: "./build"
docker_url: "{{ network.docker.url }}"
loop: "{{ network['channels'] }}"
when: add_new_org == 'false' and '2.5.' in network.version

# Generate script to modify the fetched configuration block from application channel
- name: "Modify the application channel with tls and address information of new orderer"
Expand Down
45 changes: 30 additions & 15 deletions platforms/hyperledger-fabric/configuration/add-peer.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,25 +34,39 @@
kubernetes: "{{ item.k8s }}"
release_dir: "{{playbook_dir}}/../../../{{item.gitops.release_dir}}/{{ item.name | lower }}"
loop: "{{ network['organizations'] }}"

# Setup script for Vault and OS Package Manager
- name: "Setup script for Vault and OS Package Manager"
include_role:
name: "{{ playbook_dir }}/../../shared/configuration/roles/setup/scripts"
vars:
namespace: "{{ org.name | lower }}-net"
network_type: "{{ network.type | lower }}"
kubernetes: "{{ org.k8s }}"
loop: "{{ network['organizations'] }}"
loop_control:
loop_var: org
when: org.org_status == 'new'

# Setup Vault-Kubernetes accesses and Regcred for docker registry for new organization
- include_role:
name: "{{ playbook_dir }}/../../shared/configuration/roles/setup/vault_kubernetes"
vars:
name: "{{ org.name | lower }}"
component_name: "{{ org.name | lower }}-vaultk8s-job"
component_type: "{{ org.type | lower }}"
component_ns: "{{ org.name | lower }}-net"
component_auth: "{{ network.env.type }}{{ org.name | lower }}-net-auth"
kubernetes: "{{ org.k8s }}"
vault: "{{ org.vault }}"
policy_type: "fabric"
gitops: "{{ org.gitops }}"
reset_path: "platforms/hyperledger-fabric/configuration"
loop: "{{ network['organizations'] }}"
loop_control:
loop_var: org

vars:
name: "{{ org.name | lower }}"
component_name: "{{ org.name | lower }}-vaultk8s-job"
component_type: "{{ org.type | lower }}"
component_ns: "{{ org.name | lower }}-net"
component_auth: "{{ network.env.type }}{{ org.name | lower }}-net-auth"
kubernetes: "{{ org.k8s }}"
vault: "{{ org.vault }}"
policy_type: "fabric"
gitops: "{{ org.gitops }}"
reset_path: "platforms/hyperledger-fabric/configuration"
loop: "{{ network['organizations'] }}"
loop_control:
loop_var: org
when: org.org_status == 'new'

# Create Storageclass for new organization
- include_role:
name: "{{ playbook_dir }}/../../../platforms/shared/configuration/roles/setup/storageclass"
Expand All @@ -78,6 +92,7 @@
component_type: "{{ item.type | lower}}"
component_services: "{{ item.services }}"
orderer_org: "{{ item.orderer_org | lower }}"
sc_name: "{{ component }}-{{ item.cloud_provider | lower }}-storageclass"
kubernetes: "{{ item.k8s }}"
vault: "{{ item.vault }}"
ca: "{{ item.services.ca }}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,34 @@
set -x

CURRENT_DIR=${PWD}
NETWORK_VERSION="{{ version }}"

echo "installing jq "
apt-get install -y jq
echo "installing configtxlator"
mkdir temp
cd temp/
wget https://github.com/hyperledger/fabric/releases/download/v{{ version }}/hyperledger-fabric-{{ os }}-{{ arch }}-{{ version }}.tar.gz
tar -xvf hyperledger-fabric-{{ os }}-{{ arch }}-{{ version }}.tar.gz
mv bin/configtxlator ../
cd ../
rm -r temp
if [ "$NETWORK_VERSION" != "2.5.4" ]; then
echo "installing configtxlator"
mkdir temp
cd temp/
wget https://github.com/hyperledger/fabric/releases/download/v{{ version }}/hyperledger-fabric-{{ os }}-{{ arch }}-{{ version }}.tar.gz
tar -xvf hyperledger-fabric-{{ os }}-{{ arch }}-{{ version }}.tar.gz
mv bin/configtxlator ../
cd ../
rm -r temp
fi

echo "converting the channel_config_block.pb to channel_config.json using configtxlator and jq"
configtxlator proto_decode --input {{ channel_name }}_config_block.pb --type common.Block | jq .data.data[0].payload.data.config > {{ channel_name }}_config.json
echo "adding new organization crypto material from config.json to the channel_config.json to make channel_modified_config.json"
jq --argjson a "$(cat ./orderer)" '.channel_group.values.OrdererAddresses.value.addresses += $a' {{ channel_name }}_config.json > {{ channel_name }}_modified_intermediate_config.json
jq --argjson a "$(cat ./orderer-tls)" '.channel_group.groups.Orderer.values.ConsensusType.value.metadata.consenters += $a' {{ channel_name }}_modified_intermediate_config.json > {{ channel_name }}_modified_config.json
if [ "$NETWORK_VERSION" != "2.5.4" ]; then
echo "version 2.2.2++++"
jq --argjson a "$(cat ./orderer)" '.channel_group.values.OrdererAddresses.value.addresses += $a' {{ channel_name }}_config.json > {{ channel_name }}_modified_intermediate_config.json
jq --argjson a "$(cat ./orderer-tls)" '.channel_group.groups.Orderer.values.ConsensusType.value.metadata.consenters += $a' {{ channel_name }}_modified_intermediate_config.json > {{ channel_name }}_modified_config.json
else
echo "version 2.5.4++++"
jq --argjson a "$(cat ./orderer)" '.channel_group.values.OrdererAddresses.value.addresses += $a' {{ channel_name }}_config.json > {{ channel_name }}_modified_intermediate_address_config.json
jq --argjson a "$(cat ./orderer)" '.channel_group.groups.Orderer.groups.{{ component_name }}MSP.values.Endpoints.value.addresses += $a' {{ channel_name }}_modified_intermediate_address_config.json > {{ channel_name }}_modified_intermediate_endpoints_config.json
jq --argjson a "$(cat ./orderer-tls)" '.channel_group.groups.Orderer.values.ConsensusType.value.metadata.consenters += $a' {{ channel_name }}_modified_intermediate_endpoints_config.json > {{ channel_name }}_modified_config.json
fi
echo "converting the channel_config.json and channel_modified_config.json to .pb files"
configtxlator proto_encode --input {{ channel_name }}_config.json --type common.Config --output {{ channel_name }}_config.pb
configtxlator proto_encode --input {{ channel_name }}_modified_config.json --type common.Config --output {{ channel_name }}_modified_config.pb
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,25 @@
loop_var: orderer
when:
- component_services.orderers is defined and component_services.consensus is defined
- orderer.status is not defined or orderer.status == 'new'
- (orderer.status is not defined or orderer.status == 'new') and '2.5.' not in network.version

# Create the value file for the Orderers as per requirements mentioned in network.yaml
- name: "create orderers"
include_role:
name: helm_component
vars:
name: "orderer"
org_name: "{{ item.name | lower }}"
sc_name: "{{ org_name }}-{{ item.cloud_provider | lower}}-storageclass"
component_name: "{{ orderer.name }}-{{ org_name }}"
type: "orderers"
consensus: "{{component_services.consensus}}"
loop: "{{ component_services.orderers }}"
loop_control:
loop_var: orderer
when:
- component_services.orderers is defined and component_services.consensus is defined
- (orderer.status is not defined or orderer.status == 'new') and '2.5.' in network.version

# Git Push: Push the above generated files to git directory
- name: Git Push
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,19 @@
orderer_kubeconfig: "{{ org.k8s.config_file }}"
orderer_context: "{{ org.k8s.context }}"

# Reset ca-tools pod
- name: "Reset ca-tools pod"
include_role:
name: create/refresh_certs/reset_pod
vars:
pod_name: "osn-createchannel-{{item.channel_name|lower}}"
file_path: "{{playbook_dir}}/../../../{{org.gitops.release_dir}}/{{ org.name | lower }}/{{ org.name | lower }}/{{item.channel_name|lower}}.yaml"
gitops_value: "{{ org.gitops }}"
component_ns: "{{ org.name | lower }}-net"
kubernetes: "{{ org.k8s }}"
hr_name: "channel-{{ org.name | lower }}-{{item.channel_name|lower}}"
when: add_orderer is defined and add_orderer == 'true'

# Create the value file for creator Organization
- name: "Create Create_Channel value file osnadmin"
include_role:
Expand All @@ -35,6 +48,30 @@
orderers_list: "{{ org.services.orderers }}"
genesis: "{{ lookup('file', '{{ build_path }}/channel-artifacts/genesis.block.base64') }}"
values_dir: "{{playbook_dir}}/../../../{{org.gitops.release_dir}}/{{ org.name | lower }}"
add_orderer_value: "{{ add_orderer | default('false') }}"
when: add_orderer is not defined or add_orderer == false

# Create the value file for creator Organization
- name: "Create Create_Channel value file osnadmin"
include_role:
name: helm_component
vars:
name: "{{ org.name | lower }}"
type: "osn_create_channel_job"
component_name: "{{item.channel_name|lower}}"
component_ns: "{{ org.name | lower}}-net"
git_protocol: "{{ org.gitops.git_protocol }}"
git_url: "{{ org.gitops.git_url }}"
git_branch: "{{ org.gitops.branch }}"
charts_dir: "{{ org.gitops.chart_source }}"
vault: "{{ org.vault }}"
k8s: "{{ org.k8s }}"
orderers_list: "{{ org.services.orderers }}"
first_orderer: "{{ org.services.orderers | first }}"
values_dir: "{{playbook_dir}}/../../../{{org.gitops.release_dir}}/{{ org.name | lower }}"
add_orderer_value: "{{ add_orderer | default('false') }}"
external_url_suffix: "{{ org.external_url_suffix }}"
when: add_orderer is defined and add_orderer == 'true'

# Git Push: Push the above generated files to git directory
- name: Git Push
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
tags:
- notest

# Wait for the Orderer HelmRelease
# Wait for the peer HelmRelease
- name: 'Wait for {{ peer.name }} HelmRelease in {{ namespace }}'
k8s_info:
api_version: "helm.toolkit.fluxcd.io/v2beta1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
- name: Remove existing value file for {{ peer.name }}
shell: |
rm -f {{ values_dir }}/{{ item.name | lower }}/values-{{ peer.name }}.yaml
when:
- add_peer is not defined or add_peer == 'false'

# Fetch the custom core.yaml
- name: Fetch the custom core.yaml
Expand Down
Loading

0 comments on commit 2c1f343

Please sign in to comment.