Repository navigation
Expand file tree
/
Copy pathTaskfile.yaml
More file actions
278 lines (240 loc) · 10.2 KB
/
Copy pathTaskfile.yaml
File metadata and controls
278 lines (240 loc) · 10.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
version: '3'
vars:
CLUSTER_NAME: milo-demo
MILO_DIR: "{{.TASKFILE_DIR}}/.milo"
KUBECONFIG_FILE: .test-infra/kubeconfig
env:
KUBECONFIG: "{{.TASKFILE_DIR}}/{{.KUBECONFIG_FILE}}"
tasks:
demo:up:
desc: Boot the full milo-demo stack
cmds:
- task: demo:cluster-up
- task: demo:install-infra
- task: demo:deploy-milo
- task: demo:setup-proxy-cert
- task: demo:deploy-auth
- task: demo:configure-milo-oidc
- task: demo:build-images
- task: demo:load-images
- task: demo:deploy
- task: demo:register-apis
- task: demo:deploy-portals
- task: demo:seed
- task: demo:verify
demo:down:
desc: Destroy the demo cluster
cmds:
- kind delete cluster --name {{.CLUSTER_NAME}}
- rm -rf {{.MILO_DIR}} .test-infra
demo:cluster-up:
desc: Create the kind cluster
cmds:
- kind create cluster --name {{.CLUSTER_NAME}} --config hack/kind-config.yaml
demo:install-infra:
desc: Install Flux, cert-manager, Envoy Gateway via datum-cloud/test-infra
cmds:
- |
set -e
REPO_DIR="{{.TASKFILE_DIR}}/.test-infra"
WAIT="300s"
if [ ! -d "${REPO_DIR}/.git" ]; then
rm -rf "${REPO_DIR}"
echo "Cloning test-infra..."
git clone https://github.com/datum-cloud/test-infra.git "${REPO_DIR}"
else
git -C "${REPO_DIR}" pull origin main --quiet 2>/dev/null || true
fi
kind export kubeconfig --name {{.CLUSTER_NAME}} --kubeconfig "${REPO_DIR}/kubeconfig"
echo "Installing Flux..."
kustomize build "${REPO_DIR}/components/flux" | kubectl apply -f -
kubectl -n flux-system wait deployment/{source-controller,helm-controller,kustomize-controller,notification-controller} --for=condition=Available --timeout="${WAIT}"
sleep 10
echo "Installing cert-manager..."
kustomize build "${REPO_DIR}/components/cert-manager" | kubectl apply -f -
kubectl -n cert-manager wait helmrelease/{cert-manager,cert-manager-csi-driver} --for=condition=Ready --timeout="${WAIT}"
echo "Installing Envoy Gateway..."
kustomize build "${REPO_DIR}/components/envoy-gateway-operator" | kubectl apply -f -
kubectl -n flux-system wait helmrelease/envoy-gateway --for=condition=Ready --timeout="${WAIT}"
kustomize build "${REPO_DIR}/components/envoy-gateway-operator/gateway-resources" | kubectl apply -f -
kubectl wait --for=condition=Programmed gateway/default-gateway -n envoy-gateway-system --timeout="${WAIT}" || true
echo "Infrastructure installed"
demo:deploy-milo:
desc: Clone and deploy Milo control plane
silent: true
cmds:
- |
set -e
if [ ! -d "{{.MILO_DIR}}/.git" ]; then
echo "Cloning Milo..."
git clone https://github.com/datum-cloud/milo.git "{{.MILO_DIR}}"
fi
cd "{{.MILO_DIR}}"
mkdir -p .test-infra
cp "{{.TASKFILE_DIR}}/{{.KUBECONFIG_FILE}}" .test-infra/kubeconfig
TASK_X_REMOTE_TASKFILES=1 task dev:build --force
kind load docker-image ghcr.io/datum-cloud/milo:dev --name {{.CLUSTER_NAME}}
# dev:deploy may fail on ActivityPolicy resources (activity service not deployed
# in the demo stack). All critical steps complete before that point, so tolerate
# the failure and re-apply config/services/ with ActivityPolicy filtered out.
TASK_X_REMOTE_TASKFILES=1 task dev:deploy || {
echo "dev:deploy failed; re-applying config/services/ without ActivityPolicy..."
kustomize build config/services/ | \
python3 -c "
import sys
docs = sys.stdin.read().split('\n---\n')
print('\n---\n'.join(d for d in docs if 'kind: ActivityPolicy' not in d))
" | KUBECONFIG=.milo/kubeconfig kubectl apply -f -
}
echo "Milo deployed"
demo:setup-proxy-cert:
desc: Create static front-proxy cert for Milo aggregator and configure deployment
silent: true
cmds:
- |
set -e
echo "Creating Milo front-proxy certificate..."
kubectl apply -f config/demo/milo-proxy/certificate.yaml
echo "Waiting for front-proxy cert to be issued..."
kubectl wait --for=condition=Ready certificate/milo-front-proxy-tls -n milo-system --timeout=120s
echo "Patching Milo apiserver to use static proxy cert..."
kubectl patch deployment milo-apiserver -n milo-system --type=strategic \
-p "$(cat config/demo/milo-proxy/apiserver-proxy-patch.yaml)"
echo "Waiting for Milo apiserver rollout..."
kubectl rollout status deployment/milo-apiserver -n milo-system --timeout=120s
echo "Distributing front-proxy CA to aggregated API servers..."
CA_CERT=$(kubectl get secret -n milo-system milo-front-proxy-tls \
-o jsonpath='{.data.ca\.crt}' | base64 -d)
for ns in incidents-system support-system; do
kubectl create namespace "$ns" --dry-run=client -o yaml | kubectl apply -f -
kubectl create configmap control-plane-ca -n "$ns" \
--from-literal=ca.crt="$CA_CERT" \
--dry-run=client -o yaml | kubectl apply -f -
done
echo "Front-proxy cert configured and Milo restarted"
demo:deploy-auth:
desc: Deploy Dex OIDC from support submodule
cmds:
- kubectl apply -k submodules/support/config/demo/auth/
- kubectl wait --for=condition=Available deployment/dex -n auth-system --timeout=120s
- echo "Dex deployed"
demo:build-images:
desc: Build all component images from submodule source
cmds:
- docker build -t ghcr.io/datum-cloud/incidents:dev ./submodules/incidents/
- docker build -t ghcr.io/datum-cloud/incidents-ui:dev ./submodules/incidents/ui/
- docker build -t ghcr.io/datum-cloud/support:dev ./submodules/support/
demo:load-images:
desc: Load built images into the kind cluster
cmds:
- kind load docker-image ghcr.io/datum-cloud/incidents:dev --name {{.CLUSTER_NAME}}
- kind load docker-image ghcr.io/datum-cloud/incidents-ui:dev --name {{.CLUSTER_NAME}}
- kind load docker-image ghcr.io/datum-cloud/support:dev --name {{.CLUSTER_NAME}}
demo:deploy:
desc: Deploy incidents and support services to kind cluster
cmds:
- |
kustomize build config/demo/ | \
python3 -c "
import sys
docs = sys.stdin.read().split('\n---\n')
filtered = [d for d in docs if 'kind: APIService' not in d]
print('\n---\n'.join(filtered))
" | kubectl apply -f -
- echo "Services deployed"
demo:register-apis:
desc: Register incidents and support APIServices with the Milo aggregator
silent: true
cmds:
- |
set -e
MILO_TOKEN="test-admin-token"
MILO_PORT="16443"
echo "Starting port-forward to milo-apiserver..."
kubectl port-forward -n milo-system svc/milo-apiserver "${MILO_PORT}:6443" &
PF_PID=$!
trap "kill ${PF_PID} 2>/dev/null || true" EXIT
# Wait for port-forward to be ready
for i in $(seq 1 20); do
if curl -sk "https://localhost:${MILO_PORT}/healthz" >/dev/null 2>&1; then
break
fi
sleep 1
done
KUBECTL_MILO="kubectl --server=https://localhost:${MILO_PORT} --insecure-skip-tls-verify --token=${MILO_TOKEN}"
echo "Registering incidents APIService in Milo..."
$KUBECTL_MILO apply --validate=false -f - <<'EOF'
apiVersion: apiregistration.k8s.io/v1
kind: APIService
metadata:
name: v1alpha1.incidents.operations.miloapis.com
spec:
service:
name: incidents-apiserver
namespace: incidents-system
port: 443
group: incidents.operations.miloapis.com
version: v1alpha1
insecureSkipTLSVerify: true
groupPriorityMinimum: 1000
versionPriority: 15
EOF
echo "Registering support APIService in Milo..."
$KUBECTL_MILO apply --validate=false -f - <<'EOF'
apiVersion: apiregistration.k8s.io/v1
kind: APIService
metadata:
name: v1alpha1.support.miloapis.com
spec:
service:
name: support-apiserver
namespace: support-system
port: 443
group: support.miloapis.com
version: v1alpha1
insecureSkipTLSVerify: true
groupPriorityMinimum: 1000
versionPriority: 15
EOF
$KUBECTL_MILO wait \
--for=jsonpath='{.status.conditions[?(@.type=="Available")].status}=True' \
apiservice/v1alpha1.incidents.operations.miloapis.com --timeout=120s || true
$KUBECTL_MILO wait \
--for=jsonpath='{.status.conditions[?(@.type=="Available")].status}=True' \
apiservice/v1alpha1.support.miloapis.com --timeout=120s || true
echo "APIs registered with Milo"
demo:configure-milo-oidc:
desc: Configure Milo OIDC authentication with Dex JWT validation
cmds:
- bash hack/configure-milo-oidc.sh
demo:configure:
desc: Write portal .env files for the demo cluster
cmds:
- bash hack/configure.sh
demo:deploy-portals:
desc: Build and deploy staff and cloud portals
cmds:
- task: demo:configure
- docker build -t ghcr.io/datum-cloud/staff-portal:demo ./submodules/staff-portal/
- docker build -t ghcr.io/datum-cloud/cloud-portal:demo ./submodules/cloud-portal/
- kind load docker-image ghcr.io/datum-cloud/staff-portal:demo --name {{.CLUSTER_NAME}}
- kind load docker-image ghcr.io/datum-cloud/cloud-portal:demo --name {{.CLUSTER_NAME}}
- |
kustomize build --load-restrictor LoadRestrictionsNone config/demo/portals/ | \
python3 -c "
import sys
docs = sys.stdin.read().split('\n---\n')
filtered = [d for d in docs if 'kind: ServiceMonitor' not in d]
print('\n---\n'.join(filtered))
" | kubectl apply -f -
demo:seed:
desc: Seed demo data
cmds:
- bash hack/seed-milo.sh
- bash hack/seed-incidents.sh
- bash hack/seed-support.sh
demo:verify:
desc: Run all verification checks
cmds:
- bash hack/verify-kubectl.sh
- cd verify && npm install && TMPDIR=/tmp npx playwright test