Skip to content

Commit

Permalink
Add wipe logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Prince Rachit Sinha committed Jul 6, 2021
1 parent 63c2e50 commit 41ac7d8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
17 changes: 13 additions & 4 deletions .werft/wipe-devstaging.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,32 @@
import { werft } from './util/shell';
import { wipePreviewEnvironment, listAllPreviewNamespaces } from './util/kubectl';
import fs from 'fs';


async function wipeDevstaging() {
async function wipeDevstaging(pathToKubeConfig: string) {
const namespace_raw = process.env.NAMESPACE;
const namespaces: string[] = [];
if (namespace_raw === "<no value>" || !namespace_raw) {
werft.log('wipe', "Going to wipe all namespaces");
listAllPreviewNamespaces("")
listAllPreviewNamespaces(pathToKubeConfig)
.map(ns => namespaces.push(ns));
} else {
werft.log('wipe', `Going to wipe namespace ${namespace_raw}`);
namespaces.push(namespace_raw);
}

for (const namespace of namespaces) {
await wipePreviewEnvironment("", "gitpod", namespace, { slice: 'wipe' });
await wipePreviewEnvironment(pathToKubeConfig, "gitpod", namespace, { slice: 'wipe' });
}
werft.done('wipe');
}

wipeDevstaging()
wipeDevstaging("")
// if we have "/workspace/k3s-external.yaml" present that means a k3s ws cluster
// exists, therefore, delete corresponding preview deployment from that cluster too
// NOTE: Even for a non k3s ws deployment we will attempt to clean the preview.
// This saves us from writing complex logic of querying meta cluster for registered workspaces
// Since we use the same namespace to deploy in both dev and k3s cluster, this is safe
if (fs.existsSync("/workspace/k3s-external.yaml")) {
wipeDevstaging("/workspace/k3s-external.yaml")
}
1 change: 1 addition & 0 deletions .werft/wipe-devstaging.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ pod:
gcloud auth activate-service-account --key-file /mnt/secrets/gcp-sa/service-account.json
gcloud container clusters get-credentials dev --zone europe-west1-b --project gitpod-core-dev
kubectl get secret k3sdev -n werft -o=go-template='{{index .data "k3s-external.yaml"}}' | base64 -d > /workspace/k3s-external.yaml
export NAMESPACE="{{ .Annotations.namespace }}"
sudo chown -R gitpod:gitpod /workspace
Expand Down

0 comments on commit 41ac7d8

Please sign in to comment.