Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into anmol/faucet-less
Browse files Browse the repository at this point in the history
  • Loading branch information
Anmol1696 committed Oct 9, 2023
2 parents faea233 + 010b357 commit 4bc530b
Show file tree
Hide file tree
Showing 15 changed files with 185 additions and 176 deletions.
2 changes: 0 additions & 2 deletions charts/devnet/scripts/update-config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,3 @@ sed -i -e "s#timeout_commit = \".*\"#timeout_commit = \"$TIMEOUT_COMMIT\"#g" $CH
if [ "$METRICS" == "true" ]; then
sed -i -e "s/prometheus = false/prometheus = true/g" $CHAIN_DIR/config/config.toml
fi

$CHAIN_BIN tendermint show-node-id
60 changes: 60 additions & 0 deletions charts/devnet/templates/_chains.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{{/*
Given a chain name, create a fullchain dict and return
Usage:
{{ include "devnet.getchain" (dict "name" cosmoshub-4 "file" $.File "context" $) }}
*/}}
{{- define "devnet.getchain" -}}
{{- $defaultFile := $.file -}}
{{- required "default file must have setup" $defaultFile.defaultChains -}}
{{- $chain := dict -}}
{{- range $chainIter := $.context.Values.chains -}}
{{- if eq $chainIter.name $.name -}}
{{- $chain = $chainIter | deepCopy -}}
{{- end }}
{{- end }}
{{- required "chain need to exist" $chain.type -}}

{{- $defaultChain := get $defaultFile.defaultChains $chain.type | default dict -}}

{{/* merge defaultChain values into the $chain dict*/}}
{{- $chain = merge $chain $defaultChain -}}

{{ $_ := set $chain "hostname" (include "devnet.chain.name" $chain.name) }}

{{- $faucet := get $chain "faucet" | default dict -}}
{{- $faucet = mergeOverwrite ($.context.Values.faucet | deepCopy) $faucet -}}
{{- $defaultFaucet := get $defaultFile.defaultFaucet $faucet.type | default dict -}}
{{- $faucet = merge $faucet $defaultFaucet -}}
{{ $_ = set $chain "faucet" $faucet -}}

{{- if not (hasKey $chain "upgrade")}}
{{ $_ = set $chain "upgrade" (dict "enabled" false) }}
{{- end }}

{{- if not (hasKey $chain "build")}}
{{ $_ = set $chain "build" (dict "enabled" false) }}
{{- end }}

{{- $toBuild := or $chain.build.enabled $chain.upgrade.enabled -}}
{{- $_ = set $chain "toBuild" $toBuild -}}
{{- if $toBuild -}}
{{- $_ = set $chain "image" "ghcr.io/cosmology-tech/starship/runner:latest" -}}
{{- end }}

{{- $defaultScripts := $defaultFile.defaultScripts }}
{{- $scripts := get $chain "scripts" | default dict }}
{{- $scripts = merge $scripts $defaultScripts }}
{{- $_ = set $chain "scripts" $scripts }}

{{ println "@return" }}
{{ mustToJson $chain }}
{{- end -}}

{{/*
Given a chain name, create a fullchain dict and return. Wraper
Usage:
{{ include "devnet.fullchain" (dict "name" cosmoshub-4 "file" $defaultFile "context" $) | fromtJson }}
*/}}
{{- define "devnet.fullchain"}}
{{ index (splitList "@return\n" (include "devnet.getchain" .)) 1 }}
{{- end }}
42 changes: 42 additions & 0 deletions charts/devnet/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -278,3 +278,45 @@ Usage:
{{- $tag := regexFind "[^:]+$" . -}}
{{ $tag }}
{{- end -}}

{{/*
Given a chain name, create a fullchain dict and return
Usage:
{{ include "devnet.fullchain" (dict "name" cosmoshub-4 "file" $.File "context" $) }}
*/}}
{{- define "devnet.getchain" -}}
{{- $defaultFile := $.file -}}
{{- required "default file must have setup" $defaultFile.defaultChains -}}
{{- $chain := dict -}}
{{- range $chainIter := $.context.Values.chains -}}
{{- if eq $chainIter.name $.name -}}
{{- $chain = $chainIter | deepCopy -}}
{{- end }}
{{- end }}
{{- required "chain need to exist" $chain.type -}}

{{- $defaultChain := get $defaultFile.defaultChains $chain.type | default dict -}}

{{/* merge defaultChain values into the $chain dict*/}}
{{- $chain = merge $chain $defaultChain -}}

{{- $faucet := get $chain "faucet" | default dict -}}
{{- $faucet = mergeOverwrite ($.context.Values.faucet | deepCopy) $faucet -}}
{{- $defaultFaucet := get $defaultFile.defaultFaucet $faucet.type | default dict -}}
{{- $faucet = merge $faucet $defaultFaucet -}}
{{ $_ := set $chain "faucet" $faucet -}}

{{- $upgrade := $chain.upgrade | default (dict "enabled" false) -}}
{{- $build := .build | default (dict "enabled" false) -}}
{{- $toBuild := or $build.enabled $upgrade.enabled -}}
{{- $_ = set $chain "toBuild" $toBuild -}}
{{- if $toBuild -}}
{{- $_ = set $chain "image" "ghcr.io/cosmology-tech/starship/runner:latest" -}}
{{- end }}
{{ println "@return" }}
{{ mustToJson $chain }}
{{- end -}}

{{- define "devnet.fullchain"}}
{{ index (splitList "@return\n" (include "devnet.getchain" .)) 1 }}
{{- end }}
24 changes: 3 additions & 21 deletions charts/devnet/templates/chains/cosmos/configmap.yaml
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
{{- range $chain := .Values.chains }}
{{- if ne $chain.type "virtual" }}
{{ $defaultFile := $.Files.Get "defaults.yaml" | fromYaml }}
{{ $defaultScripts := $defaultFile.defaultScripts }}
{{ $defaultChain := get $defaultFile.defaultChains $chain.type | default dict }}

# merge defaultChain values into the $chain dict
{{ $chain = merge $chain $defaultChain }}

{{ $scripts := get $chain "scripts" | default dict }}
{{ $scripts = merge $scripts $defaultScripts }}
{{ $chain := include "devnet.fullchain" (dict "name" $chain.name "file" $defaultFile "context" $) | fromJson }}
---
apiVersion: v1
kind: ConfigMap
metadata:
name: setup-scripts-{{- include "devnet.chain.name" $chain.name }}
data:
{{- range $k, $v := $scripts }}
{{- range $k, $v := $chain.scripts }}
{{- if hasKey $v "data" }}
{{ $v.name }}: |-
{{- $v.data | nindent 4 }}
Expand All @@ -25,23 +18,12 @@ data:
{{- end }}
{{- end }}
---
{{- end }}
{{- end }}
---
{{- range $chain := .Values.chains }}
{{- if ne $chain.type "virtual" }}
{{ $defaultFile := $.Files.Get "defaults.yaml" | fromYaml }}
{{ $defaultScripts := $defaultFile.defaultScripts }}
{{ $defaultChain := get $defaultFile.defaultChains $chain.type | default dict }}

# merge defaultChain values into the $chain dict
{{ $chain = merge $chain $defaultChain }}
{{- if hasKey $chain "genesis" }}
---
apiVersion: v1
kind: ConfigMap
metadata:
name: patch-{{- include "devnet.chain.name" $chain.name }}
name: patch-{{ $chain.hostname }}
data:
genesis.json: |-
{{ toJson $chain.genesis | nindent 4 }}
Expand Down
79 changes: 32 additions & 47 deletions charts/devnet/templates/chains/cosmos/genesis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,15 @@
{{- if ne $chain.type "virtual" }}
{{ $dataExposer := dict "chain" $chain.name "port" ($.Values.exposer.ports.rest | quote | default "8081") }}
{{ $defaultFile := $.Files.Get "defaults.yaml" | fromYaml }}
{{ $defaultChain := get $defaultFile.defaultChains $chain.type | default dict }}

# merge defaultChain values into the $chain dict
{{ $chain = merge $chain $defaultChain }}

{{- $upgrade := $chain.upgrade | default (dict "enabled" false) }}
{{- $build := .build | default (dict "enabled" false) -}}
{{- $toBuild := or $build.enabled $upgrade.enabled }}

