Rolling Update Pod Availability Bounds
Problem Statement
A Deployment rolling update is constrained by maxUnavailable and maxSurge. Compute the minimum available pods and the maximum total pods allowed during the rollout.
Background
For replicas desired pods:
- maxUnavailable and maxSurge may be integers or percentage strings like "25%".
- A percentage of replicas is floored for maxUnavailable and ceiled for maxSurge (Kubernetes rounding rules).
- Minimum available = replicas - maxUnavailable; maximum total = replicas + maxSurge.
Your Task
def rollout_bounds(replicas, max_unavailable, max_surge):
Return a dict {"min_available": int, "max_total": int}.
Input Format
- replicas (int), max_unavailable, max_surge (int or "NN%" string).
Output Format
- A dict of two ints.
Sample
print(rollout_bounds(10, "25%", "25%"))
Output:
{'min_available': 8, 'max_total': 13}
Example
print(rollout_bounds(10, "25%", "25%"))
{'min_available': 8, 'max_total': 13}- Parse the percentage inputs by converting them to decimal fractions: becomes for both
max_unavailableandmax_surge. - Calculate the integer value for
max_unavailableby multiplying the replicas by the fraction and flooring the result, as per Kubernetes rules for unavailability: . - Calculate the integer value for
max_surgeby multiplying the replicas by the fraction and ceiling the result, as per Kubernetes rules for surge: . - Determine the minimum available pods by subtracting the computed unavailability from the desired replicas: .
- Determine the maximum total pods by adding the computed surge to the desired replicas: .
- The final output is
{'min_available': 8, 'max_total': 13}
Constraints
- Percentages: floor for maxUnavailable, ceil for maxSurge (of replicas).
- min_available = replicas - maxUnavailable; max_total = replicas + maxSurge.
- Integer inputs are used as-is.