Skip to content

Commit

Permalink
Extend noop delete scenario to account for terminated namespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
100mik committed Nov 15, 2023
1 parent b4886df commit 00f8a7e
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions pkg/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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
Expand All @@ -289,17 +290,20 @@ func (a *App) noopDeleteDueToTerminatingNamespaces() bool {
if ns == "(cluster)" {
return false
}
if !a.isNamespaceTerminating(ns) {
if !a.isNamespaceTerminatingOrTerminated(ns) {
return false
}
}
a.log.Info("Safely performing noop delete to avoid blocking namespace deletion")
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
Expand Down

0 comments on commit 00f8a7e

Please sign in to comment.