Skip to content

Commit

Permalink
Expand test scenarios (#304)
Browse files Browse the repository at this point in the history
  • Loading branch information
bakhtin authored Oct 16, 2023
1 parent 743b34a commit 3521339
Show file tree
Hide file tree
Showing 37 changed files with 976 additions and 39 deletions.
35 changes: 29 additions & 6 deletions .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Helm
uses: azure/setup-helm@v3.3
uses: azure/setup-helm@v3.5
with:
version: v3.12.1

Expand Down Expand Up @@ -67,8 +67,9 @@ jobs:
- name: Create kind cluster
uses: helm/[email protected]
with:
node_image: kindest/node:v1.27.3
node_image: kindest/node:v1.28.0
config: chart-testing/kind-config.yaml
wait: 5m
if: steps.list-changed.outputs.changed

- name: Replace secrets in Helm charts
Expand All @@ -86,9 +87,31 @@ jobs:

- name: Run chart-testing (install)
run: |
ct install \
--target-branch ${{ github.event.repository.default_branch }} \
--charts ${{ steps.list-changed.outputs.changed }}
# Exclude charts/node as it is covered by proper tests. Exclude more charts if needed
CHARTS_WITHOUT_TESTS=$(printf "${{ steps.list-changed.outputs.changed }}" | sed -E 's|charts/node,?||g')
if [[ -n "$CHARTS_WITHOUT_TESTS" ]]; then
ct install \
--target-branch ${{ github.event.repository.default_branch }} \
--charts $CHARTS_WITHOUT_TESTS
fi
if: steps.list-changed.outputs.changed

- uses: actions/setup-go@v4
with:
go-version: '1.20'
cache-dependency-path: "charts/**/ginkgo/go.sum"
if: steps.list-changed.outputs.changed

- name: Run ginkgo tests
run: |
export KUBECONFIG=~/.kube/config
CHANGED_CHARTS=${{ steps.list-changed.outputs.changed }}
for chart in ${CHANGED_CHARTS//,/$IFS}; do
if [[ -f $chart/ci/Makefile ]]; then
pushd $chart/ci && make test
popd
fi
done
if: steps.list-changed.outputs.changed

validate-manifests:
Expand Down
1 change: 1 addition & 0 deletions charts/node/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ci/**/charts/
2 changes: 1 addition & 1 deletion charts/node/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: v2
name: node
description: A Helm chart to deploy Substrate/Polkadot nodes
type: application
version: 5.4.0
version: 5.4.1
maintainers:
- name: Parity
url: https://github.com/paritytech/helm-charts
Expand Down
2 changes: 1 addition & 1 deletion charts/node/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ This is intended behaviour. Make sure to run `git add -A` once again to stage ch

# Substrate/Polkadot node Helm chart

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

## Maintainers

Expand Down
8 changes: 8 additions & 0 deletions charts/node/ci/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cluster-create:
kind create cluster --config ../../chart-testing/kind-config.yaml --name node-testing --wait 5m
test:
docker build -f addons/nginx-assets-server/nginx-assets-server.Dockerfile -t nginx-assets-server:latest addons/nginx-assets-server
kind load docker-image --name chart-testing docker.io/library/nginx-assets-server:latest
./run-tests.sh
clean:
kind delete cluster --name node-testing
5 changes: 5 additions & 0 deletions charts/node/ci/addons/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
resources:
- metallb
- metrics-server
- nginx-ingress-controller
- nginx-assets-server
8 changes: 8 additions & 0 deletions charts/node/ci/addons/metallb/ipaddresses.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: metallb.io/v1beta1
kind: IPAddressPool
metadata:
name: kind-default
spec:
addresses:
# - 10.89.0.247-10.89.0.252 # for Podman
- 172.18.255.240-172.18.255.250 # for Docker
14 changes: 14 additions & 0 deletions charts/node/ci/addons/metallb/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
helmCharts:
- name: metallb
includeCRDs: true
valuesFile: values.yaml
releaseName: metallb
version: 0.13.11
repo: https://metallb.github.io/metallb

namespace: metallb-system

resources:
- ns.yaml
- ipaddresses.yaml
- l2advertisement.yaml
7 changes: 7 additions & 0 deletions charts/node/ci/addons/metallb/l2advertisement.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: metallb.io/v1beta1
kind: L2Advertisement
metadata:
name: kind-default
spec:
ipAddressPools:
- kind-default
4 changes: 4 additions & 0 deletions charts/node/ci/addons/metallb/ns.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
apiVersion: v1
kind: Namespace
metadata:
name: metallb-system
6 changes: 6 additions & 0 deletions charts/node/ci/addons/metallb/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
controller:
image:
tag: v0.13.11
speaker:
image:
tag: v0.13.11
21 changes: 21 additions & 0 deletions charts/node/ci/addons/metrics-server/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
helmCharts:
- name: metrics-server
includeCRDs: true
releaseName: metrics-server
version: 3.11.0
repo: https://kubernetes-sigs.github.io/metrics-server/

namespace: metrics-server

resources:
- ns.yaml

patches:
- patch: |-
- op: add
path: /spec/template/spec/containers/0/args/-
value: --kubelet-insecure-tls
target:
version: v1
kind: Deployment
name: metrics-server
4 changes: 4 additions & 0 deletions charts/node/ci/addons/metrics-server/ns.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
apiVersion: v1
kind: Namespace
metadata:
name: metrics-server
4 changes: 4 additions & 0 deletions charts/node/ci/addons/nginx-assets-server/assets/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
## Build chainspec
```
polkadot build-spec --chain rococo-local --disable-default-bootnode --raw > rococo-local.json
```
168 changes: 168 additions & 0 deletions charts/node/ci/addons/nginx-assets-server/assets/rococo-local.json

Large diffs are not rendered by default.

Binary file not shown.
5 changes: 5 additions & 0 deletions charts/node/ci/addons/nginx-assets-server/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
namespace: assets-server

resources:
- ns.yaml
- nginx-assets-server.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM docker.io/nginx:1.25.2-alpine

COPY assets/tick_v9-chain-backup.tar.gz assets/rococo-local.json /usr/share/nginx/html/
RUN tar -xzf /usr/share/nginx/html/tick_v9-chain-backup.tar.gz -C /usr/share/nginx/html/ && \
rm /usr/share/nginx/html/tick_v9-chain-backup.tar.gz
37 changes: 37 additions & 0 deletions charts/node/ci/addons/nginx-assets-server/nginx-assets-server.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: assets-server
spec:
selector:
matchLabels:
app: assets-server
template:
metadata:
labels:
app: assets-server
spec:
containers:
- name: assets-server
image: docker.io/library/nginx-assets-server:latest
imagePullPolicy: Never
resources:
limits:
memory: "128Mi"
cpu: "500m"
ports:
- name: http
containerPort: 80
---
kind: Service
apiVersion: v1
metadata:
name: assets-server
spec:
selector:
app: assets-server
ports:
- name: http
protocol: TCP
port: 80
targetPort: 80
4 changes: 4 additions & 0 deletions charts/node/ci/addons/nginx-assets-server/ns.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
apiVersion: v1
kind: Namespace
metadata:
name: assets-server
12 changes: 12 additions & 0 deletions charts/node/ci/addons/nginx-ingress-controller/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
helmCharts:
- name: ingress-nginx
includeCRDs: true
releaseName: ingress-nginx
valuesFile: values.yaml
version: 4.7.2
repo: https://kubernetes.github.io/ingress-nginx

namespace: ingress-nginx

resources:
- ns.yaml
4 changes: 4 additions & 0 deletions charts/node/ci/addons/nginx-ingress-controller/ns.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
apiVersion: v1
kind: Namespace
metadata:
name: ingress-nginx
3 changes: 3 additions & 0 deletions charts/node/ci/addons/nginx-ingress-controller/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
controller:
config:
worker-processes: 2 # https://github.com/kubernetes/ingress-nginx/issues/6141
58 changes: 58 additions & 0 deletions charts/node/ci/dev-rpc-values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
node:
chain: rococo-local
role: full
replicas: 2
chainData:
storageClass: standard
volumeSize: 1Gi
chainKeystore:
storageClass: standard
mountInMemory:
enabled: true
podManagementPolicy: Parallel
persistentVolumeClaimRetentionPolicy:
whenDeleted: Delete
whenScaled: Delete
substrateApiSidecar:
enabled: true
enableSidecarReadinessProbe: true
perNodeServices:
relayP2pService:
enabled: true
type: NodePort
setPublicAddressToExternalIp:
enabled: false
ingress:
enabled: true
annotations:
kubernetes.io/ingress.class: nginx
rules:
- host: dev-rpc.local
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: dev-rpc-node
port:
name: rpc
image:
tag: v1.0.0
repository: docker.io/parity/polkadot
wsHealthExporter:
resources:
requests:
cpu: 10m
memory: 32M
limits:
cpu: 200m
memory: 64M
env:
WSHE_NODE_MAX_UNSYNCHRONIZED_BLOCK_DRIFT: "4"
WSHE_NODE_MIN_PEERS: "0"
terminationGracePeriodSeconds: 10

substrateApiSidecar:
metrics:
enabled: true
86 changes: 86 additions & 0 deletions charts/node/ci/ginkgo/dev_rpc_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package node_test

import (
"bytes"
"context"
"encoding/json"
"fmt"
"io"
"net/http"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
appsv1 "k8s.io/api/apps/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/clientcmd"
)

var _ = Describe("dev-rpc", Ordered, func() {
var c *kubernetes.Clientset
var ctx context.Context
var cancel context.CancelFunc
const releaseName = "dev-rpc"

BeforeEach(func() {

ctx, cancel = context.WithCancel(context.Background())
config, err := clientcmd.BuildConfigFromFlags("", kubeconfig)
if err != nil {
panic(err.Error())
}
c = kubernetes.NewForConfigOrDie(config)
})

When("an RPC node is running", func() {
It("should return the list of supported RPC methods", func() {

getAvailableReplicas := func(ss *appsv1.StatefulSet) int32 { return ss.Status.AvailableReplicas }
getOpts := metav1.GetOptions{}

stsName := fmt.Sprintf("%s-node", releaseName)
By("checking all the replicas are available")
ss, err := c.AppsV1().StatefulSets(namespace).Get(ctx, stsName, getOpts)
Expect(err).NotTo(HaveOccurred())
Expect(ss.Status.Replicas).NotTo(BeZero())
origReplicas := *ss.Spec.Replicas

Eventually(func() (*appsv1.StatefulSet, error) {
return c.AppsV1().StatefulSets(namespace).Get(ctx, stsName, getOpts)
}, timeout, PollingInterval).Should(WithTransform(getAvailableReplicas, Equal(origReplicas)))

rpcIngress, err := c.NetworkingV1().Ingresses(namespace).Get(ctx, stsName, getOpts)
Expect(err).NotTo(HaveOccurred())

loadbalancerIP := rpcIngress.Status.LoadBalancer.Ingress[0].IP
rpcHostname := rpcIngress.Spec.Rules[0].Host

var resp *http.Response
var respBody []byte
var respBodyJSON map[string]interface{}

Eventually(func(g Gomega) int {
reqJSON := []byte(`{"id":42, "jsonrpc":"2.0", "method": "rpc_methods"}`)
req, err := http.NewRequest("POST", fmt.Sprintf("http://%s", loadbalancerIP), bytes.NewBuffer(reqJSON))
g.Expect(err).NotTo(HaveOccurred())
req.Host = rpcHostname
req.Header.Set("Content-Type", "application/json")
resp, err = http.DefaultClient.Do(req)
g.Expect(err).NotTo(HaveOccurred())
defer resp.Body.Close()
g.Expect(resp.StatusCode).To(Equal(http.StatusOK))
respBody, err = io.ReadAll(resp.Body)
g.Expect(err).NotTo(HaveOccurred())
errJSON := json.Unmarshal(respBody, &respBodyJSON)
g.Expect(errJSON).NotTo(HaveOccurred())
return resp.StatusCode
}, timeout, PollingInterval).Should(Equal(http.StatusOK))

Expect(respBodyJSON).To(HaveKey("result"))
})
})

AfterEach(func() {
cancel()
})
})
Loading

0 comments on commit 3521339

Please sign in to comment.