File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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 ) {
You can’t perform that action at this time.
0 commit comments