set namespace

This commit is contained in:
Mohamad Tahir 2021-10-11 13:50:56 +00:00
parent 40d584de6d
commit f518583554
No known key found for this signature in database
GPG Key ID: F5A1E5A559ED9CA8

View File

@ -102,6 +102,17 @@ export async function setContext(kubeconfigPath: string) {
}
}
export async function setContext(kubeconfigPath: string) {
let namespace = core.getInput('namespace');
if (namespace) {
//To use kubectl commands, the environment variable KUBECONFIG needs to be set for this step
process.env['KUBECONFIG'] = kubeconfigPath;
const kubectlPath = await getKubectlPath();
var toolRunner = new ToolRunner(kubectlPath, ['config', 'set-context', '--current', `--namespace="${namespace}"`]);
await toolRunner.exec();
}
}
export async function run() {
try {
let kubeconfig = '';
@ -124,6 +135,7 @@ export async function run() {
core.exportVariable('KUBECONFIG', kubeconfigPath);
console.log('KUBECONFIG environment variable is set');
await setContext(kubeconfigPath);
await setContext(kubeconfigPath);
}
} catch (ex) {
return Promise.reject(ex);