removed redirection changes, added constant for timeout

This commit is contained in:
Atharva Mulmuley 2021-04-30 12:59:50 +05:30
parent 8ff551ad06
commit 5c875f1e46
3 changed files with 12 additions and 27 deletions

View File

@ -16,8 +16,8 @@ jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
#runs-on: ubuntu-latest
runs-on: self-hosted
runs-on: ubuntu-latest
#runs-on: self-hosted
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
@ -32,15 +32,3 @@ jobs:
cluster-name: arcaction
resource-group: atharvatest2
token: '${{ secrets.SA_TOKEN }}'
- run: |
kubectl get pods -A
ls
pwd
echo 'hello world' > temp.txt
ls
cat out.log
- run: |
kubectl get pods -A
ls
pwd
cat out.log

View File

@ -17,6 +17,7 @@ const path = require("path");
const child_process_1 = require("child_process");
const fs = require("fs");
const io = require("@actions/io");
const kubeconfig_timeout = 120; //timeout in seconds
function getAzureAccessToken(servicePrincipalId, servicePrincipalKey, tenantId, authorityUrl, managementEndpointUrl) {
return __awaiter(this, void 0, void 0, function* () {
if (!servicePrincipalId || !servicePrincipalKey || !tenantId || !authorityUrl) {
@ -82,8 +83,6 @@ function getArcKubeconfig() {
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);
const out = fs.openSync('./out.log', 'a');
const err = fs.openSync('./out.log', 'a');
if (method == 'service-account') {
let saToken = core.getInput('token');
if (!saToken) {
@ -92,7 +91,7 @@ function getArcKubeconfig() {
console.log('using service account method for authenticating to arc cluster.');
const proc = child_process_1.spawn(azPath, ['connectedk8s', 'proxy', '-n', clusterName, '-g', resourceGroupName, '-f', kubeconfigPath, '--token', saToken], {
detached: true,
stdio: ['ignore', out, err]
stdio: 'ignore'
});
proc.unref();
}
@ -100,12 +99,12 @@ function getArcKubeconfig() {
console.log('using spn method for authenticating to arc cluster.');
const proc = child_process_1.spawn(azPath, ['connectedk8s', 'proxy', '-n', clusterName, '-g', resourceGroupName, '-f', kubeconfigPath], {
detached: true,
stdio: ['ignore', out, err]
stdio: 'ignore'
});
proc.unref();
}
console.log('Waiting for 2 minutes for kubeconfig to be merged....');
yield sleep(120000); //sleeping for 2 minutes to allow kubeconfig to be merged
console.log(`Waiting for ${kubeconfig_timeout} seconds for kubeconfig to be merged....`);
yield sleep(kubeconfig_timeout * 1000); //sleeping for 2 minutes to allow kubeconfig to be merged
fs.chmodSync(kubeconfigPath, '600');
core.exportVariable('KUBECONFIG', kubeconfigPath);
console.log('KUBECONFIG environment variable is set');

View File

@ -7,7 +7,7 @@ import * as path from 'path';
import {spawn} from 'child_process';
import * as fs from 'fs';
import * as io from '@actions/io';
const kubeconfig_timeout = 120;//timeout in seconds
async function getAzureAccessToken(servicePrincipalId, servicePrincipalKey, tenantId, authorityUrl, managementEndpointUrl: string): Promise<string> {
if (!servicePrincipalId || !servicePrincipalKey || !tenantId || !authorityUrl) {
@ -78,8 +78,6 @@ export async function getArcKubeconfig(): Promise<string> {
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);
const out = fs.openSync('./out.log', 'a');
const err = fs.openSync('./out.log', 'a');
if (method == 'service-account'){
let saToken = core.getInput('token');
if(!saToken){
@ -88,19 +86,19 @@ export async function getArcKubeconfig(): Promise<string> {
console.log('using service account method for authenticating to arc cluster.')
const proc=spawn(azPath,['connectedk8s','proxy','-n',clusterName,'-g',resourceGroupName,'-f',kubeconfigPath,'--token',saToken], {
detached: true,
stdio: [ 'ignore', out, err ]
stdio: 'ignore'
});
proc.unref();
} else{
console.log('using spn method for authenticating to arc cluster.')
const proc=spawn(azPath,['connectedk8s','proxy','-n',clusterName,'-g',resourceGroupName,'-f',kubeconfigPath], {
detached: true,
stdio: [ 'ignore', out, err ]
stdio: 'ignore'
});
proc.unref();
}
console.log('Waiting for 2 minutes for kubeconfig to be merged....')
await sleep(120000) //sleeping for 2 minutes to allow kubeconfig to be merged
console.log(`Waiting for ${kubeconfig_timeout} seconds for kubeconfig to be merged....`)
await sleep(kubeconfig_timeout*1000) //sleeping for 2 minutes to allow kubeconfig to be merged
fs.chmodSync(kubeconfigPath, '600');
core.exportVariable('KUBECONFIG', kubeconfigPath);
console.log('KUBECONFIG environment variable is set');