Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Utility][Infra]Deploy an Anvil node in LocalNet #971

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions build/localnet/Tiltfile
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,16 @@ for x in range(localnet_config["full_nodes"]["count"]):

k8s_resource("full-node-%s-pocket" % formatted_number, labels=["pocket-full-nodes"])

# Provisions anvil node and service for E2E testing
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯

k8s_yaml(
helm(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm getting an error coming form this line when trying to run this code locally .

Running: helm template anvil-node /Users/shakezula/dev/pokt/pocket/charts/anvil --include-crds
Error: Traceback (most recent call last):
  /Users/shakezula/dev/pokt/pocket/build/localnet/Tiltfile:319:9: in <toplevel>
Error in helm: command "helm template anvil-node /Users/shakezula/dev/pokt/pocket/charts/anvil --include-crds" failed.
error: exit status 1
stdout: ""
stderr: "Error: template: anvil/templates/deployment.yaml:8:20: executing \"anvil/templates/deployment.yaml\" at <.Values.autoscaling.enabled>: nil pointer evaluating interface {}.enabled\n\nUse --debug flag to render out invalid YAML\n"
make: *** [localnet_down] Error 1

make localnet_up and make localnet_down are both reporting this error. Have you seen this error before, by chance?

root_dir + "/charts/anvil",
name="anvil-node",
)
)

k8s_resource("anvil-node", labels=["anvil-nodes"])

