Skip to content

Commit

Permalink
fix: stop upscale while excluded when original replicas set (#80)
Browse files Browse the repository at this point in the history
* fix: stop upscale while excluded when original replicas set

* fix: rm now not needed tests

* chore: changed tests to match new logic
  • Loading branch information
jonathan-mayer authored Aug 2, 2024
1 parent 8690011 commit d17089b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 26 deletions.
4 changes: 2 additions & 2 deletions chart/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ name: py-kube-downscaler
description: A Helm chart for deploying py-kube-downscaler

type: application
version: 0.2.4
appVersion: "24.7.1"
version: 0.2.5
appVersion: "24.8.0"
2 changes: 1 addition & 1 deletion kube_downscaler/scaler.py
Original file line number Diff line number Diff line change
Expand Up @@ -858,7 +858,7 @@ def autoscale_resource(
if downtime_replicas_from_annotation is not None:
downtime_replicas = downtime_replicas_from_annotation

if exclude and not original_replicas:
if exclude:
logger.debug(
f"{resource.kind} {resource.namespace}/{resource.name} was excluded"
)
Expand Down
27 changes: 4 additions & 23 deletions tests/test_scaler.py
Original file line number Diff line number Diff line change
Expand Up @@ -518,8 +518,7 @@ def get(url, version, **kwargs):
ORIGINAL_REPLICAS_ANNOTATION
]


def test_scaler_upscale_on_exclude(monkeypatch):
def test_scaler_no_upscale_on_exclude(monkeypatch):
api = MagicMock()
monkeypatch.setattr(
"kube_downscaler.scaler.helper.get_kube_api", MagicMock(return_value=api)
Expand Down Expand Up @@ -575,18 +574,9 @@ def get(url, version, **kwargs):
enable_events=False,
)

assert api.patch.call_count == 1
assert api.patch.call_args[1]["url"] == "/deployments/deploy-1"
assert (
json.loads(api.patch.call_args[1]["data"])["spec"]["replicas"]
== ORIGINAL_REPLICAS
)
assert not json.loads(api.patch.call_args[1]["data"])["metadata"]["annotations"][
ORIGINAL_REPLICAS_ANNOTATION
]

assert api.patch.call_count == 0

def test_scaler_upscale_on_exclude_namespace(monkeypatch):
def test_scaler_no_upscale_on_exclude_namespace(monkeypatch):
api = MagicMock()
monkeypatch.setattr(
"kube_downscaler.scaler.helper.get_kube_api", MagicMock(return_value=api)
Expand Down Expand Up @@ -641,16 +631,7 @@ def get(url, version, **kwargs):
enable_events=False,
)

assert api.patch.call_count == 1
assert api.patch.call_args[1]["url"] == "/deployments/deploy-1"
assert (
json.loads(api.patch.call_args[1]["data"])["spec"]["replicas"]
== ORIGINAL_REPLICAS
)
assert not json.loads(api.patch.call_args[1]["data"])["metadata"]["annotations"][
ORIGINAL_REPLICAS_ANNOTATION
]

assert api.patch.call_count == 0

def test_scaler_always_upscale(monkeypatch):
api = MagicMock()
Expand Down

0 comments on commit d17089b

Please sign in to comment.