Skip to content

Commit

Permalink
Do not create PDBs for deployments with 0 replicas (#242)
Browse files Browse the repository at this point in the history
* Update pod_disruption_budget.py

* Add tests for zero replicas

---------

Co-authored-by: herodes1991 <[email protected]>
  • Loading branch information
herodes1991 and herodes1991 authored Apr 25, 2024
1 parent 71d11c2 commit cd6960c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def __init__(self, owner_references, extension_hook, config):

@retry_on_upsert_conflict
def deploy(self, app_spec: AppSpec, selector: dict[str, any], labels: dict[str, any]):
if app_spec.autoscaler.min_replicas == 1 or app_spec.autoscaler.max_replicas == 1:
if app_spec.autoscaler.min_replicas <= 1 or app_spec.autoscaler.max_replicas <= 1:
# delete possible existing pdb
self.delete(app_spec)
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ def test_no_pdb_gives_no_post(self, deployer: PodDisruptionBudgetDeployer, delet
delete.assert_called_with(PDB_API + app_spec.name)
pytest.helpers.assert_no_calls(post)

def test_zero_replicas_no_pdb_gives_no_post(self, deployer: PodDisruptionBudgetDeployer, delete, post, app_spec):
app_spec = app_spec._replace(
autoscaler=AutoscalerSpec(enabled=True, min_replicas=0, max_replicas=0, cpu_threshold_percentage=50)
)
deployer.deploy(app_spec, SELECTOR, LABELS)
delete.assert_called_with(PDB_API + app_spec.name)
pytest.helpers.assert_no_calls(post)

def test_no_pdb_gives_no_put(self, deployer, delete, put, app_spec):
app_spec = app_spec._replace(
autoscaler=AutoscalerSpec(enabled=True, min_replicas=1, max_replicas=1, cpu_threshold_percentage=50)
Expand Down

0 comments on commit cd6960c

Please sign in to comment.