From 588ce549ad345ba81147220cc19b9acf3b037166 Mon Sep 17 00:00:00 2001 From: andres-portainer <91705312+andres-portainer@users.noreply.github.com> Date: Thu, 14 Oct 2021 19:14:57 -0300 Subject: [PATCH] fix(namespaces): remove the stacks from the data store when deleting their corresponding Kubernetes namespace EE-1872 (#5893) * fix(namespaces): remove the stacks from the data store when deleting their corresponding Kubernetes namespace EE-1872 * add endpoint ID checking Co-authored-by: andres-portainer Co-authored-by: ArrisLee --- api/http/proxy/factory/kubernetes/namespaces.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/api/http/proxy/factory/kubernetes/namespaces.go b/api/http/proxy/factory/kubernetes/namespaces.go index daa71749f..c501f7cc7 100644 --- a/api/http/proxy/factory/kubernetes/namespaces.go +++ b/api/http/proxy/factory/kubernetes/namespaces.go @@ -46,5 +46,19 @@ func (transport *baseTransport) proxyNamespaceDeleteOperation(request *http.Requ } } } + + stacks, err := transport.dataStore.Stack().Stacks() + if err != nil { + return nil, err + } + + for _, s := range stacks { + if s.Namespace == namespace && s.EndpointID == transport.endpoint.ID { + if err := transport.dataStore.Stack().DeleteStack(s.ID); err != nil { + return nil, err + } + } + } + return transport.executeKubernetesRequest(request) }