-
Notifications
You must be signed in to change notification settings - Fork 5
492 lines (412 loc) · 19.5 KB
/
main.yaml
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
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
name: PR/main branch CI
on:
pull_request:
branches:
- main
push:
branches:
- main
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
env:
APP_SLUG: replicated-sdk-e2e
jobs:
make-tests:
env:
PACT_VERSION: ${{ github.sha }}
PACT_BROKER_BASE_URL: ${{ vars.PACT_BROKER_BASE_URL }}
PACT_BROKER_TOKEN: ${{ secrets.PACT_BROKER_TOKEN }}
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: '^1.20'
cache: false
- uses: replicatedhq/action-install-pact@v1
- run: make test
- if: github.event_name == 'push' || ( github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository )
run: make publish-pact
- if: github.event_name == 'push' || ( github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository )
run: |
make can-i-deploy || echo "::warning:: can-i-deploy says no; provider(s) must successfully verify before release"
build-and-push-e2e:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: '^1.20'
- name: build and push replicated for e2e
env:
USER: automated-${{ github.run_id }}
run: make build-ttl.sh
validate-chart:
runs-on: ubuntu-22.04
needs: [ build-and-push-e2e ]
steps:
- uses: actions/checkout@v3
- name: validate chart
run: |
output=$(helm template oci://ttl.sh/automated-${{ github.run_id }}/replicated --version 0.0.0)
if echo $output | grep -q integration-enabled; then
printf "'integration-enabled' key should not exist if value is not set by the user:\n\n%s\n\n" "$output"
exit 1
fi
if echo $output | grep -q 'kind: ConfigMap'; then
printf "legacy/deprecated configmap should not exist:\n\n%s\n\n" "$output"
exit 1
fi
if ! echo $output | grep -q 'kind: ServiceAccount'; then
printf "default service account should exist if user does not set serviceAccountName:\n\n%s\n\n" "$output"
exit 1
fi
if ! echo $output | grep -q 'kind: Role'; then
printf "default role should exist if user does not set serviceAccountName:\n\n%s\n\n" "$output"
exit 1
fi
if ! echo $output | grep -q 'kind: RoleBinding'; then
printf "default rolebinding should exist if user does not set serviceAccountName:\n\n%s\n\n" "$output"
exit 1
fi
if ! echo $output | grep -q 'statusInformers: null'; then
printf "default statusInformers should be null:\n\n%s\n\n" "$output"
exit 1
fi
output=$(helm template oci://ttl.sh/automated-${{ github.run_id }}/replicated --version 0.0.0 --set integration.enabled=true)
if ! echo $output | grep -q integration-enabled; then
printf "'integration-enabled' key should exist if value is set by the user:\n\n%s\n\n" "$output"
exit 1
fi
output=$(helm template oci://ttl.sh/automated-${{ github.run_id }}/replicated --version 0.0.0 --set serviceAccountName=foo)
if echo $output | grep -q 'kind: ServiceAccount'; then
printf "default service account should not exist if user sets serviceAccountName:\n\n%s\n\n" "$output"
exit 1
fi
if echo $output | grep -q 'kind: Role'; then
printf "default role should not exist if user sets serviceAccountName:\n\n%s\n\n" "$output"
exit 1
fi
if echo $output | grep -q 'kind: RoleBinding'; then
printf "default rolebinding should not exist if user sets serviceAccountName:\n\n%s\n\n" "$output"
exit 1
fi
if ! echo $output | grep -q 'serviceAccountName: foo'; then
printf "user-set serviceAccountName reference should exist:\n\n%s\n\n" "$output"
exit 1
fi
output=$(helm template oci://ttl.sh/automated-${{ github.run_id }}/replicated --version 0.0.0 --set userAgent=test-user-agent)
if ! echo $output | grep -q 'value: "test-user-agent"'; then
printf "user-set userAgent should exist:\n\n%s\n\n" "$output"
exit 1
fi
cat << EOF > test-values.yaml
extraEnv:
- name: TEST_EXTRA_ENV
value: test-extra-env
EOF
output=$(helm template oci://ttl.sh/automated-${{ github.run_id }}/replicated --version 0.0.0 --values test-values.yaml)
if ! echo $output | grep -q 'TEST_EXTRA_ENV'; then
printf "user-set extraEnv should exist:\n\n%s\n\n" "$output"
exit 1
fi
cat << EOF > test-values.yaml
tolerations:
- key: "test-toleration-key"
operator: "Equal"
value: "test-toleration-value"
effect: "NoSchedule"
EOF
output=$(helm template oci://ttl.sh/automated-${{ github.run_id }}/replicated --version 0.0.0 --values test-values.yaml)
if ! echo $output | grep -q 'tolerations:'; then
printf "user-set tolerations should exist:\n\n%s\n\n" "$output"
exit 1
fi
if ! echo $output | grep -q 'test-toleration-key'; then
printf "user-set tolerations key should exist:\n\n%s\n\n" "$output"
exit 1
fi
cat << EOF > test-values.yaml
statusInformers: []
EOF
output=$(helm template oci://ttl.sh/automated-${{ github.run_id }}/replicated --version 0.0.0 --values test-values.yaml)
if ! echo $output | grep -q 'statusInformers: \[\]'; then
printf "user-set empty statusInformers should exist:\n\n%s\n\n" "$output"
exit 1
fi
create-test-release:
runs-on: ubuntu-22.04
needs: [ build-and-push-e2e ]
outputs:
license-id: ${{ steps.create-customer.outputs.license-id }}
customer-id: ${{ steps.create-customer.outputs.customer-id }}
channel-slug: ${{ steps.create-release.outputs.channel-slug }}
steps:
- uses: actions/checkout@v3
- name: Package test chart
env:
REPLICATED_CHART_NAME: replicated
REPLICATED_REPOSITORY: oci://ttl.sh/automated-${{ github.run_id }}
REPLICATED_CHART_VERSION: 0.0.0
run: |
cd test-chart
envsubst < Chart.yaml.tmpl > Chart.yaml
helm dep update
helm package .
- name: Create release
id: create-release
uses: replicatedhq/replicated-actions/[email protected]
with:
app-slug: ${{ env.APP_SLUG }}
api-token: ${{ secrets.C11Y_MATRIX_TOKEN }}
chart: test-chart/test-chart-0.1.0.tgz
promote-channel: automated-${{ github.run_id }}
version: 0.1.0
- name: Create customer
id: create-customer
uses: replicatedhq/replicated-actions/create-customer@main
with:
app-slug: ${{ env.APP_SLUG }}
api-token: ${{ secrets.C11Y_MATRIX_TOKEN }}
customer-name: automated-${{ github.run_id }}
customer-email: [email protected]
license-type: dev
channel-slug: ${{ steps.create-release.outputs.channel-slug }}
entitlements: |
- name: "num_seats"
value: "10"
is-kots-install-enabled: "false"
validate-e2e:
runs-on: ubuntu-22.04
needs: [ create-test-release ]
strategy:
fail-fast: false
matrix:
cluster: [
{distribution: k3s, version: 1.26},
{distribution: eks, version: 1.27},
{distribution: gke, version: 1.27},
{distribution: kind, version: 1.27},
{distribution: openshift, version: 4.13.0-okd}
]
env:
LICENSE_ID: ${{ needs.create-test-release.outputs.license-id }}
CHANNEL_SLUG: ${{ needs.create-test-release.outputs.channel-slug }}
LICENSE_FIELDS: '[{"name":"expires_at","value": ""},{"name":"num_seats","value":"10"}]'
steps:
- uses: actions/checkout@v3
- name: Create cluster
id: create-cluster
uses: replicatedhq/replicated-actions/[email protected]
with:
api-token: ${{ secrets.C11Y_MATRIX_TOKEN }}
kubernetes-distribution: ${{ matrix.cluster.distribution }}
kubernetes-version: ${{ matrix.cluster.version }}
cluster-name: automated-${{ github.run_id }}-${{ matrix.cluster.distribution }}-${{ matrix.cluster.version }}
ttl: 2h
export-kubeconfig: true
- name: Install via Helm as standalone in integration mode
run: helm install replicated oci://ttl.sh/automated-${{ github.run_id }}/replicated --version 0.0.0 --set integration.licenseID=$LICENSE_ID --wait --timeout 2m
- name: Validate endpoints
uses: ./.github/actions/validate-endpoints
with:
license-id: ${{ env.LICENSE_ID }}
license-fields: ${{ env.LICENSE_FIELDS }}
integration-enabled: 'true'
- name: Uninstall replicated via Helm
run: helm uninstall replicated --wait --timeout 2m
- name: Install via kubectl as standalone in integration mode
run: |
helm template replicated oci://ttl.sh/automated-${{ github.run_id }}/replicated --version 0.0.0 --set integration.licenseID=$LICENSE_ID | kubectl apply -f -
kubectl rollout status deployment replicated --timeout=2m
- name: Validate endpoints
uses: ./.github/actions/validate-endpoints
with:
license-id: ${{ env.LICENSE_ID }}
license-fields: ${{ env.LICENSE_FIELDS }}
integration-enabled: 'true'
deployed-via-kubectl: 'true'
- name: Uninstall replicated via kubectl
run: |
helm template replicated oci://ttl.sh/automated-${{ github.run_id }}/replicated --version 0.0.0 --set integration.licenseID=$LICENSE_ID | kubectl delete -f -
kubectl wait --for=delete deployment/replicated --timeout=2m
- name: Login to registry
run: helm registry login registry.replicated.com --username $LICENSE_ID --password $LICENSE_ID
- name: Install via Helm as subchart in integration mode
run: helm install test-chart oci://registry.replicated.com/$APP_SLUG/$CHANNEL_SLUG/test-chart --wait --timeout 2m
- name: Validate endpoints
uses: ./.github/actions/validate-endpoints
with:
license-id: ${{ env.LICENSE_ID }}
license-fields: ${{ env.LICENSE_FIELDS }}
integration-enabled: 'true'
- name: Uninstall test-chart via Helm
run: helm uninstall test-chart --wait --timeout 2m
- name: Install via kubectl as subchart in integration mode
run: |
helm template test-chart oci://registry.replicated.com/$APP_SLUG/$CHANNEL_SLUG/test-chart | kubectl apply -f -
kubectl rollout status deployment test-chart --timeout=2m
kubectl rollout status deployment replicated --timeout=2m
- name: Validate endpoints
uses: ./.github/actions/validate-endpoints
with:
license-id: ${{ env.LICENSE_ID }}
license-fields: ${{ env.LICENSE_FIELDS }}
integration-enabled: 'true'
deployed-via-kubectl: 'true'
- name: Uninstall test-chart via kubectl
run: |
helm template test-chart oci://registry.replicated.com/$APP_SLUG/$CHANNEL_SLUG/test-chart | kubectl delete -f -
kubectl wait --for=delete deployment/test-chart --timeout=2m
kubectl wait --for=delete deployment/replicated --timeout=2m
# we have to explicitly disable integration mode here because we're using a "dev" license
- name: Install via Helm as subchart in production mode
run: helm install test-chart oci://registry.replicated.com/$APP_SLUG/$CHANNEL_SLUG/test-chart --set replicated.integration.enabled=false --wait --timeout 2m
- name: Validate endpoints
uses: ./.github/actions/validate-endpoints
with:
license-id: ${{ env.LICENSE_ID }}
license-fields: ${{ env.LICENSE_FIELDS }}
integration-enabled: 'false'
- name: Upgrade via Helm as subchart in production mode to a new version
run: |
oldpodname=$(kubectl get pods -l app.kubernetes.io/name=replicated -o jsonpath='{.items[0].metadata.name}')
helm upgrade test-chart oci://registry.replicated.com/$APP_SLUG/$CHANNEL_SLUG/test-chart --set replicated.integration.enabled=false --set replicated.versionLabel=1.0.0 --wait --timeout 2m
COUNTER=1
while kubectl get pods -l app.kubernetes.io/name=replicated -o jsonpath='{.items[0].metadata.name}' | grep -q $oldpodname; do
((COUNTER += 1))
if [ $COUNTER -gt 60 ]; then
echo "Pod did not restart after upgrade"
exit 1
fi
sleep 1
done
- name: Validate endpoints
uses: ./.github/actions/validate-endpoints
with:
license-id: ${{ env.LICENSE_ID }}
license-fields: ${{ env.LICENSE_FIELDS }}
version-label: '1.0.0'
integration-enabled: 'false'
- name: Uninstall test-chart via Helm
run: helm uninstall test-chart --wait --timeout 2m
# we have to explicitly disable integration mode here because we're using a "dev" license
- name: Install via kubectl as subchart in production mode
run: |
helm template test-chart oci://registry.replicated.com/$APP_SLUG/$CHANNEL_SLUG/test-chart --set replicated.integration.enabled=false | kubectl apply -f -
kubectl rollout status deployment test-chart --timeout=2m
kubectl rollout status deployment replicated --timeout=2m
- name: Validate endpoints
uses: ./.github/actions/validate-endpoints
with:
license-id: ${{ env.LICENSE_ID }}
license-fields: ${{ env.LICENSE_FIELDS }}
integration-enabled: 'false'
deployed-via-kubectl: 'true'
- name: Upgrade via kubectl as subchart in production mode
run: |
oldpodname=$(kubectl get pods -l app.kubernetes.io/name=replicated -o jsonpath='{.items[0].metadata.name}')
helm template test-chart oci://registry.replicated.com/$APP_SLUG/$CHANNEL_SLUG/test-chart --set replicated.integration.enabled=false --set replicated.versionLabel=1.0.0 | kubectl apply -f -
kubectl rollout status deployment test-chart --timeout=2m
kubectl rollout status deployment replicated --timeout=2m
COUNTER=1
while kubectl get pods -l app.kubernetes.io/name=replicated -o jsonpath='{.items[0].metadata.name}' | grep -q $oldpodname; do
((COUNTER += 1))
if [ $COUNTER -gt 60 ]; then
echo "Pod did not restart after upgrade"
exit 1
fi
sleep 1
done
- name: Validate endpoints
uses: ./.github/actions/validate-endpoints
with:
license-id: ${{ env.LICENSE_ID }}
license-fields: ${{ env.LICENSE_FIELDS }}
integration-enabled: 'false'
version-label: '1.0.0'
deployed-via-kubectl: 'true'
- name: Uninstall test-chart via kubectl
run: |
helm template test-chart oci://registry.replicated.com/$APP_SLUG/$CHANNEL_SLUG/test-chart --set replicated.integration.enabled=false | kubectl delete -f -
kubectl wait --for=delete deployment/test-chart --timeout=2m
kubectl wait --for=delete deployment/replicated --timeout=2m
# validate status informers
- name: Create empty status informers for validation
run: |
cat << EOF > test-values.yaml
replicated:
statusInformers: []
EOF
- name: Install via Helm as subchart in production mode and pass empty status informers
run: |
helm install test-chart oci://registry.replicated.com/$APP_SLUG/$CHANNEL_SLUG/test-chart --set replicated.integration.enabled=false -f test-values.yaml --wait --timeout 2m
COUNTER=1
while ! kubectl logs deploy/replicated | grep -qv 'Generating status informers from Helm release'; do
((COUNTER += 1))
if [ $COUNTER -gt 60 ]; then
echo "Did not receive empty status informers"
kubectl logs deploy/replicated
exit 1
fi
sleep 1
done
- name: Upgrade via Helm as subchart in production mode to use default status informers
run: |
helm upgrade test-chart oci://registry.replicated.com/$APP_SLUG/$CHANNEL_SLUG/test-chart --set replicated.integration.enabled=false --wait --timeout 2m
COUNTER=1
while ! kubectl logs deploy/replicated | grep -q 'Generating status informers from Helm release'; do
((COUNTER += 1))
if [ $COUNTER -gt 60 ]; then
echo "Did not receive default status informers"
kubectl logs deploy/replicated
exit 1
fi
sleep 1
done
- name: Uninstall test-chart via Helm
run: helm uninstall test-chart --wait --timeout 2m
- name: Install via kubectl as subchart in production mode and pass empty status informers
run: |
helm template test-chart oci://registry.replicated.com/$APP_SLUG/$CHANNEL_SLUG/test-chart --set replicated.integration.enabled=false -f test-values.yaml | kubectl apply -f -
kubectl rollout status deployment test-chart --timeout=2m
kubectl rollout status deployment replicated --timeout=2m
COUNTER=1
while ! kubectl logs deploy/replicated | grep -qv 'Generating status informers from Helm release'; do
((COUNTER += 1))
if [ $COUNTER -gt 60 ]; then
echo "Did not receive empty status informers"
kubectl logs deploy/replicated
exit 1
fi
sleep 1
done
- name: Uninstall test-chart via kubectl
run: |
helm template test-chart oci://registry.replicated.com/$APP_SLUG/$CHANNEL_SLUG/test-chart --set replicated.integration.enabled=false -f test-values.yaml | kubectl delete -f -
kubectl wait --for=delete deployment/test-chart --timeout=2m
kubectl wait --for=delete deployment/replicated --timeout=2m
- name: Remove Cluster
uses: replicatedhq/replicated-actions/[email protected]
if: ${{ success() || cancelled() }}
with:
api-token: ${{ secrets.C11Y_MATRIX_TOKEN }}
cluster-id: ${{ steps.create-cluster.outputs.cluster-id }}
cleanup-test-release:
runs-on: ubuntu-22.04
needs: [ create-test-release, validate-e2e ]
steps:
- name: Archive Customer
if: ${{ needs.create-test-release.outputs.customer-id != '' }}
uses: replicatedhq/replicated-actions/[email protected]
with:
api-token: ${{ secrets.C11Y_MATRIX_TOKEN }}
customer-id: ${{ needs.create-test-release.outputs.customer-id }}
- name: Archive Channel
if: ${{ needs.create-test-release.outputs.channel-slug != '' }}
uses: replicatedhq/replicated-actions/[email protected]
with:
app-slug: ${{ env.APP_SLUG }}
api-token: ${{ secrets.C11Y_MATRIX_TOKEN }}
channel-slug: ${{ needs.create-test-release.outputs.channel-slug }}