Skip to content

Commit 36d4eec

Browse files
authored
Fix DevWorkspace and editor template cleanup order (#24021)
* stabilize workspace deletion * restore dw patching before deletion * validate dw deletion results
1 parent dcb3d13 commit 36d4eec

1 file changed

Lines changed: 23 additions & 5 deletions

File tree

‎tests/e2e/utils/KubernetesCommandLineToolsExecutor.ts‎

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,30 @@ export class KubernetesCommandLineToolsExecutor implements IKubernetesCommandLin
145145
deleteDevWorkspace(devfileName?: string): void {
146146
Logger.debug(`${this.kubernetesCommandLineTool} - delete '${this.workspaceName}' devWorkspace`);
147147

148-
this.shellExecutor.executeCommand(
149-
`${this.kubernetesCommandLineTool} patch dw ${this.workspaceName} -n ${this.namespace} -p '{ "metadata": { "finalizers": null }}' --type merge || true`
150-
);
151-
this.shellExecutor.executeCommand(
152-
`${this.kubernetesCommandLineTool} delete dw ${this.workspaceName} -n ${this.namespace} --timeout=2m || true`
148+
const deleteDevWorkspaceOutput: ShellString = this.shellExecutor.executeCommand(
149+
`${this.kubernetesCommandLineTool} delete dw ${this.workspaceName} -n ${this.namespace} --timeout=2m --ignore-not-found=true`
153150
);
151+
if (deleteDevWorkspaceOutput.code !== 0) {
152+
Logger.warn(
153+
`Could not confirm deletion of DevWorkspace '${this.workspaceName}' within the timeout. Trying forced finalizer removal.`
154+
);
155+
156+
// as a cleanup fallback, remove finalizers that prevent the timed-out DevWorkspace deletion.
157+
this.shellExecutor.executeCommand(
158+
`${this.kubernetesCommandLineTool} patch dw ${this.workspaceName} -n ${this.namespace} -p '{ "metadata": { "finalizers": null }}' --type merge`
159+
);
160+
161+
// give the forced deletion a bounded time to complete before deleting the associated template.
162+
const waitForForcedDeletionOutput: ShellString = this.shellExecutor.executeCommand(
163+
`${this.kubernetesCommandLineTool} wait -n ${this.namespace} --for=delete dw ${this.workspaceName} --timeout=30s`
164+
);
165+
if (waitForForcedDeletionOutput.code !== 0) {
166+
Logger.warn(
167+
`Could not confirm forced deletion of DevWorkspace '${this.workspaceName}'. Its DevWorkspaceTemplate will be preserved.`
168+
);
169+
return;
170+
}
171+
}
154172

155173
let dwtName: string;
156174
if (devfileName === undefined) {

0 commit comments

Comments
 (0)