forked from Azure/azure-service-operator
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Taskfile.yml
419 lines (359 loc) · 15.3 KB
/
Taskfile.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
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
version: '3.7'
run: when_changed
output: prefixed
vars:
GENERATOR_APP: aso-gen
GENERATOR_ROOT: ./hack/generator/
GENERATOR_PACKAGE: github.com/Azure/azure-service-operator/hack/generator
CONTROLLER_APP: aso-controller
CONTROLLER_ROOT: ./hack/generated/
CONTROLLER_PACKAGE: github.com/Azure/azure-service-operator/hack/generated
SCRIPTS_ROOT: ./scripts
VERSION:
# Version tags for the v2 controller must start with "v2", e.g. "v2.0.0-alpha.0".
sh: "{{.SCRIPTS_ROOT}}/build-version.py v2"
CONTROLLER_DOCKER_IMAGE: azureserviceoperator:{{.VERSION}}
PUBLIC_REGISTRY: mcr.microsoft.com/k8s/
LOCAL_REGISTRY_CONTROLLER_DOCKER_IMAGE: localhost:5000/azureserviceoperator:latest
CROSSPLANE_APP: crossplane-gen
CROSSPLANE_ROOT: ./hack/crossplane/
# the 'api' dir contains generated code so we want to exclude it
# for go-fmt the root dir must be excluded (it recurses)
GENERATED_DIRS_TO_FMT_CMD: go list -f '{{"{{.Dir}}"}}' ./... | grep -vE '/apis(/|$)|/generated$' | tr '\n' ' '
# how long to let tests against live resources run for
LIVE_TEST_TIMEOUT: 2h
tasks:
default:
desc: Perform all fast local pre-commit tasks.
deps:
- generator:quick-checks
- controller:quick-checks
- crossplane:generate-crds
- crossplane:quick-checks
ci:
desc: Run all CI checks.
deps:
- generator:ci
- controller:ci
- crossplane:ci
cmds:
- task: verify-no-changes
ci-live:
desc: Run all CI checks with live Azure resources. Requires that auth environment variables are set.
deps:
- generator:ci
- controller:ci-live
format-code:
desc: Ensure all code is formatted
dir: hack
cmds:
- gofmt -l -s -w .
############### Generator targets ###############
basic-checks:
deps: [header-check, specifier-check, format-code]
generator:quick-checks:
cmds:
- task: generator:unit-tests
- task: basic-checks
# Lint is forced to the end because it expects the code is formatted
- task: generator:lint
generator:ci:
cmds:
- task: generator:unit-tests-cover
- task: basic-checks
# lint must be after format-code
- task: generator:lint-full
generator:unit-tests:
desc: Run {{.GENERATOR_APP}} unit tests.
dir: "{{.GENERATOR_ROOT}}"
cmds:
- go test ./... -tags=noexit -run '{{default ".*" .TEST_FILTER}}'
generator:unit-tests-cover:
desc: Run {{.GENERATOR_APP}} unit tests and output coverage.
dir: "{{.GENERATOR_ROOT}}"
cmds:
- go test ./... -tags=noexit -race -covermode atomic -coverprofile=generator-coverage.out -coverpkg=./... -run '{{default ".*" .TEST_FILTER}}'
generator:update-golden-tests:
desc: Update {{.GENERATOR_APP}} golden test outputs.
dir: "{{.GENERATOR_ROOT}}"
cmds:
- go test ./pkg/codegen -run ^TestGolden -update
generator:lint:
desc: Run {{.GENERATOR_APP}} fast lint checks.
dir: "{{.GENERATOR_ROOT}}"
cmds:
- golangci-lint run -v
generator:lint-full:
desc: Run {{.GENERATOR_APP}} all lint checks.
dir: "{{.GENERATOR_ROOT}}"
cmds:
- golangci-lint run -v --fast=false
generator:build:
desc: Generate the {{.GENERATOR_APP}} binary.
dir: "{{.GENERATOR_ROOT}}"
sources: ["**/*.go", "go.mod", "go.sum"]
cmds:
- go build -ldflags "-X {{.GENERATOR_PACKAGE}}/pkg/codegen.Version={{.VERSION}}" -o ./bin/{{.GENERATOR_APP}}
generator:diagrams:
desc: Regenerate all GraphViz diagrams
dir: "./docs/design/images"
sources: ["*/*.dot"]
cmds:
- "for f in **/*.dot; do dot -Tpng -o${f%.dot}.png $f; done"
############### Controller targets ###############
controller:quick-checks:
cmds:
- task: controller:test
# checks must be after test as that will generate code
- task: basic-checks
# Lint is forced to the end because it expects the code is formatted
- task: controller:lint
controller:ci:
cmds:
- task: controller:test-integration-envtest-cover
# checks must be after test as that will generate code
- task: basic-checks
# lint must be at end after code is formatted
- task: controller:lint-full
controller:ci-live:
cmds:
- task: controller:test-integration-envtest-live
- task: basic-checks
- task: controller:lint-full
controller:lint:
desc: Run fast lint checks.
deps: [controller:generate-crds]
dir: "{{.CONTROLLER_ROOT}}"
cmds:
- golangci-lint run -v ./...
controller:lint-full:
desc: Run all lint checks.
deps: [controller:generate-crds]
dir: "{{.CONTROLLER_ROOT}}"
cmds:
- golangci-lint run -v --fast=false --timeout 5m ./...
controller:test:
desc: Run {{.CONTROLLER_APP}} unit tests.
dir: "{{.CONTROLLER_ROOT}}"
deps: [controller:generate-crds]
cmds:
- go test -short -tags=noexit -run '{{default ".*" .TEST_FILTER}}' ./...
controller:test-cover:
desc: Run {{.CONTROLLER_APP}} unit tests and output coverage.
dir: "{{.CONTROLLER_ROOT}}"
deps: [controller:generate-crds]
cmds:
- go test -short -tags=noexit -race -covermode atomic -coverprofile=controller-coverage.out -coverpkg="./..." -run '{{default ".*" .TEST_FILTER}}' ./...
controller:build:
desc: Generate the {{.CONTROLLER_APP}} binary.
dir: "{{.CONTROLLER_ROOT}}"
sources:
# excluding the ./apis directory here
- "go.mod"
- "go.sum"
- "*.go"
- "controllers/**/*.go"
- "pkg/**/*.go"
cmds:
- CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "-X {{.CONTROLLER_PACKAGE}}/pkg/version.BuildVersion={{.VERSION}}" -o ./bin/{{.CONTROLLER_APP}}
controller:docker-build:
desc: Builds the {{.CONTROLLER_APP}} Docker image.
dir: "{{.CONTROLLER_ROOT}}"
deps: [controller:build]
sources:
- Dockerfile
- ./bin/{{.CONTROLLER_APP}}
cmds:
- docker build . -t {{.CONTROLLER_DOCKER_IMAGE}}
controller:docker-build-and-save:
desc: Builds the {{.CONTROLLER_APP}} Docker image and saves it using docker save.
dir: "{{.CONTROLLER_ROOT}}"
deps: [controller:docker-build]
cmds:
- docker save {{.CONTROLLER_DOCKER_IMAGE}} > bin/$(echo '{{.CONTROLLER_DOCKER_IMAGE}}' | sed -e 's/:/_/g').tar
controller:docker-tag-version:
desc: Tags the {{.CONTROLLER_APP}} Docker image with the appropriate version.
dir: "{{.CONTROLLER_ROOT}}"
deps: [controller:docker-build]
cmds:
- 'if [ -z "{{.DOCKER_PUSH_TARGET}}" ]; then echo "Error: DOCKER_PUSH_TARGET must be set"; exit 1; fi'
- docker tag {{.CONTROLLER_DOCKER_IMAGE}} "{{.DOCKER_PUSH_TARGET}}/{{.CONTROLLER_DOCKER_IMAGE}}"
controller:docker-push-local:
desc: Pushes the controller container image to a local registry
deps: [controller:docker-build]
dir: "{{.CONTROLLER_ROOT}}"
cmds:
- docker tag {{.CONTROLLER_DOCKER_IMAGE}} {{.LOCAL_REGISTRY_CONTROLLER_DOCKER_IMAGE}}
- docker push {{.LOCAL_REGISTRY_CONTROLLER_DOCKER_IMAGE}}
controller:test-integration-envtest:
desc: Run integration tests with envtest using record/replay.
dir: "{{.CONTROLLER_ROOT}}"
deps: [controller:generate-kustomize]
cmds:
# -race fails at the moment in controller-runtime
- go test -run '{{default ".*" .TEST_FILTER}}' ./...
controller:test-integration-envtest-cover:
desc: Run integration tests with envtest using record/replay and output coverage.
dir: "{{.CONTROLLER_ROOT}}"
deps: [controller:generate-kustomize]
cmds:
# -race fails at the moment in controller-runtime
- go test -covermode atomic -coverprofile=coverage-integration-envtest.out -coverpkg="./..." -run '{{default ".*" .TEST_FILTER}}' ./...
controller:test-integration-envtest-live:
desc: Run integration tests with envtest against live data and output coverage.
dir: "{{.CONTROLLER_ROOT}}"
deps: [controller:generate-kustomize, cleanup-azure-resources]
cmds:
# -race fails at the moment in controller-runtime
- RECORD_REPLAY=0 go test -timeout {{.LIVE_TEST_TIMEOUT}} -covermode atomic -coverprofile=coverage-integration-envtest-live.out -coverpkg="./..." -run '{{default ".*" .TEST_FILTER}}' ./...
controller:generate-types:
desc: Run {{.GENERATOR_APP}} to generate input files for controller-gen for {{.CONTROLLER_APP}}.
dir: "{{.GENERATOR_ROOT}}"
deps: [generator:build]
sources:
- ./bin/{{.GENERATOR_APP}}
- azure-arm.yaml
cmds:
- ./bin/{{.GENERATOR_APP}} gen-types azure-arm.yaml
controller:generate-crds:
desc: Run controller-gen to generate {{.CONTROLLER_APP}} CRD files.
deps: [controller:generate-types]
dir: "{{.CONTROLLER_ROOT}}"
sources:
- "apis/**/*_gen.go" # depends on all generated types
- "pkg/genruntime/**/*.go" # Also depends on the genruntime types as they're embedded into the CRDs
cmds:
- mkdir -p ./apis
- find ./apis -type f -name "zz_generated.*" -delete
- if [ -d "./config/crd/bases" ]; then find "./config/crd/bases" -type f -delete; fi
- cd apis && controller-gen object:headerFile=../../boilerplate.go.txt paths="./..." || true
- cd apis && controller-gen {{.CRD_OPTIONS}} rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=../config/crd/bases output:webhook:artifacts:config=../config/webhook output:rbac:artifacts:config=../config/rbac
vars:
CRD_OPTIONS: "crd:crdVersions=v1,allowDangerousTypes=true"
controller:generate-genruntime-deepcopy:
desc: Run controller-gen to generate {{.CONTROLLER_APP}} CRD files.
dir: "{{.CONTROLLER_ROOT}}"
sources:
- "pkg/genruntime/**/*.go"
cmds:
- find ./pkg/genruntime -type f -name "zz_generated.*" -delete
- cd pkg/genruntime && controller-gen object:headerFile=../../../boilerplate.go.txt paths="./..." || true
controller:generate-kustomize:
desc: Run {{.GENERATOR_APP}} to generate the Kustomize file for registering CRDs.
deps: [controller:generate-crds, controller:generate-genruntime-deepcopy]
sources:
- "{{.GENERATOR_ROOT}}bin/{{.GENERATOR_APP}}"
- "{{.CONTROLLER_ROOT}}config/crd/bases/**/*.yaml"
generates:
- "{{.CONTROLLER_ROOT}}config/crd/kustomization.yaml"
cmds:
- "{{.GENERATOR_ROOT}}bin/{{.GENERATOR_APP}} gen-kustomize {{.CONTROLLER_ROOT}}config/crd"
controller:run-kustomize:
desc: Generates the CRD & configuration bundle.
deps: [controller:generate-kustomize]
dir: "{{.CONTROLLER_ROOT}}"
cmds:
- mkdir -p bin # in case it doesn’t exist
- kustomize build config/default | sed -e 's@localhost:5000/azureserviceoperator:latest@{{.PUBLIC_REGISTRY}}{{.CONTROLLER_DOCKER_IMAGE}}@g' > bin/azureserviceoperator_{{.VERSION}}.yaml
controller:kind-delete:
desc: Deletes a kind cluster
cmds:
- "kind delete cluster --name=asov2"
controller:kind-create:
desc: Creates a kind cluster and local Docker registry. Images in the local registry can be pulled in the kind cluster
cmds:
- "export KIND_CLUSTER_NAME=asov2 && {{.SCRIPTS_ROOT}}/kind-with-registry.sh"
controller:install:
desc: Installs the controller, webhooks, and CRDs into the default kubectl cluster
deps: [controller:generate-kustomize]
cmds:
- "cd {{.CONTROLLER_ROOT}} && kustomize build config/default | kubectl apply -f -" # TODO: may need | sed "s_${CONFIG_REGISTRY}_${REGISTRY}/${IMG}_" at some point
- "{{.SCRIPTS_ROOT}}/deploy_testing_secret.sh"
controller:install-cert-manager:
desc: Installs cert manager
cmds:
- "kubectl create namespace cert-manager"
- "kubectl label namespace cert-manager cert-manager.io/disable-validation=true"
- "kubectl apply -f https://github.com/jetstack/cert-manager/releases/download/v1.1.0/cert-manager.yaml" # TODO: Bump this version?
############### Crossplane targets ###############
crossplane:quick-checks:
cmds:
- task: basic-checks
# TODO: We currently have no tests
# crossplane:test:
# desc: Run {{.CROSSPLANE_APP}} unit tests.
# dir: "{{.CROSSPLANE_ROOT}}"
# cmds:
# - go test ./... -tags=noexit
# crossplane:update-golden-tests:
# desc: Update {{.CROSSPLANE_APP}} golden test outputs.
# dir: "{{.CROSSPLANE_ROOT}}"
# cmds:
# - go test ./pkg/codegen -run ^TestGolden$ -update
# TODO: No non-generated code in this directory at the moment
# crossplane:lint:
# desc: Run {{.CROSSPLANE_APP}} fast lint checks.
# dir: "{{.CROSSPLANE_ROOT}}"
# cmds:
# - golangci-lint run -v
crossplane:generate-crds:
desc: Run controller-gen to generate {{.CROSSPLANE_APP}} CRD files.
deps: [crossplane:generate-types]
dir: "{{.CROSSPLANE_ROOT}}"
sources:
- "apis/**/*_gen.go" # depends on all generated types
cmds:
- mkdir -p ./apis
- find ./apis -type f -name "zz_generated.*" -delete
- if [ -d "./config/crd/bases" ]; then find "./config/crd/bases" -type f -delete; fi
- cd apis && controller-gen object:headerFile=../../boilerplate.go.txt paths="./..." || true
- cd apis && controller-gen {{.CRD_OPTIONS}} rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=../config/crd/bases output:webhook:artifacts:config=../config/webhook
vars:
CRD_OPTIONS: "crd:crdVersions=v1,allowDangerousTypes=true"
crossplane:generate-types:
desc: Run {{.GENERATOR_APP}} to generate input files for controller-gen for {{.CROSSPLANE_APP}}.
dir: "{{.GENERATOR_ROOT}}"
deps: [generator:build]
sources:
- ./bin/{{.GENERATOR_APP}}
- azure-crossplane.yaml
cmds:
- ./bin/{{.GENERATOR_APP}} gen-types azure-crossplane.yaml
crossplane:ci:
deps: [header-check, specifier-check, crossplane:generate-crds]
############### Shared targets ###############
cleanup-azure-resources:
desc: Removes any old resources created by integration tests.
# This finds all resource groups which match the specified pattern (asotest*)
# and are older than a day (86400 seconds). This is a bit horrible but it works...
# [*]: this must match what is specified in raw_client.go
cmds:
- |
rgs=`az group list --query '[*].{Name: name, CreatedAt: tags.CreatedAt}' \
| jq -r '.[] | select(.Name | test("^asotest")) | select(.CreatedAt == null or now-(.CreatedAt | fromdate) > 86400) | .Name'`; \
for rgname in ${rgs[@]} ; do \
echo "$rgname will be deleted"; \
az group delete --name $rgname --no-wait --yes; \
done
header-check:
desc: Ensure all files have an appropriate license header.
cmds: [python3 ./scripts/check_headers.py]
specifier-check:
desc: Check that format specifiers %v and %+v are not used
# Both %v and %+v result in all the values from structs being dumped into the string. If that
# struct happens to contain a secret or sensitive information, it ends up dumped out in an
# uncontrolled way, potentially leading to a security issue or a problem with PII disclosure.
# The buried risk here is that while %v might be safe now, a future change to the struct might
# introduce a disclosure later on.
cmds:
- cmd: echo "==> Checking format specifiers <=="
silent: true
- cmd: '! git grep -e "%+v" -e "%v" --break --heading --line-number -I "*.go"'
verify-no-changes:
desc: Checks that there are no uncommitted modifications to files
cmds:
- cmd: 'if [ -n "{{.CHANGED}}" ]; then echo "Error: files were modified during the build (did you forget to commit generated files?):"; echo "{{.CHANGED}}"; git diff; exit 1; fi'
silent: true
vars:
CHANGED:
sh: git status --porcelain