mirror of
https://github.com/ditkrg/k8s-set-context.git
synced 2026-01-23 06:16:48 +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() {
|
export async function run() {
|
||||||
try {
|
try {
|
||||||
let kubeconfig = '';
|
let kubeconfig = '';
|
||||||
@ -124,6 +135,7 @@ export async function run() {
|
|||||||
core.exportVariable('KUBECONFIG', kubeconfigPath);
|
core.exportVariable('KUBECONFIG', kubeconfigPath);
|
||||||
console.log('KUBECONFIG environment variable is set');
|
console.log('KUBECONFIG environment variable is set');
|
||||||
await setContext(kubeconfigPath);
|
await setContext(kubeconfigPath);
|
||||||
|
await setContext(kubeconfigPath);
|
||||||
}
|
}
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
return Promise.reject(ex);
|
return Promise.reject(ex);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user