Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support for multiple bakers #74

Merged
merged 9 commits into from
Jan 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions baker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM tezos/tezos:v8-release
RUN sudo apk add jq bash
COPY entrypoint.sh /
ENTRYPOINT ["/entrypoint.sh"]
CMD []
8 changes: 8 additions & 0 deletions baker/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

set -x

baker_command=$(echo $CHAIN_PARAMS | jq -r '.baker_command')
POD_INDEX=$(echo $POD_NAME | sed -e s/tezos-bootstrap-node-//)
baker_account=$(echo $NODES | jq -r "[.[] | select(.bake_for)] | . [${POD_INDEX}].bake_for")
/usr/local/bin/${baker_command} -d /var/tezos/client run with local node /var/tezos/node ${baker_account:?Error: baker account not set}
3 changes: 2 additions & 1 deletion chain-initiator/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ until nslookup tezos-bootstrap-node-rpc; do echo waiting for tezos-bootstrap-nod
until wget -O- http://tezos-bootstrap-node-rpc:8732/version; do sleep 2; done;

protocol_hash=$(echo $CHAIN_PARAMS | jq -r '.protocol_hash')
/usr/local/bin/tezos-client -A tezos-bootstrap-node-rpc -P 8732 -d /var/tezos/client -l --block genesis activate protocol "${protocol_hash}" with fitness -1 and key genesis and parameters /etc/tezos/parameters.json
activation_account=$(echo $CHAIN_PARAMS | jq -r '.activation_account')
/usr/local/bin/tezos-client -A tezos-bootstrap-node-rpc -P 8732 -d /var/tezos/client -l --block genesis activate protocol "${protocol_hash}" with fitness -1 and key "${activation_account}" and parameters /etc/tezos/parameters.json
67 changes: 38 additions & 29 deletions charts/tezos/templates/bootstrap.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
{{- /* Function to get number of bakers */}}
{{- define "bakers" }}
{{- range $i, $node := $.Values.nodes }}
{{- if (hasKey $node "bake_for") }}
{{ $i }}: true
{{- end }}
{{- end }}
{{- end -}}
{{- if not .Values.is_invitation }}
apiVersion: batch/v1
kind: Job
Expand All @@ -24,6 +32,8 @@ spec:
envFrom:
- secretRef:
name: tezos-secret
- configMapRef:
name: tezos-config
volumeMounts:
- mountPath: /var/tezos
name: var-volume
Expand Down Expand Up @@ -61,16 +71,17 @@ spec:
---
{{- if not .Values.is_invitation }}
apiVersion: apps/v1
kind: Deployment
kind: StatefulSet
metadata:
name: tezos-bootstrap-node
namespace: {{ .Release.Namespace }}
spec:
podManagementPolicy: Parallel
replicas: {{ include "bakers" . | fromYaml | values | len }}
serviceName: tezos-bootstrap-node-rpc
nicolasochem marked this conversation as resolved.
Show resolved Hide resolved
selector:
matchLabels:
app: tezos-bootstrap-node
strategy:
type: Recreate
template:
metadata:
labels:
Expand Down Expand Up @@ -109,37 +120,26 @@ spec:
name: config-volume
- mountPath: /var/tezos
name: var-volume
- args:
- "-A"
- localhost
- "-P"
- '8732'
- "-d"
- /var/tezos/client
- run
- with
- local
- node
- /var/tezos/node
- baker
command:
- "{{ .Values.baker_command }}"
image: "{{ .Values.images.tezos }}"
name: baker-job
- image: "{{ .Values.tezos_k8s_images.baker }}"
imagePullPolicy: IfNotPresent
name: baker
volumeMounts:
- mountPath: /var/tezos
name: var-volume
envFrom:
- configMapRef:
name: tezos-config
- secretRef:
name: tezos-secret
env:
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
{{- if .Values.zerotier_in_use }}
- args:
- "-c"
- "echo 'starting zerotier' && zerotier-one /var/tezos/zerotier"
- "-P"
- '8732'
- "-d"
- /var/tezos/client
- run
- baker
command:
- sh
image: "{{ .Values.tezos_k8s_images.zerotier }}"
Expand Down Expand Up @@ -183,6 +183,8 @@ spec:
envFrom:
- secretRef:
name: tezos-secret
- configMapRef:
name: tezos-config
volumeMounts:
- mountPath: /var/tezos
name: var-volume
Expand Down Expand Up @@ -226,7 +228,14 @@ spec:
name: dev-net-tun
- emptyDir: {}
name: config-volume
- name: var-volume
persistentVolumeClaim:
claimName: tezos-bootstrap-node-pv-claim
volumeClaimTemplates:
- metadata:
name: var-volume
namespace: {{ .Release.Namespace }}
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: "15Gi"
{{- end }}
61 changes: 6 additions & 55 deletions charts/tezos/templates/configs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@ data:
"bootstrap_peers": {{ toJson .Values.bootstrap_peers }},
"chain_name": "{{ .Values.chain_name }}",
"genesis_block": "{{ .Values.genesis.genesis_chain_id }}",
"activation_account": "{{ (index .Values.accounts 0).name }}",
"timestamp": "{{ .Values.genesis.bootstrap_timestamp }}",
"zerotier_in_use": {{ .Values.zerotier_in_use }},
"baker_command": "{{ .Values.baker_command }}",
"protocol_hash": "{{ .Values.protocol.hash }}"
}
NODES: |
{{ .Values.nodes | toJson | indent 4}}
kind: ConfigMap
metadata:
name: tezos-config
Expand All @@ -25,63 +29,10 @@ metadata:
name: zerotier-config
namespace: {{ .Release.Namespace }}
---
{{- /*

https://stackoverflow.com/questions/61153730/creating-a-filtered-list-using-helm-template-helpers

Helm templating is very string based and so is unable to do common operations
like mapping over a list

The BOOTSTRAP_ACCOUNTS secrets variable is essentially the following:

```python3
" ".join(account.name for account in Values.accounts if account.bootstrap)
```

So to recreate in helm, we do the following:

1. First, use helms text templating to build a yaml list (see `define "boostrapAccounts"`)
2. Then, use the builtin `fromYaml` function to get the list of account names
3. Use the `join` builtin function

Theres one caveat in that `fromYaml` expects an object, so we cant directly
make a yaml list. So we simply make dummmy keys and then call `values` to get
the list of values, which is the list we want

*/ -}}

