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 73b25fd
Showing 1 changed file with 6 additions and 0 deletions.
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 73b25fd

Please sign in to comment.