From 51070b0ddc17627ca5baf24ef2a98b1946492efa Mon Sep 17 00:00:00 2001 From: Arash Deshmeh Date: Mon, 7 Aug 2023 15:33:46 -0400 Subject: [PATCH 1/2] Deploy an Anvil node in LocalNet --- build/localnet/Tiltfile | 10 +++ charts/anvil/.helmignore | 23 +++++ charts/anvil/Chart.yaml | 20 +++++ charts/anvil/templates/NOTES.txt | 22 +++++ charts/anvil/templates/_helpers.tpl | 62 ++++++++++++++ charts/anvil/templates/configmap-genesis.yaml | 23 +++++ charts/anvil/templates/deployment.yaml | 84 +++++++++++++++++++ charts/anvil/templates/service.yaml | 14 ++++ charts/anvil/templates/serviceaccount.yaml | 12 +++ .../templates/tests/test-connection.yaml | 15 ++++ charts/anvil/values.yaml | 24 ++++++ 11 files changed, 309 insertions(+) create mode 100644 charts/anvil/.helmignore create mode 100644 charts/anvil/Chart.yaml create mode 100644 charts/anvil/templates/NOTES.txt create mode 100644 charts/anvil/templates/_helpers.tpl create mode 100644 charts/anvil/templates/configmap-genesis.yaml create mode 100644 charts/anvil/templates/deployment.yaml create mode 100644 charts/anvil/templates/service.yaml create mode 100644 charts/anvil/templates/serviceaccount.yaml create mode 100644 charts/anvil/templates/tests/test-connection.yaml create mode 100644 charts/anvil/values.yaml diff --git a/build/localnet/Tiltfile b/build/localnet/Tiltfile index d4534df35..d6c2e6180 100644 --- a/build/localnet/Tiltfile +++ b/build/localnet/Tiltfile @@ -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 +k8s_yaml( + helm( + root_dir + "/charts/anvil", + name="anvil-node", + ) +) + +k8s_resource("anvil-node", labels=["anvil-nodes"]) + # Exposes grafana k8s_resource( new_name="grafana", diff --git a/charts/anvil/.helmignore b/charts/anvil/.helmignore new file mode 100644 index 000000000..0e8a0eb36 --- /dev/null +++ b/charts/anvil/.helmignore @@ -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/ diff --git a/charts/anvil/Chart.yaml b/charts/anvil/Chart.yaml new file mode 100644 index 000000000..c64b9cf5d --- /dev/null +++ b/charts/anvil/Chart.yaml @@ -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" diff --git a/charts/anvil/templates/NOTES.txt b/charts/anvil/templates/NOTES.txt new file mode 100644 index 000000000..22a853e0d --- /dev/null +++ b/charts/anvil/templates/NOTES.txt @@ -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 }} diff --git a/charts/anvil/templates/_helpers.tpl b/charts/anvil/templates/_helpers.tpl new file mode 100644 index 000000000..2c28f1fcf --- /dev/null +++ b/charts/anvil/templates/_helpers.tpl @@ -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). +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 }} diff --git a/charts/anvil/templates/configmap-genesis.yaml b/charts/anvil/templates/configmap-genesis.yaml new file mode 100644 index 000000000..beb8b628b --- /dev/null +++ b/charts/anvil/templates/configmap-genesis.yaml @@ -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" } + } + } diff --git a/charts/anvil/templates/deployment.yaml b/charts/anvil/templates/deployment.yaml new file mode 100644 index 000000000..81e833a1b --- /dev/null +++ b/charts/anvil/templates/deployment.yaml @@ -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 }} diff --git a/charts/anvil/templates/service.yaml b/charts/anvil/templates/service.yaml new file mode 100644 index 000000000..425a207c8 --- /dev/null +++ b/charts/anvil/templates/service.yaml @@ -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 }} diff --git a/charts/anvil/templates/serviceaccount.yaml b/charts/anvil/templates/serviceaccount.yaml new file mode 100644 index 000000000..abed979e5 --- /dev/null +++ b/charts/anvil/templates/serviceaccount.yaml @@ -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 }} diff --git a/charts/anvil/templates/tests/test-connection.yaml b/charts/anvil/templates/tests/test-connection.yaml new file mode 100644 index 000000000..9f0f59f8c --- /dev/null +++ b/charts/anvil/templates/tests/test-connection.yaml @@ -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 diff --git a/charts/anvil/values.yaml b/charts/anvil/values.yaml new file mode 100644 index 000000000..8a28f71ac --- /dev/null +++ b/charts/anvil/values.yaml @@ -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 From 5ce1218f208a3883c832dd4b4bbff5f42ff9ae7b Mon Sep 17 00:00:00 2001 From: github-actions Date: Mon, 7 Aug 2023 19:46:34 +0000 Subject: [PATCH 2/2] add generated helm docs --- charts/anvil/README.md | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 charts/anvil/README.md diff --git a/charts/anvil/README.md b/charts/anvil/README.md new file mode 100644 index 000000000..3fbea8517 --- /dev/null +++ b/charts/anvil/README.md @@ -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:** + +## Source Code + +* +* + +## 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)