# Exposes grafana
k8s_resource(
new_name="grafana",
Expand Down
23 changes: 23 additions & 0 deletions charts/anvil/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*.orig
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
20 changes: 20 additions & 0 deletions charts/anvil/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
apiVersion: v2
name: anvil
description: Anvil node for E2E testing of Pocket Network Protocol - decentralized blockchain infrastructure
home: https://pokt.network
sources:
- https://github.com/foundry-rs/foundry
- https://github.com/pokt-network/pocket

type: application

# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.1.0

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "1.0.0"
29 changes: 29 additions & 0 deletions charts/anvil/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# anvil

![Version: 0.1.0](https://img.shields.io/badge/Version-0.1.0-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 1.0.0](https://img.shields.io/badge/AppVersion-1.0.0-informational?style=flat-square)

Anvil node for E2E testing of Pocket Network Protocol - decentralized blockchain infrastructure

**Homepage:** <https://pokt.network>

## Source Code

* <https://github.com/foundry-rs/foundry>
* <https://github.com/pokt-network/pocket>

## Values

| Key | Type | Default | Description |
|-----|------|---------|-------------|
| image.pullPolicy | string | `"IfNotPresent"` | |
| image.repository | string | `"ghcr.io/foundry-rs/foundry"` | |
| image.tag | string | `"v1.0.0"` | |
| replicaCount | int | `1` | |
| service.port | int | `8545` | |
| service.type | string | `"ClusterIP"` | |
| serviceAccount.annotations | object | `{}` | |
| serviceAccount.create | bool | `true` | |
| serviceAccount.name | string | `""` | |

----------------------------------------------
Autogenerated from chart metadata using [helm-docs v1.11.0](https://github.com/norwoodj/helm-docs/releases/v1.11.0)
22 changes: 22 additions & 0 deletions charts/anvil/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
1. Get the application URL by running these commands:
{{- if .Values.ingress.enabled }}
{{- range $host := .Values.ingress.hosts }}
{{- range .paths }}
http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ .path }}
{{- end }}
{{- end }}
{{- else if contains "NodePort" .Values.service.type }}
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "anvil.fullname" . }})
export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}")
echo http://$NODE_IP:$NODE_PORT
{{- else if contains "LoadBalancer" .Values.service.type }}
NOTE: It may take a few minutes for the LoadBalancer IP to be available.
You can watch the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "anvil.fullname" . }}'
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "anvil.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}")
echo http://$SERVICE_IP:{{ .Values.service.port }}
{{- else if contains "ClusterIP" .Values.service.type }}
export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "anvil.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}")
export CONTAINER_PORT=$(kubectl get pod --namespace {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}")
echo "Visit http://127.0.0.1:8080 to use your application"
kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:$CONTAINER_PORT
{{- end }}
62 changes: 62 additions & 0 deletions charts/anvil/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "anvil.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great comment, good to know 👍

If release name contains chart name it will be used as a full name.
*/}}
{{- define "anvil.fullname" -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- $name := default .Chart.Name .Values.nameOverride }}
{{- if contains $name .Release.Name }}
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- end }}
{{- end }}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "anvil.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "anvil.labels" -}}
helm.sh/chart: {{ include "anvil.chart" . }}
{{ include "anvil.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}

{{/*
Selector labels
*/}}
{{- define "anvil.selectorLabels" -}}
app.kubernetes.io/name: {{ include "anvil.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

{{/*
Create the name of the service account to use
*/}}
{{- define "anvil.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "anvil.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
23 changes: 23 additions & 0 deletions charts/anvil/templates/configmap-genesis.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "anvil.fullname" . }}-genesis
labels:
{{- include "anvil.labels" . | nindent 4 }}
data:
# genesis.json for a custom relay chain/service used in E2E tests. This genesis.json is provided as input to the Anvil node, and account and balance
# values are hardcoded in the E2E tests.
#
# Genesis sets the following account and balance:
#
# account: 0xa0Ee7A142d267C1f36714E4a8F75612F20a79720 : one of the development accounts setup automatically by Anvil
# balance: 400000 : arbitrarily selected value, will be hard-coded in E2E tests
genesis.json: |
{
"chain_id": "test-eth",
"difficulty": "1",
"gasLimit": "8000000",
"alloc": {
"0xa0Ee7A142d267C1f36714E4a8F75612F20a79720": { "balance": "400000", "private_key": "0x2a871d0798f97d79848a013d4936a73bf4cc922c825d33c1cf7073dff6d409c6" }
}
}
84 changes: 84 additions & 0 deletions charts/anvil/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "anvil.fullname" . }}
labels:
{{- include "anvil.labels" . | nindent 4 }}
spec:
{{- if not .Values.autoscaling.enabled }}
replicas: {{ .Values.replicaCount }}
{{- end }}
selector:
matchLabels:
{{- include "anvil.selectorLabels" . | nindent 6 }}
template:
metadata:
{{- with .Values.podAnnotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "anvil.selectorLabels" . | nindent 8 }}
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
serviceAccountName: {{ include "anvil.serviceAccountName" . }}
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 8 }}
containers:
- name: {{ .Chart.Name }}
securityContext:
{{- toYaml .Values.securityContext | nindent 12 }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
env:
- name: POD_IP
valueFrom:
fieldRef:
fieldPath: status.podIP
command: ["/bin/sh","-c"]
args: ["anvil --host $POD_IP --port {{ .Values.service.port }} --init /anvil/configs/genesis.json"]
ports:
- name: http
containerPort: {{ .Values.service.port }}
protocol: TCP
volumeMounts:
- name: genesis-volume
mountPath: /anvil/configs/genesis.json
subPath: genesis.json
livenessProbe:
exec:
command:
- sh
- -c
- "netstat -an | grep {{ .Values.service.port }}"
initialDelaySeconds: 10
periodSeconds: 5
readinessProbe:
exec:
command:
- sh
- -c
- "netstat -an | grep {{ .Values.service.port }}"
initialDelaySeconds: 10
periodSeconds: 10
resources:
{{- toYaml .Values.resources | nindent 12 }}
volumes:
- name: genesis-volume
configMap:
name: {{ include "anvil.fullname" . }}-genesis
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
14 changes: 14 additions & 0 deletions charts/anvil/templates/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: v1
kind: Service
metadata:
name: {{ include "anvil.fullname" . }}
labels:
{{- include "anvil.labels" . | nindent 4 }}
spec:
type: {{ .Values.service.type }}
ports:
- port: {{ .Values.service.port }}
protocol: TCP
name: rpc
selector:
{{- include "anvil.selectorLabels" . | nindent 4 }}
12 changes: 12 additions & 0 deletions charts/anvil/templates/serviceaccount.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{{- if .Values.serviceAccount.create -}}
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ include "anvil.serviceAccountName" . }}
labels:
{{- include "anvil.labels" . | nindent 4 }}
{{- with .Values.serviceAccount.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
{{- end }}
15 changes: 15 additions & 0 deletions charts/anvil/templates/tests/test-connection.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: v1
kind: Pod
metadata:
name: "{{ include "anvil.fullname" . }}-test-connection"
labels:
{{- include "anvil.labels" . | nindent 4 }}
annotations:
"helm.sh/hook": test
spec:
containers:
- name: wget
image: busybox
command: ['wget']
args: ['{{ include "anvil.fullname" . }}:{{ .Values.service.port }}']
restartPolicy: Never
24 changes: 24 additions & 0 deletions charts/anvil/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Default values for anvil.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.

replicaCount: 1

image:
repository: ghcr.io/foundry-rs/foundry
# Overrides the image tag whose default is the chart appVersion.
tag: "v1.0.0"
pullPolicy: IfNotPresent

serviceAccount:
# Specifies whether a service account should be created
create: true
# Annotations to add to the service account
annotations: {}
# The name of the service account to use.
# If not set and create is true, a name is generated using the fullname template
name: ""

service:
type: ClusterIP
port: 8545