-
Notifications
You must be signed in to change notification settings - Fork 27
/
config.yml
306 lines (297 loc) · 10.2 KB
/
config.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
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
# Unless explicitly stated otherwise all files in this repository are licensed
# under the Apache License Version 2.0.
# This product includes software developed at Datadog (https://www.datadoghq.com/).
# Copyright 2021 Datadog, Inc.
version: 2.1
commands:
go_save_cache:
description: "Save $GOHOME directory into the cache for the actual revision"
steps:
- save_cache:
key: env-{{ .Revision }}
paths:
- /go
- /usr/local/bin/golangci-lint
- /usr/local/kubebuilder
- /usr/local/bin/helm
go_restore_cache:
description: "Restore golang cache"
steps:
- restore_cache:
key: env-{{ .Revision }}
python_install_requirements:
description: "Install requirements in requirements.txt using pip"
steps:
- run:
name: Install Python requirements
command: pip3 install -r tasks/requirements.txt
alpine_install_git:
description: "Install git using alpine apk"
steps:
- run:
name: Install git
command: apk update && apk add git
templates:
# sets the working directory to the project path
working_directory: &working_directory
working_directory: /go/src/github.com/DataDog/chaos-controller
executors:
golang:
<<: *working_directory
docker:
# TODO: Publicize the chaos controller ci image to the datadog docker registry
#- image: datadog/chaos-controller-runner-circle:<< pipeline.parameters.CURRENT_CI_IMAGE >>
- image: golang:1.18-buster
environment:
KUBEBUILDER_VERSION: 3.1.0
KUBEBUILDER_ARCH: amd64
GOLANGCI_LINT_VERSION: 1.45.2
HELM_VERSION: 3.5.4
golang_large:
<<: *working_directory
docker:
# TODO: Publicize the chaos controller ci image to the datadog docker registry
#- image: datadog/chaos-controller-runner-circle:<< pipeline.parameters.CURRENT_CI_IMAGE >>
- image: golang:1.18-buster
resource_class: medium+
environment:
KUBEBUILDER_VERSION: 3.1.0
KUBEBUILDER_ARCH: amd64
GOLANGCI_LINT_VERSION: 1.45.2
HELM_VERSION: 3.5.4
python:
<<: *working_directory
docker:
- image: python:3.8.1-alpine3.10
bash:
<<: *working_directory
docker:
- image: bash:5.0
ubuntu:
machine:
image: ubuntu-2004:202107-02
jobs:
# prepares the CI environment by checking out the code,
# installing a bunch of tools and downloading modules dependencies
# into the Go home path so we don't have to do it again in other
# CI jobs
prepare-env:
executor: golang
steps:
- checkout
- run:
name: Install kubebuilder
command: |
cd /usr/local
mkdir -p "/usr/local/kubebuilder/bin"
curl -L -O "https://github.com/kubernetes-sigs/kubebuilder/releases/download/v${KUBEBUILDER_VERSION}/kubebuilder_${KUBEBUILDER_VERSION}_linux_${KUBEBUILDER_ARCH}"
mv kubebuilder_${KUBEBUILDER_VERSION}_linux_${KUBEBUILDER_ARCH} kubebuilder/bin/
export PATH="/usr/local/kubebuilder/bin:${PATH}"
- run:
name: Install envtest
command: |
export ENVTEST_ASSETS_DIR="/usr/local/kubebuilder"
mkdir -p ${ENVTEST_ASSETS_DIR}
test -f ${ENVTEST_ASSETS_DIR}/setup-envtest.sh || curl -sSLo ${ENVTEST_ASSETS_DIR}/setup-envtest.sh https://raw.githubusercontent.com/kubernetes-sigs/controller-runtime/v0.8.3/hack/setup-envtest.sh
source ${ENVTEST_ASSETS_DIR}/setup-envtest.sh; fetch_envtest_tools ${ENVTEST_ASSETS_DIR}; setup_envtest_env ${ENVTEST_ASSETS_DIR};
- run:
name: Install golangci-lint tool
command: |
cd /usr/local
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v${GOLANGCI_LINT_VERSION}
- run:
name: Install helm
command: |
cd /usr/local
curl -L -O "https://get.helm.sh/helm-v${HELM_VERSION}-linux-amd64.tar.gz"
tar -xvzf helm-v${HELM_VERSION}-linux-amd64.tar.gz
mv linux-amd64/helm /usr/local/bin/helm
chmod +x /usr/local/bin/helm
- run:
name: Cache local dependencies
command: go mod download
- go_save_cache
# ensures that Go dependencies are up-to-date
dependencies:
executor: golang
steps:
- go_restore_cache
- run:
name: Ensure dependencies are up-to-date
command: |
go mod tidy
go mod vendor
git diff --exit-code
# this will fail if changes in packages are checked into git but the updated manifests are not
manifests:
executor: golang
steps:
- go_restore_cache
- run:
name: Ensure manifests are checked into git
command: |
make manifests
git diff --exit-code
# vets the code
vet:
executor: golang
steps:
- go_restore_cache
- run: make vet
# formats the code to ensure it complies with Go standards
fmt:
executor: golang
steps:
- go_restore_cache
- run: make fmt
# runs the golangci-lint linters
lint:
executor: golang_large
steps:
- go_restore_cache
- run: make lint
# runs the tests
test:
executor: golang
steps:
- go_restore_cache
- run: make test
# run e2e tests
e2e-test:
executor: ubuntu
steps:
- run:
name: Create missing cache directories
command: |
sudo mkdir -p /go /usr/local/bin /usr/local/kubebuilder
sudo chown circleci:circleci /go /usr/local/bin /usr/local/kubebuilder
- go_restore_cache
- run:
name: Edit controller chart
<<: *working_directory
command: |
sudo snap install yq
yq e '.controller.expiredDisruptionGCDelay = "10s"' -i chart/values.yaml
- run:
name: Wait for Docker Daemon to be up and running
command: |
for i in 0..9; do
docker version
ret=$?
if [ $ret -eq 0 ]; then
exit 0
fi
sleep 5
done
- run:
name: Configure Minikube
command: |
curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube_latest_amd64.deb
sudo dpkg -i minikube_latest_amd64.deb
minikube start --vm-driver=docker --container-runtime=containerd --kubernetes-version=v1.19.14
minikube status
- run:
name: Install requirements
command: minikube kubectl -- apply -f https://github.com/jetstack/cert-manager/releases/download/v1.3.0/cert-manager.yaml
- run:
name: Build and load images
<<: *working_directory
environment:
GOBIN: /home/circleci/.go_workspace/bin
command: make minikube-build
- run:
name: Run e2e tests
<<: *working_directory
command: make e2e-test
no_output_timeout: 15m
# ensures that the file containing 3rd-party licenses is up-to-date
third-party-licenses:
executor: python
steps:
- alpine_install_git
- checkout
- python_install_requirements
- run:
name: Ensure 3rd-party licenses are up-to-date
command: inv license-check
- run: git diff --exit-code
# ensures that the license header is present on all the needed files
license-header:
executor: python
steps:
- alpine_install_git
- checkout
- python_install_requirements
- run:
name: Ensure license header is present
command: inv header-check
# ensures that the grpc protobuf files genereated by grpc/disruptionlistener/disruptionlistener.proto are up to date
disruptionlistener-protobuf:
executor: golang
steps:
- checkout
- run:
command: |
cd grpc/disruptionlistener
apt-get update
apt-get install unzip -y
PROTOC_VERSION=3.17.3
PROTOC_ZIP=protoc-$PROTOC_VERSION-linux-x86_64.zip
curl -OL https://github.com/protocolbuffers/protobuf/releases/download/v$PROTOC_VERSION/$PROTOC_ZIP
unzip -o $PROTOC_ZIP -d /usr/local bin/protoc
unzip -o $PROTOC_ZIP -d /usr/local 'include/*'
rm -f $PROTOC_ZIP
go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.27.1
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.1.0
protoc --proto_path=. --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative disruptionlistener.proto
- run: git diff --exit-code ':!go.*'
# ensures that the grpc protobuf files genereated by dogfood/chaosdogfood/chaosdogfood.proto are up to date
chaosdogfood-protobuf:
executor: golang
steps:
- checkout
- run:
command: |
cd dogfood/chaosdogfood
apt-get update
apt-get install unzip -y
PROTOC_VERSION=3.17.3
PROTOC_ZIP=protoc-$PROTOC_VERSION-linux-x86_64.zip
curl -OL https://github.com/protocolbuffers/protobuf/releases/download/v$PROTOC_VERSION/$PROTOC_ZIP
unzip -o $PROTOC_ZIP -d /usr/local bin/protoc
unzip -o $PROTOC_ZIP -d /usr/local 'include/*'
rm -f $PROTOC_ZIP
go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.27.1
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.1.0
protoc --proto_path=. --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative chaosdogfood.proto
- run: git diff --exit-code ':!go.*'
workflows:
version: 2
test_and_build:
jobs:
- prepare-env
- dependencies:
requires:
- prepare-env
- manifests:
requires:
- prepare-env
- vet:
requires:
- prepare-env
- fmt:
requires:
- prepare-env
- lint:
requires:
- prepare-env
- test:
requires:
- prepare-env
- e2e-test:
requires:
- prepare-env
- third-party-licenses
- license-header
- disruptionlistener-protobuf
- chaosdogfood-protobuf