Skip to content

Commit 41ac7d8

Browse files
author
Prince Rachit Sinha
committed
Add wipe logic
1 parent 63c2e50 commit 41ac7d8

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

.werft/wipe-devstaging.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,32 @@
11
import { werft } from './util/shell';
22
import { wipePreviewEnvironment, listAllPreviewNamespaces } from './util/kubectl';
3+
import fs from 'fs';
34

45

5-
async function wipeDevstaging() {
6+
async function wipeDevstaging(pathToKubeConfig: string) {
67
const namespace_raw = process.env.NAMESPACE;
78
const namespaces: string[] = [];
89
if (namespace_raw === "<no value>" || !namespace_raw) {
910
werft.log('wipe', "Going to wipe all namespaces");
10-
listAllPreviewNamespaces("")
11+
listAllPreviewNamespaces(pathToKubeConfig)
1112
.map(ns => namespaces.push(ns));
1213
} else {
1314
werft.log('wipe', `Going to wipe namespace ${namespace_raw}`);
1415
namespaces.push(namespace_raw);
1516
}
1617

1718
for (const namespace of namespaces) {
18-
await wipePreviewEnvironment("", "gitpod", namespace, { slice: 'wipe' });
19+
await wipePreviewEnvironment(pathToKubeConfig, "gitpod", namespace, { slice: 'wipe' });
1920
}
2021
werft.done('wipe');
2122
}
2223

23-
wipeDevstaging()
24+
wipeDevstaging("")
25+
// if we have "/workspace/k3s-external.yaml" present that means a k3s ws cluster
26+
// exists, therefore, delete corresponding preview deployment from that cluster too
27+
// NOTE: Even for a non k3s ws deployment we will attempt to clean the preview.
28+
// This saves us from writing complex logic of querying meta cluster for registered workspaces
29+
// Since we use the same namespace to deploy in both dev and k3s cluster, this is safe
30+
if (fs.existsSync("/workspace/k3s-external.yaml")) {
31+
wipeDevstaging("/workspace/k3s-external.yaml")
32+
}

.werft/wipe-devstaging.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ pod:
3232
gcloud auth activate-service-account --key-file /mnt/secrets/gcp-sa/service-account.json
3333
gcloud container clusters get-credentials dev --zone europe-west1-b --project gitpod-core-dev
3434
35+
kubectl get secret k3sdev -n werft -o=go-template='{{index .data "k3s-external.yaml"}}' | base64 -d > /workspace/k3s-external.yaml
3536
export NAMESPACE="{{ .Annotations.namespace }}"
3637
sudo chown -R gitpod:gitpod /workspace
3738

0 commit comments

Comments
 (0)