{{- define "bootstrapAccounts" }}
value:
{{- range $i, $account := $.Values.accounts }}
{{- if $account.bootstrap }}
{{ $i }}: {{ $account.name | quote }}
{{- end }}
{{- end }}
{{- end -}}

apiVersion: v1
data:
BOOTSTRAP_ACCOUNTS: |
{{ include "bootstrapAccounts" . | fromYaml | values | join " " | b64enc | indent 4 }}
{{- if .Values.is_invitation }}
KEYS_TYPE: |
{{ "public" | b64enc | indent 4 }}
{{- range $account := $.Values.accounts }}
{{- if not $account.private }}
{{ $account.name | indent 2 }}_public_key: |
{{ $account.key | b64enc | indent 4 }}
{{- end }}
{{- end }}
{{- else }}
KEYS_TYPE: |
{{ "secret" | b64enc | indent 4 }}
{{- range $account := $.Values.accounts }}
{{- if $account.private }}
{{ $account.name | indent 2 }}_secret_key: |
{{ $account.key | b64enc | indent 4 }}
{{- end }}
{{- end }}
{{- end }}
ACCOUNTS: |
{{ .Values.accounts | toJson | b64enc | indent 4 }}
kind: Secret
metadata:
name: tezos-secret
Expand Down
2 changes: 2 additions & 0 deletions charts/tezos/templates/node.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ spec:
envFrom:
- secretRef:
name: tezos-secret
- configMapRef:
name: tezos-config
volumeMounts:
- mountPath: /var/tezos
name: var-volume
Expand Down
17 changes: 2 additions & 15 deletions charts/tezos/templates/static.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ metadata:
namespace: {{ .Release.Namespace }}
spec:
ports:
- nodePort: 31732
port: 8732
- port: 8732
selector:
app: tezos-bootstrap-node
type: NodePort
Expand All @@ -19,21 +18,9 @@ metadata:
namespace: {{ .Release.Namespace }}
spec:
ports:
- nodePort: 30732
port: 9732
- port: 9732
selector:
app: tezos-bootstrap-node
type: NodePort
---
{{ end }}
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: tezos-bootstrap-node-pv-claim
namespace: {{ .Release.Namespace }}
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: "15Gi"
2 changes: 2 additions & 0 deletions charts/tezos/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ images:
# Images that are part of the tezos-k8s repo go here
tezos_k8s_images:
chain_initiator: tezos-k8s-chain-initiator:dev
baker: tezos-k8s-baker:dev
key_importer: tezos-k8s-key-importer:dev
config_generator: tezos-k8s-config-generator:dev
key_importer: tezos-k8s-key-importer:dev
zerotier: tezos-k8s-zerotier:dev
Expand Down
4 changes: 2 additions & 2 deletions config-generator/entrypoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ def main():
if CHAIN_PARAMS["zerotier_in_use"]:
with open("/var/tezos/zerotier_data.json", "r") as f:
net_addr = json.load(f)[0]["assignedAddresses"][0].split("/")[0]
if bootstrap_peers == [] and "bootstrap" not in socket.gethostname():
if bootstrap_peers == []:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the logic here now that we want all bootstrap peers to know about each other? We should probably filter out the node's own ip like we talked about.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in nicolasochem#1 that I will submit next as a PR.

