Skip to content

Commit

Permalink
added delete verification to delete namespace
Browse files Browse the repository at this point in the history
Signed-off-by: Jeromy Cannon <[email protected]>
  • Loading branch information
jeromy-cannon committed Feb 14, 2025
1 parent 74edacd commit 50f0491
Showing 1 changed file with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import {type V1Status, type CoreV1Api} from '@kubernetes/client-node';
import {StatusCodes} from 'http-status-codes';
import {SoloError} from '../../../../errors.js';
import {NamespaceName} from '../../../resources/namespace/namespace_name.js';
import {ResourceDeleteError} from '../../../errors/resource_operation_errors.js';
import {ResourceType} from '../../../resources/resource_type.js';
import {sleep} from '../../../../helpers.js';
import {Duration} from '../../../../time/duration.js';

export class K8ClientNamespaces implements Namespaces {
constructor(private readonly kubeClient: CoreV1Api) {}
Expand All @@ -26,6 +26,17 @@ export class K8ClientNamespaces implements Namespaces {
public async delete(namespace: NamespaceName): Promise<boolean> {
try {
const resp: {response: any; body?: V1Status} = await this.kubeClient.deleteNamespace(namespace.name);
let namespaceExists = true;
while (namespaceExists) {
const response = await this.kubeClient.readNamespace(namespace.name);

if (!response?.body?.metadata?.deletionTimestamp) {
namespaceExists = false;
} else {
await sleep(Duration.ofSeconds(1));
}
}

return resp.response.statusCode === StatusCodes.OK;
} catch {
return false;
Expand Down

0 comments on commit 50f0491

Please sign in to comment.