-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathTaskfile.yml
More file actions
294 lines (281 loc) · 12.3 KB
/
Copy pathTaskfile.yml
File metadata and controls
294 lines (281 loc) · 12.3 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
version: '3'
dotenv: ['.taskenv', '.secret/.env', '{{.HOME}}/.env' ]
vars:
LOCAL_BIN: bin
CONTROLLER_TOOLS_VERSION: v0.18.0
ENVTEST_VERSION: release-0.17
CRD_DIRECTORY: config/crd
TEST_SETUP_DIRECTORY: setup/01-platform-mesh-system
KCP_APIGEN_VERSION: v0.30.1
GOMPLATE_VERSION: v4.3.0
KUSTOMIZE_VERSION: v5.4.3
OCM_VERSION: 0.24.0
KIND_VERSION: v0.29.0
YAML_PATCH_VERSION: v0.0.11
KUBECTL: kubectl
GOARCH:
sh: go env GOARCH
GOOS:
sh: go env GOOS
KUSTOMIZE: "{{.LOCAL_BIN}}/kustomize"
tasks:
## Setup
setup:mockery:
internal: true
cmds:
- test -s {{.LOCAL_BIN}}/mockery || GOBIN=$(pwd)/{{.LOCAL_BIN}} go install github.com/vektra/mockery/v3@v3.7.0
setup:go-test-coverage:
internal: true
cmds:
- test -s {{.LOCAL_BIN}}/go-test-coverage || GOBIN=$(pwd)/{{.LOCAL_BIN}} go install github.com/vladopajic/go-test-coverage/v2@v2.18.3
setup:kustomize:
internal: true
cmds:
- test -s {{.KUSTOMIZE}} || GOBIN=$(pwd)/{{.LOCAL_BIN}} go install sigs.k8s.io/kustomize/kustomize/v5@{{.KUSTOMIZE_VERSION}}
setup:controller-gen:
internal: true
cmds:
- test -s {{.LOCAL_BIN}}/controller-gen || GOBIN=$(pwd)/{{.LOCAL_BIN}} go install sigs.k8s.io/controller-tools/cmd/controller-gen@{{.CONTROLLER_TOOLS_VERSION}}
setup:gomplate:
internal: true
cmds:
- test -s {{.LOCAL_BIN}}/gomplate || curl -o {{.LOCAL_BIN}}/gomplate -sSL https://github.com/hairyhenderson/gomplate/releases/download/{{ .GOMPLATE_VERSION }}/gomplate_{{ .GOOS }}-{{ .GOARCH }} && chmod +x {{.LOCAL_BIN}}/gomplate && chmod 755 {{.LOCAL_BIN}}/gomplate
setup:golangci-lint:
internal: true
cmds:
- test -s {{.LOCAL_BIN}}/golangci-lint || GOBIN=$(pwd)/{{.LOCAL_BIN}} go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
setup:ocm:
internal: true
cmds:
- test -s {{.LOCAL_BIN}}/ocm || (curl -o {{.LOCAL_BIN}}/ocm.tar.gz -sSL https://github.com/open-component-model/ocm/releases/download/v{{ .OCM_VERSION }}/ocm-{{ .OCM_VERSION }}-{{ .GOOS }}-{{ .GOARCH }}.tar.gz && tar -xzf {{ .LOCAL_BIN }}/ocm.tar.gz -C {{ .LOCAL_BIN }} && rm {{ .LOCAL_BIN }}/ocm.tar.gz && chmod +x {{.LOCAL_BIN}}/ocm && chmod 755 {{.LOCAL_BIN}}/ocm)
setup:mkcert:
internal: true
cmds:
- test -s {{.LOCAL_BIN}}/mkcert || GOBIN=$(pwd)/{{.LOCAL_BIN}} go install filippo.io/mkcert@latest
- export PATH=$(pwd)/{{.LOCAL_BIN}}:$PATH
setup:kind:
internal: true
cmds:
- test -s {{.LOCAL_BIN}}/kind || GOBIN=$(pwd)/{{.LOCAL_BIN}} go install sigs.k8s.io/kind@{{ .KIND_VERSION }}
- export PATH=$(pwd)/{{.LOCAL_BIN}}:$PATH
setup:kcp-api-gen:
internal: true
cmds:
- test -s {{.LOCAL_BIN}}/apigen || GOBIN=$(pwd)/{{.LOCAL_BIN}} go install github.com/kcp-dev/sdk/cmd/apigen@{{.KCP_APIGEN_VERSION}}
setup:yaml-patch:
internal: true
cmds:
- test -s {{.LOCAL_BIN}}/apigen || GOBIN=$(pwd)/{{.LOCAL_BIN}} go install github.com/pivotal-cf/yaml-patch/cmd/yaml-patch@{{.YAML_PATCH_VERSION}}
## Development
mockery:
deps: [setup:mockery]
cmds:
- "{{.LOCAL_BIN}}/mockery"
kindtest:
deps: [setup:mkcert, setup:kind]
env:
GO111MODULE: on
cmds:
- |
export PATH=$(pwd)/{{.LOCAL_BIN}}:$PATH
go test -timeout 30m -coverprofile=cover.out github.com/platform-mesh/platform-mesh-operator/test/e2e/kind {{.ADDITIONAL_COMMAND_ARGS}}
test:
deps: [mockery, setup:kind, setup:mkcert]
env:
GO111MODULE: on
cmds:
- cmd: |
if [ "$GITHUB_WORKFLOW" = "ci" ]; then
echo "Running tests in Github Actions"
PATH=$(pwd)/{{.LOCAL_BIN}}:$PATH go test -v -timeout 30m -coverprofile=cover.out ./... {{.ADDITIONAL_COMMAND_ARGS}} || {
echo "---Listing HelmReleases"
kubectl get helmreleases -A
echo "---Describing non-ready HelmReleases"
kubectl get helmreleases -A -o json | jq -r '.items[] | select(.status.conditions // [] | map(select(.type=="Ready" and .status=="True")) | length == 0) | "\(.metadata.namespace)/\(.metadata.name)"' | while read hr; do
echo "=== $hr ==="
kubectl describe helmrelease -n "${hr%%/*}" "${hr##*/}"
done
kubectl get resources -A
kubectl get ocirepositories -A
kubectl -n platform-mesh-system describe PlatformMesh platform-mesh
echo "---Non-Running Pods"
kubectl get pods -A
kubectl get pods -A -o json | jq -r '.items[] | select(.status.phase != "Running") | "\(.metadata.namespace)/\(.metadata.name)"' | while read pod; do
echo "=== describe $pod ==="
kubectl describe pod -n "${pod%%/*}" "${pod##*/}"
echo "=== logs $pod ==="
kubectl logs -n "${pod%%/*}" "${pod##*/}" --all-containers --tail=50 2>&1 || true
done
echo "---OpenFGA Pods (all)"
kubectl get pods -n platform-mesh-system -l app.kubernetes.io/name=openfga -o wide 2>&1 || true
kubectl get pods -n platform-mesh-system -l app.kubernetes.io/name=postgres -o wide 2>&1 || true
kubectl get pods -n platform-mesh-system | grep -iE "openfga|postgres" || true
for pod in $(kubectl get pods -n platform-mesh-system -o name 2>/dev/null | grep -iE "openfga|postgres"); do
echo "=== describe $pod ==="
kubectl -n platform-mesh-system describe "$pod" 2>&1 || true
echo "=== logs $pod ==="
kubectl -n platform-mesh-system logs "$pod" --all-containers --tail=100 2>&1 || true
done
exit 1
}
else
export PATH=$(pwd)/{{.LOCAL_BIN}}:$PATH
go test -timeout 30m -coverprofile=cover.out ./... {{.ADDITIONAL_COMMAND_ARGS}}
fi
ignore_error: false
fuzz:
desc: "Run fuzz tests with a configurable duration (default 30s per target)"
vars:
FUZZTIME: '{{.FUZZTIME | default "30s"}}'
cmds:
- go test ./pkg/ocm/ -run=^$ -fuzz=FuzzParseRef -fuzztime={{.FUZZTIME}} -count=1
manifests:
deps: [setup:controller-gen]
cmds:
- "{{.LOCAL_BIN}}/controller-gen rbac:roleName=manager-role crd paths=./... output:crd:artifacts:config={{.CRD_DIRECTORY}}"
apigen:
deps: [setup:kcp-api-gen, setup:yaml-patch]
cmds:
- task: manifests
- cmd: |
apigen_crds=(
# Add your apigen input CRDs below.
{{.CRD_DIRECTORY}}/providers.platform-mesh.io_providers.yaml
)
apigen_dest=(
# Add your apigen output paths below.
./manifests/kcp/01-platform-mesh-system/apiexport-providers.platform-mesh.io.yaml
./manifests/kcp/01-platform-mesh-system/apiresourceschema-providers.providers.platform-mesh.io.yaml
)
# NOTE: this script also applies yaml-patch files from {{.CRD_DIRECTORY}}/apigen/patches onto {{.CRD_DIRECTORY}}/apigen/out.
# Please put your patch files there if needed.
# Each patch file {{.CRD_DIRECTORY}}/apigen/patches/<NAME>.yaml-patch
# is applied against {{.CRD_DIRECTORY}}/apigen/out/ <NAME>.yaml
# Prepare dir structure for apigen.
mkdir -p {{.CRD_DIRECTORY}}/apigen/{crds,out}
for manifest in "${apigen_crds[@]}"; do
cp "${manifest}" {{.CRD_DIRECTORY}}/apigen/crds
done
{{.LOCAL_BIN}}/apigen \
--input-dir {{.CRD_DIRECTORY}}/apigen/crds \
--output-dir {{.CRD_DIRECTORY}}/apigen/out
# Apply patches.
for patch in ./config/crd/apigen/patches/*.yaml-patch; do
[[ -f "${patch}" ]] || continue
out="$(basename ${patch} | sed 's/-patch$//')"
{{.LOCAL_BIN}}/yaml-patch -o "${patch}" < "{{.CRD_DIRECTORY}}/apigen/out/${out}" > "{{.CRD_DIRECTORY}}/apigen/out/${out}.patched"
mv "{{.CRD_DIRECTORY}}/apigen/out/${out}.patched" "{{.CRD_DIRECTORY}}/apigen/out/${out}"
done
# Move files from apigen/out into whereever apigen_dest points to.
for dest in "${apigen_dest[@]}"; do
manifest="$(basename ${dest})"
mv "{{.CRD_DIRECTORY}}/apigen/out/${manifest}" "${dest}"
done
ignore_error: false
generate:
cmds:
- task: manifests
- "{{.LOCAL_BIN}}/controller-gen object:headerFile=hack/boilerplate.go.txt paths=./..."
- task: apigen
ignore_error: false
build:
cmds:
- go build -o bin/manager main.go
fuzz:
desc: "Run fuzz tests with a configurable duration (default 30s per target)"
vars:
FUZZTIME: '{{.FUZZTIME | default "30s"}}'
cmds:
- go test ./api/v1alpha1/ -run=^$ -fuzz=FuzzPlatformMeshRoundTrip -fuzztime={{.FUZZTIME}} -count=1
docker-build:
cmds:
- docker build .
docker:kind:
desc: "Build container image with current tag from kind cluster and load it"
vars:
CONTAINER_RUNTIME: '{{.CONTAINER_RUNTIME | default "docker"}}'
KIND_CLUSTER: '{{.KIND_CLUSTER | default "platform-mesh"}}'
DEPLOYMENT_NAME: '{{.DEPLOYMENT_NAME | default "platform-mesh-operator"}}'
DEPLOYMENT_NAMESPACE: '{{.DEPLOYMENT_NAMESPACE | default "platform-mesh-system"}}'
IMAGE_TAG:
sh: kubectl get deployment {{.DEPLOYMENT_NAME}} -n {{.DEPLOYMENT_NAMESPACE}} -o jsonpath='{.spec.template.spec.containers[0].image}' | cut -d':' -f2
IMAGE_NAME: ghcr.io/platform-mesh/platform-mesh-operator:{{.IMAGE_TAG}}
cmds:
- echo "Building image with tag {{.IMAGE_TAG}} using {{.CONTAINER_RUNTIME}}"
- "{{.CONTAINER_RUNTIME}} build -t {{.IMAGE_NAME}} ."
- |
if [ "{{.CONTAINER_RUNTIME}}" = "podman" ]; then
{{.CONTAINER_RUNTIME}} save {{.IMAGE_NAME}} -o /tmp/kind-image.tar
kind load image-archive /tmp/kind-image.tar --name {{.KIND_CLUSTER}}
rm -f /tmp/kind-image.tar
else
kind load docker-image {{.IMAGE_NAME}} --name {{.KIND_CLUSTER}}
fi
- kubectl rollout restart deployment/{{.DEPLOYMENT_NAME}} -n {{.DEPLOYMENT_NAMESPACE}}
- echo "Image loaded and deployment restarted"
## Testing
fmt:
cmds:
- go fmt ./...
lint:
deps: [setup:golangci-lint]
cmds:
- task: fmt
- "{{.LOCAL_BIN}}/golangci-lint run --timeout 15m ./..."
cover:
deps:
- task: setup:go-test-coverage
- task: test
vars:
ADDITIONAL_COMMAND_ARGS: -coverprofile=./cover.out -covermode=atomic -coverpkg=./...
cmds:
- "{{.LOCAL_BIN}}/go-test-coverage --threshold-file 30 --threshold-package 60 --threshold-total 45 --profile cover.out --config ./.testcoverage.yml"
helm-unittest:
cmds:
- helm unittest chart
validate:
cmds:
- task: lint
- task: test
install:
deps: [setup:kustomize]
cmds:
- "{{.KUSTOMIZE}} build config/crd | {{.KUBECTL}} apply -f -"
run:
cmds:
- source .env && go run ./main.go operator
bump-versions:
deps: [setup:ocm]
cmds:
- task: bump-versions-internal
bump-versions-internal:
internal: true
vars:
SERVICES:
- account-operator
- account-ui
- apeiro-example-content
- apeiro-portal
- portal
- extension-manager-operator
- fga-operator
- rebac-authz-webhook
- iam-service
- infra
- kcp
- keycloak
- kubernetes-graphql-gateway
- openfga
- observability
- crossplane
- istiod
- istio-gateway
- istio-base
- example-resources
PLATFORM_MESH_COMP:
sh: "{{.LOCAL_BIN}}/ocm get componentversions --latest github.com/platform-mesh/platform-mesh --repo ghcr.io/platform-mesh -o json"
cmds:
- PLATFORM_MESH_COMP_VERSION=$(echo "{{ .PLATFORM_MESH_COMP }}" | yq -r '.items[0].component.version') yq -i ".spec.version.semver = strenv(PLATFORM_MESH_COMP_VERSION)" deployment/component-version.yaml
- for:
var: SERVICES
cmd: COMP_VERSION=$(echo "{{ .PLATFORM_MESH_COMP }}" | yq -r '.items[0].component.componentReferences[] | select(.name == "{{ .ITEM }}").version') yq -i ".spec.sourceRef.resourceRef.version = strenv(COMP_VERSION)" deployment/{{ range splitList "-" .ITEM }}{{ . }}{{ end }}/resource.yaml