-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtusk.yml
305 lines (261 loc) · 9.2 KB
/
tusk.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
interpreter: bash -c
name: hoy-chains
usage: |
automation for managing chains on the hoy cluster
options:
launchdir:
usage: >
Don't set this option. Its a work around for a go-tusk peculiarity
environment: PWD
force:
usage: force operation, deleting previous materials if necessary
short: f
type: bool
bbake:
default: 'tusk -qf /home/robin/polysensus/ops/benchblock/tusk.yml'
tuskdir:
private: true
usage: "so all tasks can refer to the directory containing this tusk file"
default:
command: echo $(pwd)
context:
private: true
default: "hoy-1"
namespace-prefix:
private: true # hide for now
default: "chains-"
tasks:
chainid:
usage: "chainid from name"
args:
name:
run:
- command:
exec: |
set -e
cat <<PYEND | python3
lexicon = dict(a=0, j=0, s=0, b=1, k=1, t=1, c=2, l=2, u=2, d=3, m=3, v=3, e=4, n=4, w=4, f=6, o=6, x=6, g=7, p=7, y=7, h=8, q=8, z=8, i=9, r=9)
print(''.join([str(lexicon[ch]) for ch in "${name}"]))
PYEND
new:
usage: "create a new chain"
options:
namespace-prefix:
default: "chains"
short: "p"
primary-domain:
default: "polysensus.io"
forwardauth-url:
default: http://auth-traefikforward.hoy-iam-dev.svc.cluster.local:8401
cluster-name:
default: "hoy"
numnodes:
default: 9
short: "n"
profile:
default: "configs/low-latency.yml"
# XXX: TODO these need to go in a profile.json
numcandidates:
default: 2
numendorsers:
default: 5
committeequorum:
default: 3
netrestrict:
# default is the pod ip (cluster) range for the hoy-dev subnet-dev-1 subnet
default: "10.2.16.0/20"
args:
name:
run:
- command:
exec: |
set -e
DIR=$(cd ${launchdir} && cd ${dir} && pwd)
CHAINID=$(tusk -qf ${tuskdir}/tusk.yml chainid ${name})
echo "CHAINID: $CHAINID"
[ -d chains/${name}-$CHAINID ] && ! ${force} && echo "chain dir chains/${name}-$CHAINID exists, refusing to create"
DOMAIN_SYMBOL=$(echo "${primary-domain}" | tr '.' '-')
CHAIN_FQDN="${cluster-name}.${primary-domain}"
CHAIN_FQDN_SYMBOL=$(echo "$CHAIN_FQDN" | tr '.' '-')
SECURE_TOKEN_SERVICE_FQDN="sts.${cluster-name}.${primary-domain}"
NODE_PATH="/chains/${name}-$CHAINID/node"
FORWARDAUTH_URL="${forwardauth-url}$NODE_PATH/exchange"
NODE_NAMESPACE="${namespace-prefix}-${name}"
FLUX_DESTDIR="fluxcd/${name}-$CHAINID"
CHAINDIR="chains/${name}-$CHAINID"
BOOTNODE0_IP=34.142.43.54
BOOTNODE0_NODEPORT=31210
BOOTNODE1_IP=34.142.43.54
BOOTNODE1_NODEPORT=31213
BBAKE="${bbake}"
# Note there is something VERY wierd abot options / args processing
# with tusk. The error 'task "xxx" requires exactly 2 args, got 1'
# meanst that one of the options is causing a mis count. *either*
# on needs a space replacing with an equals --foo bar -> --foo=bar
# OR we need a --bar=foo to become --bar foo. netrestrict requires
# a space. the rest all need =. this is clearly bad behaviour in
# tusk
${BBAKE} new \
--netrestrict ${netrestrict} \
--init-only \
--k8s \
-p=${profile} \
--chainid=$CHAINID \
--networkid=$CHAINID \
--node-namespace=$NODE_NAMESPACE \
--maxnodes=${numnodes} \
--numcandidates=${numcandidates} \
--numendorsers=${numendorsers} \
--committeequorum=${committeequorum} \
--sealedsecrets-cert=https://${cluster-name}.${primary-domain}/_/sealed-secrets/v1/cert.pem \
--apisec \
--apisec-certname=wild-$CHAIN_FQDN_SYMBOL \
--apisec-certissuer letsencrypt-prod-primary-dns \
--apisec-ingresshost=$CHAIN_FQDN \
--apisec-issuer=https://${SECURE_TOKEN_SERVICE_FQDN} \
--apisec-nodepath=$NODE_PATH \
--apisec-tokenex=$FORWARDAUTH_URL \
--bootnode0-ip=$BOOTNODE0_IP \
--bootnode0-nodeport=$BOOTNODE0_NODEPORT \
--bootnode1-ip=$BOOTNODE1_IP \
--bootnode1-nodeport=$BOOTNODE1_NODEPORT \
--pyenv=$(pwd)/.local/pyenv \
$CHAINDIR rrr
${BBAKE} rrr --init-only $CHAINDIR
genesis:
usage: "generate keys, alpha and genesis document for the initial node set"
args:
name:
run:
- command:
exec: |
set -e
BBAKE="${bbake}"
DIR=$(cd ${launchdir} && cd ${dir} && pwd)
CHAINID=$(tusk -qf ${tuskdir}/tusk.yml chainid ${name})
FLUX_DESTDIR="fluxcd/${name}-$CHAINID"
CHAINDIR="chains/${name}-$CHAINID"
for cmd in gethkeys gethstatic rrralpha rrrinit; do
${BBAKE} ${cmd} $CHAINDIR
echo "Completed: $cmd"
done
hydrate:
usage: |
generate the node kubernetes manifests. this can update geth command line
options for the nodes and tweak the consensus parameters (for as long as
those are available on the cli).
This command DOES NOT change keys or genesis
args:
name:
run:
- command:
exec: |
set -e
BBAKE="${bbake}"
DIR=$(cd ${launchdir} && cd ${dir} && pwd)
CHAINID=$(tusk -qf ${tuskdir}/tusk.yml chainid ${name})
FLUX_DESTDIR="fluxcd/${name}-$CHAINID"
CHAINDIR="chains/${name}-$CHAINID"
for cmd in clientcfg rrropts gethk8s; do
${BBAKE} ${cmd} $CHAINDIR
echo "Completed: $cmd"
done
nodekey:
usage: |
get the node private key directly from the cluster
options:
node:
short: "n"
default: 0
args:
name:
run:
- command:
exec: |
set -e
NAMESPACE=${namespace-prefix}${name}
CONTEXT=${context}
kubectl get secret --context ${CONTEXT} --namespace $NAMESPACE \
ethnodekey-${node} -o json \
| jq -r .data.key | base64 -d
nodewallet:
usage: |
get the node wallet directly from the cluster, requries forgers & cast installed
run:
- command:
exec: |
set -e
NAMESPACE=${namespace-prefix}${name}
CONTEXT=${context}
PRIVATE_KEY=$(kubectl get secret --context $CONTEXT --namespace $NAMESPACE \
ethnodekey-0 -o json \
| jq -r .data.key | base64 -d)
cast wallet address --private-key $PRIVATE_KEY | cut -d ' ' -f2
resetchanges:
usage: |
Undo local (and not committed) changes to the resources
run:
- command:
exec: |
set -e
git checkout chains
git clean -fdx
reconcile:
usage: |
reconcile flux source & kustomization
run:
- command:
exec: |
set -e
flux -n flux-system reconcile source git hoy-chains
flux -n flux-system reconcile kustomization hoy-chains
fluxseal:
usage: |
(re)generate bitnami sealed secrets and related kz manifests for use with gitops and flux
This DOES NOT need to be run after running hydrate
args:
name:
run:
- command:
exec: |
set -e
BBAKE="${bbake}"
DIR=$(cd ${launchdir} && cd ${dir} && pwd)
CHAINID=$(tusk -qf ${tuskdir}/tusk.yml chainid ${name})
FLUX_DESTDIR="fluxcd/${name}-$CHAINID"
CHAINDIR="chains/${name}-$CHAINID"
${BBAKE} gethsealedsecrets --destdir=$FLUX_DESTDIR $CHAINDIR
# Now move the sensitive material to .local
for i in $(seq 0 $((${numnodes} - 1))); do
mkdir -p .local/$CHAINDIR/rrr/nodes/node$i
mv -v $CHAINDIR/rrr/nodes/node$i/key .local/$CHAINDIR/rrr/nodes/node$i
done
suspend-cd:
usage: suspend the automatic fluxcd kustomization reconciliation
run:
- command:
exec: |
flux suspend kustomization -n flux-system hoy-chains
resume-cd:
usage: resume the automatic fluxcd kustomization reconciliation
run:
- command:
exec: |
flux resume kustomization -n flux-system hoy-chains
reset-chain:
usage: |
bring down the network and delete the persistentvolumeclaim's
args:
name:
run:
- task: suspend-cd
- command:
exec: |
CHAIN_NAMESPACE=${namespace-prefix}${name}
for name in $(kubectl get -n $CHAIN_NAMESPACE statefulset -l app.kubernetes.io/part-of=ethnet -o name); do
kubectl delete -n $CHAIN_NAMESPACE $name
done
for name in $(kubectl get -n $CHAIN_NAMESPACE persistentvolumeclaim -l app.kubernetes.io/part-of=ethnet -o name); do
kubectl delete -n $CHAIN_NAMESPACE $name
done
- task: resume-cd