Skip to content

Commit ef05923

Browse files
committed
Resolve confusing use of TooManyRequests error for eviction
1 parent c44bf18 commit ef05923

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

pkg/registry/core/pod/storage/eviction.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,25 @@ func (r *EvictionREST) checkAndDecrement(namespace string, podName string, pdb p
434434
}
435435
if pdb.Status.DisruptionsAllowed == 0 {
436436
err := errors.NewTooManyRequests("Cannot evict pod as it would violate the pod's disruption budget.", 0)
437-
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)})
437+
condition := meta.FindStatusCondition(pdb.Status.Conditions, policyv1.DisruptionAllowedCondition)
438+
if condition.Status == metav1.ConditionFalse {
439+
err.ErrStatus.Details.Causes = append(
440+
err.ErrStatus.Details.Causes,
441+
metav1.StatusCause{
442+
Type: metav1.CauseType(condition.Type),
443+
Message: condition.Message,
444+
},
445+
)
446+
return err
447+
}
448+
449+
err.ErrStatus.Details.Causes = append(
450+
err.ErrStatus.Details.Causes,
451+
metav1.StatusCause{
452+
Type: policyv1.DisruptionBudgetCause,
453+
Message: fmt.Sprintf("The disruption budget %s needs %d healthy pods and has %d currently", pdb.Name, pdb.Status.DesiredHealthy, pdb.Status.CurrentHealthy),
454+
},
455+
)
438456
return err
439457
}
440458

0 commit comments

Comments
 (0)