Skip to content

Commit

Permalink
Remove Helm related cleanup logic
Browse files Browse the repository at this point in the history
  • Loading branch information
mads-hartmann authored and roboquat committed Sep 16, 2022
1 parent d51dc31 commit 44b1dca
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 76 deletions.
2 changes: 1 addition & 1 deletion .werft/jobs/build/deploy-to-preview-environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { previewNameFromBranchName } from "../../util/preview";
import { createDNSRecord } from "../../util/gcloud";
import { SpanStatusCode } from "@opentelemetry/api";

// used by both deploys (helm and Installer)
// used by Installer
const PROXY_SECRET_NAME = "proxy-config-certificates";
const IMAGE_PULL_SECRET_NAME = "gcp-sa-registry-auth";
const STACKDRIVER_SERVICEACCOUNT = JSON.parse(
Expand Down
76 changes: 1 addition & 75 deletions .werft/util/kubectl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,13 @@ import { getGlobalWerftInstance } from "./werft";

export const IS_PREVIEW_APP_LABEL: string = "isPreviewApp";

export const helmInstallName = "gitpod";

export function setKubectlContextNamespace(namespace: string, shellOpts: ExecOptions) {
[`kubectl config current-context`, `kubectl config set-context --current --namespace=${namespace}`].forEach((cmd) =>
exec(cmd, shellOpts),
);
}

export async function wipePreviewEnvironmentAndNamespace(
helmInstallName: string,
namespace: string,
kubeconfig: string,
shellOpts: ExecOptions,
Expand All @@ -23,9 +20,6 @@ export async function wipePreviewEnvironmentAndNamespace(
// wipe preview envs built with installer
await wipePreviewEnvironmentInstaller(namespace, kubeconfig, shellOpts);

// wipe preview envs previously built with helm
await wipePreviewEnvironmentHelm(helmInstallName, namespace, kubeconfig, shellOpts);

deleteAllWorkspaces(namespace, kubeconfig, shellOpts);

await deleteAllUnnamespacedObjects(namespace, kubeconfig, shellOpts);
Expand All @@ -35,28 +29,15 @@ export async function wipePreviewEnvironmentAndNamespace(
}

export async function wipeAndRecreateNamespace(
helmInstallName: string,
namespace: string,
kubeconfig: string,
shellOpts: ExecOptions,
) {
await wipePreviewEnvironmentAndNamespace(helmInstallName, namespace, kubeconfig, shellOpts);
await wipePreviewEnvironmentAndNamespace(namespace, kubeconfig, shellOpts);

createNamespace(namespace, kubeconfig, shellOpts);
}

export async function wipePreviewEnvironmentHelm(
helmInstallName: string,
namespace: string,
kubeconfig: string,
shellOpts: ExecOptions,
) {
// uninstall helm first so that:
// - ws-scaler can't create new ghosts in the meantime
// - ws-manager can't start new probes/workspaces
uninstallHelm(helmInstallName, namespace, shellOpts);
}

async function wipePreviewEnvironmentInstaller(namespace: string, kubeconfig: string, shellOpts: ExecOptions) {
const slice = shellOpts.slice || "installer";
const werft = getGlobalWerftInstance();
Expand All @@ -74,23 +55,6 @@ async function wipePreviewEnvironmentInstaller(namespace: string, kubeconfig: st
}
}

function uninstallHelm(installationName: string, namespace: string, shellOpts: ExecOptions) {
const installations = exec(`helm --namespace ${namespace} list -q`, {
...shellOpts,
silent: true,
dontCheckRc: true,
async: false,
})
.stdout.split("\n")
.map((o) => o.trim())
.filter((o) => o.length > 0);
if (!installations.some((i) => i === installationName)) {
return;
}

exec(`helm --namespace ${namespace} delete ${installationName} --wait`, shellOpts);
}

// Delete pods for running workspaces, even if they are stuck in terminating because of the finalizer decorator
function deleteAllWorkspaces(namespace: string, kubecofig: string, shellOpts: ExecOptions) {
const objs = exec(
Expand Down Expand Up @@ -220,44 +184,6 @@ export function deleteNamespace(wait: boolean, namespace: string, kubeconfig: st
}
}

export async function deleteNonNamespaceObjects(
namespace: string,
destname: string,
kubeconfig: string,
shellOpts: ExecOptions,
) {
exec(
`/usr/local/bin/helm3 --kubeconfig ${kubeconfig} delete gitpod-${destname} || echo gitpod-${destname} was not installed yet`,
{ ...shellOpts },
);

let objs = [];
["node-daemon", "cluster", "workspace", "ws-sync", "ws-manager-node", "ws-daemon", "registry-facade"].forEach(
(comp) =>
["ClusterRole", "ClusterRoleBinding", "PodSecurityPolicy"].forEach((kind) =>
exec(
`kubectl --kubeconfig ${kubeconfig} get ${kind} -l component=${comp} --no-headers -o=custom-columns=:metadata.name | grep ${namespace}-ns`,
{ ...shellOpts, dontCheckRc: true, async: false },
)
.split("\n")
.map((o) => o.trim())
.filter((o) => o.length > 0)
.forEach((obj) => objs.push({ kind: kind, obj: obj })),
),
);

const promisedDeletes: Promise<any>[] = [];
objs.forEach((o) => {
promisedDeletes.push(
exec(`kubectl --kubeconfig ${kubeconfig} delete ${o.kind} ${o.obj}`, {
...shellOpts,
async: true,
}) as Promise<any>,
);
});
await Promise.all(promisedDeletes);
}

export interface PortRange {
start: number;
end: number;
Expand Down

0 comments on commit 44b1dca

Please sign in to comment.