-
Notifications
You must be signed in to change notification settings - Fork 0
275 lines (252 loc) · 8.05 KB
/
test.yaml
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
name: Test
on:
workflow_dispatch:
inputs:
run_lint:
description: Run helm lint
type: boolean
required: true
default: true
run_validate:
description: Run validate manifests
type: boolean
required: true
default: true
run_test:
description: Run integration/ test
type: boolean
required: true
default: true
run_ct:
description: Run chart testing
required: true
default: true
workflow_call:
inputs:
ref:
type: string
required: true
run_lint:
type: boolean
required: true
run_validate:
type: boolean
required: true
run_test:
type: boolean
required: true
run_ct:
type: boolean
required: true
helm_args:
type: string
required: false
load_artifact:
type: boolean
required: false
secrets:
VAULT_URL:
description: Vault URL
required: false
VAULT_ROLE:
description: Vault role
required: false
jobs:
check:
name: Get git reference
runs-on: ubuntu-latest
outputs:
ref: ${{ steps.get_git_ref.outputs.ref }}
steps:
- id: get_git_ref
run: |
if [ -n "${{ inputs.ref }}" ]; then
echo "ref=${{ inputs.ref }}" >> $GITHUB_OUTPUT
else
echo "ref=${{ github.ref_name }}" >> $GITHUB_OUTPUT
fi
lint:
name: Helm lint
if: ${{ inputs.run_lint }}
runs-on: ubuntu-latest
needs: check
steps:
- name: Checkout
uses: actions/checkout@v3
with:
ref: ${{ needs.check.outputs.ref }}
- name: Helm lint
run: |
helm version
helm lint helm/. --debug
validate:
name: Validate manifests
if: ${{ inputs.run_validate }}
env:
KUBEVAL_SCHEMA_LOCATION: 'https://raw.githubusercontent.com/yannh/kubernetes-json-schema/master/'
needs: check
runs-on: ubuntu-latest
strategy:
matrix:
kubeVersion:
- 1.19.16
- 1.20.15
- 1.21.14
- 1.22.17
- 1.23.9
- 1.24.9
- 1.25.16
- 1.26.15
- 1.27.13
- 1.28.9
- 1.29.4
steps:
- name: Checkout
uses: actions/checkout@v3
with:
ref: ${{ needs.check.outputs.ref }}
- name: Helm template
run: helm template helm/. > result-${{ matrix.kubeVersion }}.yaml --kube-version ${{ matrix.kubeVersion }} --debug
- name: Kubeval
uses: instrumenta/kubeval-action@master
with:
files: result-${{ matrix.kubeVersion }}.yaml
version: ${{ matrix.kubeVersion }}
ignore_missing_schemas: false
test:
name: Installation test
runs-on: self-hosted-amd64-1cpu
if: ${{ inputs.run_test }}
needs: check
env:
ARCH: amd64
strategy:
matrix:
kubeVersion:
- 1.19.16
- 1.20.15
- 1.21.14
- 1.22.17
- 1.23.17
- 1.24.17
- 1.25.16
- 1.26.14
- 1.27.11
- 1.28.7
- 1.29.2
steps:
- name: Import secrets
uses: hashicorp/vault-action@130d1f5f4fe645bb6c83e4225c04d64cfb62de6e # v2.5.0
id: secrets
with:
exportEnv: true
url: ${{ secrets.VAULT_URL }}
role: ${{ secrets.VAULT_ROLE }}
method: kubernetes
path: kubernetes-ci
secrets: |
kv-gitlab-ci/data/github/shared/dockerhub-creds user | DOCKERHUB_USER ;
kv-gitlab-ci/data/github/shared/dockerhub-creds password | DOCKERHUB_PASSWORD ;
kv-gitlab-ci/data/github/sidecar api_token ;
- name: Checkout
uses: actions/checkout@v3
with:
ref: ${{ needs.check.outputs.ref }}
- name: Create cluster
run: |
echo ${DOCKERHUB_PASSWORD} | docker login -u ${DOCKERHUB_USER} --password-stdin
kind create cluster \
--config ${GITHUB_WORKSPACE}/helm/test/kind/kind.yaml \
--image kindest/node:v${{ matrix.kubeVersion }} \
--name kind \
--wait 240s
kubectl cluster-info
kubectl wait --for=condition=Ready pods --all --timeout=180s -n kube-system
echo "current-context:" $(kubectl config current-context)
- name: Load cache
if: ${{ inputs.load_artifact }}
uses: actions/download-artifact@v4
with:
name: sidecar-${{ env.ARCH }}.tar
- name: Load image
if: ${{ inputs.load_artifact }}
run: kind load image-archive sidecar-${{ env.ARCH }}.tar
- name: Install Helm chart
run: |
unset KUBERNETES_SERVICE_HOST
echo "[test-env] creating secret docker-registry ..."
kubectl create secret docker-registry dockerhub-secret \
--docker-server="https://index.docker.io/v1/" \
--docker-username="${DOCKERHUB_USER}" \
--docker-password="${DOCKERHUB_PASSWORD}" \
helm install wallarm-sidecar ./helm -f helm/values.test.yaml \
--set config.wallarm.api.token=${API_TOKEN} \
--debug \
--timeout 5m0s \
--wait ${{ inputs.helm_args }}
sleep 5
kubectl wait --for=condition=Ready pods --all --timeout=5m0s || (
kubectl describe pod -l app.kubernetes.io/component=postanalytics &&
kubectl describe pod -l app.kubernetes.io/component=controller &&
kubectl get pods -A &&
kubectl get secrets -A &&
kubectl get jobs -A && exit 1)
- name: Deploy pytest
run: |
unset KUBERNETES_SERVICE_HOST
kubectl create namespace pytest
kubectl -n pytest create secret docker-registry dockerhub-secret \
--docker-server="https://index.docker.io/v1/" \
--docker-username="${DOCKERHUB_USER}" \
--docker-password="${DOCKERHUB_PASSWORD}" \
kubectl apply -f kind/docker/manifests/init/pytest.yaml
while [[ -z $(kubectl -n pytest get pods -o name) ]]; do
sleep 1
done
kubectl -n pytest wait pods --all --for=condition=Ready --timeout=60s
- name: Run test
run: |
unset KUBERNETES_SERVICE_HOST
POD_NAME=$(kubectl get pods -n pytest -o name | cut -d '/' -f 2)
kubectl -n pytest exec -t ${POD_NAME} -- pytest -n 6 helm/test
chart-testing:
name: Chart testing - install
runs-on: self-hosted-amd64-1cpu
needs: check
steps:
- name: Import secrets
uses: hashicorp/vault-action@130d1f5f4fe645bb6c83e4225c04d64cfb62de6e # v2.5.0
id: secrets
with:
exportEnv: true
url: ${{ secrets.VAULT_URL }}
role: ${{ secrets.VAULT_ROLE }}
method: kubernetes
path: kubernetes-ci
secrets: |
kv-gitlab-ci/data/github/shared/dockerhub-creds user | DOCKERHUB_USER ;
kv-gitlab-ci/data/github/shared/dockerhub-creds password | DOCKERHUB_PASSWORD ;
kv-gitlab-ci/data/github/sidecar api_token | WALLARM_API_TOKEN ;
- name: Checkout
uses: actions/checkout@v3
with:
ref: ${{ needs.check.outputs.ref }}
- name: Create cluster
run: |
echo ${DOCKERHUB_PASSWORD} | docker login -u ${DOCKERHUB_USER} --password-stdin
kind create cluster --image kindest/node:v1.28.7
kubectl wait --for=condition=Ready pods --all --timeout=180s -n kube-system
- name: Load cache
if: ${{ inputs.load_artifact }}
uses: actions/download-artifact@v4
with:
name: sidecar-amd64.tar
- name: Load image
if: ${{ inputs.load_artifact }}
run: kind load image-archive sidecar-amd64.tar
- name: Run test
env:
HELM_ARGS: ${{ inputs.helm_args }}
run: make ct-install