added a fix for using self-hosted runners

This commit is contained in:
Atharva Mulmuley 2021-04-29 14:05:41 +05:30
parent f0fc3cfe22
commit 322d1f8ec1
2 changed files with 8 additions and 6 deletions

View File

@ -16,6 +16,7 @@ const az_login = require("./main");
const path = require("path");
const child_process_1 = require("child_process");
const fs = require("fs");
const io = require("@actions/io");
function getAzureAccessToken(servicePrincipalId, servicePrincipalKey, tenantId, authorityUrl, managementEndpointUrl) {
return __awaiter(this, void 0, void 0, function* () {
if (!servicePrincipalId || !servicePrincipalKey || !tenantId || !authorityUrl) {
@ -72,23 +73,23 @@ function getArcKubeconfig() {
yield az_login.executeAzCliCommand(`account show`, false);
yield az_login.executeAzCliCommand(`extension add -n connectedk8s`, false);
yield az_login.executeAzCliCommand(`extension list`, false);
yield az_login.executeAzCliCommand(`connectedk8s --help`, false);
const runnerTempDirectory = process.env['RUNNER_TEMP']; // Using process.env until the core libs are updated
const kubeconfigPath = path.join(runnerTempDirectory, `kubeconfig_${Date.now()}`);
let azPath = yield io.which("az", true);
if (method == 'service-account') {
let saToken = core.getInput('token');
if (!saToken) {
throw Error("'saToken' is not passed for 'service-account' method.");
}
console.log('using service account method for authenticating to arc cluster.');
child_process_1.spawn('az', ['connectedk8s', 'proxy', '-n', clusterName, '-g', resourceGroupName, '-f', kubeconfigPath, '--token', saToken], {
child_process_1.spawn(azPath, ['connectedk8s', 'proxy', '-n', clusterName, '-g', resourceGroupName, '-f', kubeconfigPath, '--token', saToken], {
detached: true,
stdio: 'ignore'
}).unref();
}
else {
console.log('using spn method for authenticating to arc cluster.');
child_process_1.spawn('az.cmd', ['connectedk8s', 'proxy', '-n', clusterName, '-g', resourceGroupName, '-f', kubeconfigPath], {
child_process_1.spawn(azPath, ['connectedk8s', 'proxy', '-n', clusterName, '-g', resourceGroupName, '-f', kubeconfigPath], {
detached: true,
stdio: 'ignore'
}).unref();

View File

@ -6,6 +6,7 @@ import * as az_login from './main';
import * as path from 'path';
import {spawn} from 'child_process';
import * as fs from 'fs';
import * as io from '@actions/io';
async function getAzureAccessToken(servicePrincipalId, servicePrincipalKey, tenantId, authorityUrl, managementEndpointUrl: string): Promise<string> {
@ -68,22 +69,22 @@ export async function getArcKubeconfig(): Promise<string> {
await az_login.executeAzCliCommand(`account show`, false);
await az_login.executeAzCliCommand(`extension add -n connectedk8s`, false);
await az_login.executeAzCliCommand(`extension list`, false);
await az_login.executeAzCliCommand(`connectedk8s --help`, false);
const runnerTempDirectory = process.env['RUNNER_TEMP']; // Using process.env until the core libs are updated
const kubeconfigPath = path.join(runnerTempDirectory, `kubeconfig_${Date.now()}`);
let azPath = await io.which("az", true);
if (method == 'service-account'){
let saToken = core.getInput('token');
if(!saToken){
throw Error("'saToken' is not passed for 'service-account' method.")
}
console.log('using service account method for authenticating to arc cluster.')
spawn('az',['connectedk8s','proxy','-n',clusterName,'-g',resourceGroupName,'-f',kubeconfigPath,'--token',saToken], {
spawn(azPath,['connectedk8s','proxy','-n',clusterName,'-g',resourceGroupName,'-f',kubeconfigPath,'--token',saToken], {
detached: true,
stdio: 'ignore'
}).unref();
} else{
console.log('using spn method for authenticating to arc cluster.')
spawn('az.cmd',['connectedk8s','proxy','-n',clusterName,'-g',resourceGroupName,'-f',kubeconfigPath], {
spawn(azPath,['connectedk8s','proxy','-n',clusterName,'-g',resourceGroupName,'-f',kubeconfigPath], {
detached: true,
stdio: 'ignore'
}).unref();