-
Notifications
You must be signed in to change notification settings - Fork 9
160 lines (141 loc) · 7.11 KB
/
e2e-test.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
name: e2e test Kubernetes
on:
pull_request:
paths:
- "ci/**"
- "example-values/**"
- "chart/**"
- "box-chart/**"
- ".github/workflows/**"
- "docs/**"
workflow_dispatch:
inputs:
infraNamespace:
description: "Infra namespace"
default: "service"
type: string
schemaNamespace:
description: "Schema namespace"
default: "th2-schema"
type: string
env:
INFRA_NAMESPACE: "${{ github.event.inputs.infraNamespace || 'service' }}"
MONITORING_NAMESPACE: monitoring
SCHEMA_NAMESPACE: "${{ github.event.inputs.schemaNamespace || 'th2-schema' }}"
REPOSITORY_URL: "${{ github.event.pull_request.base.repo.clone_url }}"
REPOSITORY_REF_NAME: "${{ github.event.pull_request.head.ref }}"
LOKI_USERNAME: "${{ secrets.LOKI_USERNAME }}"
LOKI_PASSWORD: "${{ secrets.LOKI_PASSWORD }}"
pull_request: "${{ github.event.pull_request.number }}"
commit_hash: "${{ github.event.pull_request.head.sha }}"
jobs:
deploy-and-test:
strategy:
matrix:
k8s-version:
- kindest/node:v1.22.17@sha256:9af784f45a584f6b28bce2af84c494d947a05bd709151466489008f80a9ce9d5
- kindest/node:v1.25.3@sha256:f52781bc0d7a19fb6c405c2af83abfeb311f130707a0e219175677e366cc45d1
- kindest/node:v1.26.0@sha256:691e24bd2417609db7e589e1a479b902d2e209892a10ce375fab60a8407c7352
max-parallel: 3
fail-fast: false
name: ${{ github.job }}
if: |
!contains(github.event.pull_request.labels, 'automated')
runs-on: ubuntu-latest
steps:
- name: Go cache dependencies
uses: actions/cache@v3
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- uses: actions/checkout@v3
- name: Create k8s Kind Cluster
uses: helm/[email protected]
with:
config: ./ci/kind-cluster.yaml
node_image: ${{ matrix.k8s-version }}
- name: Copy box-chart into build context
run: |
cp -r ./box-chart ./infra-repo/
- name: set up docker buildx plugin
uses: docker/setup-buildx-action@v2
- name: Read infra-repo version
id: chart
uses: actions-tools/yaml-outputs@v2
with:
file-path: "./chart/values.yaml"
- name: Build infra-repo image
id: build
uses: docker/build-push-action@v4
with:
file: ./infra-repo/Dockerfile
context: ./infra-repo/
push: false
load: true
tags: ghcr.io/th2-net/infra-repo:e2e
cache-from: type=registry,ref=ghcr.io/th2-net/infra-repo:${{ steps.chart.outputs.infraRepo__image__tag }}
- name: Init test schema
run: |
mkdir ./e2e-test-schema.git/
git config --global user.email "ci@actions"
git config --global user.name "CI"
git --git-dir=./e2e-test-schema.git/ --bare init
git --git-dir=./e2e-test-schema.git/ --work-tree=./ci/e2e-test-schema/ add .
git --git-dir=./e2e-test-schema.git/ --work-tree=./ci/e2e-test-schema/ commit -m "Init repo"
git --git-dir=./e2e-test-schema.git/ --work-tree=./ci/e2e-test-schema/ branch schema
docker exec chart-testing-control-plane mkdir -p /opt/git/ /opt/jupiter_users /opt/jupiter_db
docker cp ./e2e-test-schema.git/ chart-testing-control-plane:/opt/git/
kind load docker-image --name chart-testing ghcr.io/th2-net/infra-repo:e2e
- name: Install python and ansible dependencies
run: |
ansible-galaxy collection install community.crypto:==1.3.0 community.kubernetes:==1.1.1
pip install kubernetes==12.0.0
- name: Run th2-infra deployment via Ansible
run: |
kubectl -n kube-system scale deployment coredns --replicas 1
ANSIBLE_STDOUT_CALLBACK=yaml ansible-playbook ./ci/e2e-via-ssh-deployment-playbook.yaml -e 'ansible_python_interpreter=/usr/bin/python3'
kubectl -n $INFRA_NAMESPACE patch deployments.apps infra-mgr -p '{"spec":{"template":{"spec":{"initContainers":[{"name":"init-myservice","image":"busybox:1.30.1","command":["sh","-c","until nc -vz infra-git 22; do echo \"Waiting for infra-git service\"; sleep 2; done;"]}]}}}}'
kubectl -n $INFRA_NAMESPACE patch deployments.apps infra-operator -p '{"spec":{"template":{"spec":{"initContainers":[{"name":"init-myservice","image":"busybox:1.30.1","command":["sh","-c","until nc -vz rabbitmq 5672; do echo \"Waiting for rabbitmq service\"; sleep 2; done;"]}]}}}}'
kubectl get pods --all-namespaces
- name: Sleep for 5 minutes
run: sleep 5m
shell: bash
- name: Testing
run: |
cd ./ci
go test -failfast th2_infra_test.go
- name: Getting logs
if: always()
run: |
echo -e "\n\033[0;31m[Pods]\033[0m" && kubectl get pods -o wide --all-namespaces || true
echo -e "\n\033[0;31m[Services]\033[0m" && kubectl get svc --all-namespaces || true
echo -e "\n\033[0;31m[Ingresses]\033[0m" && kubectl describe ingress --all-namespaces || true
echo -e "\n\033[0;31m[HelmReleases]\033[0m" && kubectl get hr --all-namespaces || true
echo -e "\n\033[0;31m[Nodes]\033[0m" && kubectl describe nodes || true
echo -e "\n\033[0;31m[Configmaps]\033[0m" && kubectl get configmaps --all-namespaces || true
echo -e "\n\033[0;31m[Secrets]\033[0m" && kubectl get secrets --all-namespaces || true
echo -e "\n\033[0;31m[Events]\033[0m" && kubectl get events --all-namespaces --sort-by='.metadata.creationTimestamp' || true
echo -e "\n\033[0;31m[PV]\033[0m" && kubectl get pv || true
for D in $(kubectl -n $INFRA_NAMESPACE get deployments --no-headers -o custom-columns=":metadata.name")
do
kubectl -n $INFRA_NAMESPACE logs deployment/$D --all-containers --timestamps > $D.log || true
done
kubectl -n $INFRA_NAMESPACE logs rabbitmq-0 > rabbitmq.log || true
kubectl -n $INFRA_NAMESPACE logs cassandra-0 > cassandra.log || true
kubectl -n $INFRA_NAMESPACE exec cassandra-0 -- cat /opt/bitnami/cassandra/logs/cassandra.log > cassandra-container.log || true
kubectl -n $INFRA_NAMESPACE logs daemonsets/grafana-agent-logs --all-containers --timestamps > grafana-agent-logs.log || true
for D in $(kubectl -n $SCHEMA_NAMESPACE get deployments --no-headers -o custom-columns=":metadata.name")
do
kubectl -n $SCHEMA_NAMESPACE logs deployment/$D --timestamps > $D.log || true
done
echo -e "Grafana link: https://th2.grafana.net/explore?orgId=1&left=%7B%22datasource%22:%22grafanacloud-th2-logs%22,%22queries%22:%5B%7B%22refId%22:%22A%22,%22expr%22:%22%7Brun%3D%5C%22"$pull_request":"$commit_hash"%5C%22%7D%22%7D%5D,%22range%22:%7B%22from%22:%22now-30d%22,%22to%22:%22now%22%7D%7D" >> $GITHUB_STEP_SUMMARY || true
- name: Uploading logs
if: always()
uses: actions/upload-artifact@v3
with:
name: infra-logs-${{ strategy.job-index }}
path: "*.log"