Skip to content

Commit 5c92439

Browse files
mads-hartmannroboquat
authored andcommitted
Handle preview deployment failures on main more robustly
Rather than relying on catching errors everywhere and using exit 0 in the implementation of preview environment deployments, this moves the try/catch all the way to the top. This ensure that preview deployment errors never breaks the main build. Using exit 0 is also not ideal as it means we might not flush traces, so getting rid of those is nice.
1 parent c7c2a92 commit 5c92439

File tree

2 files changed

+23
-49
lines changed

2 files changed

+23
-49
lines changed

.werft/build.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,16 @@ async function run(context: any) {
6060
return
6161
}
6262

63-
await deployToPreviewEnvironment(werft, config)
63+
try {
64+
await deployToPreviewEnvironment(werft, config)
65+
} catch (e) {
66+
// We currently don't support concurrent deployments to the same preview environment.
67+
// Until we do we don't want errors to mark the main build as failed.
68+
if (config.mainBuild) {
69+
return
70+
}
71+
throw e
72+
}
73+
6474
await triggerIntegrationTests(werft, config, context.Owner)
6575
}

.werft/jobs/build/deploy-to-preview-environment.ts

Lines changed: 12 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,7 @@ export async function deployToPreviewEnvironment(werft: Werft, jobConfig: JobCon
142142
await installMetaCertificates(werft, jobConfig.repository.branch, withVM, 'default', PREVIEW_K3S_KUBECONFIG_PATH, vmSlices.COPY_CERT_MANAGER_RESOURCES)
143143
werft.done(vmSlices.COPY_CERT_MANAGER_RESOURCES)
144144
} catch (err) {
145-
if (!jobConfig.mainBuild) {
146-
werft.fail(vmSlices.COPY_CERT_MANAGER_RESOURCES, err);
147-
}
148-
exec('exit 0')
145+
werft.fail(vmSlices.COPY_CERT_MANAGER_RESOURCES, err);
149146
}
150147

151148
// Deploying monitoring satellite to VM-based preview environments is currently best-effort.
@@ -262,10 +259,7 @@ async function deployToDevWithInstaller(werft: Werft, jobConfig: JobConfig, depl
262259
}
263260
werft.done(installerSlices.CLEAN_ENV_STATE);
264261
} catch (err) {
265-
if (!jobConfig.mainBuild) {
266-
werft.fail(installerSlices.CLEAN_ENV_STATE, err);
267-
}
268-
exec('exit 0')
262+
werft.fail(installerSlices.CLEAN_ENV_STATE, err);
269263
}
270264

271265
if (!withVM) {
@@ -278,10 +272,7 @@ async function deployToDevWithInstaller(werft: Werft, jobConfig: JobConfig, depl
278272
await installMetaCertificates(werft, jobConfig.repository.branch, jobConfig.withVM, namespace, CORE_DEV_KUBECONFIG_PATH, installerSlices.COPY_CERTIFICATES);
279273
werft.done(installerSlices.COPY_CERTIFICATES);
280274
} catch (err) {
281-
if (!jobConfig.mainBuild) {
282-
werft.fail(installerSlices.COPY_CERTIFICATES, err);
283-
}
284-
exec('exit 0')
275+
werft.fail(installerSlices.COPY_CERTIFICATES, err);
285276
}
286277
}
287278

@@ -295,10 +286,7 @@ async function deployToDevWithInstaller(werft: Werft, jobConfig: JobConfig, depl
295286
exec(`kubectl --kubeconfig ${deploymentKubeconfig} create secret docker-registry ${IMAGE_PULL_SECRET_NAME} -n ${namespace} --from-file=.dockerconfigjson=./${IMAGE_PULL_SECRET_NAME}`, { slice: installerSlices.IMAGE_PULL_SECRET });
296287
}
297288
catch (err) {
298-
if (!jobConfig.mainBuild) {
299-
werft.fail(installerSlices.IMAGE_PULL_SECRET, err);
300-
}
301-
exec('exit 0')
289+
werft.fail(installerSlices.IMAGE_PULL_SECRET, err);
302290
}
303291
}
304292
werft.done(installerSlices.IMAGE_PULL_SECRET);
@@ -338,10 +326,7 @@ async function deployToDevWithInstaller(werft: Werft, jobConfig: JobConfig, depl
338326
installer.postProcessing(installerSlices.INSTALLER_POST_PROCESSING)
339327
installer.install(installerSlices.APPLY_INSTALL_MANIFESTS)
340328
} catch (err) {
341-
if (!jobConfig.mainBuild) {
342-
werft.fail(phases.DEPLOY, err)
343-
}
344-
exec('exit 0')
329+
werft.fail(phases.DEPLOY, err)
345330
}
346331

