Skip to content

Commit 258b832

Browse files
committed
Update clean-up cronjob to delete previews with parallel individual jobs
Signed-off-by: ArthurSens <[email protected]>
1 parent 6e3ec5e commit 258b832

File tree

2 files changed

+19
-16
lines changed

2 files changed

+19
-16
lines changed

.werft/platform-delete-preview-environments-cron.ts

+9-16
Original file line numberDiff line numberDiff line change
@@ -124,18 +124,6 @@ async function deletePreviewEnvironments() {
124124
werft.done(SLICES.DETERMINING_STALE_PREVIEW_ENVIRONMENTS);
125125
}
126126

127-
werft.phase("Deleting stale preview environments");
128-
if (DRY_RUN) {
129-
previewsToDelete.forEach((preview) => {
130-
werft.log(
131-
SLICES.DELETING_PREVIEW_ENVIRONMNETS,
132-
`Would have deleted preview environment ${preview.name} (${preview.namespace})`,
133-
);
134-
});
135-
werft.done(SLICES.DELETING_PREVIEW_ENVIRONMNETS);
136-
return;
137-
}
138-
139127
try {
140128
const promises: Promise<any>[] = [];
141129
previewsToDelete.forEach((preview) => promises.push(removePreviewEnvironment(preview)));
@@ -228,11 +216,16 @@ async function determineStalePreviewEnvironments(options: {
228216

229217
async function removePreviewEnvironment(previewEnvironment: PreviewEnvironment) {
230218
const sliceID = `Deleting preview ${previewEnvironment.name}`;
231-
werft.log(sliceID, `Starting deletion of all resources related to ${previewEnvironment.name}`);
219+
werft.log(sliceID, `Triggering job to delete ${previewEnvironment.name}. DRY_RUN=${DRY_RUN}`);
232220
try {
233-
// We're running these promises sequentially to make it easier to read the log output.
234-
await previewEnvironment.removeDNSRecords(sliceID);
235-
await previewEnvironment.delete();
221+
exec(
222+
`sudo chown -R gitpod:gitpod /workspace && git config --global user.name roboquat && git config --global user.email [email protected]`,
223+
{slice: sliceID}
224+
)
225+
exec(
226+
`werft job run github -j .werft/platform-delete-preview-environment.yaml -f -a preview=${previewEnvironment.name} -a dry-run=${DRY_RUN}`,
227+
{slice: sliceID}
228+
)
236229
werft.done(sliceID);
237230
} catch (e) {
238231
werft.failSlice(sliceID, e);

.werft/platform-delete-preview-environments-cron.yaml

+10
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,16 @@ pod:
4545
secretKeyRef:
4646
name: honeycomb-api-key
4747
key: apikey
48+
- name: ROBOQUAT_TOKEN
49+
valueFrom:
50+
secretKeyRef:
51+
name: github-roboquat-automatic-changelog
52+
key: token
53+
# Used by the Werft CLI through werft-credential-helper.sh
54+
- name: WERFT_GITHUB_TOKEN_PATH
55+
value: "/mnt/secrets/github-token-gitpod-bot/token"
56+
- name: WERFT_CREDENTIAL_HELPER
57+
value: "/workspace/dev/preview/werft-credential-helper.sh"
4858
command:
4959
- bash
5060
- -c

0 commit comments

Comments
 (0)