From dc367015d136789ca0d6c2f3bf48b9c89c258074 Mon Sep 17 00:00:00 2001 From: Jehoszafat Zimnowoda Date: Fri, 18 Jun 2021 18:25:28 +0200 Subject: [PATCH 1/5] feat: fault tolerant retry --- package-lock.json | 83 +++++++++++++++++++++- package.json | 5 +- src/tasks/drone/drone.ts | 4 +- src/tasks/gitea/gitea-add-users-to-team.ts | 3 +- src/tasks/gitea/gitea-drone-oauth.ts | 4 +- src/tasks/gitea/gitea.ts | 4 +- src/tasks/harbor/harbor.ts | 4 +- src/tasks/keycloak/keycloak.ts | 5 +- src/utils.ts | 19 +++++ 9 files changed, 121 insertions(+), 10 deletions(-) diff --git a/package-lock.json b/package-lock.json index 3e63d379..a13682f0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,7 +13,7 @@ "@redkubes/gitea-client-node": "1.1.1", "@redkubes/harbor-client-node": "^2.2.1", "@redkubes/keycloak-client-node": "^11.0.0", - "@types/lodash": "^4.14.158", + "async-retry": "^1.3.1", "aws-sdk": "^2.742.0", "axios": "^0.21.1", "bluebird": "^3.7.2", @@ -24,15 +24,18 @@ "lodash": "^4.17.21", "lowdb": "^1.0.0", "morgan": "^1.10.0", + "node-fetch": "^2.6.1", "ts-custom-error": "^3.2.0" }, "devDependencies": { "@commitlint/cli": "^11.0.0", "@commitlint/config-conventional": "^11.0.0", "@hkdobrev/run-if-changed": "^0.3.1", + "@types/async-retry": "^1.4.2", "@types/chai": "^4.2.12", "@types/chai-as-promised": "^7.1.3", "@types/express": "^4.17.7", + "@types/lodash": "^4.14.158", "@types/lowdb": "^1.0.9", "@types/mocha": "^7.0.2", "@types/node": "^13.13.15", @@ -975,6 +978,15 @@ "node": ">=10" } }, + "node_modules/@types/async-retry": { + "version": "1.4.2", + "resolved": "https://registry.npmjs.org/@types/async-retry/-/async-retry-1.4.2.tgz", + "integrity": "sha512-GUDuJURF0YiJZ+CBjNQA0+vbP/VHlJbB0sFqkzsV7EcOPRfurVonXpXKAt3w8qIjM1TEzpz6hc6POocPvHOS3w==", + "dev": true, + "dependencies": { + "@types/retry": "*" + } + }, "node_modules/@types/bluebird": { "version": "3.5.32", "resolved": "https://registry.npmjs.org/@types/bluebird/-/bluebird-3.5.32.tgz", @@ -1097,7 +1109,8 @@ "node_modules/@types/lodash": { "version": "4.14.158", "resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.14.158.tgz", - "integrity": "sha512-InCEXJNTv/59yO4VSfuvNrZHt7eeNtWQEgnieIA+mIC+MOWM9arOWG2eQ8Vhk6NbOre6/BidiXhkZYeDY9U35w==" + "integrity": "sha512-InCEXJNTv/59yO4VSfuvNrZHt7eeNtWQEgnieIA+mIC+MOWM9arOWG2eQ8Vhk6NbOre6/BidiXhkZYeDY9U35w==", + "dev": true }, "node_modules/@types/lowdb": { "version": "1.0.9", @@ -1182,6 +1195,12 @@ "@types/node": "*" } }, + "node_modules/@types/retry": { + "version": "0.12.0", + "resolved": "https://registry.npmjs.org/@types/retry/-/retry-0.12.0.tgz", + "integrity": "sha512-wWKOClTTiizcZhXnPY4wikVAwmdYHp8q6DmC+EJUzAMsycb7HB32Kh9RN4+0gExjmPmZSAQjgURXIGATPegAvA==", + "dev": true + }, "node_modules/@types/serve-static": { "version": "1.13.5", "resolved": "https://registry.npmjs.org/@types/serve-static/-/serve-static-1.13.5.tgz", @@ -1650,6 +1669,14 @@ "node": ">=4" } }, + "node_modules/async-retry": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/async-retry/-/async-retry-1.3.1.tgz", + "integrity": "sha512-aiieFW/7h3hY0Bq5d+ktDBejxuwR78vRu9hDUdR8rNhSaQ29VzPL4AoIRG7D/c7tdenwOcKvgPM6tIxB3cB6HA==", + "dependencies": { + "retry": "0.12.0" + } + }, "node_modules/asynckit": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", @@ -9481,6 +9508,14 @@ "semver": "bin/semver" } }, + "node_modules/node-fetch": { + "version": "2.6.1", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.1.tgz", + "integrity": "sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw==", + "engines": { + "node": "4.x || >=6.0.0" + } + }, "node_modules/node-notifier": { "version": "8.0.1", "resolved": "https://registry.npmjs.org/node-notifier/-/node-notifier-8.0.1.tgz", @@ -10913,6 +10948,14 @@ "node": ">=0.12" } }, + "node_modules/retry": { + "version": "0.12.0", + "resolved": "https://registry.npmjs.org/retry/-/retry-0.12.0.tgz", + "integrity": "sha1-G0KmJmoh8HQh0bC1S33BZ7AcATs=", + "engines": { + "node": ">= 4" + } + }, "node_modules/rewire": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/rewire/-/rewire-3.0.2.tgz", @@ -14063,6 +14106,15 @@ "defer-to-connect": "^2.0.0" } }, + "@types/async-retry": { + "version": "1.4.2", + "resolved": "https://registry.npmjs.org/@types/async-retry/-/async-retry-1.4.2.tgz", + "integrity": "sha512-GUDuJURF0YiJZ+CBjNQA0+vbP/VHlJbB0sFqkzsV7EcOPRfurVonXpXKAt3w8qIjM1TEzpz6hc6POocPvHOS3w==", + "dev": true, + "requires": { + "@types/retry": "*" + } + }, "@types/bluebird": { "version": "3.5.32", "resolved": "https://registry.npmjs.org/@types/bluebird/-/bluebird-3.5.32.tgz", @@ -14185,7 +14237,8 @@ "@types/lodash": { "version": "4.14.158", "resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.14.158.tgz", - "integrity": "sha512-InCEXJNTv/59yO4VSfuvNrZHt7eeNtWQEgnieIA+mIC+MOWM9arOWG2eQ8Vhk6NbOre6/BidiXhkZYeDY9U35w==" + "integrity": "sha512-InCEXJNTv/59yO4VSfuvNrZHt7eeNtWQEgnieIA+mIC+MOWM9arOWG2eQ8Vhk6NbOre6/BidiXhkZYeDY9U35w==", + "dev": true }, "@types/lowdb": { "version": "1.0.9", @@ -14270,6 +14323,12 @@ "@types/node": "*" } }, + "@types/retry": { + "version": "0.12.0", + "resolved": "https://registry.npmjs.org/@types/retry/-/retry-0.12.0.tgz", + "integrity": "sha512-wWKOClTTiizcZhXnPY4wikVAwmdYHp8q6DmC+EJUzAMsycb7HB32Kh9RN4+0gExjmPmZSAQjgURXIGATPegAvA==", + "dev": true + }, "@types/serve-static": { "version": "1.13.5", "resolved": "https://registry.npmjs.org/@types/serve-static/-/serve-static-1.13.5.tgz", @@ -14654,6 +14713,14 @@ "integrity": "sha512-+Ryf6g3BKoRc7jfp7ad8tM4TtMiaWvbF/1/sQcZPkkS7ag3D5nMBCe2UfOTONtAkaG0tO0ij3C5Lwmf1EiyjHg==", "dev": true }, + "async-retry": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/async-retry/-/async-retry-1.3.1.tgz", + "integrity": "sha512-aiieFW/7h3hY0Bq5d+ktDBejxuwR78vRu9hDUdR8rNhSaQ29VzPL4AoIRG7D/c7tdenwOcKvgPM6tIxB3cB6HA==", + "requires": { + "retry": "0.12.0" + } + }, "asynckit": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", @@ -20986,6 +21053,11 @@ } } }, + "node-fetch": { + "version": "2.6.1", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.1.tgz", + "integrity": "sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw==" + }, "node-notifier": { "version": "8.0.1", "resolved": "https://registry.npmjs.org/node-notifier/-/node-notifier-8.0.1.tgz", @@ -22096,6 +22168,11 @@ "integrity": "sha512-TTlYpa+OL+vMMNG24xSlQGEJ3B/RzEfUlLct7b5G/ytav+wPrplCpVMFuwzXbkecJrb6IYo1iFb0S9v37754mg==", "dev": true }, + "retry": { + "version": "0.12.0", + "resolved": "https://registry.npmjs.org/retry/-/retry-0.12.0.tgz", + "integrity": "sha1-G0KmJmoh8HQh0bC1S33BZ7AcATs=" + }, "rewire": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/rewire/-/rewire-3.0.2.tgz", diff --git a/package.json b/package.json index 4360ca4f..83eeec63 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "@redkubes/gitea-client-node": "1.1.1", "@redkubes/harbor-client-node": "^2.2.1", "@redkubes/keycloak-client-node": "^11.0.0", - "@types/lodash": "^4.14.158", + "async-retry": "^1.3.1", "aws-sdk": "^2.742.0", "axios": "^0.21.1", "bluebird": "^3.7.2", @@ -25,6 +25,7 @@ "lodash": "^4.17.21", "lowdb": "^1.0.0", "morgan": "^1.10.0", + "node-fetch": "^2.6.1", "ts-custom-error": "^3.2.0" }, "description": "Tasks needed by the Otomi Container Platform to glue all the pieces together.", @@ -32,9 +33,11 @@ "@commitlint/cli": "^11.0.0", "@commitlint/config-conventional": "^11.0.0", "@hkdobrev/run-if-changed": "^0.3.1", + "@types/async-retry": "^1.4.2", "@types/chai": "^4.2.12", "@types/chai-as-promised": "^7.1.3", "@types/express": "^4.17.7", + "@types/lodash": "^4.14.158", "@types/lowdb": "^1.0.9", "@types/mocha": "^7.0.2", "@types/node": "^13.13.15", diff --git a/src/tasks/drone/drone.ts b/src/tasks/drone/drone.ts index 0d08079e..ed0e0988 100644 --- a/src/tasks/drone/drone.ts +++ b/src/tasks/drone/drone.ts @@ -1,5 +1,5 @@ import * as drone from 'drone-node' -import { doApiCall, handleErrors } from '../../utils' +import { doApiCall, faultTolerantFetch, handleErrors } from '../../utils' import { cleanEnv, DRONE_URL, DRONE_TOKEN } from '../../validators' import { orgName, repoName } from '../common' @@ -21,6 +21,8 @@ const client = new drone.Client({ const errors: string[] = [] async function main(): Promise { + await faultTolerantFetch(env.DRONE_URL) + // first two steps are not working, and drone discourse mentions only real users being able to do this: // https://discourse.drone.io/t/not-found-from-machine-user/7073/4?u=morriz diff --git a/src/tasks/gitea/gitea-add-users-to-team.ts b/src/tasks/gitea/gitea-add-users-to-team.ts index 6a678ec0..399f5eb5 100644 --- a/src/tasks/gitea/gitea-add-users-to-team.ts +++ b/src/tasks/gitea/gitea-add-users-to-team.ts @@ -1,5 +1,5 @@ import { OrganizationApi, AdminApi, User, Team } from '@redkubes/gitea-client-node' -import { doApiCall } from '../../utils' +import { doApiCall, faultTolerantFetch } from '../../utils' import { cleanEnv, GITEA_PASSWORD, GITEA_URL } from '../../validators' import { orgName, teamNameOwners, username } from '../common' @@ -9,6 +9,7 @@ const env = cleanEnv({ }) const errors: string[] = [] export default async function main(): Promise { + await faultTolerantFetch(env.GITEA_URL) let giteaUrl = env.GITEA_URL if (giteaUrl.endsWith('/')) { giteaUrl = giteaUrl.slice(0, -1) diff --git a/src/tasks/gitea/gitea-drone-oauth.ts b/src/tasks/gitea/gitea-drone-oauth.ts index 69c579d2..f87269e9 100644 --- a/src/tasks/gitea/gitea-drone-oauth.ts +++ b/src/tasks/gitea/gitea-drone-oauth.ts @@ -5,7 +5,7 @@ import cookie from 'cookie' import { UserApi, CreateOAuth2ApplicationOptions } from '@redkubes/gitea-client-node' import { cleanEnv, GITEA_PASSWORD, GITEA_URL, DRONE_URL } from '../../validators' -import { createSecret, doApiCall, getApiClient, getSecret } from '../../utils' +import { createSecret, doApiCall, faultTolerantFetch, getApiClient, getSecret } from '../../utils' import { GiteaDroneError } from './common' import { username } from '../common' @@ -93,6 +93,8 @@ async function authorizeOAuthApp(oauthData: DroneSecret): Promise { } async function main(): Promise { + await faultTolerantFetch(env.GITEA_URL) + // fresh cluster: no secret no oauth app // already exists: cluster with predeployed secret and oauth app const remoteSecret = (await getSecret(secretName, namespace)) as DroneSecret diff --git a/src/tasks/gitea/gitea.ts b/src/tasks/gitea/gitea.ts index 9a2dd314..e27dca67 100644 --- a/src/tasks/gitea/gitea.ts +++ b/src/tasks/gitea/gitea.ts @@ -1,5 +1,5 @@ import { OrganizationApi, CreateRepoOption, CreateOrgOption, CreateTeamOption } from '@redkubes/gitea-client-node' -import { doApiCall } from '../../utils' +import { doApiCall, faultTolerantFetch } from '../../utils' import { cleanEnv, GITEA_PASSWORD, GITEA_URL } from '../../validators' import { orgName, repoName, username, teamNameViewer } from '../common' @@ -27,6 +27,8 @@ export async function createTeam(orgApi: OrganizationApi): Promise { } export default async function main(): Promise { + await faultTolerantFetch(env.GITEA_URL) + let giteaUrl = env.GITEA_URL if (giteaUrl.endsWith('/')) { giteaUrl = giteaUrl.slice(0, -1) diff --git a/src/tasks/harbor/harbor.ts b/src/tasks/harbor/harbor.ts index 069473a8..63a60edc 100644 --- a/src/tasks/harbor/harbor.ts +++ b/src/tasks/harbor/harbor.ts @@ -20,7 +20,7 @@ import { OIDC_VERIFY_CERT, TEAM_NAMES, } from '../../validators' -import { createSecret, ensure, getApiClient, getSecret, doApiCall, handleErrors } from '../../utils' +import { createSecret, ensure, getApiClient, getSecret, doApiCall, handleErrors, faultTolerantFetch } from '../../utils' const env = cleanEnv({ HARBOR_BASE_URL, @@ -142,6 +142,8 @@ async function ensureSecret(): Promise { } async function main(): Promise { + await faultTolerantFetch(env.HARBOR_BASE_URL) + await ensureSecret() // now we can set the token on our apis diff --git a/src/tasks/keycloak/keycloak.ts b/src/tasks/keycloak/keycloak.ts index c7623479..75896895 100644 --- a/src/tasks/keycloak/keycloak.ts +++ b/src/tasks/keycloak/keycloak.ts @@ -19,7 +19,8 @@ import { KEYCLOAK_ADDRESS, KEYCLOAK_REALM, } from '../../validators' -import { doApiCall, ensure, handleErrors } from '../../utils' + +import { faultTolerantFetch, doApiCall, ensure, handleErrors } from '../../utils' const env = cleanEnv({ IDP_ALIAS, @@ -32,6 +33,8 @@ const env = cleanEnv({ const errors: string[] = [] async function main(): Promise { + await faultTolerantFetch(env.KEYCLOAK_ADDRESS) + let basePath let token try { diff --git a/src/utils.ts b/src/utils.ts index 0343f54c..17b45cdf 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,6 +1,8 @@ import http from 'http' import { findIndex, mapValues } from 'lodash' import { CoreV1Api, KubeConfig, V1Secret, V1ObjectMeta, V1ServiceAccount } from '@kubernetes/client-node' +import retry, { Options } from 'async-retry' +import fetch from 'node-fetch' let apiClient: CoreV1Api @@ -185,3 +187,20 @@ export async function deletePullSecret(teamId: string, name: string): Promise { + await retry(async (bail) => { + // if anything throws, we retry + const res = await fetch(url) + if ([401, 403].includes(res.status)) { + bail(new Error(`HTTP code: ${res.status}`)) + } + }, retryOptions) +} From 5385b4b0439d68369a4b28274cdc71516e6ee9a1 Mon Sep 17 00:00:00 2001 From: Jehoszafat Zimnowoda Date: Thu, 8 Jul 2021 16:44:27 +0200 Subject: [PATCH 2/5] fix: harbor proxy --- bin/start-proxies.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/start-proxies.sh b/bin/start-proxies.sh index 129de03d..2c58c130 100755 --- a/bin/start-proxies.sh +++ b/bin/start-proxies.sh @@ -2,5 +2,5 @@ k="kubectl" $k -n team-admin port-forward svc/drone 8081:80 & $k -n gitea port-forward svc/gitea-http 8082:3000 & -$k -n harbor port-forward svc/harbor-harbor-core 8083:80 & +$k -n harbor port-forward svc/harbor-core 8083:80 & $k -n keycloak port-forward svc/keycloak-http 8084:80 & From aaee4618c77687440a6b927e876efbd951a466a4 Mon Sep 17 00:00:00 2001 From: Jehoszafat Zimnowoda Date: Thu, 8 Jul 2021 16:53:06 +0200 Subject: [PATCH 3/5] feat: use types for node-fetch --- package-lock.json | 48 +++++++++++++++++++++++++++++++++++++++++++++++ package.json | 1 + src/utils.ts | 4 ++-- 3 files changed, 51 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index a13682f0..b2b15f2b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -39,6 +39,7 @@ "@types/lowdb": "^1.0.9", "@types/mocha": "^7.0.2", "@types/node": "^13.13.15", + "@types/node-fetch": "^2.5.11", "@types/sinon": "^9.0.4", "@types/sinon-chai": "^3.2.4", "@typescript-eslint/eslint-plugin": "^2.34.0", @@ -1152,6 +1153,30 @@ "resolved": "https://registry.npmjs.org/@types/node/-/node-13.13.15.tgz", "integrity": "sha512-kwbcs0jySLxzLsa2nWUAGOd/s21WU1jebrEdtzhsj1D4Yps1EOuyI1Qcu+FD56dL7NRNIJtDDjcqIG22NwkgLw==" }, + "node_modules/@types/node-fetch": { + "version": "2.5.11", + "resolved": "https://registry.npmjs.org/@types/node-fetch/-/node-fetch-2.5.11.tgz", + "integrity": "sha512-2upCKaqVZETDRb8A2VTaRymqFBEgH8u6yr96b/u3+1uQEPDRo3mJLEiPk7vdXBHRtjwkjqzFYMJXrt0Z9QsYjQ==", + "dev": true, + "dependencies": { + "@types/node": "*", + "form-data": "^3.0.0" + } + }, + "node_modules/@types/node-fetch/node_modules/form-data": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-3.0.1.tgz", + "integrity": "sha512-RHkBKtLWUVwd7SqRIvCZMEvAMoGUp0XU+seQiZejj0COz3RI3hWP4sCv3gZWWLjJTd7rGwcsF5eKZGii0r/hbg==", + "dev": true, + "dependencies": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "mime-types": "^2.1.12" + }, + "engines": { + "node": ">= 6" + } + }, "node_modules/@types/normalize-package-data": { "version": "2.4.0", "resolved": "https://registry.npmjs.org/@types/normalize-package-data/-/normalize-package-data-2.4.0.tgz", @@ -14280,6 +14305,29 @@ "resolved": "https://registry.npmjs.org/@types/node/-/node-13.13.15.tgz", "integrity": "sha512-kwbcs0jySLxzLsa2nWUAGOd/s21WU1jebrEdtzhsj1D4Yps1EOuyI1Qcu+FD56dL7NRNIJtDDjcqIG22NwkgLw==" }, + "@types/node-fetch": { + "version": "2.5.11", + "resolved": "https://registry.npmjs.org/@types/node-fetch/-/node-fetch-2.5.11.tgz", + "integrity": "sha512-2upCKaqVZETDRb8A2VTaRymqFBEgH8u6yr96b/u3+1uQEPDRo3mJLEiPk7vdXBHRtjwkjqzFYMJXrt0Z9QsYjQ==", + "dev": true, + "requires": { + "@types/node": "*", + "form-data": "^3.0.0" + }, + "dependencies": { + "form-data": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-3.0.1.tgz", + "integrity": "sha512-RHkBKtLWUVwd7SqRIvCZMEvAMoGUp0XU+seQiZejj0COz3RI3hWP4sCv3gZWWLjJTd7rGwcsF5eKZGii0r/hbg==", + "dev": true, + "requires": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "mime-types": "^2.1.12" + } + } + } + }, "@types/normalize-package-data": { "version": "2.4.0", "resolved": "https://registry.npmjs.org/@types/normalize-package-data/-/normalize-package-data-2.4.0.tgz", diff --git a/package.json b/package.json index 83eeec63..81515ed0 100644 --- a/package.json +++ b/package.json @@ -41,6 +41,7 @@ "@types/lowdb": "^1.0.9", "@types/mocha": "^7.0.2", "@types/node": "^13.13.15", + "@types/node-fetch": "^2.5.11", "@types/sinon": "^9.0.4", "@types/sinon-chai": "^3.2.4", "@typescript-eslint/eslint-plugin": "^2.34.0", diff --git a/src/utils.ts b/src/utils.ts index 17b45cdf..6752cca1 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -97,7 +97,7 @@ export async function doApiCall( } } -export function handleErrors(errors: string[]) { +export function handleErrors(errors: string[]): void { if (errors.length) { console.error(`Errors found: ${JSON.stringify(errors, null, 2)}`) process.exit(1) @@ -200,7 +200,7 @@ export async function faultTolerantFetch(url: string): Promise { // if anything throws, we retry const res = await fetch(url) if ([401, 403].includes(res.status)) { - bail(new Error(`HTTP code: ${res.status}`)) + bail(new Error(`GET ${res.url} ${res.status}`)) } }, retryOptions) } From d5eae1e50c0e13a88e6ebd94ba5d03763bb2c167 Mon Sep 17 00:00:00 2001 From: Jehoszafat Zimnowoda Date: Thu, 8 Jul 2021 17:44:40 +0200 Subject: [PATCH 4/5] feat: handle featch errors and follow redirects --- package-lock.json | 2 +- src/utils.ts | 35 ++++++++++++++++++++++++++--------- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/package-lock.json b/package-lock.json index b4c98286..29efae0f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5,7 +5,7 @@ "requires": true, "packages": { "": { - "version": "0.2.6", + "version": "0.2.7", "license": "Apache-2.0", "dependencies": { "@apidevtools/json-schema-ref-parser": "^9.0.6", diff --git a/src/utils.ts b/src/utils.ts index fa77ae84..cc466b76 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -2,7 +2,8 @@ import http from 'http' import { findIndex, mapValues } from 'lodash' import { CoreV1Api, KubeConfig, V1Secret, V1ObjectMeta, V1ServiceAccount } from '@kubernetes/client-node' import retry, { Options } from 'async-retry' -import fetch from 'node-fetch' +import fetch, { RequestInit } from 'node-fetch' +import { exit } from 'process' let apiClient: CoreV1Api @@ -189,18 +190,34 @@ export async function deletePullSecret(teamId: string, name: string): Promise { - await retry(async (bail) => { - // if anything throws, we retry - const res = await fetch(url) - if ([401, 403].includes(res.status)) { - bail(new Error(`GET ${res.url} ${res.status}`)) - } - }, retryOptions) + try { + await retry(async (bail) => { + try { + const fetchOptions: RequestInit = { + redirect: 'follow', + } + const res = await fetch(url, fetchOptions) + if (res.status !== 200) { + console.warn(`GET ${res.url} ${res.status}`) + bail(new Error(`Retry`)) + } + } catch (e) { + // Print system erros like ECONNREFUSED + console.error(e.message) + throw e + } + }, retryOptions) + } catch (e) { + console.log('Max retry tries has been reached') + exit(1) + } } From d5c9b20837bc76a9725df5d8c2a48db995662a01 Mon Sep 17 00:00:00 2001 From: Maurice Faber Date: Tue, 13 Jul 2021 16:16:12 +0200 Subject: [PATCH 5/5] fix: regression --- src/tasks/otomi/otomi-chart.ts | 1 - src/utils.test.ts | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/tasks/otomi/otomi-chart.ts b/src/tasks/otomi/otomi-chart.ts index 43971969..69ead11e 100644 --- a/src/tasks/otomi/otomi-chart.ts +++ b/src/tasks/otomi/otomi-chart.ts @@ -3,7 +3,6 @@ import yaml from 'js-yaml' import fs from 'fs' import $RefParser from '@apidevtools/json-schema-ref-parser' import { cleanEnv, OTOMI_VALUES_INPUT, OTOMI_SCHEMA_PATH, OTOMI_ENV_DIR } from '../../validators' -import { removeEmpty } from '../../utils' const env = cleanEnv({ OTOMI_VALUES_INPUT, diff --git a/src/utils.test.ts b/src/utils.test.ts index 0037ad6c..60e5901b 100644 --- a/src/utils.test.ts +++ b/src/utils.test.ts @@ -4,7 +4,7 @@ import sinon from 'sinon' import { expect } from 'chai' import { cloneDeep } from 'lodash' import http from 'http' -import { cleanValues, createPullSecret, deletePullSecret, getApiClient, objectToArray } from './utils' +import { createPullSecret, deletePullSecret, getApiClient, objectToArray } from './utils' describe('Utils', () => { it('should convert an object to array', (done) => {