347332
werft.log(installerSlices.DEPLOYMENT_WAITING, "Waiting until all pods are ready.");
@@ -410,10 +395,7 @@ async function deployToDevWithHelm(werft: Werft, jobConfig: JobConfig, deploymen
410395
await addDNSRecord(werft, deploymentConfig.namespace, deploymentConfig.domain, false, CORE_DEV_KUBECONFIG_PATH)
411396
werft.done('prep');
412397
} catch (err) {
413-
if (!jobConfig.mainBuild) {
414-
werft.fail('prep', err);
415-
}
416-
exec('exit 0')
398+
werft.fail('prep', err);
417399
}
418400

419401
// core-dev specific section start
@@ -435,10 +417,7 @@ async function deployToDevWithHelm(werft: Werft, jobConfig: JobConfig, deploymen
435417
}` );
436418
werft.done('secret');
437419
} catch (err) {
438-
if (!jobConfig.mainBuild) {
439-
werft.fail('secret', err);
440-
}
441-
exec('exit 0')
420+
werft.fail('secret', err);
442421
}
443422

444423
werft.log("authProviders", "copy authProviders")
@@ -450,10 +429,7 @@ async function deployToDevWithHelm(werft: Werft, jobConfig: JobConfig, deploymen
450429
exec(`yq merge --inplace .werft/jobs/build/helm/values.dev.yaml ./authProviders`, { slice: "authProviders" })
451430
werft.done('authProviders');
452431
} catch (err) {
453-
if (!jobConfig.mainBuild) {
454-
werft.fail('authProviders', err);
455-
}
456-
exec('exit 0')
432+
werft.fail('authProviders', err);
457433
}
458434
// core-dev specific section end
459435

@@ -478,10 +454,7 @@ async function deployToDevWithHelm(werft: Werft, jobConfig: JobConfig, deploymen
478454
});
479455
await installMonitoringSatellite.install()
480456
} catch (err) {
481-
if (!jobConfig.mainBuild) {
482-
werft.fail('observability', err);
483-
}
484-
exec('exit 0')
457+
werft.fail('observability', err);
485458
}
486459
} else {
487460
exec(`echo '"with-observability" annotation not set, skipping...'`, { slice: `observability` })
@@ -500,10 +473,7 @@ async function deployToDevWithHelm(werft: Werft, jobConfig: JobConfig, deploymen
500473
werft.log('helm', 'done');
501474
werft.done('helm');
502475
} catch (err) {
503-
if (!jobConfig.mainBuild) {
504-
werft.fail('deploy', err);
505-
}
506-
exec('exit 0')
476+
werft.fail('deploy', err);
507477
} finally {
508478
// produce the result independently of Helm succeding, so that in case Helm fails we still have the URL.
509479
exec(`werft log result -d "dev installation" -c github-check-preview-env url ${url}/workspaces`);
@@ -559,10 +529,7 @@ async function deployToDevWithHelm(werft: Werft, jobConfig: JobConfig, deploymen
559529
try {
560530
exec(`docker run --rm eu.gcr.io/gitpod-core-dev/build/versions:${version} cat /versions.yaml | tee versions.yaml`);
561531
} catch (err) {
562-
if (!jobConfig.mainBuild) {
563-
werft.fail('helm', err);
564-
}
565-
exec('exit 0')
532+
werft.fail('helm', err);
566533
}
567534
const pathToVersions = `${shell.pwd().toString()}/versions.yaml`;
568535
flags += ` -f ${pathToVersions}`;
@@ -590,10 +557,7 @@ async function deployToDevWithHelm(werft: Werft, jobConfig: JobConfig, deploymen
590557
await deleteNonNamespaceObjects(namespace, destname, CORE_DEV_KUBECONFIG_PATH, { ...shellOpts, slice: 'predeploy cleanup' });
591558
werft.done('predeploy cleanup');
592559
} catch (err) {
593-
if (!jobConfig.mainBuild) {
594-
werft.fail('predeploy cleanup', err);
595-
}
596-
exec('exit 0')
560+
werft.fail('predeploy cleanup', err);
597561
}
598562
}
599563
}

0 commit comments

Comments
 (0)