Skip to content

Commit

Permalink
Merge pull request #19 from chainflip-io/feat/node-port
Browse files Browse the repository at this point in the history
  • Loading branch information
tomjohnburton authored Sep 12, 2023
2 parents 125fff7 + 45df115 commit 62fda7e
Show file tree
Hide file tree
Showing 15 changed files with 377 additions and 125 deletions.
2 changes: 1 addition & 1 deletion charts/node/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ maintainers:

type: application

version: 0.2.7
version: 0.3.0

appVersion: "0.9.0"
1 change: 1 addition & 0 deletions charts/node/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ Common labels
Selector labels
*/}}
{{- define "chainflip-engine.selectorLabels" -}}
chainflip.io/name: {{ .Release.Name }}
chainflip.io/unit: chainflip-engine
{{- end }}

Expand Down
19 changes: 10 additions & 9 deletions charts/node/templates/engine-cm.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{{- if and (eq .Values.common.role "validator") (eq .Values.engine.settings.existingConfigMap "") }}
{{- $node_endpoint := printf "ws://%s:%s" (include "chainflip-node.fullname" .) .Values.node.ports.rpc -}}
{{- $node_endpoint := printf "ws://%s:%s" (include "chainflip-node.fullname" .) (.Values.node.ports.rpc.port | toString) -}}
apiVersion: v1
kind: ConfigMap
metadata:
Expand All @@ -9,8 +9,8 @@ data:
# Default configurations for the CFE
[node_p2p]
node_key_file = "{{ .Values.common.keys.keysPath }}/{{ .Values.common.keys.nodeKeyFileName }}"
ip_address = "{{ .Values.engine.settings.node_p2p.ip_address | required "You must set an IP address for the node_p2p section e.g. 172.20.220.1" }}"
port = {{ .Values.engine.ports.ip }}
ip_address = "{{ .Values.engine.settings.node_p2p.ip_address | required "You must set an IP address for the node_p2p section e.g. 172.20.220.1, 3.20.245.2" }}"
port = {{ .Values.engine.ports.ip.port }}
allow_local_ip = {{ .Values.engine.settings.node_p2p.allow_local_ip }}
[state_chain]
Expand All @@ -24,10 +24,10 @@ data:
ws_node_endpoint = "{{ required "Please provide a ws_node_endpoint of an Ethereum node" .Values.engine.settings.eth.ws_node_endpoint }}"
http_node_endpoint = "{{ required "Please provide a http_node_endpoint of an Ethereum node" .Values.engine.settings.eth.http_node_endpoint }}"
{{ if .Values.engine.healthcheck.enabled }}
{{ if .Values.engine.ports.healthcheck.enabled }}
[health_check]
hostname = "{{ .Values.engine.healthcheck.hostname }}"
port = {{ .Values.engine.healthcheck.port }}
hostname = "{{ .Values.engine.ports.healthcheck.hostname }}"
port = {{ .Values.engine.ports.healthcheck.port }}
{{- end }}
[signing]
Expand All @@ -41,9 +41,10 @@ data:
http_node_endpoint = "{{ required "Please provide a http_node_endpoint of an Bitcoin node" .Values.engine.settings.btc.http_node_endpoint }}"
rpc_user = "{{ .Values.engine.settings.btc.rpc_user }}"
rpc_password = "{{ .Values.engine.settings.btc.rpc_password }}"
{{- if .Values.engine.metrics.enabled }}
{{- if .Values.engine.ports.metrics.enabled }}
[prometheus]
hostname = "{{ .Values.engine.metrics.hostname }}"
port = {{ .Values.engine.metrics.port }}
hostname = "{{ .Values.engine.ports.metrics.hostname }}"
port = {{ .Values.engine.ports.metrics.port }}
{{- end }}
{{- end }}
51 changes: 36 additions & 15 deletions charts/node/templates/engine-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,48 +3,69 @@ apiVersion: v1
kind: Service
metadata:
name: {{ include "chainflip-engine.fullname" . }}
{{- with .Values.engine.service.annotations }}
{{- with .Values.engine.ports.ip.service.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
labels:
{{- include "chainflip-engine.labels" . | nindent 4 }}
spec:
type: {{ .Values.engine.service.type }}
clusterIP: {{ .Values.engine.settings.node_p2p.ip_address | required "You must set an IP address for the node_p2p section e.g. 172.20.220.1" }}
type: {{ .Values.engine.ports.ip.service.type }}
{{- if .Values.engine.settings.node_p2p.allow_local_ip }}
clusterIP: {{ .Values.engine.settings.node_p2p.ip_address }}
{{- end }}
ports:
- name: ip
port: {{ .Values.engine.ports.ip }}
port: {{ .Values.engine.ports.ip.port }}
targetPort: ip
{{- if eq .Values.engine.ports.ip.service.type "NodePort" }}
nodePort: {{ .Values.engine.ports.ip.service.nodePort | default .Values.engine.ports.ip.port }}
{{- end }}
protocol: TCP
{{- if .Values.engine.healthcheck.enabled }}
- name: healthcheck
port: {{ .Values.engine.healthcheck.port }}
targetPort: healthcheck
protocol: TCP
{{- end }}
selector:
{{- include "chainflip-engine.selectorLabels" . | nindent 4 }}
{{- end }}
---
{{- if .Values.engine.metrics.enabled }}
{{- end }}
{{- if .Values.engine.ports.metrics.enabled }}
apiVersion: v1
kind: Service
metadata:
name: {{ include "chainflip-engine.fullname" . }}-metrics
{{- with .Values.engine.metrics.service.annotations }}
{{- with .Values.engine.ports.metrics.service.annotations }}
annotations:
{{ . | toYaml | nindent 4 }}
{{- end }}
labels:
{{- include "chainflip-engine.labels" . | nindent 4 }}
spec:
type: {{ .Values.engine.metrics.service.type }}
type: {{ .Values.engine.ports.metrics.service.type }}
ports:
- name: metrics
port: {{ .Values.engine.metrics.port }}
port: {{ .Values.engine.ports.metrics.port }}
targetPort: metrics
protocol: TCP
selector:
{{- include "chainflip-engine.selectorLabels" . | nindent 4 }}
---
{{- end }}
{{- if .Values.engine.ports.healthcheck.enabled }}
apiVersion: v1
kind: Service
metadata:
name: {{ include "chainflip-engine.fullname" . }}-healthcheck
{{- with .Values.engine.ports.healthcheck.service.annotations }}
annotations:
{{ . | toYaml | nindent 4 }}
{{- end }}
labels:
{{- include "chainflip-engine.labels" . | nindent 4 }}
spec:
type: {{ .Values.engine.ports.healthcheck.service.type }}
ports:
- name: healthcheck
port: {{ .Values.engine.ports.healthcheck.port }}
targetPort: healthcheck
protocol: TCP
selector:
{{- include "chainflip-engine.selectorLabels" . | nindent 4 }}
{{- end }}
16 changes: 8 additions & 8 deletions charts/node/templates/engine-statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ spec:
- |
set -x
while true; do
nc -zv {{ include "chainflip-node.fullname" . }} {{ .Values.node.ports.rpc }}
nc -zv {{ include "chainflip-node.fullname" . }} {{ .Values.node.ports.rpc.port }}
if [ $? -eq 0 ]; then
exit 0
fi
Expand All @@ -53,18 +53,17 @@ spec:
{{- toYaml . | nindent 12 }}
{{- end }}
ports:
- containerPort: {{ .Values.engine.ports.ip }}
- containerPort: {{ .Values.engine.ports.ip.port }}
name: ip
protocol: TCP
{{- if .Values.engine.healthcheck.enabled }}
- containerPort: {{ .Values.engine.healthcheck.port }}
name: healthcheck
{{- end }}
{{- if .Values.engine.metrics.enabled }}
- containerPort: {{ .Values.engine.metrics.port }}
{{- if .Values.engine.ports.metrics.enabled }}
- containerPort: {{ .Values.engine.ports.metrics.port }}
name: metrics
protocol: TCP
{{- end }}
{{- if .Values.engine.ports.healthcheck.enabled }}
- containerPort: {{ .Values.engine.ports.healthcheck.port }}
name: healthcheck
readinessProbe:
httpGet:
path: /health
Expand All @@ -83,6 +82,7 @@ spec:
timeoutSeconds: 5
successThreshold: 1
failureThreshold: 3
{{- end }}
{{- with .Values.engine.resources }}
resources:
{{- toYaml . | nindent 12 }}
Expand Down
15 changes: 10 additions & 5 deletions charts/node/templates/hook-create-keys.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ spec:
- sh
- -c
- |
chainflip-cli generate-keys json > /tmp/keys.json
chainflip-cli generate-keys --json > /tmp/keys.json
- name: extract-keys
image: stedolan/jq:latest
securityContext:
Expand All @@ -64,10 +64,15 @@ spec:
- /bin/sh
- -c
- |
kubectl create secret generic {{ include "node.fullname" . }} \
--from-file=/tmp/signing-key \
--from-file=/tmp/node-key \
--from-file=/tmp/ethereum-key
if ! kubectl get secret {{ include "node.fullname" . }}; then
echo "Secret does not exist, creating..."
kubectl create secret generic {{ include "node.fullname" . }} \
--from-file=/tmp/signing-key \
--from-file=/tmp/node-key \
--from-file=/tmp/ethereum-key
else
echo "Secret already exists, skipping..."
fi
volumes:
- name: keys
emptyDir: {}
Expand Down
2 changes: 1 addition & 1 deletion charts/node/templates/node-ingress.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{{- if .Values.node.ingress.enabled -}}
{{- $fullName := include "chainflip-node.fullname" . -}}
{{- $svcPort := .Values.node.ports.rpc -}}
{{- $svcPort := .Values.node.ports.rpc.port -}}
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
Expand Down
39 changes: 31 additions & 8 deletions charts/node/templates/node-service.yaml
Original file line number Diff line number Diff line change
@@ -1,43 +1,66 @@
{{- if .Values.node.ports.rpc.enabled }}
apiVersion: v1
kind: Service
metadata:
name: {{ include "chainflip-node.fullname" . }}
{{- with .Values.node.service.annotations }}
{{- with .Values.node.ports.rpc.service.annotations }}
annotations:
{{ . | toYaml | nindent 4 }}
{{- end }}
labels:
{{- include "chainflip-node.labels" . | nindent 4 }}
spec:
type: {{ .Values.node.service.type }}
type: {{ .Values.node.ports.rpc.service.type }}
selector:
{{- include "chainflip-node.selectorLabels" . | nindent 4 }}
ports:
- name: rpc
port: {{ .Values.node.ports.rpc }}
port: {{ .Values.node.ports.rpc.port }}
targetPort: rpc
protocol: TCP
---
{{- end }}
{{- if .Values.node.ports.p2p.enabled }}
apiVersion: v1
kind: Service
metadata:
name: {{ include "chainflip-node.fullname" . }}-p2p
{{- with .Values.node.ports.p2p.service.annotations }}
annotations:
{{ . | toYaml | nindent 4 }}
{{- end }}
labels:
{{- include "chainflip-node.labels" . | nindent 4 }}
spec:
type: {{ .Values.node.ports.p2p.service.type }}
selector:
{{- include "chainflip-node.selectorLabels" . | nindent 4 }}
ports:
- name: p2p
port: {{ .Values.node.ports.p2p }}
port: {{ .Values.node.ports.p2p.port }}
{{- if eq .Values.node.ports.p2p.service.type "NodePort" }}
nodePort: {{ .Values.node.ports.p2p.service.nodePort | default .Values.node.ports.p2p.port }}
{{- end }}
targetPort: p2p
protocol: TCP
---
{{- if .Values.node.metrics.enabled }}
{{- end }}
{{- if .Values.node.ports.metrics.enabled }}
apiVersion: v1
kind: Service
metadata:
name: {{ include "chainflip-node.fullname" . }}-metrics
{{- with .Values.node.metrics.service.annotations }}
{{- with .Values.node.ports.metrics.service.annotations }}
annotations:
{{ . | toYaml | nindent 4 }}
{{- end }}
labels:
{{- include "chainflip-node.labels" . | nindent 4 }}
spec:
type: {{ .Values.node.metrics.service.type }}
type: {{ .Values.node.ports.metrics.service.type }}
ports:
- name: metrics
port: {{ .Values.node.metrics.port }}
port: {{ .Values.node.ports.metrics.port }}
targetPort: metrics
protocol: TCP
selector:
Expand Down
30 changes: 20 additions & 10 deletions charts/node/templates/node-statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -85,38 +85,48 @@ spec:
- --blocks-pruning=archive
- --state-pruning=archive
{{- end }}
- --port={{ .Values.node.ports.p2p }}
{{- if .Values.node.metrics.enabled }}
- --prometheus-port={{ .Values.node.metrics.port }}
{{- if .Values.node.metrics.expose }}
- --port={{ .Values.node.ports.p2p.port }}
{{- if .Values.node.ports.metrics.enabled }}
- --prometheus-port={{ .Values.node.ports.metrics.port }}
{{- if .Values.node.ports.metrics.expose }}
- --prometheus-external
{{- end }}
{{- end }}
{{- if .Values.node.legacyRpc }}
- --rpc-port=9933
- --ws-port={{ .Values.node.ports.rpc }}
- --ws-port={{ .Values.node.ports.rpc.port }}
- --unsafe-ws-external
{{- else }}
- --rpc-port={{ .Values.node.ports.rpc }}
- --rpc-port={{ .Values.node.ports.rpc.port }}
{{- end }}
{{- if .Values.node.ports.rpc.expose }}
- --rpc-cors=all
- --rpc-methods=unsafe
- --unsafe-rpc-external
{{- end }}
{{- with .Values.node.extraArgs }}
{{- toYaml . | nindent 12 }}
{{- end }}
{{- with .Values.node.ports }}
{{- if or (.p2p.enabled) (.rpc.enabled) (.metrics.enabled) }}
ports:
{{- if .rpc.enabled }}
- name: rpc
containerPort: {{ .Values.node.ports.rpc }}
containerPort: {{ .rpc.port }}
protocol: TCP
{{- end }}
{{- if .p2p.enabled }}
- name: p2p
containerPort: {{ .Values.node.ports.p2p }}
containerPort: {{ .p2p.port }}
protocol: TCP
{{- if .Values.node.metrics.enabled }}
{{- end }}
{{- if .metrics.enabled }}
- name: metrics
containerPort: {{ .Values.node.metrics.port }}
containerPort: {{ .metrics.port }}
protocol: TCP
{{- end }}
{{- end }}
{{- end }}
{{- with .Values.node.resources }}
resources:
{{- toYaml . | nindent 12 }}
Expand Down
26 changes: 26 additions & 0 deletions charts/node/tests/engine_service_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
suite: Engine service tests
templates:
- engine-service.yaml
values:
- values/happy.values.yaml
tests:
- it: should create two engine services by default
asserts:
- hasDocuments:
count: 2
- isKind:
of: Service
- it: should assign the default ip port if no nodePort is set
asserts:
- equal:
path: spec.ports[0].port
value: 30078
documentIndex: 0
- equal:
path: spec.ports[0].name
value: ip
documentIndex: 0
- equal:
path: spec.ports[0].targetPort
value: ip
documentIndex: 0
2 changes: 1 addition & 1 deletion charts/node/tests/engine_test.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
suite: chainflip-node tests
suite: chainflip-engine tests
templates:
- engine-statefulset.yaml
tests:
Expand Down
Loading

0 comments on commit 62fda7e

Please sign in to comment.