-
Notifications
You must be signed in to change notification settings - Fork 13
321 lines (264 loc) · 11.3 KB
/
cloud-tests.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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
name: Cloud tests
on:
schedule:
# Every Sunday at 11PM
- cron: '0 23 * * 0'
workflow_dispatch:
inputs:
cnspecImageTag:
required: true
type: string
default: latest-rootless
description: The image tag to use for the cnspec image
mondooOperatorImageTag:
required: true
type: string
default: main
description: The image tag to use for the mondoo operator image
secrets:
MONDOO_CLIENT:
required: true
AZURE_CLIENT_ID:
required: true
AZURE_CLIENT_SECRET:
required: true
AZURE_SUBSCRIPTION_ID:
required: true
AZURE_TENANT_ID:
required: true
AWS_ACCESS_KEY_ID:
required: true
AWS_SECRET_ACCESS_KEY:
required: true
GCP_SERVICE_ACCOUNT:
required: true
env:
MONDOO_OPERATOR_IMAGE_TAG: ${{ github.event.inputs.mondooOperatorImageTag || 'main' }}
CNSPEC_IMAGE_TAG: ${{ github.event.inputs.cnspecImageTag || 'latest-rootless' }}
jobs:
aks-integration-test:
runs-on: ubuntu-latest
name: AKS integration tests
env:
ARM_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
ARM_CLIENT_SECRET: ${{ secrets.AZURE_CLIENT_SECRET }}
ARM_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
ARM_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
KUBECONFIG: ${{ format('{0}/{1}', github.workspace, '.github/terraform/aks/kubeconfig') }}
strategy:
fail-fast: false
matrix:
k8s-version: ["1.27", "1.28", "1.29"]
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # fetch is needed for "git tag --list" in the Makefile
- name: Import environment variables from file
run: cat ".github/env" >> $GITHUB_ENV
- name: Setup Terraform
uses: hashicorp/setup-terraform@v3
- name: Terraform init
run: terraform init
working-directory: .github/terraform/aks
- name: Terraform plan
run: terraform plan -out aks-${{ matrix.k8s-version }}.json
env:
TF_VAR_k8s_version: ${{ matrix.k8s-version }}
working-directory: .github/terraform/aks
- name: Terraform apply
run: terraform apply -auto-approve aks-${{ matrix.k8s-version }}.json
env:
TF_VAR_k8s_version: ${{ matrix.k8s-version }}
working-directory: .github/terraform/aks
- uses: actions/setup-go@v5
with:
go-version: "${{ env.golang-version }}"
cache: true
- name: Get operator version
run: echo "OPERATOR_VERSION=$(docker run ghcr.io/mondoohq/mondoo-operator:${{ env.MONDOO_OPERATOR_IMAGE_TAG }} version --simple)" >> $GITHUB_ENV
- name: Wait a bit for the cluster to become more stable
run: kubectl -n kube-system wait --for=condition=Ready pods --all --timeout=60s
- name: Run integration tests
env:
MONDOO_API_TOKEN: ${{ secrets.MONDOO_TEST_ORG_TOKEN }}
run: VERSION=${{ env.OPERATOR_VERSION }} K8S_DISTRO=aks make test/integration/ci
- name: Clean up AKS terraform
run: terraform destroy -auto-approve
if: success() || failure()
working-directory: .github/terraform/aks
- run: mv integration-tests.xml integration-tests-aks-${{ matrix.k8s-version }}.xml
if: success() || failure()
- name: Upload cloud test results
uses: actions/upload-artifact@v4 # upload test results
if: success() || failure() # run this step even if previous step failed
with: # upload a combined archive with unit and integration test results
name: cloud-test-results-aks-${{ matrix.k8s-version }}
path: |
integration-tests-aks-${{ matrix.k8s-version }}.xml
.github/terraform/aks/aks-${{ matrix.k8s-version }}.json
- name: Upload test logs artifact
uses: actions/upload-artifact@v4
if: failure()
with:
name: test-logs-aks-${{ matrix.k8s-version }}
path: /home/runner/work/mondoo-operator/mondoo-operator/tests/integration/_output/
eks-integration-test:
runs-on: ubuntu-latest
name: EKS integration tests
strategy:
fail-fast: false
max-parallel: 3 # Otherwise we will hit AWS VPC quota limits
matrix:
k8s-version: ["1.25", "1.26", "1.27", "1.28", "1.29"]
env:
TF_VAR_test_name: ${{ github.event.inputs.mondooOperatorImageTag }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_REGION: us-east-2
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # fetch is needed for "git tag --list" in the Makefile
- name: Import environment variables from file
run: cat ".github/env" >> $GITHUB_ENV
- name: Setup Terraform
uses: hashicorp/setup-terraform@v3
- run: terraform init
working-directory: .github/terraform/aws
- name: Plan EKS
run: terraform plan -out eks-${{ matrix.k8s-version }}.json
env:
TF_VAR_kubernetes_version: ${{ matrix.k8s-version }}
working-directory: .github/terraform/aws
- name: Apply EKS
run: terraform apply -auto-approve eks-${{ matrix.k8s-version }}.json
env:
TF_VAR_kubernetes_version: ${{ matrix.k8s-version }}
working-directory: .github/terraform/aws
- uses: actions/setup-go@v5
with:
go-version: "${{ env.golang-version }}"
cache: true
- name: Get operator version
run: echo "OPERATOR_VERSION=$(docker run ghcr.io/mondoohq/mondoo-operator:${{ env.MONDOO_OPERATOR_IMAGE_TAG }} version --simple)" >> $GITHUB_ENV
- name: Wait a bit for the cluster to become more stable
run: kubectl -n kube-system wait --for=condition=Ready pods --all --timeout=60s
- name: Run integration tests
env:
MONDOO_API_TOKEN: ${{ secrets.MONDOO_TEST_ORG_TOKEN }}
run: VERSION=${{ env.OPERATOR_VERSION }} K8S_DISTRO=eks make test/integration/ci
- name: Clean up EKS terraform
run: terraform destroy -auto-approve
working-directory: .github/terraform/aws
if: success() || failure()
- run: mv integration-tests.xml integration-tests-eks-${{ matrix.k8s-version }}.xml
if: success() || failure()
- name: Upload test results
uses: actions/upload-artifact@v4 # upload test results
if: success() || failure() # run this step even if previous step failed
with: # upload a combined archive with unit and integration test results
name: cloud-test-results-eks-${{ matrix.k8s-version }}
path: integration-tests-eks-${{ matrix.k8s-version }}.xml
- name: Upload test logs artifact
uses: actions/upload-artifact@v4
if: failure()
with:
name: test-logs-eks-${{ matrix.k8s-version }}
path: /home/runner/work/mondoo-operator/mondoo-operator/tests/integration/_output/
gke-integration-test:
runs-on: ubuntu-latest
name: GKE integration tests
strategy:
fail-fast: false
matrix:
k8s-version: ["1.27", "1.28", "1.29"]
env:
GOOGLE_APPLICATION_CREDENTIALS: ${{ format('{0}/{1}', github.workspace, 'gcp_sa.json') }}
KUBECONFIG: ${{ format('{0}/{1}', github.workspace, '.github/terraform/gke/kubeconfig') }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # fetch is needed for "git tag --list" in the Makefile
- name: Import environment variables from file
run: cat ".github/env" >> $GITHUB_ENV
- name: Setup GCP service account
run: echo ${{ secrets.GCP_SERVICE_ACCOUNT }} | base64 -d > gcp_sa.json
- name: Setup Terraform
uses: hashicorp/setup-terraform@v3
- run: terraform init
working-directory: .github/terraform/gke
- name: Plan GKE
run: terraform plan -out gke-${{ matrix.k8s-version }}.json
env:
TF_VAR_k8s_version: ${{ matrix.k8s-version }}
working-directory: .github/terraform/gke
- name: Apply GKE
run: terraform apply -auto-approve gke-${{ matrix.k8s-version }}.json
env:
TF_VAR_k8s_version: ${{ matrix.k8s-version }}
working-directory: .github/terraform/gke
- uses: actions/setup-go@v5
with:
go-version: "${{ env.golang-version }}"
cache: true
- name: Get operator version
run: echo "OPERATOR_VERSION=$(docker run ghcr.io/mondoohq/mondoo-operator:${{ env.MONDOO_OPERATOR_IMAGE_TAG }} version --simple)" >> $GITHUB_ENV
- name: Wait a bit for the cluster to become more stable
run: kubectl -n kube-system wait --for=condition=Ready pods --all --timeout=300s
- name: Run integration tests
env:
MONDOO_API_TOKEN: ${{ secrets.MONDOO_TEST_ORG_TOKEN }}
run: VERSION=${{ env.OPERATOR_VERSION }} K8S_DISTRO=gke make test/integration/ci
- name: Clean up GKE terraform
run: terraform destroy -auto-approve
working-directory: .github/terraform/gke
if: success() || failure()
- name: Cleanup GCP service account
run: rm gcp_sa.json
if: success() || failure()
- run: mv integration-tests.xml integration-tests-gke-${{ matrix.k8s-version }}.xml
if: success() || failure()
- name: Upload test results
uses: actions/upload-artifact@v4 # upload test results
if: success() || failure() # run this step even if previous step failed
with: # upload a combined archive with unit and integration test results
name: cloud-test-results-gke-${{ matrix.k8s-version }}
path: integration-tests-gke-${{ matrix.k8s-version }}.xml
- name: Upload test logs artifact
uses: actions/upload-artifact@v4
if: failure()
with:
name: test-logs-gke-${{ matrix.k8s-version }}
path: /home/runner/work/mondoo-operator/mondoo-operator/tests/integration/_output/
test-report:
name: Report test results
runs-on: ubuntu-latest
needs: [eks-integration-test,aks-integration-test,gke-integration-test]
if: always()
steps:
- name: Download test results
uses: actions/download-artifact@v4
with:
pattern: cloud-test-results-*
merge-multiple: true
- name: Publish Test Results
uses: EnricoMi/publish-unit-test-result-action@v2
with:
commit: ${{ github.event.workflow_run.head_sha }}
event_file: ${{ github.event_path }}
event_name: ${{ github.event.workflow_run.event }}
files: "*.xml"
discord-notification:
runs-on: ubuntu-latest
name: Send Discord notification
needs: [eks-integration-test,aks-integration-test,gke-integration-test]
# Run only if the previous job has failed and only if it's running against the main branch
if: ${{ always() && contains(join(needs.*.result, ','), 'fail') && github.ref_name == 'main' }}
steps:
- uses: sarisia/actions-status-discord@v1
with:
webhook: ${{ secrets.DISCORD_WEBHOOK }}
status: Failure
url: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
description: Workflow ${{ github.workflow }} failed for commit ${{ github.sha }}.
color: 0xff4d4d