Skip to content

Commit

Permalink
Support STS token and retry
Browse files Browse the repository at this point in the history
Signed-off-by: denverdino <[email protected]>
  • Loading branch information
denverdino committed Nov 29, 2022
1 parent 5f33ef1 commit d2631e5
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 5 deletions.
23 changes: 20 additions & 3 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

17 changes: 16 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ async function run() {
endpoint: APIEndpoint,
apiVersion: '2015-12-15'
});
let result = await client.request('GET', `/k8s/${clusterId}/user_config`)
let result = await requestWithRetry(client, 'GET', `/k8s/${clusterId}/user_config`)
let kubeconfig = result.config
const runnerTempDirectory = process.env['RUNNER_TEMP']; // Using process.env until the core libs are updated
const kubeconfigPath = path.join(runnerTempDirectory, `kubeconfig_${Date.now()}`);
Expand All @@ -34,4 +34,19 @@ async function run() {
core.setFailed(`Failed to get kubeconfig file for Kubernetes cluster: ${err}`);
}
}

async function requestWithRetry(client, method, path, retries = 3, retryDelay = 1000) {
try {
return await client.request(method, path);
} catch (err) {
if (retries > 0) {
core.info(`Retrying after ${retryDelay}ms...`);
await new Promise(resolve => setTimeout(resolve, retryDelay));
return await requestWithRetry(client, method, path, retries - 1, retryDelay * 2);
} else {
throw err;
}
}
}

run();

0 comments on commit d2631e5

Please sign in to comment.