-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathtaskfile.yaml
More file actions
390 lines (384 loc) · 12.4 KB
/
taskfile.yaml
File metadata and controls
390 lines (384 loc) · 12.4 KB
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
version: "3"
env:
GOBIN:
sh: |
if [[ -z "$(go env GOBIN)" ]]; then
echo "$(go env GOPATH)/bin"
else
echo "$(go env GOBIN)"
fi
run: when_changed
set:
- e
- pipefail
vars:
IMAGE: '{{ .IMAGE | default "controller-manager" }}'
tools:
map:
controller-gen:
url: sigs.k8s.io/controller-tools/cmd/controller-gen
version: 0.18.0
conversion-gen:
url: k8s.io/code-generator/cmd/conversion-gen
version: 0.33.2
golangci-lint:
url: github.com/golangci/golangci-lint/v2/cmd/golangci-lint
version: 2.2.1
gofumpt:
url: mvdan.cc/gofumpt
version: 0.9.1
golines:
url: github.com/segmentio/golines
version: 0.13.0
kustomize:
url: sigs.k8s.io/kustomize/kustomize/v5
version: 5.7.1
grype:
url: github.com/anchore/grype/cmd/grype
version: 0.104.2
# not the good yq, but the good one has no "just run" option
yq:
url: github.com/mikefarah/yq/v4
version: 4.49.2
controllerGenCmd: 'go run {{ (index .tools "controller-gen").url }}@v{{ (index .tools "controller-gen").version }}'
conversionGenCmd: 'go run {{ (index .tools "conversion-gen").url }}@v{{ (index .tools "conversion-gen").version }}'
golangciLintCmd: 'go run {{ (index .tools "golangci-lint").url }}@v{{ (index .tools "golangci-lint").version }}'
gofumptCmd: 'go run {{ (index .tools "gofumpt").url }}@v{{ (index .tools "gofumpt").version }}'
golinesCmd: 'go run {{ (index .tools "golines").url }}@v{{ (index .tools "golines").version }}'
kustomizeCmd: 'go run {{ (index .tools "kustomize").url }}@v{{ (index .tools "kustomize").version }}'
grypeCmd: 'go run {{ (index .tools "grype").url }}@v{{ (index .tools "grype").version }}'
yqCmd: 'go run {{ (index .tools "yq").url }}@v{{ (index .tools "yq").version }}'
buildDir: build
artifactsDir: _artifacts
# TODO: until https://github.com/go-task/task/issues/178 is done
version:
sh: git describe --tags 2>/dev/null | awk -F - 'NF==3 {printf("%s-%04d-%s", $1, $2, $3)} NF!=3 {print $1}'
tasks:
default:
cmd:
task: build
manifests:
cmds:
- task: manifest-kustomize
- mkdir -p {{ .buildDir }}/config
- rm -f {{ .buildDir }}/config/kustomization.yaml
- env -C {{ .buildDir }}/config {{ .kustomizeCmd }} create --resources ../../config
- env -C {{ .buildDir }}/config {{ .kustomizeCmd }} edit set image controller-manager={{ .IMAGE }}
- "{{ .kustomizeCmd }} build {{ .buildDir }}/config > {{ .buildDir }}/control-plane-components.yaml"
- |
declare -a supportedVersions
mapfile -t supportedVersions <<< "$(sed -n -r 's#^\s+cluster.x-k8s.io/(v\S+): \S+#\1#gp' {{ .buildDir }}/crds/controlplane.* | sort -u)"
declare -a currentVersion
mapfile -t currentVersion <<< "$({{ .yqCmd }} -r '.["."] | split(".") | "\(.[0])\n\(.[1])"' .github/release-please/manifest.json)"
if ! [[ -f metadata.yaml ]]; then
cat <<EOF | cut -c 5- > metadata.yaml
apiVersion: clusterctl.cluster.x-k8s.io/v1alpha3
kind: Metadata
releaseSeries: []
EOF
fi
for version in "${supportedVersions[@]}"; do
MAJOR="${currentVersion[0]}" MINOR="${currentVersion[1]}" VERSION="$version" {{ .yqCmd }} -i '.releaseSeries = (.releaseSeries + [{"major":env(MAJOR),"minor":env(MINOR),"contract":strenv(VERSION)}] | unique | sort_by(.major, .minor) | reverse)' metadata.yaml
done
mv metadata.yaml {{ .buildDir }}/metadata.yaml
generates:
- "{{ .buildDir }}/control-plane-components.yaml"
- "{{ .buildDir }}/metadata.yaml"
generate:
cmds:
- task: generate-deepcopy
- task: generate-conversion
format:
deps:
- clean-files
- generate
sources:
- ./**/*.go
cmds:
- "{{ .gofumptCmd }} -w api cmd pkg"
- "{{ .golinesCmd }} --ignore-generated --ignored-dirs=.go -m 120 -w ."
- "{{ .golangciLintCmd }} fmt"
vulnerabilities:
sources:
- go.mod
- go.sum
cmd: "{{ .grypeCmd }} --name cacpphcp dir:. --exclude ./build --exclude ./*/worktree*/* --only-fixed --by-cve --fail-on negligible"
lint:
vars:
fix: '{{ .fix | default "false" }}'
deps:
- artifacts-dir
- format
- vulnerabilities
sources:
- ./**/*.go
- ./.golangci.yaml
cmd: "{{ .golangciLintCmd }} run --fix={{ .fix }}"
generates:
- ./**/*.go
- "{{ .artifactsDir }}/golangci-lint.json"
test:
label: "test {{ .path }}"
deps:
- artifacts-dir
- generate
- format
vars:
path: '{{ .path | default "." }}'
sources:
- ./**/*.go
- go.sum
cmd: go test ./{{ .path }}/... -coverprofile {{ .artifactsDir }}/cover.out
generates:
- "{{ .artifactsDir }}/cover.out"
pre-commit:
cmds:
- task: compile
- task: manifests
- task: test
- task: lint
check-diff:
deps:
- manifests
- generate
- format
cmd: git diff --exit-code
clean:
cmds:
- buildah manifest rm {{ .IMAGE }} 2>/dev/null || true
- rm -rf {{ .buildDir }}
- rm -rf {{ .artifactsDir }}
status:
- (! buildah manifest inspect {{ .IMAGE }} 2>/dev/null) || false
- test ! -d {{ .buildDir }}
- test ! -d {{ .artifactsDir }}
compile:
label: compile {{ .arch }}
deps:
- tidy
- build-dir
- generate
sources:
- ./**/*.go
- go.mod
- go.sum
- exclude: pkg/**/*_test.go
vars:
arch: '{{ .arch | default ARCH }}'
env:
CGO_ENABLED: '0'
GOARCH: '{{ .arch }}'
GOOS: linux
cmd: go build -ldflags="-X=main.version={{ .version }} -s -w" -trimpath -o {{ .buildDir }}/manager-{{ .arch }} ./cmd/hosted-control-plane-controller/main.go
generates:
- "{{ .buildDir }}/manager-{{ .arch }}"
status:
- test -x {{ .buildDir }}/manager-{{ .arch }}
image:
label: image {{ .arch }}
deps:
- compile
vars:
arch: '{{ .arch | default ARCH }}'
oldDigests:
sh: >-
(buildah manifest inspect {{ .IMAGE }} 2> /dev/null || echo '{}') | {{ .yqCmd }} -r '.manifests // [] | map(select(.platform.architecture == "{{ .arch }}")) | map(.digest)[]' 2>/dev/null || true
sources:
- Containerfile
- .containerignore
- "{{ .buildDir }}/manager-{{ .arch }}"
cmds:
- for:
var: oldDigests
cmd: "buildah manifest remove {{ .IMAGE }} {{ .ITEM }} || true"
- "buildah build --arch {{ .arch }} --manifest {{ .IMAGE }} --build-arg=manager={{ .buildDir }}/manager-{{ .arch }} ."
status:
- "buildah manifest inspect {{ .IMAGE }} | grep -q {{ .arch }}"
build:
method: none
deps:
- tidy
- build-dir
- manifests
- generate
sources:
- ./**/*.go
- go.sum
vars:
archs: "{{ ARCH }},amd64,arm64"
cmds:
- for: &forArch
var: archs
split: ","
as: arch
task: compile
vars:
arch: "{{ .arch }}"
- for: *forArch
task: image
vars:
arch: "{{ .arch }}"
get-version:
cmd: echo {{ .version }}
dev:
cmd:
task: telepresence
_generate-deepcopy:
label: generate-deepcopy {{ .API }}
internal: true
desc: Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations for {{ .API }}.
deps:
- tidy
sources:
- api/{{ .API }}/*.go
- exclude: api/{{ .API }}/zz_generated.deepcopy.go
cmds:
- '{{ .controllerGenCmd }} object paths="./api/{{ .API }}/..."'
generates:
- api/{{ .API }}/zz_generated.deepcopy.go
generate-deepcopy:
method: none
vars:
APIS:
sh: find ./api -mindepth 1 -maxdepth 1 -type d | xargs -r basename
cmds:
- for:
var: APIS
task: _generate-deepcopy
vars:
API: "{{ .ITEM }}"
_generate-conversion:
internal: true
label: generate-conversions {{ .API }}
desc: Generate code containing Conversion method implementations for {{ .API }}.
deps:
- tidy
sources:
- api/{{ .API }}/*.go
- exclude: api/{{ .API }}/zz_generated.deepcopy.go
cmds:
- cmd: "{{ .conversionGenCmd }} --output-file=zz_generated.conversion.go --go-header-file=/dev/null ./api/{{ .API }}"
generates:
- api/{{ .API }}/zz_generated.conversion.go
generate-conversion:
method: none
vars:
APIS:
sh: grep -Pl '// \+k8s:conversion-gen=(?!false)' api/*/doc.go 2>/dev/null | xargs -r dirname | xargs -r basename
cmds:
- for:
var: APIS
task: _generate-conversion
vars:
API: "{{ .ITEM }}"
tidy:
internal: true
sources:
- '**/*.go'
- go.mod
generates:
- go.sum
cmd: go mod tidy
clean-files:
internal: true
cmd: find -type f -size 0 -name '*.go' -delete
status:
- find -type f -size 0 -name '*.go' -exec false {} + -quit
build-dir:
internal: true
cmd: mkdir -p {{ .buildDir }}
status:
- test -d {{ .buildDir }}
artifacts-dir:
internal: true
cmd: mkdir -p {{ .artifactsDir }}
status:
- test -d {{ .artifactsDir }}
telepresence:
internal: true
interactive: true
preconditions:
- command -v kubectl
- command -v telepresence
- sh: telepresence version | grep -q v2
- command -v flux
- sh: "[[ -L /var/run/secrets ]]"
msg: "symlink missing: sudo ln -s /tmp/operator/var/run/secrets /var/run/secrets"
- sh: "grep ^user_allow_other /etc/fuse.conf"
msg: |
# add user_allow_other to config file
visudo /etc/fuse.conf
requires:
vars:
- KUBECONFIG
env:
NAMESPACE: capi-hosted-control-plane-system
DEPLOYMENT_NAME: capi-hosted-control-plane-controller-manager
# always run the cleanup stuff
ignore_error: true
cmds:
- telepresence helm install -n $NAMESPACE --set agent.securityContext.runAsNonRoot=false --set agent.mountPolicies./tmp=RemoteReadOnly
- defer: telepresence helm uninstall -n $NAMESPACE
- telepresence connect --manager-namespace=$NAMESPACE --namespace $NAMESPACE --also-proxy 212.15.209.254/32,212.15.216.1/32
- defer: sudo pkill telepresence
- defer: telepresence quit -s
- telepresence replace $DEPLOYMENT_NAME --port=9443:webhooks --mount /tmp/operator --env-json /tmp/operator-env.json -- sleep infinity
manifest-rbac:
internal: true
desc: Generate RBAC manifests.
sources:
- api/**/*.go
- exclude: api/**/zz_generated.deepcopy.go
- exclude: api/**/zz_generated.conversion.go
- pkg/**/*.go
- exclude: pkg/**/*_test.go
cmds:
- "{{ .controllerGenCmd }} rbac:roleName=manager paths=./api/... paths=./pkg/... output:rbac:artifacts:config={{ .buildDir }}/rbac"
generates:
- "{{ .buildDir }}/rbac/role.yaml"
manifest-webhooks:
internal: true
desc: Generate WebhookConfiguration manifests.
sources:
- api/**/*.go
- exclude: api/**/zz_generated.deepcopy.go
- exclude: api/**/zz_generated.conversion.go
- pkg/**/*.go
- exclude: pkg/**/*_test.go
cmds:
- "{{ .controllerGenCmd }} webhook paths=./api/... paths=./pkg/... output:webhook:artifacts:config={{ .buildDir }}/webhooks"
generates:
- "{{ .buildDir }}/webhooks/manifests.yaml"
manifest-crds:
internal: true
desc: Generate CustomResourceDefinition manifests
sources:
- api/**/*.go
- exclude: api/**/zz_generated.deepcopy.go
- exclude: api/**/zz_generated.conversion.go
cmds:
- "{{ .controllerGenCmd }} crd paths=./api/... output:crd:artifacts:config={{ .buildDir }}/crds"
generates:
- "{{ .buildDir }}/crds/controlplane.cluster.x-k8s.io_hostedcontrolplanes.yaml"
- "{{ .buildDir }}/crds/controlplane.cluster.x-k8s.io_hostedcontrolplanetemplates.yaml"
manifest-kustomize:
internal: true
desc: Generate `kustomization.yaml`s for all generated manifests
deps:
- manifest-rbac
- manifest-crds
- manifest-webhooks
vars:
files:
- "{{ .buildDir }}/rbac"
- "{{ .buildDir }}/webhooks"
- "{{ .buildDir }}/crds"
cmds:
- for:
var: files
cmd: rm -f {{ .ITEM }}/kustomization.yaml
- for:
var: files
cmd: env -C {{ .ITEM }} {{ .kustomizeCmd }} create --autodetect
generates:
- "{{ .buildDir }}/*/kustomization.yaml"