From 06aee8998ef07d65876d2eda7ced63047c37428d Mon Sep 17 00:00:00 2001 From: Soumik Majumder <33070011+100mik@users.noreply.github.com> Date: Mon, 20 Nov 2023 15:18:35 +0530 Subject: [PATCH] Extend noop delete scenario to account for terminated namespaces (#1404) Signed-off-by: Soumik Majumder --- pkg/app/app.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/pkg/app/app.go b/pkg/app/app.go index 69b0bf1ae5..42027dcf9d 100644 --- a/pkg/app/app.go +++ b/pkg/app/app.go @@ -16,6 +16,7 @@ import ( "github.com/vmware-tanzu/carvel-kapp-controller/pkg/reftracker" "github.com/vmware-tanzu/carvel-kapp-controller/pkg/template" v1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "sigs.k8s.io/yaml" ) @@ -280,7 +281,7 @@ func (a *App) noopDeleteDueToTerminatingNamespaces() bool { if a.app.Status.Deploy == nil || a.app.Status.Deploy.KappDeployStatus == nil || a.app.Spec.ServiceAccountName == "" { return false } - if !a.isNamespaceTerminating(a.app.Namespace) { + if !a.isNamespaceTerminatingOrTerminated(a.app.Namespace) { return false } // Ensure that no cluster scoped resources are created by the app @@ -289,7 +290,7 @@ func (a *App) noopDeleteDueToTerminatingNamespaces() bool { if ns == "(cluster)" { return false } - if !a.isNamespaceTerminating(ns) { + if !a.isNamespaceTerminatingOrTerminated(ns) { return false } } @@ -297,9 +298,12 @@ func (a *App) noopDeleteDueToTerminatingNamespaces() bool { return true } -func (a *App) isNamespaceTerminating(namespace string) bool { +func (a *App) isNamespaceTerminatingOrTerminated(namespace string) bool { status, err := a.compInfo.NamespaceStatus(namespace) if err != nil { + if errors.IsNotFound(err) { + return true + } a.log.Error(err, "Error getting app namespace status", "app", a.app.Name, "namespace", a.app.Namespace) } return status.Phase == v1.NamespaceTerminating