Skip to content

Commit

Permalink
add and use template function to evaluate fullchain dict from just th…
Browse files Browse the repository at this point in the history
…e name, used in all relayers (#256)
  • Loading branch information
Anmol1696 authored Oct 1, 2023
1 parent 77d641a commit 1fbc3e8
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 43 deletions.
18 changes: 18 additions & 0 deletions charts/devnet/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,24 @@ If release name contains chart name it will be used as a full name.
{{- end }}
{{- end }}

{{/*
Given the name of the name, return full chain, merged with the default chain
Usage:
{{ include "devnet.fullchain" (dict "name" "osmosis-1" "defaultFile" $defaultFile "context" $) }}
*/}}
{{- define "devnet.fullchain" -}}
{{ $defaultFile := .defaultFile }}
{{ $fullchain := dict }}
{{- range $chain := .context.Values.chains }}
{{- if eq $chain.name .name }}
{{ $defaultChain := get $defaultFile.defaultChains $chain.type | default dict }}
{{ $chain = merge $chain $defaultChain }}
{{ $fullchain = $chain }}
{{- end }}
{{- end }}
{{ mustToJson $fullchain }}
{{- end }}

{{/*
Create chart name and version as used by the chart label.
*/}}
Expand Down
9 changes: 2 additions & 7 deletions charts/devnet/templates/relayers/go-relayer/configmap.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{{- $keys := .Files.Get "configs/keys.json" | fromJson }}
{{ $defaultFile := $.Files.Get "defaults.yaml" | fromYaml }}
{{- range $relayer := .Values.relayers }}
{{- if eq $relayer.type "go-relayer" }}
---
Expand All @@ -22,11 +23,7 @@ data:
}
{{- range $i, $chain := $relayer.chains }}
{{- range $fullchain := $.Values.chains }}
{{- if eq $fullchain.name $chain }}
{{ $defaultFile := $.Files.Get "defaults.yaml" | fromYaml }}
{{ $defaultChain := get $defaultFile.defaultChains $fullchain.type | default dict }}
{{ $fullchain = merge $fullchain $defaultChain }}
{{ $fullchain := include "devnet.fullchain" (dict "name" $chain "defaultFile" $defaultFile "context" $) | mustFromJson }}
{{ $fullchain.name }}.json: |-
{
"type": "cosmos",
Expand All @@ -46,8 +43,6 @@ data:
}
}
{{- end }}
{{- end }}
{{- end }}
---
{{- end }}
{{- end }}
8 changes: 1 addition & 7 deletions charts/devnet/templates/relayers/go-relayer/statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,7 @@ spec:
rly config init
{{- range $i, $chain := $relayer.chains }}
{{- range $fullchain := $.Values.chains }}
{{- if eq $fullchain.name $chain }}
{{ $defaultFile := $.Files.Get "defaults.yaml" | fromYaml }}
{{ $defaultChain := get $defaultFile.defaultChains $fullchain.type | default dict }}
{{ $fullchain = merge $fullchain $defaultChain }}
{{ $fullchain := include "devnet.fullchain" (dict "name" $chain "defaultFile" $defaultFile "context" $) | mustFromJson }}
echo "Adding {{ $fullchain.name }} chain"
rly chains add --file "/configs/{{ $fullchain.name }}.json" {{ $fullchain.name }}
Expand All @@ -77,8 +73,6 @@ spec:
echo "Transfer tokens to address $RLY_ADDR on {{ $fullchain.name }} chain with denom $DENOM"
bash -e /scripts/transfer-tokens.sh $RLY_ADDR $DENOM http://{{ include "devnet.chain.name" $fullchain.name }}-genesis.$NAMESPACE.svc.cluster.local:8000/credit
{{- end }}
{{- end }}
{{- end }}
PATHEND="{{ index $relayer.chains 0 }}-{{ index $relayer.chains 1 }}"
echo "Creating path $PATHEND"
Expand Down
8 changes: 1 addition & 7 deletions charts/devnet/templates/relayers/hermes/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,7 @@ data:
# by the telemetry service. Default: 3001
port = {{ $relayer.config.telemetry.port }}
{{- range $i, $chain := $relayer.chains }}
{{- range $fullchain := $.Values.chains }}
{{- if eq $fullchain.name $chain }}
{{ $defaultFile := $.Files.Get "defaults.yaml" | fromYaml }}
{{ $defaultChain := get $defaultFile.defaultChains $fullchain.type | default dict }}
{{ $fullchain = merge $fullchain $defaultChain }}
{{ $fullchain := include "devnet.fullchain" (dict "name" $chain "defaultFile" $defaultFile "context" $) | mustFromJson }}
[[chains]]
id = "{{ $chain }}"
key_name = "{{ $chain }}"
Expand Down Expand Up @@ -125,8 +121,6 @@ data:
gas_price = { price = 0.25, denom = "{{ $fullchain.denom }}" }
{{- end }}
{{- end }}
{{- end }}
{{- end }}
---
{{- end }}
{{- end }}
8 changes: 1 addition & 7 deletions charts/devnet/templates/relayers/hermes/statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,7 @@ spec:
echo $MNEMONIC > $RELAYER_DIR/mnemonic.txt
{{- range $i, $chain := $relayer.chains }}
{{- range $fullchain := $.Values.chains }}
{{- if eq $fullchain.name $chain }}
{{ $defaultFile := $.Files.Get "defaults.yaml" | fromYaml }}
{{ $defaultChain := get $defaultFile.defaultChains $fullchain.type | default dict }}
{{ $fullchain = merge $fullchain $defaultChain }}
{{ $fullchain := include "devnet.fullchain" (dict "name" $chain "defaultFile" $defaultFile "context" $) | mustFromJson }}
echo "Creating key for {{ $chain }}..."
hermes keys add \
--chain {{ $chain }} \
Expand All @@ -81,8 +77,6 @@ spec:
echo "Transfer tokens to address $RLY_ADDR"
bash -e /scripts/transfer-tokens.sh $RLY_ADDR $DENOM http://{{- include "devnet.chain.name" $fullchain.name }}-genesis.$NAMESPACE.svc.cluster.local:8000/credit
{{- end }}
{{- end }}
{{- end }}
hermes create channel \
--a-chain {{ index $relayer.chains 0 }} \
Expand Down
11 changes: 3 additions & 8 deletions charts/devnet/templates/relayers/ts-relayer/configmap.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{{- $keys := .Files.Get "configs/keys.json" | fromJson }}
{{- $defaultFile := $.Files.Get "defaults.yaml" | fromYaml }}
{{- range $relayer := .Values.relayers }}
{{- if eq $relayer.type "ts-relayer" }}
---
Expand All @@ -17,12 +18,8 @@ data:
chains:
{{- range $i, $chain := $relayer.chains }}
{{ $chain }}:
{{- range $fullchain := $.Values.chains }}
{{- if eq $fullchain.name $chain }}
{{ $defaultFile := $.Files.Get "defaults.yaml" | fromYaml }}
{{ $defaultChain := get $defaultFile.defaultChains $fullchain.type | default dict }}
{{ $fullchain = merge $fullchain $defaultChain }}
chain_id: {{ $chain }}
{{ $fullchain := include "devnet.fullchain" (dict "name" $chain "defaultFile" $defaultFile "context" $) | mustFromJson }}
chain_id: {{ $chain }}
# You can include multiple RPC endpoints and it will rotate through them if
# one is down (TODO)
rpc:
Expand All @@ -39,8 +36,6 @@ data:
ics20_port: 'transfer'
estimated_block_time: {{ $.Values.timeouts.timeout_commit | toString | replace "ms" "" | float64 }}
estimated_indexer_time: {{ $.Values.timeouts.time_iota_ms | toString | replace "ms" "" | float64 }}
{{- end }}
{{- end }}
{{- end }}
---
{{- end }}
Expand Down
8 changes: 1 addition & 7 deletions charts/devnet/templates/relayers/ts-relayer/statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,12 @@ spec:
sed -i -e "s/<MNEMONIC>/$MNEMONIC/g" $RELAYER_DIR/app.yaml
{{- range $i, $chain := $relayer.chains }}
{{- range $fullchain := $.Values.chains }}
{{- if eq $fullchain.name $chain }}
{{ $defaultFile := $.Files.Get "defaults.yaml" | fromYaml }}
{{ $defaultChain := get $defaultFile.defaultChains $fullchain.type | default dict }}
{{ $fullchain = merge $fullchain $defaultChain }}
{{ $fullchain := include "devnet.fullchain" (dict "name" $chain "defaultFile" $defaultFile "context" $) | mustFromJson }}
DENOM="{{ $fullchain.denom }}"
RLY_ADDR=$(ibc-setup keys list | grep "{{ $fullchain.name }}" | awk '{print $2}')
echo "Transfer tokens to address $RLY_ADDR"
bash -e /scripts/transfer-tokens.sh $RLY_ADDR $DENOM http://{{ include "devnet.chain.name" $fullchain.name }}-genesis.$NAMESPACE.svc.cluster.local:8000/credit
{{- end }}
{{- end }}
{{- end }}
if [ $RLY_INDEX -eq 0 ]; then
echo "Setting up default ics20 channel"
Expand Down

0 comments on commit 1fbc3e8

Please sign in to comment.