add cleanup interface
This commit is contained in:
		
							parent
							
								
									8193b689ed
								
							
						
					
					
						commit
						99f9120d74
					
				|  | @ -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); | ||||
|     }); | ||||
|  |  | |||
|  | @ -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: | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue