forked from gatekeeper/gatekeeper-operator
-
Notifications
You must be signed in to change notification settings - Fork 4
246 lines (201 loc) · 7.52 KB
/
ci_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
name: CI-Tests
on:
push:
branches:
- main
- release-[0-9]+.[0-9]+
pull_request:
branches:
- main
- release-[0-9]+.[0-9]+
defaults:
run:
shell: bash
jobs:
verify-and-unit-tests:
name: Run verify and unit tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: go.mod
- name: Verify modules
run: |
go mod tidy
go mod verify
git diff --exit-code
- name: Verify format
run: |
make fmt
git diff --exit-code
make lint
- name: Verify manifests
run: |
# The 'release' target calls the 'manifests' target
make release
git diff --exit-code
- name: Verify imported manifests
run: |
make import-manifests
git diff --exit-code
- name: Verify bindata
run: |
make update-bindata
git diff --exit-code
- name: Unit and Integration Tests
run: |
make test
echo "::group::Test coverage"
make test-coverage
echo "::endgroup::"
- name: Run Gosec Security Scanner
uses: securego/[email protected]
with:
args: -no-fail -fmt sonarqube -out gosec.json -stdout -exclude-dir=.go -exclude-dir=test ./...
- name: Store the GitHub triggering event for the sonarcloud workflow
if: |
github.repository_owner == 'stolostron'
run: |
cat <<'EOF' > event.json
${{ toJSON(github.event) }}
EOF
- name: Upload artifacts
if: |
github.repository_owner == 'stolostron'
uses: actions/upload-artifact@v4
with:
name: artifacts
path: |
event.json
gosec.json
coverage_unit.out
e2e-tests:
name: Run e2e tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: go.mod
- name: Download binaries
run: |
make download-binaries
- name: Create K8s KinD Cluster
run: |
make test-cluster
- name: Build and Push Test Container Image to KIND node
run: |
make docker-build IMG=localhost:5000/gatekeeper-operator:$GITHUB_SHA
kind load docker-image localhost:5000/gatekeeper-operator:$GITHUB_SHA
- name: E2E Tests
run: |
make deploy-ci NAMESPACE=gatekeeper-system IMG=localhost:5000/gatekeeper-operator:$GITHUB_SHA
kubectl -n gatekeeper-system wait deployment/gatekeeper-operator-controller --for condition=Available --timeout=90s
kubectl -n gatekeeper-system logs deployment/gatekeeper-operator-controller -c manager -f 2>&1 | tee operator.log &
make test-e2e NAMESPACE=gatekeeper-system
- name: Debug
if: ${{ failure() }}
run: |
echo "::group:Deployments"
kubectl -n gatekeeper-system get all
echo "---"
kubectl -n gatekeeper-system get deployment/gatekeeper-operator-controller -o yaml
echo "::endgroup::"
echo "::group::Operator Logs"
cat operator.log
echo "::endgroup::"
e2e-openshift-tests:
name: Run e2e Openshift tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version-file: go.mod
- name: Download binaries
run: |
make download-binaries
- name: Create K8s KinD Cluster
run: |
make test-cluster
make test-openshift-setup
- name: Build and Push Test Container Image to KIND node
run: |
make docker-build IMG=localhost:5000/gatekeeper-operator:$GITHUB_SHA
kind load docker-image localhost:5000/gatekeeper-operator:$GITHUB_SHA
- name: E2E Openshift Tests
run: |
make deploy-ci NAMESPACE=openshift-gatekeeper-system IMG=localhost:5000/gatekeeper-operator:$GITHUB_SHA
kubectl -n openshift-gatekeeper-system wait deployment/gatekeeper-operator-controller --for condition=Available --timeout=90s
kubectl -n openshift-gatekeeper-system logs deployment/gatekeeper-operator-controller -c manager -f 2>&1 | tee operator.log &
make test-e2e-openshift
- name: Debug
if: ${{ failure() }}
run: |
echo "::group:Deployments"
kubectl -n openshift-gatekeeper-system get all
echo "---"
kubectl -n openshift-gatekeeper-system get deployment/gatekeeper-operator-controller -o yaml
echo "::endgroup::"
echo "::group::Operator Logs"
cat operator.log
echo "::endgroup::"
gatekeeper-e2e-tests:
name: Run gatekeeper e2e tests
runs-on: ubuntu-latest
defaults:
run:
working-directory: gatekeeper-operator
steps:
- uses: actions/checkout@v4
with:
path: gatekeeper-operator
- uses: actions/setup-go@v5
with:
go-version-file: gatekeeper-operator/go.mod
cache-dependency-path: gatekeeper-operator/go.sum
- name: Download binaries
run: |
make download-binaries
- name: Create K8s KinD Cluster
run: |
make test-cluster
- name: Build and Push Test Container Image to KIND node
run: |
make docker-build IMG=localhost:5000/gatekeeper-operator:$GITHUB_SHA
kind load docker-image localhost:5000/gatekeeper-operator:$GITHUB_SHA
- name: Set Up Environment Variables
run: |
GATEKEEPER_VERSION=v$(cat GATEKEEPER_VERSION 2>/dev/null || cat VERSION)
echo "GATEKEEPER_VERSION=${GATEKEEPER_VERSION}" >> ${GITHUB_ENV}
- name: Deploy operator
env:
NAMESPACE: gatekeeper-system
run: |
make deploy-ci IMG=localhost:5000/gatekeeper-operator:$GITHUB_SHA
kubectl -n ${NAMESPACE} wait deployment/gatekeeper-operator-controller --for condition=Available --timeout=90s
echo "BATS_PATH=$PWD/ci-tools/bin" >> ${GITHUB_ENV}
make test-gatekeeper-e2e
# Checkout a local copy of Gatekeeper to use its bats e2e tests.
- name: Checkout Gatekeeper to verify imported manifests
uses: actions/checkout@v4
with:
repository: open-policy-agent/gatekeeper
ref: ${{ env.GATEKEEPER_VERSION }}
path: gatekeeper
- name: Gatekeeper E2E Tests
working-directory: gatekeeper
run: |
echo "::group::Patch Gatekeeper tests / Build and push test image"
export PATH=${{ env.BATS_PATH }}:$PATH
echo "* Patching test command for exempt namespaces:"
replace='num_namespaces=$(($(kubectl get ns -o json | jq '\''.items | length'\'')-$(kubectl get ns | grep excluded | wc -l)))'
sed -i "s/num_namespaces=.*/$replace/" test/bats/test.bats
echo "* Patching svc manifest NodePort (See https://github.com/open-policy-agent/gatekeeper/pull/3267):"
yq '.spec.type = "NodePort"' -i test/bats/tests/mutations/mutate_svc.yaml
test/externaldata/dummy-provider/scripts/generate-tls-certificate.sh
docker build -t dummy-provider:test -f test/externaldata/dummy-provider/Dockerfile test/externaldata/dummy-provider
kind load docker-image --name kind dummy-provider:test
echo "::endgroup::"
make test-e2e GATEKEEPER_NAMESPACE=${NAMESPACE} ENABLE_MUTATION_TESTS=1