From 322d1f8ec10314820093d86de83b3dcaa100c94a Mon Sep 17 00:00:00 2001 From: Atharva Mulmuley Date: Thu, 29 Apr 2021 14:05:41 +0530 Subject: [PATCH] added a fix for using self-hosted runners --- lib/arc-login.js | 7 ++++--- src/arc-login.ts | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/arc-login.js b/lib/arc-login.js index 9a6204c..8dba837 100644 --- a/lib/arc-login.js +++ b/lib/arc-login.js @@ -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(); diff --git a/src/arc-login.ts b/src/arc-login.ts index 5c01dec..5a6b95b 100644 --- a/src/arc-login.ts +++ b/src/arc-login.ts @@ -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 { @@ -68,22 +69,22 @@ export async function getArcKubeconfig(): Promise { 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();