recan session during node stage
Signed-off-by: Travis Glenn Hansen <travisghansen@yahoo.com>
This commit is contained in:
		
							parent
							
								
									a029ee624c
								
							
						
					
					
						commit
						69b610b503
					
				|  | @ -40,6 +40,8 @@ Predominantly 3 things are needed: | ||||||
| ## Guides | ## Guides | ||||||
| 
 | 
 | ||||||
| - https://jonathangazeley.com/2021/01/05/using-truenas-to-provide-persistent-storage-for-kubernetes/ | - https://jonathangazeley.com/2021/01/05/using-truenas-to-provide-persistent-storage-for-kubernetes/ | ||||||
|  | - https://gist.github.com/admun/4372899f20421a947b7544e5fc9f9117 (migrating | ||||||
|  |   from `nfs-client-provisioner` to `democratic-csi`) | ||||||
| 
 | 
 | ||||||
| ## Node Prep | ## Node Prep | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -343,6 +343,7 @@ class CsiBaseDriver { | ||||||
|           // put these options in place to force targets managed by csi to be explicitly attached (in the case of unclearn shutdown etc)
 |           // put these options in place to force targets managed by csi to be explicitly attached (in the case of unclearn shutdown etc)
 | ||||||
|           let nodeDB = { |           let nodeDB = { | ||||||
|             "node.startup": "manual", |             "node.startup": "manual", | ||||||
|  |             //"node.session.scan": "manual",
 | ||||||
|           }; |           }; | ||||||
|           const nodeDBKeyPrefix = "node-db."; |           const nodeDBKeyPrefix = "node-db."; | ||||||
|           for (const key in normalizedSecrets) { |           for (const key in normalizedSecrets) { | ||||||
|  | @ -359,6 +360,15 @@ class CsiBaseDriver { | ||||||
|           // login
 |           // login
 | ||||||
|           await iscsi.iscsiadm.login(volume_context.iqn, portal); |           await iscsi.iscsiadm.login(volume_context.iqn, portal); | ||||||
| 
 | 
 | ||||||
|  |           // get associated session
 | ||||||
|  |           let session = await iscsi.iscsiadm.getSession( | ||||||
|  |             volume_context.iqn, | ||||||
|  |             portal | ||||||
|  |           ); | ||||||
|  | 
 | ||||||
|  |           // rescan in scenarios when login previously occurred but volumes never appeared
 | ||||||
|  |           await iscsi.iscsiadm.rescanSession(session); | ||||||
|  | 
 | ||||||
|           // find device name
 |           // find device name
 | ||||||
|           device = `/dev/disk/by-path/ip-${portal}-iscsi-${volume_context.iqn}-lun-${volume_context.lun}`; |           device = `/dev/disk/by-path/ip-${portal}-iscsi-${volume_context.iqn}-lun-${volume_context.lun}`; | ||||||
|           let deviceByPath = device; |           let deviceByPath = device; | ||||||
|  |  | ||||||
|  | @ -1,4 +1,5 @@ | ||||||
| const cp = require("child_process"); | const cp = require("child_process"); | ||||||
|  | const { setegid } = require("process"); | ||||||
| 
 | 
 | ||||||
| function getIscsiValue(value) { | function getIscsiValue(value) { | ||||||
|   if (value == "<empty>") return null; |   if (value == "<empty>") return null; | ||||||
|  | @ -147,6 +148,27 @@ class ISCSI { | ||||||
|         await iscsi.exec(options.paths.iscsiadm, args); |         await iscsi.exec(options.paths.iscsiadm, args); | ||||||
|       }, |       }, | ||||||
| 
 | 
 | ||||||
|  |       /** | ||||||
|  |        * get session object by iqn/portal | ||||||
|  |        */ | ||||||
|  |       async getSession(tgtIQN, portal) { | ||||||
|  |         const sessions = await iscsi.iscsiadm.getSessions(); | ||||||
|  | 
 | ||||||
|  |         let session = false; | ||||||
|  |         sessions.every((i_session) => { | ||||||
|  |           if ( | ||||||
|  |             `${i_session.iqn}:${i_session.target}` == tgtIQN && | ||||||
|  |             portal == i_session.portal | ||||||
|  |           ) { | ||||||
|  |             session = i_session; | ||||||
|  |             return false; | ||||||
|  |           } | ||||||
|  |           return true; | ||||||
|  |         }); | ||||||
|  | 
 | ||||||
|  |         return session; | ||||||
|  |       }, | ||||||
|  | 
 | ||||||
|       /** |       /** | ||||||
|        * iscsiadm -m session |        * iscsiadm -m session | ||||||
|        */ |        */ | ||||||
|  | @ -178,7 +200,7 @@ class ISCSI { | ||||||
|           fields = entry.split(" "); |           fields = entry.split(" "); | ||||||
|           sessions.push({ |           sessions.push({ | ||||||
|             protocol: entry.split(":")[0], |             protocol: entry.split(":")[0], | ||||||
|             id: fields[1].replace("[", "").replace("]", ""), |             id: Number(fields[1].replace("[", "").replace("]", "")), | ||||||
|             portal: fields[2].split(",")[0], |             portal: fields[2].split(",")[0], | ||||||
|             target_portal_group_tag: fields[2].split(",")[1], |             target_portal_group_tag: fields[2].split(",")[1], | ||||||
|             iqn: fields[3].split(":")[0], |             iqn: fields[3].split(":")[0], | ||||||
|  | @ -438,6 +460,36 @@ class ISCSI { | ||||||
| 
 | 
 | ||||||
|         return true; |         return true; | ||||||
|       }, |       }, | ||||||
|  | 
 | ||||||
|  |       /** | ||||||
|  |        * iscsiadm -m session -r SID --rescan | ||||||
|  |        * | ||||||
|  |        * @param {*} session | ||||||
|  |        */ | ||||||
|  |       async rescanSession(session) { | ||||||
|  |         let sid; | ||||||
|  |         if (typeof session === "object") { | ||||||
|  |           sid = session.id; | ||||||
|  |         } else { | ||||||
|  |           sid = session; | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         // make sure session is a valid number
 | ||||||
|  |         if (session !== 0 && session > 0) { | ||||||
|  |           throw new Error("cannot scan empty session id"); | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         let args = []; | ||||||
|  |         args = args.concat(["-m", "session", "-r", sid, "--rescan"]); | ||||||
|  | 
 | ||||||
|  |         try { | ||||||
|  |           await iscsi.exec(options.paths.iscsiadm, args); | ||||||
|  |         } catch (err) { | ||||||
|  |           throw err; | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         return true; | ||||||
|  |       }, | ||||||
|     }; |     }; | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue