Skip to content

Commit dc6cf08

Browse files
fix: Deleting community module issue (kyma-project#4211)
* Correct error handling and wait longer for delete * Improve error handling * Update public/i18n/en.yaml Co-authored-by: Grzegorz Karaluch <grzegorz.karaluch@sap.com> --------- Co-authored-by: Grzegorz Karaluch <grzegorz.karaluch@sap.com>
1 parent 3e49312 commit dc6cf08

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

public/i18n/en.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -934,6 +934,7 @@ modules:
934934
module-uninstall: Community Module deleted
935935
modules-updated: Community Modules updated
936936
resources-delete-failure: 'Failed to delete the {{module}} because the following resources cannot be deleted: {{resources}}'
937+
resources-delete-in-progress: Resources are still being deleted. Try again later.
937938
source-yaml-added: Source YAML added
938939
source-yaml-failed: Failed to add Source YAML
939940
source-yaml-fetch-failed: 'Failed to download source yaml: {{error}}'

src/components/Modules/components/ModulesDeleteBox.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ export const ModulesDeleteBox = ({
218218
const allStillExistingResources = await checkIfAllResourcesAreDeleted(
219219
fetchFn,
220220
associatedResourcesUrls,
221+
t,
221222
);
222223
if (allStillExistingResources.length !== 0) {
223224
notification.notifyError({

src/components/Modules/deleteModulesHelpers.tsx

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { getUrl } from 'resources/Namespaces/YamlUpload/useUploadResources';
1010
import { postForCommunityResources } from 'components/Modules/community/communityModulesHelpers';
1111
import { HttpError } from 'shared/hooks/BackendAPI/config';
1212
import retry from 'shared/utils/retry';
13+
import { TFunction } from 'i18next';
1314

1415
interface Counts {
1516
[key: string]: number;
@@ -281,14 +282,20 @@ export const deleteResources = async (
281282
export const checkIfAllResourcesAreDeleted = async (
282283
fetchFn: Function,
283284
resourcesUrls: string[],
285+
t: TFunction,
284286
) => {
287+
let urlDuringError = '';
288+
let isDeletionInProgress = false;
285289
const results = await Promise.all(
286290
resourcesUrls.map(async (url) => {
287291
const result = await retry(
288292
async () => {
289293
try {
290294
const result = await fetchFn(url);
291295
const resources = await result.json();
296+
urlDuringError = url;
297+
isDeletionInProgress =
298+
!!resources?.items?.[0]?.metadata?.deletionTimestamp;
292299
return resources?.items.length === 0;
293300
} catch (e) {
294301
if (e instanceof HttpError && e.code === 404) {
@@ -297,13 +304,20 @@ export const checkIfAllResourcesAreDeleted = async (
297304
throw e;
298305
}
299306
},
300-
3,
301-
1000,
307+
5,
308+
3000,
302309
);
303310
return { resource: url, result };
304311
}),
305-
);
306-
console.log(results);
312+
).catch((e) => {
313+
console.warn(e);
314+
if (isDeletionInProgress) {
315+
throw new Error(
316+
t('modules.community.messages.resources-delete-in-progress'),
317+
);
318+
}
319+
return [{ resource: urlDuringError, result: false }];
320+
});
307321
return results.filter((v) => !v.result).map((r) => r.resource);
308322
};
309323

0 commit comments

Comments
 (0)