bootstrap_peers.extend(get_zerotier_bootstrap_peer_ips())
else:
bootstrap_peers.append("tezos-bootstrap-node-p2p:9732")

config_json = json.dumps(
get_node_config(
CHAIN_PARAMS["chain_name"],
bootstrap_accounts["genesis"],
bootstrap_accounts[CHAIN_PARAMS["activation_account"]],
CHAIN_PARAMS["timestamp"],
bootstrap_peers,
CHAIN_PARAMS["genesis_block"],
Expand Down
4 changes: 4 additions & 0 deletions devspace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ images:
image: tezos-k8s-zerotier
dockerfile: ./zerotier/Dockerfile
context: ./zerotier
baker:
image: tezos-k8s-baker
dockerfile: ./baker/Dockerfile
context: ./baker
chain-initiator:
image: tezos-k8s-chain-initiator
dockerfile: ./chain-initiator/Dockerfile
Expand Down
1 change: 1 addition & 0 deletions key-importer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
FROM tezos/tezos:v8-release
RUN sudo apk add --no-cache jq
COPY entrypoint.sh /
ENTRYPOINT ["/entrypoint.sh"]
CMD []
10 changes: 7 additions & 3 deletions key-importer/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
mkdir -p /var/tezos/client
chmod -R 777 /var/tezos/client

for acct in ${BOOTSTRAP_ACCOUNTS}; do
key=$(eval echo \$${acct}_${KEYS_TYPE}_key)
tezos-client -d /var/tezos/client --protocol PsDELPH1Kxsx import ${KEYS_TYPE} key $acct unencrypted:${key} -f
echo $ACCOUNTS | jq -c --raw-output .[] | while read line; do
key=$(echo $line | jq -r '.key')
name=$(echo $line | jq -r '.name')
keytype=$(echo $line | jq -r '.type')
protocol=$(echo $CHAIN_PARAMS | jq -r '.protocol_hash')
printf "\nImporting key ${name}\n"
tezos-client -d /var/tezos/client --protocol ${protocol} import ${keytype} key ${name} unencrypted:${key} -f
done
3 changes: 2 additions & 1 deletion mkchain/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ You can explicitly specify some values by:
| -------------------------------- | ------------------ | --------------------------------------------------------------------------- | ---------------------- |
| bootstrap_peer | --bootstrap-peer | Peer ip to connect to | |
| images.tezos | --docker-image | Version of the Tezos docker image | tezos/tezos:v8-release |
| number_of_nodes | --number-of-nodes | Number of peers in the cluster | 1 |
| number_of_nodes | --number-of-nodes | Total number of nodes in the cluster | 1 |
| number_of_bakers | --number-of-bakers | Number of nodes in the cluster that are bakers | 1 |
| rpc_auth | --rpc-auth | Whether or not an [RPC auth](../rpc-auth/README.md) backend will be spun up | False |
| zerotier_config.zerotier_network | --zerotier-network | Zerotier network id for external chain access | |
| zerotier_config.zerotier_token | --zerotier-token | Zerotier token for external chain access | |
Loading