PIXELBANKv9.1.0
Menu

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:

Input:
print(rollout_bounds(10, "25%", "25%"))
Output:
{'min_available': 8, 'max_total': 13}
Reasoning:
  • Parse the percentage inputs by converting them to decimal fractions: 25%25\% becomes 0.250.25 for both max_unavailable and max_surge.
  • Calculate the integer value for max_unavailable by multiplying the replicas by the fraction and flooring the result, as per Kubernetes rules for unavailability: ⌊10×0.25⌋=⌊2.5⌋=2\lfloor 10 \times 0.25 \rfloor = \lfloor 2.5 \rfloor = 2.
  • Calculate the integer value for max_surge by multiplying the replicas by the fraction and ceiling the result, as per Kubernetes rules for surge: ⌈10×0.25⌉=⌈2.5⌉=3\lceil 10 \times 0.25 \rceil = \lceil 2.5 \rceil = 3.
  • Determine the minimum available pods by subtracting the computed unavailability from the desired replicas: 10−2=810 - 2 = 8.
  • Determine the maximum total pods by adding the computed surge to the desired replicas: 10+3=1310 + 3 = 13.
  • 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.
🔒

Editor locked

The code editor is locked for Pro problems. It is only available for free problems. Please upgrade to gain access to the code editor for all problems.

solution.py

Test Results

0/0
Run code to see test results.