added a fix for using self-hosted runners
This commit is contained in:
parent
f0fc3cfe22
commit
322d1f8ec1
@ -16,6 +16,7 @@ const az_login = require("./main");
|
|||||||
const path = require("path");
|
const path = require("path");
|
||||||
const child_process_1 = require("child_process");
|
const child_process_1 = require("child_process");
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
|
const io = require("@actions/io");
|
||||||
function getAzureAccessToken(servicePrincipalId, servicePrincipalKey, tenantId, authorityUrl, managementEndpointUrl) {
|
function getAzureAccessToken(servicePrincipalId, servicePrincipalKey, tenantId, authorityUrl, managementEndpointUrl) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
if (!servicePrincipalId || !servicePrincipalKey || !tenantId || !authorityUrl) {
|
if (!servicePrincipalId || !servicePrincipalKey || !tenantId || !authorityUrl) {
|
||||||
@ -72,23 +73,23 @@ function getArcKubeconfig() {
|
|||||||
yield az_login.executeAzCliCommand(`account show`, false);
|
yield az_login.executeAzCliCommand(`account show`, false);
|
||||||
yield az_login.executeAzCliCommand(`extension add -n connectedk8s`, false);
|
yield az_login.executeAzCliCommand(`extension add -n connectedk8s`, false);
|
||||||
yield az_login.executeAzCliCommand(`extension list`, 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 runnerTempDirectory = process.env['RUNNER_TEMP']; // Using process.env until the core libs are updated
|
||||||
const kubeconfigPath = path.join(runnerTempDirectory, `kubeconfig_${Date.now()}`);
|
const kubeconfigPath = path.join(runnerTempDirectory, `kubeconfig_${Date.now()}`);
|
||||||
|
let azPath = yield io.which("az", true);
|
||||||
if (method == 'service-account') {
|
if (method == 'service-account') {
|
||||||
let saToken = core.getInput('token');
|
let saToken = core.getInput('token');
|
||||||
if (!saToken) {
|
if (!saToken) {
|
||||||
throw Error("'saToken' is not passed for 'service-account' method.");
|
throw Error("'saToken' is not passed for 'service-account' method.");
|
||||||
}
|
}
|
||||||
console.log('using service account method for authenticating to arc cluster.');
|
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,
|
detached: true,
|
||||||
stdio: 'ignore'
|
stdio: 'ignore'
|
||||||
}).unref();
|
}).unref();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
console.log('using spn method for authenticating to arc cluster.');
|
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,
|
detached: true,
|
||||||
stdio: 'ignore'
|
stdio: 'ignore'
|
||||||
}).unref();
|
}).unref();
|
||||||
|
@ -6,6 +6,7 @@ import * as az_login from './main';
|
|||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import {spawn} from 'child_process';
|
import {spawn} from 'child_process';
|
||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
|
import * as io from '@actions/io';
|
||||||
|
|
||||||
async function getAzureAccessToken(servicePrincipalId, servicePrincipalKey, tenantId, authorityUrl, managementEndpointUrl: string): Promise<string> {
|
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(`account show`, false);
|
||||||
await az_login.executeAzCliCommand(`extension add -n connectedk8s`, false);
|
await az_login.executeAzCliCommand(`extension add -n connectedk8s`, false);
|
||||||
await az_login.executeAzCliCommand(`extension list`, 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 runnerTempDirectory = process.env['RUNNER_TEMP']; // Using process.env until the core libs are updated
|
||||||
const kubeconfigPath = path.join(runnerTempDirectory, `kubeconfig_${Date.now()}`);
|
const kubeconfigPath = path.join(runnerTempDirectory, `kubeconfig_${Date.now()}`);
|
||||||
|
let azPath = await io.which("az", true);
|
||||||
if (method == 'service-account'){
|
if (method == 'service-account'){
|
||||||
let saToken = core.getInput('token');
|
let saToken = core.getInput('token');
|
||||||
if(!saToken){
|
if(!saToken){
|
||||||
throw Error("'saToken' is not passed for 'service-account' method.")
|
throw Error("'saToken' is not passed for 'service-account' method.")
|
||||||
}
|
}
|
||||||
console.log('using service account method for authenticating to arc cluster.')
|
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,
|
detached: true,
|
||||||
stdio: 'ignore'
|
stdio: 'ignore'
|
||||||
}).unref();
|
}).unref();
|
||||||
} else{
|
} else{
|
||||||
console.log('using spn method for authenticating to arc cluster.')
|
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,
|
detached: true,
|
||||||
stdio: 'ignore'
|
stdio: 'ignore'
|
||||||
}).unref();
|
}).unref();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user