From ef0592337e68b6de3470100d5e555a6739d0804e Mon Sep 17 00:00:00 2001 From: Keisuke Ishigami Date: Mon, 21 Jul 2025 17:08:45 +0900 Subject: [PATCH] Resolve confusing use of TooManyRequests error for eviction --- pkg/registry/core/pod/storage/eviction.go | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/pkg/registry/core/pod/storage/eviction.go b/pkg/registry/core/pod/storage/eviction.go index f088cf37de365..3132bc3c4f434 100644 --- a/pkg/registry/core/pod/storage/eviction.go +++ b/pkg/registry/core/pod/storage/eviction.go @@ -434,7 +434,25 @@ func (r *EvictionREST) checkAndDecrement(namespace string, podName string, pdb p } if pdb.Status.DisruptionsAllowed == 0 { err := errors.NewTooManyRequests("Cannot evict pod as it would violate the pod's disruption budget.", 0) - err.ErrStatus.Details.Causes = append(err.ErrStatus.Details.Causes, metav1.StatusCause{Type: policyv1.DisruptionBudgetCause, Message: fmt.Sprintf("The disruption budget %s needs %d healthy pods and has %d currently", pdb.Name, pdb.Status.DesiredHealthy, pdb.Status.CurrentHealthy)}) + condition := meta.FindStatusCondition(pdb.Status.Conditions, policyv1.DisruptionAllowedCondition) + if condition.Status == metav1.ConditionFalse { + err.ErrStatus.Details.Causes = append( + err.ErrStatus.Details.Causes, + metav1.StatusCause{ + Type: metav1.CauseType(condition.Type), + Message: condition.Message, + }, + ) + return err + } + + err.ErrStatus.Details.Causes = append( + err.ErrStatus.Details.Causes, + metav1.StatusCause{ + Type: policyv1.DisruptionBudgetCause, + Message: fmt.Sprintf("The disruption budget %s needs %d healthy pods and has %d currently", pdb.Name, pdb.Status.DesiredHealthy, pdb.Status.CurrentHealthy), + }, + ) return err }