Skip to content

Commit 6645022

Browse files
committed
Update status before returning err
1 parent 0f7becb commit 6645022

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

pkg/controller/namespace/deletion/namespaced_resources_deleter.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,11 @@ func (d *namespacedResourcesDeleter) deleteAllContent(ctx context.Context, ns *v
553553
// Check if any pods remain before proceeding to delete other resources
554554
if numRemainingTotals.gvrToNumRemaining[podsGVR] > 0 {
555555
logger.V(5).Info("Namespace controller - pods still remain, delaying deletion of other resources", "namespace", namespace)
556+
if hasChanged := conditionUpdater.Update(ns); hasChanged {
557+
if _, err = d.nsClient.UpdateStatus(ctx, ns, metav1.UpdateOptions{}); err != nil {
558+
utilruntime.HandleError(fmt.Errorf("couldn't update status condition for namespace %q: %w", namespace, err))
559+
}
560+
}
556561
return estimate, utilerrors.NewAggregate(errs)
557562
}
558563
}

test/e2e/apimachinery/namespace.go

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -549,12 +549,30 @@ func ensurePodsAreRemovedFirstInOrderedNamespaceDeletion(ctx context.Context, f
549549
pod, err = f.ClientSet.CoreV1().Pods(nsName).Get(ctx, pod.Name, metav1.GetOptions{})
550550
framework.ExpectNoError(err, "failed to get pod %q in namespace %q", pod.Name, nsName)
551551
if pod.DeletionTimestamp == nil {
552-
framework.Failf("Pod %q in namespace %q does not have a metadata.deletionTimestamp set", pod.Name, nsName)
552+
framework.Logf("Pod %q in namespace %q does not yet have a metadata.deletionTimestamp set, retrying...", pod.Name, nsName)
553+
return false, nil
553554
}
554-
_, err = f.ClientSet.CoreV1().Namespaces().Get(ctx, nsName, metav1.GetOptions{})
555+
ns, err := f.ClientSet.CoreV1().Namespaces().Get(ctx, nsName, metav1.GetOptions{})
555556
if err != nil && apierrors.IsNotFound(err) {
556557
return false, fmt.Errorf("namespace %s was deleted unexpectedly", nsName)
557558
}
559+
ginkgo.By("Read namespace status")
560+
nsResource := v1.SchemeGroupVersion.WithResource("namespaces")
561+
unstruct, err := f.DynamicClient.Resource(nsResource).Get(ctx, ns.Name, metav1.GetOptions{}, "status")
562+
framework.ExpectNoError(err, "failed to fetch NamespaceStatus %s", ns)
563+
nsStatus, err := unstructuredToNamespace(unstruct)
564+
framework.ExpectNoError(err, "Getting the status of the namespace %s", ns)
565+
gomega.Expect(nsStatus.Status.Phase).To(gomega.Equal(v1.NamespaceTerminating), "The phase returned was %v", nsStatus.Status.Phase)
566+
hasContextFailure := false
567+
for _, cond := range nsStatus.Status.Conditions {
568+
if cond.Type == v1.NamespaceDeletionContentFailure {
569+
hasContextFailure = true
570+
}
571+
}
572+
if !hasContextFailure {
573+
framework.Logf("Namespace %q does not yet have a NamespaceDeletionContentFailure condition, retrying...", nsName)
574+
return false, nil
575+
}
558576
return true, nil
559577
}))
560578

0 commit comments

Comments
 (0)