Skip to content

Commit 59d4642

Browse files
authored
Extend noop delete scenario to account for terminated namespaces (#1404)
Signed-off-by: Soumik Majumder <[email protected]>
1 parent b4886df commit 59d4642

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

pkg/app/app.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"github.com/vmware-tanzu/carvel-kapp-controller/pkg/reftracker"
1717
"github.com/vmware-tanzu/carvel-kapp-controller/pkg/template"
1818
v1 "k8s.io/api/core/v1"
19+
"k8s.io/apimachinery/pkg/api/errors"
1920
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2021
"sigs.k8s.io/yaml"
2122
)
@@ -280,7 +281,7 @@ func (a *App) noopDeleteDueToTerminatingNamespaces() bool {
280281
if a.app.Status.Deploy == nil || a.app.Status.Deploy.KappDeployStatus == nil || a.app.Spec.ServiceAccountName == "" {
281282
return false
282283
}
283-
if !a.isNamespaceTerminating(a.app.Namespace) {
284+
if !a.isNamespaceTerminatingOrTerminated(a.app.Namespace) {
284285
return false
285286
}
286287
// Ensure that no cluster scoped resources are created by the app
@@ -289,17 +290,20 @@ func (a *App) noopDeleteDueToTerminatingNamespaces() bool {
289290
if ns == "(cluster)" {
290291
return false
291292
}
292-
if !a.isNamespaceTerminating(ns) {
293+
if !a.isNamespaceTerminatingOrTerminated(ns) {
293294
return false
294295
}
295296
}
296297
a.log.Info("Safely performing noop delete to avoid blocking namespace deletion")
297298
return true
298299
}
299300

300-
func (a *App) isNamespaceTerminating(namespace string) bool {
301+
func (a *App) isNamespaceTerminatingOrTerminated(namespace string) bool {
301302
status, err := a.compInfo.NamespaceStatus(namespace)
302303
if err != nil {
304+
if errors.IsNotFound(err) {
305+
return true
306+
}
303307
a.log.Error(err, "Error getting app namespace status", "app", a.app.Name, "namespace", a.app.Namespace)
304308
}
305309
return status.Phase == v1.NamespaceTerminating

0 commit comments

Comments
 (0)