Skip to content

Commit

Permalink
Descriptive restore error on terminating namespace
Browse files Browse the repository at this point in the history
Signed-off-by: Tiger Kaovilai <[email protected]>
  • Loading branch information
kaovilai committed Feb 13, 2024
1 parent 3b8370e commit bbd910c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions changelogs/unreleased/7424-kaovilai
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Descriptive restore error when restoring into a terminating namespace
6 changes: 6 additions & 0 deletions pkg/util/kube/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ func EnsureNamespaceExistsAndIsReady(namespace *corev1api.Namespace, client core
// required for keeping track of number of restored items
var nsCreated bool
var ready bool
// if namespace is marked for deletion, and we timed out, report an error
var markedForDeletion bool
err := wait.PollImmediate(time.Second, timeout, func() (bool, error) {
clusterNS, err := client.Get(context.TODO(), namespace.Name, metav1.GetOptions{})

Expand All @@ -87,6 +89,7 @@ func EnsureNamespaceExistsAndIsReady(namespace *corev1api.Namespace, client core

if clusterNS != nil && (clusterNS.GetDeletionTimestamp() != nil || clusterNS.Status.Phase == corev1api.NamespaceTerminating) {
// Marked for deletion, keep waiting
markedForDeletion = true
return false, nil
}

Expand All @@ -97,6 +100,9 @@ func EnsureNamespaceExistsAndIsReady(namespace *corev1api.Namespace, client core

// err will be set if we timed out or encountered issues retrieving the namespace,
if err != nil {
if markedForDeletion {
return false, nsCreated, errors.Wrapf(err, "timed out waiting for namespace %s marked for deletion to disappear before restoring", namespace.Name)
}
return false, nsCreated, errors.Wrapf(err, "error getting namespace %s", namespace.Name)
}

Expand Down

0 comments on commit bbd910c

Please sign in to comment.