mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-25 12:43:23 +00:00
Update status before returning err
This commit is contained in:
parent
f12dbc31a9
commit
ae9dcc0a75
@ -553,6 +553,11 @@ func (d *namespacedResourcesDeleter) deleteAllContent(ctx context.Context, ns *v
|
|||||||
// Check if any pods remain before proceeding to delete other resources
|
// Check if any pods remain before proceeding to delete other resources
|
||||||
if numRemainingTotals.gvrToNumRemaining[podsGVR] > 0 {
|
if numRemainingTotals.gvrToNumRemaining[podsGVR] > 0 {
|
||||||
logger.V(5).Info("Namespace controller - pods still remain, delaying deletion of other resources", "namespace", namespace)
|
logger.V(5).Info("Namespace controller - pods still remain, delaying deletion of other resources", "namespace", namespace)
|
||||||
|
if hasChanged := conditionUpdater.Update(ns); hasChanged {
|
||||||
|
if _, err = d.nsClient.UpdateStatus(ctx, ns, metav1.UpdateOptions{}); err != nil {
|
||||||
|
utilruntime.HandleError(fmt.Errorf("couldn't update status condition for namespace %q: %w", namespace, err))
|
||||||
|
}
|
||||||
|
}
|
||||||
return estimate, utilerrors.NewAggregate(errs)
|
return estimate, utilerrors.NewAggregate(errs)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -549,12 +549,30 @@ func ensurePodsAreRemovedFirstInOrderedNamespaceDeletion(ctx context.Context, f
|
|||||||
pod, err = f.ClientSet.CoreV1().Pods(nsName).Get(ctx, pod.Name, metav1.GetOptions{})
|
pod, err = f.ClientSet.CoreV1().Pods(nsName).Get(ctx, pod.Name, metav1.GetOptions{})
|
||||||
framework.ExpectNoError(err, "failed to get pod %q in namespace %q", pod.Name, nsName)
|
framework.ExpectNoError(err, "failed to get pod %q in namespace %q", pod.Name, nsName)
|
||||||
if pod.DeletionTimestamp == nil {
|
if pod.DeletionTimestamp == nil {
|
||||||
framework.Failf("Pod %q in namespace %q does not have a metadata.deletionTimestamp set", pod.Name, nsName)
|
framework.Logf("Pod %q in namespace %q does not yet have a metadata.deletionTimestamp set, retrying...", pod.Name, nsName)
|
||||||
|
return false, nil
|
||||||
}
|
}
|
||||||
_, err = f.ClientSet.CoreV1().Namespaces().Get(ctx, nsName, metav1.GetOptions{})
|
ns, err := f.ClientSet.CoreV1().Namespaces().Get(ctx, nsName, metav1.GetOptions{})
|
||||||
if err != nil && apierrors.IsNotFound(err) {
|
if err != nil && apierrors.IsNotFound(err) {
|
||||||
return false, fmt.Errorf("namespace %s was deleted unexpectedly", nsName)
|
return false, fmt.Errorf("namespace %s was deleted unexpectedly", nsName)
|
||||||
}
|
}
|
||||||
|
ginkgo.By("Read namespace status")
|
||||||
|
nsResource := v1.SchemeGroupVersion.WithResource("namespaces")
|
||||||
|
unstruct, err := f.DynamicClient.Resource(nsResource).Get(ctx, ns.Name, metav1.GetOptions{}, "status")
|
||||||
|
framework.ExpectNoError(err, "failed to fetch NamespaceStatus %s", ns)
|
||||||
|
nsStatus, err := unstructuredToNamespace(unstruct)
|
||||||
|
framework.ExpectNoError(err, "Getting the status of the namespace %s", ns)
|
||||||
|
gomega.Expect(nsStatus.Status.Phase).To(gomega.Equal(v1.NamespaceTerminating), "The phase returned was %v", nsStatus.Status.Phase)
|
||||||
|
hasContextFailure := false
|
||||||
|
for _, cond := range nsStatus.Status.Conditions {
|
||||||
|
if cond.Type == v1.NamespaceDeletionContentFailure {
|
||||||
|
hasContextFailure = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !hasContextFailure {
|
||||||
|
framework.Logf("Namespace %q does not yet have a NamespaceDeletionContentFailure condition, retrying...", nsName)
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
return true, nil
|
return true, nil
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user