fix(k8s): check if app has stack before removing. (#5919)

pull/6020/head
fhanportainer 3 years ago committed by GitHub
parent 85a6a80722
commit ebfabe6c47
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -4,7 +4,7 @@ import KubernetesStackHelper from 'Kubernetes/helpers/stackHelper';
import KubernetesApplicationHelper from 'Kubernetes/helpers/application'; import KubernetesApplicationHelper from 'Kubernetes/helpers/application';
import KubernetesConfigurationHelper from 'Kubernetes/helpers/configurationHelper'; import KubernetesConfigurationHelper from 'Kubernetes/helpers/configurationHelper';
import { KubernetesApplicationTypes } from 'Kubernetes/models/application/models'; import { KubernetesApplicationTypes } from 'Kubernetes/models/application/models';
import { KubernetesPortainerApplicationStackNameLabel } from 'Kubernetes/models/application/models';
class KubernetesApplicationsController { class KubernetesApplicationsController {
/* @ngInject */ /* @ngInject */
constructor($async, $state, Notifications, KubernetesApplicationService, HelmService, KubernetesConfigurationService, Authentication, ModalService, LocalStorage, StackService) { constructor($async, $state, Notifications, KubernetesApplicationService, HelmService, KubernetesConfigurationService, Authentication, ModalService, LocalStorage, StackService) {
@ -81,15 +81,19 @@ class KubernetesApplicationsController {
await this.HelmService.uninstall(this.endpoint.Id, application); await this.HelmService.uninstall(this.endpoint.Id, application);
} else { } else {
await this.KubernetesApplicationService.delete(application); await this.KubernetesApplicationService.delete(application);
if (application.Metadata.labels[KubernetesPortainerApplicationStackNameLabel]) {
// Update applications in stack // Update applications in stack
const stack = this.state.stacks.find((x) => x.Name === application.StackName); const stack = this.state.stacks.find((x) => x.Name === application.StackName);
const index = stack.Applications.indexOf(application); const index = stack.Applications.indexOf(application);
stack.Applications.splice(index, 1); stack.Applications.splice(index, 1);
// remove stack if no app left in the stack // remove stack if no app left in the stack
if (stack.Applications.length === 0 && application.StackId) { if (stack.Applications.length === 0 && application.StackId) {
await this.StackService.remove({ Id: application.StackId }, false, this.endpoint.Id); await this.StackService.remove({ Id: application.StackId }, false, this.endpoint.Id);
} }
} }
}
this.Notifications.success('Application successfully removed', application.Name); this.Notifications.success('Application successfully removed', application.Name);
const index = this.state.applications.indexOf(application); const index = this.state.applications.indexOf(application);
this.state.applications.splice(index, 1); this.state.applications.splice(index, 1);

Loading…
Cancel
Save