mirror of
https://github.com/ditkrg/k8s-set-context.git
synced 2026-01-22 22:06:49 +00:00
set namespace
This commit is contained in:
parent
40d584de6d
commit
f518583554
12
src/login.ts
12
src/login.ts
@ -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);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user