# read faucet from chain values and merge with default faucet values
{{ $faucet := get $chain "faucet" | default dict }}
{{ $faucet = mergeOverwrite ($.Values.faucet | deepCopy) $faucet }}

{{ $defaultFaucet := get $defaultFile.defaultFaucet $faucet.type | default dict }}
{{ $faucet = merge $faucet $defaultFaucet }}

{{ $image := $chain.image }}
{{- if $toBuild }}
{{ $image = "ghcr.io/cosmology-tech/starship/runner:latest" }}
{{- end }}
{{ $chain := include "devnet.fullchain" (dict "name" $chain.name "file" $defaultFile "context" $) | fromJson }}
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: {{ include "devnet.chain.name" $chain.name }}-genesis
name: {{ $chain.hostname }}-genesis
spec:
serviceName: {{ include "devnet.chain.name" $chain.name }}-genesis
serviceName: {{ $chain.hostname }}-genesis
replicas: 1
revisionHistoryLimit: 3
selector:
Expand All @@ -51,7 +33,7 @@ spec:
spec:
{{- include "imagePullSecrets" $chain | indent 6 }}
initContainers:
{{- if $toBuild }}
{{- if $chain.toBuild }}
- name: init-build-images
image: ghcr.io/cosmology-tech/starship/builder:latest
imagePullPolicy: IfNotPresent
Expand All @@ -63,12 +45,12 @@ spec:
go install github.com/cosmos/cosmos-sdk/cosmovisor/cmd/cosmovisor@v1.0.0
# Build genesis
{{- if $upgrade.enabled }}
{{- if $chain.upgrade.enabled }}
UPGRADE_NAME=genesis CODE_TAG={{ $chain.upgrade.genesis }} bash -e /scripts/build-chain.sh
{{- range $upgrade := $chain.upgrade.upgrades }}
UPGRADE_NAME={{ $upgrade.name }} CODE_TAG={{ $upgrade.version }} bash -e /scripts/build-chain.sh
{{- end }}
{{- else if $build.enabled }}
{{- else if $chain.build.enabled }}
UPGRADE_NAME=genesis CODE_TAG={{ $chain.build.source }} bash -e /scripts/build-chain.sh
{{- end }}
env:
Expand All @@ -91,7 +73,7 @@ spec:
name: scripts
{{- end }}
- name: init-genesis
image: {{ $image }}
image: {{ $chain.image }}
imagePullPolicy: Always
env:
{{- include "devnet.defaultEvnVars" $chain | indent 12 }}
Expand All @@ -100,7 +82,7 @@ spec:
- name: KEYS_CONFIG
value: /configs/keys.json
- name: FAUCET_ENABLED
value: "{{ $faucet.enabled }}"
value: "{{ $chain.faucet.enabled }}"
- name: NUM_VALIDATORS
value: "{{ $chain.numValidators }}"
command:
Expand All @@ -109,7 +91,7 @@ spec:
- |
VAL_INDEX=${HOSTNAME##*-}
echo "Validator Index: $VAL_INDEX"
{{- if $toBuild }}
{{- if $chain.toBuild }}
cp $CHAIN_DIR/cosmovisor/genesis/bin/$CHAIN_BIN /usr/bin
{{- end }}
Expand All @@ -130,7 +112,7 @@ spec:
- mountPath: /scripts
name: scripts
- name: init-config
image: {{ $image }}
image: {{ $chain.image }}
imagePullPolicy: Always
env:
{{- include "devnet.defaultEvnVars" $chain | indent 12 }}
Expand All @@ -146,6 +128,9 @@ spec:
- |
VAL_INDEX=${HOSTNAME##*-}
echo "Validator Index: $VAL_INDEX"
{{- if $chain.toBuild }}
cp $CHAIN_DIR/cosmovisor/genesis/bin/$CHAIN_BIN /usr/bin
{{- end }}
echo "Running setup config script..."
{{- if hasKey $chain "genesis" }}
Expand All @@ -165,9 +150,9 @@ spec:
name: patch
{{- end }}
{{/*if faucet is of type starship, then initialize faucet binary*/}}
{{- if and ($faucet.enabled) (eq $faucet.type "starship") }}
{{- if and ($chain.faucet.enabled) (eq $chain.faucet.type "starship") }}
- name: init-faucet
image: {{ $faucet.image }}
image: {{ $chain.faucet.image }}
imagePullPolicy: IfNotPresent
command:
- bash
Expand All @@ -183,18 +168,18 @@ spec:
{{- end }}
containers:
- name: validator
image: {{ $image }}
image: {{ $chain.image }}
imagePullPolicy: Always
env:
{{- include "devnet.defaultEvnVars" $chain | indent 12 }}
{{- include "devnet.evnVars" $chain | indent 12 }}
- name: FAUCET_ENABLED
value: "{{ $faucet.enabled }}"
value: "{{ $chain.faucet.enabled }}"
command:
- bash
- "-c"
- |
{{- if $toBuild }}
{{- if $chain.toBuild }}
/usr/bin/cosmovisor start
{{- else }}
$CHAIN_BIN start
Expand Down Expand Up @@ -233,16 +218,16 @@ spec:
name: node
- mountPath: /configs
name: addresses
{{- if $faucet.enabled }}
{{- if eq $faucet.type "cosmjs" }}
{{- if $chain.faucet.enabled }}
{{- if eq $chain.faucet.type "cosmjs" }}
- name: faucet
image: {{ $faucet.image }}
image: {{ $chain.faucet.image }}
imagePullPolicy: Always
env:
- name: FAUCET_CONCURRENCY
value: "{{ $faucet.concurrency }}"
value: "{{ $chain.faucet.concurrency }}"
- name: FAUCET_PORT
value: "{{ $faucet.ports.rest }}"
value: "{{ $chain.faucet.ports.rest }}"
- name: FAUCET_MEMO
value: "faucet txn"
- name: FAUCET_GAS_PRICE
Expand Down Expand Up @@ -285,22 +270,22 @@ spec:
volumeMounts:
- mountPath: /configs
name: addresses
resources: {{- include "getResourceObject" $faucet.resources | trim | nindent 12 }}
resources: {{- include "getResourceObject" $chain.faucet.resources | trim | nindent 12 }}
readinessProbe:
httpGet:
path: /status
port: {{ $faucet.ports.rest }}
port: {{ $chain.faucet.ports.rest }}
initialDelaySeconds: 10
periodSeconds: 10
{{- else if eq $faucet.type "starship" }}
{{- else if eq $chain.faucet.type "starship" }}
- name: faucet
image: {{ $image }}
image: {{ $chain.image }}
imagePullPolicy: Always
env:
- name: FAUCET_CONCURRENCY
value: "{{ $faucet.concurrency }}"
value: "{{ $chain.faucet.concurrency }}"
- name: FAUCET_HTTP_PORT
value: "{{ $faucet.ports.rest }}"
value: "{{ $chain.faucet.ports.rest }}"
- name: FAUCET_CHAIN_BINARY
value: "{{ $chain.binary }}"
- name: FAUCET_CHAIN_ID
Expand Down Expand Up @@ -337,11 +322,11 @@ spec:
name: addresses
- mountPath: /faucet
name: faucet
resources: {{- include "getResourceObject" $faucet.resources | trim | nindent 12 }}
resources: {{- include "getResourceObject" $chain.faucet.resources | trim | nindent 12 }}
readinessProbe:
httpGet:
path: /status
port: {{ $faucet.ports.rest }}
port: {{ $chain.faucet.ports.rest }}
initialDelaySeconds: 10
periodSeconds: 10
{{- end }}
Expand All @@ -360,7 +345,7 @@ spec:
configMap:
name: patch-{{- include "devnet.chain.name" $chain.name }}
{{- end }}
{{- if and ($faucet.enabled) (eq $faucet.type "starship") }}
{{- if and ($chain.faucet.enabled) (eq $chain.faucet.type "starship") }}
- name: faucet
emptyDir: { }
{{- end }}
Expand Down
1 change: 0 additions & 1 deletion charts/devnet/templates/chains/cosmos/service.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{{ $portMap := dict "p2p" 26656 "rpc" 26657 "grpc" 9090 "rest" 1317 }}
{{- range $chain := .Values.chains }}
{{- if ne $chain.type "virtual" }}

---
apiVersion: v1
kind: Service
Expand Down
Loading

0 comments on commit 4bc530b

Please sign in to comment.