From 1ead121c9b92a02c0d2bd32bd5a666dc1e46d8b0 Mon Sep 17 00:00:00 2001
From: Ali <83188384+testA113@users.noreply.github.com>
Date: Tue, 12 Nov 2024 09:03:22 +1300
Subject: [PATCH] fix(apps): for helm uninstall, ignore manual associated
 resource deletion [r8s-124] (#103)

---
 .../queries/useDeleteApplicationsMutation.ts   | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/app/react/kubernetes/applications/queries/useDeleteApplicationsMutation.ts b/app/react/kubernetes/applications/queries/useDeleteApplicationsMutation.ts
index a1c242e3f..047cf1a44 100644
--- a/app/react/kubernetes/applications/queries/useDeleteApplicationsMutation.ts
+++ b/app/react/kubernetes/applications/queries/useDeleteApplicationsMutation.ts
@@ -115,13 +115,19 @@ async function deleteApplications(
   );
 
   // update associated k8s ressources
-  const servicesToDelete = getServicesFromApplications(applications);
+  // helm uninstall will update associated k8s ressources for helm apps, so don't manually delete Helm app associated k8s resources
+  const nonHelmApplications = applications.filter(
+    (app) => app.ApplicationType !== 'Helm'
+  );
+  const servicesToDelete = getServicesFromApplications(nonHelmApplications);
   // axios error handling is done inside deleteServices already
-  await deleteServices({
-    environmentId,
-    data: servicesToDelete,
-  });
-  const hpasToDelete = applications
+  if (Object.keys(servicesToDelete).length > 0) {
+    await deleteServices({
+      environmentId,
+      data: servicesToDelete,
+    });
+  }
+  const hpasToDelete = nonHelmApplications
     .map((app) => app.HorizontalPodAutoscaler)
     .filter((hpa) => !!hpa);
   const settledHpaDeletions = await getAllSettledItems(hpasToDelete, (hpa) =>