Created
July 10, 2020 14:46
-
-
Save Dvorson/1ddc0a6c2e8ba646861458b2185de121 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function portForward(podName, localPort, remotePort) { | |
return new Promise((resolve, reject) => { | |
const child = spawn('oc', ['port-forward', podName, `${localPort}:${remotePort}`]); // , { stdio: 'inherit' }); | |
['exit', 'SIGINT', 'SIGUSR1', 'SIGUSR2', 'uncaughtException', 'SIGTERM'].forEach(signal => { | |
process.on(signal, () => { | |
child.stdin.pause(); | |
child.kill(); | |
}); | |
}); | |
child.stderr.on('data', err => reject(err)); | |
child.on('close', code => { | |
console.log(`Port forwarding ${podName} exited with code ${code}`); | |
child.stdin.pause(); | |
process.exit(); | |
}); | |
child.stdout.on('data', data => { | |
console.log(`${podName}: ${data}`); | |
if (data.includes('Forwarding from')) { | |
console.log(`Started port forwarding for ${podName}`); | |
child.stdout.off('data'); | |
resolve(); | |
} | |
}); | |
}).catch(err => console.error(`${err}`)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment