From a18d947f5aa48eb04e09f6e9190bb1038a510e5f Mon Sep 17 00:00:00 2001 From: Alejandro Avagnina Date: Sat, 30 Sep 2023 10:44:20 -0300 Subject: [PATCH] fix: wks ingress create/delete logic (#41) * chore: remove ingress when workspace is disabled * chore: remove unneeded k8s client * fix: regenerate openUrl and health url on update * fix: ingress delete logic --- operator/src/workspaces/handlers.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/operator/src/workspaces/handlers.ts b/operator/src/workspaces/handlers.ts index 611467c..a9fdfff 100644 --- a/operator/src/workspaces/handlers.ts +++ b/operator/src/workspaces/handlers.ts @@ -84,11 +84,17 @@ export async function handleResource( async function handleIngress(ns: string, name: string, spec: Workspace.Spec, owner: CustomResource) { const { net } = getClients(); - if (spec.enabled) { + const exists = await net.readNamespacedIngress(name, ns).catch(() => false); + + if (spec.enabled && !exists) { + console.log('Creating ingress for workspace', name); await net .createNamespacedIngress(ns, ingress(name, buildDnsZone(spec), owner)) - .catch(() => console.log('Error creating ingress for workspace', name)); - } else { + .catch((err: any) => console.log('Error creating ingress for workspace', name, err.body)); + } + + if (!spec.enabled && exists) { + console.log('Deleting ingress for workspace', name); await net.deleteNamespacedIngress(name, ns).catch(() => console.log('Error deleting ingress for workspace', name)); } }