add cleanup interface

This commit is contained in:
Danil Uzlov 2025-03-26 08:15:12 +00:00
parent 8193b689ed
commit 99f9120d74
2 changed files with 20 additions and 0 deletions

View File

@ -486,6 +486,21 @@ const signalMapping = {
} }
} }
if (driver && typeof driver.getCleanupHandlers === 'function') {
const cleanup = driver.getCleanupHandlers();
console.log(`running driver ${cleanup.length} cleanup handlers`);
for (const c of cleanup) {
try {
c();
} catch (e) {
console.log("cleanup handler failed");
console.log(e);
}
}
} else {
console.log(`current driver does not support cleanup`);
}
console.log("server fully shutdown, exiting"); console.log("server fully shutdown, exiting");
process.exit(codeNumber); process.exit(codeNumber);
}); });

View File

@ -33,6 +33,7 @@ class CsiBaseDriver {
constructor(ctx, options) { constructor(ctx, options) {
this.ctx = ctx; this.ctx = ctx;
this.options = options || {}; this.options = options || {};
this.cleanup = [];
if (!this.options.hasOwnProperty("node")) { if (!this.options.hasOwnProperty("node")) {
this.options.node = {}; this.options.node = {};
@ -51,6 +52,10 @@ class CsiBaseDriver {
} }
} }
getCleanupHandlers() {
return this.cleanup;
}
/** /**
* abstract way of retrieving values from parameters/secrets * abstract way of retrieving values from parameters/secrets
* in order of preference: * in order of preference: