Skip to content

Commit

Permalink
feature: add registry.locahost for setting rpc, grpc and rest addre…
Browse files Browse the repository at this point in the history
…sses (#214)

* add ability to set endpoints based on localhost in registry service

* add todo comment

* set localhost var before for loop

* fix typos in helper function, update test to assert for values if needed

* add seperate vars for reading and exposing api endpoint from registry, use custom local registry image for testing

* fix tests, typos

* fix liniting issues
  • Loading branch information
Anmol1696 committed Sep 5, 2023
1 parent 39adb37 commit b18b37a
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 9 deletions.
50 changes: 50 additions & 0 deletions charts/devnet/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,63 @@ Returns a comma seperated list of chain id
{{ join "," $values }}
{{- end -}}

{{/*
Returns a comma seperated list of urls for the RPC address based on internal DNS
*/}}
{{- define "devnet.chains.internal.rpc.addrs" -}}
{{- $values := list -}}
{{- range $chain := .Values.chains -}}
{{- $values = printf "http://%s-genesis.$(NAMESPACE).svc.cluster.local:26657" $chain.name | append $values -}}
{{- end -}}
{{ join "," $values }}
{{- end -}}

{{/*
Returns a comma seperated list of urls for the RPC address
*/}}
{{- define "devnet.chains.rpc.addrs" -}}
{{- $localhost := .Values.registry.localhost -}}
{{- $values := list -}}
{{- range $chain := .Values.chains -}}
{{- if and ($localhost) (($chain.ports).rpc) -}}
{{- $values = printf "http://localhost:%v" $chain.ports.rpc | append $values -}}
{{- else -}}
{{- $values = printf "http://%s-genesis.$(NAMESPACE).svc.cluster.local:26657" $chain.name | append $values -}}
{{- end -}}
{{- end -}}
{{ join "," $values }}
{{- end -}}

{{/*
Returns a comma seperated list of urls for the GRPC address.
If registry.localhost is set to true, then use $chain ports
*/}}
{{- define "devnet.chains.grpc.addrs" -}}
{{- $localhost := .Values.registry.localhost -}}
{{- $values := list -}}
{{- range $chain := .Values.chains -}}
{{- if and ($localhost) (($chain.ports).grpc) -}}
{{- $values = printf "http://localhost:%v" $chain.ports.grpc | append $values -}}
{{- else -}}
{{- $values = printf "http://%s-genesis.$(NAMESPACE).svc.cluster.local:9091" $chain.name | append $values -}}
{{- end -}}
{{- end -}}
{{ join "," $values }}
{{- end -}}

{{/*
Returns a comma seperated list of urls for the Rest address.
If registry.localhost is set to true, then use $chain ports
*/}}
{{- define "devnet.chains.rest.addrs" -}}
{{- $localhost := .Values.registry.localhost -}}
{{- $values := list -}}
{{- range $chain := .Values.chains -}}
{{- if and ($localhost) (($chain.ports).rest) -}}
{{- $values = printf "http://localhost:%v" $chain.ports.rest | append $values -}}
{{- else -}}
{{- $values = printf "http://%s-genesis.$(NAMESPACE).svc.cluster.local:1317" $chain.name | append $values -}}
{{- end -}}
{{- end -}}
{{ join "," $values }}
{{- end -}}
Expand Down
6 changes: 6 additions & 0 deletions charts/devnet/templates/registry.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,13 @@ spec:
- name: REGISTRY_CHAIN_CLIENT_IDS
value: "{{ include "devnet.chains.ids" . }}"
- name: REGISTRY_CHAIN_CLIENT_RPCS
value: "{{ include "devnet.chains.internal.rpc.addrs" . }}"
- name: REGISTRY_CHAIN_API_RPCS
value: "{{ include "devnet.chains.rpc.addrs" . }}"
- name: REGISTRY_CHAIN_API_GRPCS
value: "{{ include "devnet.chains.grpc.addrs" . }}"
- name: REGISTRY_CHAIN_API_RESTS
value: "{{ include "devnet.chains.rest.addrs" . }}"
- name: REGISTRY_CHAIN_REGISTRY
value: "/configs"
- name: REGISTRY_CHAIN_CLIENT_EXPOSERS
Expand Down
3 changes: 3 additions & 0 deletions charts/devnet/values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,9 @@
"image": {
"type": "string"
},
"localhost": {
"type": "boolean"
},
"ports": {
"type": "object",
"properties": {
Expand Down
5 changes: 4 additions & 1 deletion charts/devnet/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,10 @@ explorer:

registry:
enabled: false
image: ghcr.io/cosmology-tech/starship/registry:20230829-eaeeb62
# test image, todo: change this to registry service image
image: anmol1696/registry:20230905-7b331fe
# image: ghcr.io/cosmology-tech/starship/registry:20230829-eaeeb62
localhost: true
ports:
rest: 6060
grpc: 7070
Expand Down
1 change: 1 addition & 0 deletions registry/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ run-local:

## Docker commands
docker-setup:
-docker buildx rm starship
docker buildx create --use --name starship

docker-build:
Expand Down
14 changes: 9 additions & 5 deletions registry/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,16 @@ type Config struct {
ChainClientHome string `name:"chain-client-home" json:"chain_client_home" env:"CHAIN_CLIENT_HOME" usage:"Path to the home of lens client directory"`
// ChainClientIDs is a comma seperated list of chain ids for various chains
ChainClientIDs string `name:"chain-client-ids" json:"chain_client_ids" env:"CHAIN_CLIENT_IDS" usage:"Comma seperated list of chain ids for various chains"`
// ChainClientRPCs is a comma seperated list of chain rpc address for various chains
// ChainClientRPCs is a comma seperated list of chain rpc address for various chains, used to create connections
// Note: ChainClientRPCs is different from ChainAPIRPCs, as ChainClientRPCs is used for internal routing
// whereas ChainAPIRPCs is used for /chains endpoint result
ChainClientRPCs string `name:"chain-client-rpcs" json:"chain_client_rpcs" env:"CHAIN_CLIENT_RPCS" usage:"Comma seperated list of chain rpc address for various chains"`
// ChainClientGRPCs is a comma seperated list of chain grpc address for various chains
ChainClientGRPCs string `name:"chain-client-grpcs" json:"chain_client_grpcs" env:"CHAIN_CLIENT_GRPCS" usage:"Comma seperated list of chain grpc address for various chains"`
// ChainClientRESTs is a comma seperated list of chain rest address for various chains
ChainClientRESTs string `name:"chain-client-rests" json:"chain_client_rests" env:"CHAIN_CLIENT_RESTS" usage:"Comma seperated list of chain rest address for various chains"`
// ChainAPIRPCs is a comma seperated list of chain rpc address for various chains, used at output of chain.apis.rpc
ChainAPIRPCs string `name:"chain-api-rpcs" json:"chain_api_rpcs" env:"CHAIN_API_RPCS" usage:"Comma seperated list of chain rpc address, used at output of chain.apis.rpc"`
// ChainAPIGRPCs is a comma seperated list of chain rpc address for various chains, used at output of chain.apis.grpc
ChainAPIGRPCs string `name:"chain-api-grpcs" json:"chain_api_grpcs" env:"CHAIN_API_GRPCS" usage:"Comma seperated list of chain grpc address for various chains, used at output of chain.apis.grpc"`
// ChainAPIRESTs is a comma seperated list of chain rpc address for various chains, used at output of chain.apis.rest
ChainAPIRESTs string `name:"chain-api-rests" json:"chain_api_rests" env:"CHAIN_API_RESTS" usage:"Comma seperated list of chain rest address for various chains, used at output of chain.apis.rest"`
// ChainClientExposers is a comma seperated list of chain exposer endpoints for various chains
ChainClientExposers string `name:"chain-client-exposer" json:"chain_client_exposers" env:"CHAIN_CLIENT_EXPOSERS" usage:"Comma seperated list of chain exposer address"`
// Verbose switches on debug logging
Expand Down
6 changes: 3 additions & 3 deletions registry/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,9 @@ func (a *AppServer) getChainAPIs(ctx context.Context, client *ChainClient) (*pb.
}

apis := &pb.APIs{
Rpc: apiFactory(a.config.ChainClientRPCs),
Grpc: apiFactory(a.config.ChainClientGRPCs),
Rest: apiFactory(a.config.ChainClientRESTs),
Rpc: apiFactory(a.config.ChainAPIRPCs),
Grpc: apiFactory(a.config.ChainAPIGRPCs),
Rest: apiFactory(a.config.ChainAPIRESTs),
}

return apis, nil
Expand Down
9 changes: 9 additions & 0 deletions tests/e2e/registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,15 @@ func (s *TestSuite) TestRegistry_GetChain() {

s.Assert().Equal(chain.Name, respChain.ChainId)
s.Assert().Equal(chain.Type, respChain.ChainName)
if chain.Ports.Rpc != 0 {
s.Assert().Equal(fmt.Sprintf("http://localhost:%d", chain.Ports.Rpc), respChain.Apis.Rpc[0].Address)
}
if chain.Ports.Grpc != 0 {
s.Assert().Equal(fmt.Sprintf("http://localhost:%d", chain.Ports.Grpc), respChain.Apis.Grpc[0].Address)
}
if chain.Ports.Rest != 0 {
s.Assert().Equal(fmt.Sprintf("http://localhost:%d", chain.Ports.Rest), respChain.Apis.Rest[0].Address)
}
}
}

Expand Down

0 comments on commit b18b37a

Please sign in to comment.