Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend noop delete scenario to account for terminated namespaces #1404

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading