Skip to content
This repository was archived by the owner on Oct 3, 2020. It is now read-only.

Commit b2aad83

Browse files
authored
#85 fix UnboundLocalError (#86)
1 parent abecab5 commit b2aad83

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

kube_downscaler/scaler.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ def autoscale_resource(
8989
)
9090
else:
9191
ignore = False
92+
is_uptime = True
9293

9394
upscale_period = resource.annotations.get(
9495
UPSCALE_PERIOD_ANNOTATION, upscale_period

tests/test_scaler.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -712,3 +712,59 @@ def get(url, version, **kwargs):
712712
"spec": {"suspend": False, "startingDeadlineSeconds": 0},
713713
}
714714
assert json.loads(api.patch.call_args[1]["data"]) == patch_data
715+
716+
717+
def test_scaler_downscale_period_no_error(monkeypatch, caplog):
718+
api = MagicMock()
719+
monkeypatch.setattr(
720+
"kube_downscaler.scaler.helper.get_kube_api", MagicMock(return_value=api)
721+
)
722+
723+
def get(url, version, **kwargs):
724+
if url == "pods":
725+
data = {"items": []}
726+
elif url == "cronjobs":
727+
data = {
728+
"items": [
729+
{
730+
"metadata": {
731+
"name": "cronjob-1",
732+
"namespace": "default",
733+
"creationTimestamp": "2019-03-01T16:38:00Z",
734+
"annotations": {},
735+
},
736+
"spec": {"suspend": False},
737+
},
738+
]
739+
}
740+
elif url == "namespaces/default":
741+
data = {"metadata": {}}
742+
else:
743+
raise Exception(f"unexpected call: {url}, {version}, {kwargs}")
744+
745+
response = MagicMock()
746+
response.json.return_value = data
747+
return response
748+
749+
api.get = get
750+
751+
include_resources = frozenset(["cronjobs"])
752+
scale(
753+
namespace=None,
754+
upscale_period="never",
755+
downscale_period="Mon-Tue 19:00-19:00 UTC",
756+
default_uptime="always",
757+
default_downtime="never",
758+
include_resources=include_resources,
759+
exclude_namespaces=[],
760+
exclude_deployments=[],
761+
exclude_statefulsets=[],
762+
exclude_cronjobs=[],
763+
dry_run=False,
764+
grace_period=300,
765+
downtime_replicas=0,
766+
)
767+
768+
assert api.patch.call_count == 0
769+
for record in caplog.records:
770+
assert record.levelname != "ERROR"

0 commit comments

Comments
 (0)