Skip to content
This repository has been archived by the owner on Feb 5, 2024. It is now read-only.

Commit

Permalink
Merge pull request #102 from SubstraFoundation/channels-share-chaincode
Browse files Browse the repository at this point in the history
Allow the same chaincode to be used on multiple channels
  • Loading branch information
Kelvin-M authored Dec 2, 2020
2 parents b1644ed + 5d22e24 commit a4696f3
Show file tree
Hide file tree
Showing 24 changed files with 318 additions and 194 deletions.
4 changes: 4 additions & 0 deletions charts/hlf-k8s/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

# 5.0.0

- Add support for using the same chaincode on multiple channels.
- This changes the structure of the `appChannels` value. Please see [`UPDGRADE.md`](./UPGRADE.md).

## 4.0.0

Expand Down
2 changes: 1 addition & 1 deletion charts/hlf-k8s/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
apiVersion: v1
name: hlf-k8s
home: https://substra.org/
version: 4.0.1
version: 5.0.0
description: Tolling package for Substra that configure the network
icon: https://avatars1.githubusercontent.com/u/38098422?s=200&v=4
sources:
Expand Down
50 changes: 28 additions & 22 deletions charts/hlf-k8s/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,19 @@ The following table lists the configurable parameters of the hlf-k8s chart and d
| `appChannels[].chaincodes` | The chaincodes to install on the Peer. See [Install a chaincode](#install-a-chaincode). | `[]` |
| `appChannels[].chaincodes[].name` | The name of the chaincode | (undefined) |
| `appChannels[].chaincodes[].version` | The chaincode version | (undefined) |
| `appChannels[].chaincodes[].address` | The URL to the chaincode service | (undefined) |
| `appChannels[].chaincodes[].port` | The port to the chaincode service | (undefined) |
| `appChannels[].chaincodes[].policy` | The chaincode policy | (undefined) |
| `appChannels[].chaincodes[].image.repository` | `chaincode` image repository | (undefined) |
| `appChannels[].chaincodes[].image.tag` | `chaincode` image tag | (undefined) |
| `appChannels[].chaincodes[].image.pullPolicy` | Image pull policy | (undefined) |
| `appChannels[].chaincodes[].policy` | The chaincode policy for this channel | (undefined) |
| `appChannels[].ingress.enabled` | If true, Ingress will be created for this application channel operator. | `false` |
| `appChannels[].ingress.annotations` | Application channel operator ingress annotations | (undefined) |
| `appChannels[].ingress.tls` | Application channel operator ingress TLS configuration | (undefined) |
| `appChannels[].ingress.hosts` | Application channel operator ingress hosts | (undefined) |
| `chaincodes` | The chaincodes to install on the peer | `[]` |
| `chaincodes[].name` | The name of the chaincode | (undefined) |
| `chaincodes[].version` | The chaincode version | (undefined) |
| `chaincodes[].address` | The URL to the chaincode service | (undefined) |
| `chaincodes[].port` | The port to the chaincode service | (undefined) |
| `chaincodes[].image.repository` | `chaincode` image repository | (undefined) |
| `chaincodes[].image.tag` | `chaincode` image tag | (undefined) |
| `chaincodes[].image.pullPolicy` | Image pull policy | (undefined) |
| `configOperator.ingress.enabled` | If true, Ingress will be created for the config operator. | `false` |
| `configOperator.ingress.annotations` | Config operator ingress annotations | (undefined) |
| `configOperator.ingress.tls` | Config operator ingress TLS configuration | (undefined) |
Expand Down Expand Up @@ -125,18 +128,22 @@ Install a chaincode on a peer using the following values.
On a peer:

```yaml
chaincodes:
- name: mycc
version: "1.0"
address: "chaincode-org-0-substra-chaincode-chaincode.org-0"
port: "7052"
image:
repository: substrafoundation/substra-chaincode
tag: 0.1.1
pullPolicy: IfNotPresent

appChannels:
- channelName: mychannel
chaincodes:
- name: mycc
version: "1.0"
address: "chaincode-org-0-substra-chaincode-chaincode.org-0"
port: "7052"
policy: "OR('Org1MSP.member','Org2MSP.member')"
image:
repository: substrafoundation/substra-chaincode
tag: 0.1.0
pullPolicy: IfNotPresent
version: "1.0"
```
Expand Down Expand Up @@ -164,15 +171,14 @@ Finally, modify deployment values to use your chaincode image:

For instance with `substrafoundation/substra-chaincode:my-tag`
```yaml
chaincodes:
- address: network-org-1-peer-1-hlf-k8s-chaincode-mycc.org-1
policy: "OR('MyOrg1MSP.member','MyOrg2MSP.member')"
name: mycc
port: 7052
version: "1.0"
image:
repository: substrafoundation/substra-chaincode
tag: my-tag
chaincodes:
- address: network-org-1-peer-1-hlf-k8s-chaincode-mycc.org-1
name: mycc
port: 7052
version: "1.0"
image:
repository: substrafoundation/substra-chaincode
tag: my-tag
```
### Add an organization to the system channel
Expand Down
26 changes: 26 additions & 0 deletions charts/hlf-k8s/UPGRADE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,32 @@
# Changelog


# 5.0.0

Chaincode properties have been moved from `appChannels[].chaincodes[]` to `chaincodes[]`, which the exception of the `policy`, `name` and `version` fields.

Example:

```yaml
chaincodes:
- name: mycc
address: network-org-1-peer-1-hlf-k8s-chaincode-mycc.org-1
port: 7052
version: "1.0"
image:
repository: substrafoundation/substra-chaincode
tag: 0.1.1
pullPolicy: IfNotPresent


appChannels:
- channelName: mychannel
chaincodes:
- name: mycc
policy: "OR('MyOrg1MSP.member','MyOrg2MSP.member')"
version: "1.0"
```
## 4.0.0
Expand Down
23 changes: 17 additions & 6 deletions charts/hlf-k8s/templates/deployment-appchannel-operator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -287,17 +287,27 @@ spec:
## CHAINCODES
{{- range .chaincodes }}
{{- range $cc := .chaincodes }}
## Wait readiness
{{/* Find associated chaincode */}}
{{ $chaincode := "" }}
{{- range $.Values.chaincodes }}
{{- if and (eq .name $cc.name) (eq .version $cc.version) }}
- {{ $chaincode = . }}
{{- end }}
{{- end }}
{{ with $chaincode }}
## Wait readiness: {{ .name }}
while true; do
# Chaincode commit
printf "[DEBUG] Wait chaincode ready {{ .name }} {{ .version }} on channel {{ $value.channelName }}\n"
peer lifecycle chaincode checkcommitreadiness \
--signature-policy "{{ .policy}}" \
--signature-policy "{{ $cc.policy }}" \
--channelID {{ $value.channelName }} \
--name {{ .name }} \
--version {{ .version }} \
Expand All @@ -318,7 +328,7 @@ spec:
done
## Commit chaincode
## Commit chaincode {{ .name }}
peer lifecycle chaincode querycommitted --channelID {{ $value.channelName }} > chaincode.{{ .name }}.list 2>&1
Expand All @@ -330,7 +340,7 @@ spec:
ENDORSEMENT=$(cat endorsement.config| tr '\n' ' ')
peer lifecycle chaincode commit \
--signature-policy "{{ .policy}}" \
--signature-policy "{{ $cc.policy }}" \
--channelID {{ $value.channelName }} \
--name {{ .name }} \
--version {{ .version }} \
Expand All @@ -351,7 +361,7 @@ spec:
fi
## Init chaincode
## Init chaincode {{ .name }}
if [[ ! -e chaincode.{{ .name }}.init ]]; then
touch chaincode.{{ .name }}.init
Expand All @@ -376,6 +386,7 @@ spec:
fi
{{ end }}
{{ end }}
sleep 10
Expand Down
24 changes: 16 additions & 8 deletions charts/hlf-k8s/templates/deployment-chaincode-operator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
# limitations under the License.

{{- if index .Values "hlf-peer" "enabled" }}
{{- range $index, $value :=.Values.appChannels }}
{{- range .chaincodes }}
{{- range .Values.chaincodes }}
---
apiVersion: apps/v1
kind: Deployment
Expand Down Expand Up @@ -122,14 +121,20 @@ spec:
## Approve chaincode
{{ $chaincode := . }}
{{- range $channel := $.Values.appChannels }}
{{- range $channel.chaincodes }}
{{- if and (eq .name $chaincode.name) (eq .version $chaincode.version) }}
while true ; do
printf "[DEBUG] Approving chaincode {{ .name }} {{ .version }} with ccid ${CHAINCODE_CCID}\n"
printf "[DEBUG] Approving chaincode {{ .name }} {{ $chaincode.version }} with ccid ${CHAINCODE_CCID} on channel {{ $channel.channelName }}\n"
peer lifecycle chaincode approveformyorg \
--signature-policy "{{ .policy}}" \
--channelID {{ $value.channelName }} \
--channelID {{ $channel.channelName }} \
--name {{ .name }} \
--version {{ .version }} \
--version {{ $chaincode.version }} \
--package-id $CHAINCODE_CCID \
--sequence 1 \
--init-required \
Expand All @@ -141,7 +146,7 @@ spec:
-o {{ index $.Values "hlf-ord" "host" }}:{{ index $.Values "hlf-ord" "port" }} > /dev/null 2>&1
peer lifecycle chaincode queryapproved \
--channelID {{ $value.channelName }} \
--channelID {{ $channel.channelName }} \
--name {{ .name }} \
--sequence 1 \
--tls \
Expand All @@ -156,12 +161,16 @@ spec:
break
fi
printf "[DEBUG] Chaincode {{ .name }} {{ .version }} with ccid ${CHAINCODE_CCID} is not approved\n"
printf "[DEBUG] Chaincode {{ .name }} {{ .version }} with ccid ${CHAINCODE_CCID} is not approved on channel {{ $channel.channelname }}\n"
sleep 5
done
{{- end }}
{{- end }}
{{- end }}
sleep 10
done
resources:
Expand Down Expand Up @@ -282,4 +291,3 @@ spec:
{{- end }}
{{- end }}
{{- end }}
{{- end }}
18 changes: 8 additions & 10 deletions charts/hlf-k8s/templates/deployment-chaincode.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
{{- if index .Values "hlf-peer" "enabled" }}
{{- range .Values.appChannels }}
{{- range .chaincodes }}
{{- range .Values.chaincodes }}
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ template "substra.fullname" $ }}-chaincode-{{ .name}}
name: {{ template "substra.fullname" $ }}-chaincode-{{ .name }}
labels:
app.kubernetes.io/managed-by: {{ $.Release.Service }}
app.kubernetes.io/instance: {{ $.Release.Name }}
Expand All @@ -16,16 +15,16 @@ spec:
replicas: 1
selector:
matchLabels:
app.kubernetes.io/name: {{ template "substra.name" $ }}-chaincode-{{ .name}}
app.kubernetes.io/name: {{ template "substra.name" $ }}-chaincode-{{ .name }}
app.kubernetes.io/instance: {{ $.Release.Name }}
template:
metadata:
labels:
app.kubernetes.io/name: {{ template "substra.name" $ }}-chaincode-{{ .name}}
app.kubernetes.io/name: {{ template "substra.name" $ }}-chaincode-{{ .name }}
app.kubernetes.io/instance: {{ $.Release.Name }}
spec:
containers:
- name: substra-chaincode-{{ .name}}
- name: substra-chaincode-{{ .name }}
image: {{ .image.repository }}:{{ .image.tag }}
imagePullPolicy: "{{ .image.pullPolicy }}"
command: ['./chaincode']
Expand Down Expand Up @@ -61,12 +60,12 @@ spec:
apiVersion: v1
kind: Service
metadata:
name: {{ template "substra.fullname" $ }}-chaincode-{{ .name}}
name: {{ template "substra.fullname" $ }}-chaincode-{{ .name }}
labels:
app.kubernetes.io/managed-by: {{ $.Release.Service }}
app.kubernetes.io/instance: {{ $.Release.Name }}
helm.sh/chart: {{ $.Chart.Name }}-{{ $.Chart.Version }}
app.kubernetes.io/name: {{ template "substra.name" $ }}-chaincode-{{ .name}}
app.kubernetes.io/name: {{ template "substra.name" $ }}-chaincode-{{ .name }}
spec:
type: ClusterIP
ports:
Expand All @@ -75,8 +74,7 @@ spec:
protocol: TCP
targetPort: {{ .port }}
selector:
app.kubernetes.io/name: {{ template "substra.name" $ }}-chaincode-{{ .name}}
app.kubernetes.io/name: {{ template "substra.name" $ }}-chaincode-{{ .name }}
app.kubernetes.io/instance: {{ $.Release.Name }}
{{- end }}
{{- end }}
{{- end }}
4 changes: 1 addition & 3 deletions charts/hlf-k8s/templates/job-hook-delete-secrets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,9 @@ spec:
- secrets
- -n
- {{ .Release.Namespace }}
{{- range .Values.appChannels }}
{{- range .chaincodes }}
{{- range .Values.chaincodes }}
- chaincode-ccid-{{ .name }}
{{- end }}
{{- end }}
- --ignore-not-found=true
- --wait=true
- -v=4
Expand Down
21 changes: 12 additions & 9 deletions charts/hlf-k8s/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,16 @@ systemChannel:
Type: ImplicitMeta
Rule: "MAJORITY Admins"
chaincodes: []
# - name: mycc
# version: "1.0"
# address: "chaincode-org-0-substra-chaincode-chaincode.org-0"
# port: "7052"
# image:
# repository: substrafoundation/substra-chaincode
# tag: 0.1.1
# pullPolicy: IfNotPresent


appChannels:
- channelName: mychannel
Expand Down Expand Up @@ -98,16 +108,9 @@ appChannels:
Rule: "MAJORITY Admins"
chaincodes: []
# -
# name: mycc
# - name: mycc
# policy: "OR('MyOrg1MSP.member','MyOrg2MSP.member')"
# version: "1.0"
# address: "chaincode-org-0-substra-chaincode-chaincode.org-0"
# port: "7052"
# policy: "OR('Org1MSP.member','Org2MSP.member')"
# image:
# repository: substrafoundation/substra-chaincode
# tag: 0.1.0
# pullPolicy: IfNotPresent

ingress:
enabled: false
Expand Down
Loading

0 comments on commit a4696f3

Please sign in to comment.