Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-try namespace provisioning #688

Merged
merged 2 commits into from
Dec 12, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 23 additions & 7 deletions packages/dashboard-frontend/src/store/SanityCheck/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,20 @@
* Red Hat, Inc. - initial API and implementation
*/

import axios from 'axios';
import { Action, Reducer } from 'redux';
import { AppThunk } from '..';
import { container } from '../../inversify.config';
import { getDefer } from '../../services/helpers/deferred';
import { delay } from '../../services/helpers/delay';
import { CheWorkspaceClient } from '../../services/workspace-client/cheworkspace/cheWorkspaceClient';
import { isForbidden, isUnauthorized } from '../../services/workspace-client/helpers';
import { createObject } from '../helpers';

const WorkspaceClient = container.get(CheWorkspaceClient);

const secToStale = 5;
const timeToStale = secToStale * 1000;
const maxAttemptsNumber = 2;

export interface State {
authorized: Promise<boolean>;
Expand Down Expand Up @@ -85,12 +90,23 @@ export const actionCreators: ActionCreators = {
lastFetched: Date.now(),
});

await axios.get('/api/kubernetes/namespace');
deferred.resolve(true);

dispatch({
type: Type.RECEIVED_BACKEND_CHECK,
});
for (let attempt = 1; attempt <= maxAttemptsNumber; attempt++) {
try {
await WorkspaceClient.restApiClient.provisionKubernetesNamespace();

deferred.resolve(true);
dispatch({
type: Type.RECEIVED_BACKEND_CHECK,
});

break;
} catch (e) {
if (attempt === maxAttemptsNumber) {
throw e;
}
delay(1000);
}
}
} catch (e) {
let errorMessage =
'Backend in not available. Try to refresh the page or re-login to the Dashboard.';
Expand Down