From ebfabe6c47d7d2b67f56e281eac53da18a593671 Mon Sep 17 00:00:00 2001 From: fhanportainer <79428273+fhanportainer@users.noreply.github.com> Date: Thu, 4 Nov 2021 08:30:19 +1300 Subject: [PATCH] fix(k8s): check if app has stack before removing. (#5919) --- .../applications/applicationsController.js | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/app/kubernetes/views/applications/applicationsController.js b/app/kubernetes/views/applications/applicationsController.js index 3825fb1ba..ed4b7299b 100644 --- a/app/kubernetes/views/applications/applicationsController.js +++ b/app/kubernetes/views/applications/applicationsController.js @@ -4,7 +4,7 @@ import KubernetesStackHelper from 'Kubernetes/helpers/stackHelper'; import KubernetesApplicationHelper from 'Kubernetes/helpers/application'; import KubernetesConfigurationHelper from 'Kubernetes/helpers/configurationHelper'; import { KubernetesApplicationTypes } from 'Kubernetes/models/application/models'; - +import { KubernetesPortainerApplicationStackNameLabel } from 'Kubernetes/models/application/models'; class KubernetesApplicationsController { /* @ngInject */ constructor($async, $state, Notifications, KubernetesApplicationService, HelmService, KubernetesConfigurationService, Authentication, ModalService, LocalStorage, StackService) { @@ -81,13 +81,17 @@ class KubernetesApplicationsController { await this.HelmService.uninstall(this.endpoint.Id, application); } else { await this.KubernetesApplicationService.delete(application); - // Update applications in stack - const stack = this.state.stacks.find((x) => x.Name === application.StackName); - const index = stack.Applications.indexOf(application); - stack.Applications.splice(index, 1); - // remove stack if no app left in the stack - if (stack.Applications.length === 0 && application.StackId) { - await this.StackService.remove({ Id: application.StackId }, false, this.endpoint.Id); + + if (application.Metadata.labels[KubernetesPortainerApplicationStackNameLabel]) { + // Update applications in stack + const stack = this.state.stacks.find((x) => x.Name === application.StackName); + const index = stack.Applications.indexOf(application); + stack.Applications.splice(index, 1); + + // remove stack if no app left in the stack + if (stack.Applications.length === 0 && application.StackId) { + await this.StackService.remove({ Id: application.StackId }, false, this.endpoint.Id); + } } } this.Notifications.success('Application successfully removed', application.Name);