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)); } }