diff --git a/bin/democratic-csi b/bin/democratic-csi index 3d6b39e..949613b 100755 --- a/bin/democratic-csi +++ b/bin/democratic-csi @@ -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"); process.exit(codeNumber); }); diff --git a/src/driver/index.js b/src/driver/index.js index f0fe630..06038f2 100644 --- a/src/driver/index.js +++ b/src/driver/index.js @@ -33,6 +33,7 @@ class CsiBaseDriver { constructor(ctx, options) { this.ctx = ctx; this.options = options || {}; + this.cleanup = []; if (!this.options.hasOwnProperty("node")) { this.options.node = {}; @@ -51,6 +52,10 @@ class CsiBaseDriver { } } + getCleanupHandlers() { + return this.cleanup; + } + /** * abstract way of retrieving values from parameters/secrets * in order of preference: