Skip to content

Commit d17089b

Browse files
fix: stop upscale while excluded when original replicas set (#80)
* fix: stop upscale while excluded when original replicas set * fix: rm now not needed tests * chore: changed tests to match new logic
1 parent 8690011 commit d17089b

3 files changed

Lines changed: 7 additions & 26 deletions

File tree

chart/Chart.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ name: py-kube-downscaler
33
description: A Helm chart for deploying py-kube-downscaler
44

55
type: application
6-
version: 0.2.4
7-
appVersion: "24.7.1"
6+
version: 0.2.5
7+
appVersion: "24.8.0"

kube_downscaler/scaler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -858,7 +858,7 @@ def autoscale_resource(
858858
if downtime_replicas_from_annotation is not None:
859859
downtime_replicas = downtime_replicas_from_annotation
860860

861-
if exclude and not original_replicas:
861+
if exclude:
862862
logger.debug(
863863
f"{resource.kind} {resource.namespace}/{resource.name} was excluded"
864864
)

tests/test_scaler.py

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -518,8 +518,7 @@ def get(url, version, **kwargs):
518518
ORIGINAL_REPLICAS_ANNOTATION
519519
]
520520

521-
522-
def test_scaler_upscale_on_exclude(monkeypatch):
521+
def test_scaler_no_upscale_on_exclude(monkeypatch):
523522
api = MagicMock()
524523
monkeypatch.setattr(
525524
"kube_downscaler.scaler.helper.get_kube_api", MagicMock(return_value=api)
@@ -575,18 +574,9 @@ def get(url, version, **kwargs):
575574
enable_events=False,
576575
)
577576

578-
assert api.patch.call_count == 1
579-
assert api.patch.call_args[1]["url"] == "/deployments/deploy-1"
580-
assert (
581-
json.loads(api.patch.call_args[1]["data"])["spec"]["replicas"]
582-
== ORIGINAL_REPLICAS
583-
)
584-
assert not json.loads(api.patch.call_args[1]["data"])["metadata"]["annotations"][
585-
ORIGINAL_REPLICAS_ANNOTATION
586-
]
587-
577+
assert api.patch.call_count == 0
588578

589-
def test_scaler_upscale_on_exclude_namespace(monkeypatch):
579+
def test_scaler_no_upscale_on_exclude_namespace(monkeypatch):
590580
api = MagicMock()
591581
monkeypatch.setattr(
592582
"kube_downscaler.scaler.helper.get_kube_api", MagicMock(return_value=api)
@@ -641,16 +631,7 @@ def get(url, version, **kwargs):
641631
enable_events=False,
642632
)
643633

644-
assert api.patch.call_count == 1
645-
assert api.patch.call_args[1]["url"] == "/deployments/deploy-1"
646-
assert (
647-
json.loads(api.patch.call_args[1]["data"])["spec"]["replicas"]
648-
== ORIGINAL_REPLICAS
649-
)
650-
assert not json.loads(api.patch.call_args[1]["data"])["metadata"]["annotations"][
651-
ORIGINAL_REPLICAS_ANNOTATION
652-
]
653-
634+
assert api.patch.call_count == 0
654635

655636
def test_scaler_always_upscale(monkeypatch):
656637
api = MagicMock()

0 commit comments

Comments
 (0)