diff --git a/api/kubernetes/cli/applications.go b/api/kubernetes/cli/applications.go index 1694af44f..e68137c69 100644 --- a/api/kubernetes/cli/applications.go +++ b/api/kubernetes/cli/applications.go @@ -341,7 +341,7 @@ func updateApplicationWithService(application *models.K8sApplication, services [ for _, service := range services { serviceSelector := labels.SelectorFromSet(service.Spec.Selector) - if service.Namespace == application.ResourcePool && serviceSelector.Matches(labels.Set(application.MatchLabels)) { + if service.Namespace == application.ResourcePool && !serviceSelector.Empty() && serviceSelector.Matches(labels.Set(application.MatchLabels)) { application.ServiceType = string(service.Spec.Type) application.Services = append(application.Services, service) } diff --git a/app/react/kubernetes/applications/queries/useDeleteApplicationsMutation.ts b/app/react/kubernetes/applications/queries/useDeleteApplicationsMutation.ts index 0813b877b..a1c242e3f 100644 --- a/app/react/kubernetes/applications/queries/useDeleteApplicationsMutation.ts +++ b/app/react/kubernetes/applications/queries/useDeleteApplicationsMutation.ts @@ -151,20 +151,16 @@ function getServicesFromApplications( (namespaceServicesMap, application) => { const serviceNames = application.Services?.map((service) => service.metadata?.name).filter( - (name): name is string => !!name + (name) => name !== undefined ) || []; - if (namespaceServicesMap[application.ResourcePool]) { - return { - ...namespaceServicesMap, - [application.ResourcePool]: [ - ...namespaceServicesMap[application.ResourcePool], - ...serviceNames, - ], - }; - } + const existingServices = + namespaceServicesMap[application.ResourcePool] || []; + const uniqueServicesForNamespace = Array.from( + new Set([...existingServices, ...serviceNames]) + ); return { ...namespaceServicesMap, - [application.ResourcePool]: serviceNames, + [application.ResourcePool]: uniqueServicesForNamespace, }; }, {}