forked from open-component-model/open-component-model
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTaskfile.yml
More file actions
348 lines (299 loc) · 12.2 KB
/
Copy pathTaskfile.yml
File metadata and controls
348 lines (299 loc) · 12.2 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
version: '3'
env:
CONTROLLER_IMG: '{{ env "CONTROLLER_IMG" | default "ghcr.io/open-component-model/kubernetes/controller:latest" }}'
vars:
GOBIN:
sh: 'go env GOBIN || echo $(go env GOPATH)/bin'
PROJECT_ROOT:
sh: 'git rev-parse --show-toplevel'
# Tool versions: load from project root, then override with local .env if set
CONTROLLER_TOOLS_VERSION:
sh: 'source {{.PROJECT_ROOT}}/.env && [ -f .env ] && source .env; echo "$CONTROLLER_TOOLS_VERSION"'
ENVTEST_VERSION:
sh: 'source {{.PROJECT_ROOT}}/.env && [ -f .env ] && source .env; echo "$ENVTEST_VERSION"'
ENVTEST_K8S_VERSION:
sh: 'source {{.PROJECT_ROOT}}/.env && [ -f .env ] && source .env; echo "$ENVTEST_K8S_VERSION"'
KIND_NODE_IMAGE_VERSION:
sh: 'source {{.PROJECT_ROOT}}/.env && [ -f .env ] && source .env; echo "$KIND_NODE_IMAGE_VERSION"'
HELM_DOCS_VERSION:
sh: 'source {{.PROJECT_ROOT}}/.env && [ -f .env ] && source .env; echo "${HELM_DOCS_VERSION:-v1.14.2}"'
YQ_VERSION:
sh: 'source {{.PROJECT_ROOT}}/.env && [ -f .env ] && source .env; echo "${YQ_VERSION:-v4.49.2}"'
CONTAINER_TOOL: '{{.CONTAINER_TOOL | default "docker"}}'
LOCALBIN: '{{.TASKFILE_DIR}}/bin'
KUBECTL: '{{.KUBECTL | default "kubectl"}}'
CONTROLLER_GEN: '{{.LOCALBIN}}/controller-gen-{{.CONTROLLER_TOOLS_VERSION}}'
ENVTEST: '{{.LOCALBIN}}/setup-envtest-{{.ENVTEST_VERSION}}'
HELM_DOCS: '{{.LOCALBIN}}/helm-docs-{{.HELM_DOCS_VERSION}}'
YQ: '{{.LOCALBIN}}/yq-{{.YQ_VERSION}}'
IGNORE_NOT_FOUND: '{{.IGNORE_NOT_FOUND | default "false"}}'
PLATFORMS: '{{.PLATFORMS | default "linux/arm64,linux/amd64"}}'
tasks:
default:
desc: "Build the project (default task)"
cmds: [ task: build ]
# Development
manifests:
desc: "Generate raw CRD into config/crd/bases and RBAC YAML into bin/gen (consumed by helm/generate-crds and helm/generate-rbac)"
deps: [controller-gen]
cmds:
- rm -rf bin/gen config/crd/bases
- mkdir -p bin/gen/rbac config/crd/bases
- '"{{.CONTROLLER_GEN}}" rbac:roleName=manager-role crd paths="{{ .TASKFILE_DIR }}/..." output:rbac:artifacts:config=bin/gen/rbac output:crd:artifacts:config=config/crd/bases'
generate:
desc: "Generate Go deepcopy and runtime.Object implementations"
deps: [controller-gen]
cmd: '"{{.CONTROLLER_GEN}}" object paths="{{ .TASKFILE_DIR }}/..."'
fmt:
desc: "Format Go source files"
cmd: 'go fmt "{{ .TASKFILE_DIR }}/..."'
vet:
desc: "Run Go vet to check for common issues"
cmd: 'go vet "{{ .TASKFILE_DIR }}/..."'
test:
desc: "Run unit and integration tests with coverage"
deps: [manifests, generate, envtest]
env:
ENVTEST_K8S_VERSION: '{{.ENVTEST_K8S_VERSION}}'
cmds:
- |
KUBEBUILDER_ASSETS=$({{ .ENVTEST }} use {{ .ENVTEST_K8S_VERSION }} --bin-dir {{.LOCALBIN}} -p path)
echo "Using KUBEBUILDER_ASSETS: $KUBEBUILDER_ASSETS"
go test $(go list ./... | grep -v /e2e) -coverprofile cover.out
test/e2e/setup/local:
desc: "Set up a local Kind cluster for E2E tests"
deps:
# We depend on a locally built image, so we need to load that into the local machine.
- task: docker-build
vars:
LOAD: "true"
cmds:
- 'KIND_NODE_IMAGE_VERSION={{.KIND_NODE_IMAGE_VERSION}} bash test/e2e/hacks/setup.sh'
- 'kind load docker-image {{.CONTROLLER_IMG}} --name ocm-e2e'
test/e2e/setup/teardown:
desc: "Delete the 'ocm-e2e' Kind cluster and its registry. Only affects resources created by test/e2e/setup/local."
cmds:
- 'kind delete cluster --name ocm-e2e 2>/dev/null || true'
- 'docker rm -f ocm-e2e-registry 2>/dev/null || true'
test/e2e:
desc: "Run end-to-end tests against a running cluster. Pass ginkgo flags via `--`, e.g. `task test/e2e -- -ginkgo.focus=helm-simple`. Omit to run all scenarios."
dotenv: [ '{{.TASKFILE_DIR}}/test/e2e/hacks/.env' ]
cmds:
- task: helm/install
- PROJECT_DIR='{{.TASKFILE_DIR}}' go test '{{.TASKFILE_DIR}}/test/e2e/' -v -timeout 30m -ginkgo.v {{.CLI_ARGS}}
test/e2e/fresh:
desc: "Teardown, setup, and run E2E tests from scratch. Pass ginkgo flags via `--`, e.g. `task test/e2e/fresh -- -ginkgo.focus=helm-simple`."
cmds:
- task: test/e2e/setup/teardown
- task: test/e2e/setup/local
- task: test/e2e
vars:
CLI_ARGS: '{{.CLI_ARGS}}'
# Build
build:
desc: "Build the controller manager binary"
deps: [manifests, generate, fmt, vet]
cmd: 'go build -o bin/manager {{.TASKFILE_DIR}}/cmd/main.go'
run:
desc: "Run the controller manager locally (installs CRDs into the current kube-context first)"
deps: [manifests, generate, fmt, vet, helm/install-crds]
cmds:
- 'go run {{.TASKFILE_DIR}}/cmd/main.go'
# Always build only for the host architecture.
# We force "linux" OS because all Docker base images are Linux,
# and derive the arch dynamically from the host Go toolchain.
docker-build:
desc: "Build the Docker image for the host architecture"
cmd:
task: docker-build/multi-arch
vars:
PLATFORMS:
sh: 'echo "linux/$(go env GOARCH)"'
# Multi-arch capable build task.
# In this setup it is used only with a single platform (the local arch),
# but it still supports --push / --load flags if desired.
docker-build/multi-arch:
desc: "Build a multi-architecture Docker image"
requires:
vars: [ PLATFORMS, CONTROLLER_IMG ]
cmd: |
args=(
--platform={{.PLATFORMS}}
-f '{{.TASKFILE_DIR}}/Dockerfile' '{{.TASKFILE_DIR}}'
)
# Add tags - CONTROLLER_IMG can be space-separated for multiple tags
for tag in {{.CONTROLLER_IMG}}; do
args+=(-t "$tag")
done
# If LOAD is set, load single-arch image into local daemon
if [ "{{.LOAD | default ""}}" = "true" ]; then
args+=(--load)
fi
# If PUSH is set, push image (or manifest) to registry
if [ "{{.PUSH | default ""}}" = "true" ]; then
args+=(--push)
fi
# If OCI_OUTPUT is set, write OCI layout tar to that path
if [ -n "{{.OCI_OUTPUT | default ""}}" ]; then
mkdir -p "$(dirname '{{.OCI_OUTPUT}}')"
args+=(--output "type=oci,dest={{.OCI_OUTPUT}},oci-mediatypes=true")
fi
# Run docker (or podman) buildx with the constructed args
{{.CONTAINER_TOOL}} buildx build "${args[@]}"
oci/extract:
desc: "Extract an OCI layout tar archive into a directory"
requires:
vars: [TAR_PATH, OUTPUT_DIR]
cmds:
- mkdir -p "{{.OUTPUT_DIR}}"
- tar -xf "{{.TAR_PATH}}" -C "{{.OUTPUT_DIR}}"
# Helm chart tasks
helm/generate-crds:
desc: "Generate Helm-wrapped CRD templates from controller-gen output"
deps: [manifests, yq]
cmd: 'YQ="{{.YQ}}" {{.TASKFILE_DIR}}/hack/helm.generate.sh {{.TASKFILE_DIR}}/config/crd/bases {{.TASKFILE_DIR}}/chart'
helm/generate-rbac:
desc: "Generate chart/templates/rbac/manager-role.yaml from controller-gen RBAC output"
deps: [manifests, yq]
cmd: 'YQ="{{.YQ}}" {{.TASKFILE_DIR}}/hack/rbac.generate.sh {{.TASKFILE_DIR}}/bin/gen/rbac {{.TASKFILE_DIR}}/chart'
helm/generate:
desc: "Regenerate chart CRDs and manager-role from controller-gen output"
cmds:
- task: helm/generate-crds
- task: helm/generate-rbac
helm/schema:
desc: "Generate JSON schema from chart values.yaml"
silent: true
deps: [helm-schema-plugin]
dir: chart
cmd: 'helm schema -f values.yaml -o values.schema.json'
sources:
- chart/values.yaml
generates:
- chart/values.schema.json
helm/lint:
desc: "Lint the Helm chart"
cmd: 'helm lint chart/'
helm/validate:
desc: "Validate the Helm chart (regenerate, then lint, template, and verify CRDs/RBAC/schema/docs are in sync)"
silent: true
cmds:
- task: helm/generate
- task: helm/schema
- task: helm/docs
- task: helm/lint
- task: helm/template
- |
status=$(git status --porcelain)
if [ -n "$status" ]; then
echo "ERROR: Working tree is dirty after generation. Commit all generated files before pushing."
echo "$status"
git diff
exit 1
fi
helm/package:
desc: "Package the Helm chart with the specified version"
deps: [yq]
cmds:
- mkdir -p dist
- '{{ if .IMAGE_REPOSITORY }}{{.YQ}} -i ".manager.image.repository = \"{{.IMAGE_REPOSITORY}}\"" chart/values.yaml{{end}}'
- '{{ if .VERSION }}{{.YQ}} -i ".manager.image.tag = \"{{.VERSION}}{{ if .IMAGE_DIGEST }}@{{.IMAGE_DIGEST}}{{ end }}\"" chart/values.yaml{{end}}'
- helm package chart/ --destination dist/ {{if .VERSION}}--version {{.VERSION}}{{end}} {{if .APP_VERSION}}--app-version {{.APP_VERSION}}{{end}}
helm/push:
desc: "Push packaged Helm chart to OCI registry"
requires:
vars: [VERSION, REGISTRY]
cmds:
- helm push dist/chart-{{.VERSION}}.tgz oci://{{.REGISTRY}}
helm/template:
desc: "Render Helm chart templates with test values"
silent: true
cmds:
- mkdir -p dist
- helm template ocm-k8s-toolkit chart/ --namespace ocm-k8s-toolkit-system -f chart/test-values.yaml > dist/generated.yaml
helm/install:
desc: "Install the Helm chart"
cmds:
- |
helm upgrade --install ocm-k8s-toolkit chart/ \
-f chart/test-values.yaml \
--namespace ocm-k8s-toolkit-system \
--create-namespace \
--wait \
--timeout 120s
helm/install-crds:
desc: "Render the chart CRDs and apply them to the current kube-context"
deps: [helm/generate-crds]
cmd: 'helm template ocm-k8s-toolkit chart/ --show-only "templates/crd/*.yaml" | kubectl apply --server-side --force-conflicts -f -'
helm/uninstall:
desc: "Uninstall the Helm chart"
cmd: 'helm uninstall ocm-k8s-toolkit --namespace ocm-k8s-toolkit-system --ignore-not-found'
helm/docs:
desc: "Generate Helm chart documentation"
deps: [helm-docs]
dir: chart
cmds:
- '"{{.HELM_DOCS}}"'
# Strip SHA digests from README.md for cleaner documentation
# The digest is kept in values.yaml for security, but removed from docs for readability
- tmp=$(mktemp) && sed 's/@sha256:[a-f0-9]\{64\}//g' README.md > "$tmp" && mv "$tmp" README.md
sources:
- chart/values.yaml
- chart/README.md
generates:
- chart/README.md
# Tool installers (all via helper)
controller-gen:
desc: "Install controller-gen"
deps:
- task: go-install-tool
vars: { TOOL_PATH: '{{.CONTROLLER_GEN}}', PACKAGE: sigs.k8s.io/controller-tools/cmd/controller-gen, VERSION: '{{.CONTROLLER_TOOLS_VERSION}}' }
generates: [ '{{.CONTROLLER_GEN}}' ]
envtest:
desc: "Install setup-envtest"
deps:
- task: go-install-tool
vars: { TOOL_PATH: '{{.ENVTEST}}', PACKAGE: sigs.k8s.io/controller-runtime/tools/setup-envtest, VERSION: '{{.ENVTEST_VERSION}}' }
generates: [ '{{.ENVTEST}}' ]
yq:
desc: "Install yq"
deps:
- task: go-install-tool
vars: { TOOL_PATH: '{{.YQ}}', PACKAGE: github.com/mikefarah/yq/v4, VERSION: '{{.YQ_VERSION}}' }
generates: [ '{{.YQ}}' ]
go-install-tool:
internal: true
silent: true
desc: "Install a go tool to a specific path"
cmd: |
set -e
tmp=$(mktemp -d)
trap 'rm -rf "$tmp"' EXIT
# install into temp dir
GOBIN=$tmp go install {{.PACKAGE}}@{{.VERSION}}
# figure out binary name (strip version suffix if present)
name=$(basename {{.TOOL_PATH}} | sed 's/-{{.VERSION}}$//')
# move binary if names differ
if [ "$name" != "$(basename {{.TOOL_PATH}})" ]; then
# make sure target dir exists
mkdir -p "$(dirname {{.TOOL_PATH}})"
mv "$tmp/$name" {{.TOOL_PATH}}
fi
generates:
- '{{.TOOL_PATH}}'
helm-docs:
desc: "Install helm-docs"
deps:
- task: go-install-tool
vars: { TOOL_PATH: '{{.HELM_DOCS}}', PACKAGE: github.com/norwoodj/helm-docs/cmd/helm-docs, VERSION: '{{.HELM_DOCS_VERSION}}' }
generates: [ '{{.HELM_DOCS}}' ]
helm-schema-plugin:
internal: true
silent: true
desc: "Install helm-values-schema-json plugin if not present"
cmd: |
if ! helm plugin list | grep -q "schema"; then
helm plugin install https://github.com/losisin/helm-values-schema-json.git --verify=false
fi
status:
- helm plugin list | grep -q "schema"