From 5c875f1e46bce2efa0b0f2ccc8cad46b1485d906 Mon Sep 17 00:00:00 2001 From: Atharva Mulmuley Date: Fri, 30 Apr 2021 12:59:50 +0530 Subject: [PATCH] removed redirection changes, added constant for timeout --- .github/workflows/main.yml | 16 ++-------------- lib/arc-login.js | 11 +++++------ src/arc-login.ts | 12 +++++------- 3 files changed, 12 insertions(+), 27 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index b7daffaf..c7e814d7 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -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 \ No newline at end of file diff --git a/lib/arc-login.js b/lib/arc-login.js index 6482efb6..9c9ea0bc 100644 --- a/lib/arc-login.js +++ b/lib/arc-login.js @@ -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'); diff --git a/src/arc-login.ts b/src/arc-login.ts index 23cf9f65..0fd06855 100644 --- a/src/arc-login.ts +++ b/src/arc-login.ts @@ -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 { if (!servicePrincipalId || !servicePrincipalKey || !tenantId || !authorityUrl) { @@ -78,8 +78,6 @@ export async function getArcKubeconfig(): Promise { 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 { 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');