forked from gatekeeper/gatekeeper-operator
-
Notifications
You must be signed in to change notification settings - Fork 4
227 lines (187 loc) · 6.83 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
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:
gosec:
name: Run gosec scan
runs-on: ubuntu-latest
steps:
- name: Checkout Gatekeeper
uses: actions/checkout@v4
- 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: Upload artifacts
uses: actions/upload-artifact@v3
with:
name: artifacts
path: gosec.json
verify-and-unit-tests:
name: Run verify and unit tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0 # Fetch all history for all tags and branches
- uses: actions/setup-go@v3
with:
go-version-file: go.mod
- name: Verify modules
run: go mod verify
- name: Verify format
run: |
make fmt
git diff --exit-code
- name: Verify manifests
run: |
make manifests
git diff --exit-code
- name: Verify imported manifests
run: |
make import-manifests
git diff --exit-code
- name: Verify bindata
run: |
make verify-bindata
- name: Unit and Integration Tests
run: |
make test
echo "::group::Test coverage"
make test-coverage
echo "::endgroup::"
- name: Upload artifacts
uses: actions/upload-artifact@v3
with:
name: artifacts
path: coverage_unit.out
e2e-tests:
name: Run e2e tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0 # Fetch all history for all tags and branches
- uses: actions/setup-go@v3
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 > operator.log &
make test-e2e NAMESPACE=gatekeeper-system
- name: Debug
if: ${{ failure() }}
run: |
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@v3
- uses: actions/setup-go@v3
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 patch deployment gatekeeper-operator-controller -p '{"spec" : {"template" :{"spec" : {"securityContext" :{"seccompProfile" : {"type": "RuntimeDefault"}}}}}}'
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 > operator.log &
make test-e2e-openshift
- name: Debug
if: ${{ failure() }}
run: |
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@v3
with:
path: gatekeeper-operator
fetch-depth: 0 # Fetch all history for all tags and branches
- uses: actions/setup-go@v3
with:
go-version-file: gatekeeper-operator/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: Set Up Environment Variables
run: |
GATEKEEPER_VERSION=v$(cat GATEKEEPER_VERSION || cat VERSION)
echo "GATEKEEPER_VERSION=${GATEKEEPER_VERSION}" >> ${GITHUB_ENV}
# Checkout a local copy of Gatekeeper to use its bats e2e tests.
- name: Checkout Gatekeeper to verify imported manifests
uses: actions/checkout@v3
with:
repository: open-policy-agent/gatekeeper
ref: ${{ env.GATEKEEPER_VERSION }}
path: gatekeeper
fetch-depth: 0 # Fetch all history for all tags and branches
- name: Gatekeeper E2E Tests
env:
NAMESPACE: gatekeeper-system
run: |
make download-binaries
make deploy-ci IMG=localhost:5000/gatekeeper-operator:$GITHUB_SHA
kubectl -n ${NAMESPACE} wait deployment/gatekeeper-operator-controller --for condition=Available --timeout=90s
make test-gatekeeper-e2e
export PATH=$PWD/ci-tools/bin:$PATH
cd ../gatekeeper
test/externaldata/dummy-provider/scripts/generate-tls-certificate.sh
(
cd test/externaldata/dummy-provider
go mod init github.com/open-policy-agent/gatekeeper/test/externaldata/dummy-provider
go get github.com/open-policy-agent/frameworks/[email protected]
sed -i 's/go mod init &&//' Dockerfile
)
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
make test-e2e GATEKEEPER_NAMESPACE=${NAMESPACE} ENABLE_MUTATION_TESTS=1