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

Commit

Permalink
#85 fix UnboundLocalError (#86)
Browse files Browse the repository at this point in the history
  • Loading branch information
hjacobs authored Feb 7, 2020
1 parent abecab5 commit b2aad83
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
1 change: 1 addition & 0 deletions kube_downscaler/scaler.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ def autoscale_resource(
)
else:
ignore = False
is_uptime = True

upscale_period = resource.annotations.get(
UPSCALE_PERIOD_ANNOTATION, upscale_period
Expand Down
56 changes: 56 additions & 0 deletions tests/test_scaler.py
Original file line number Diff line number Diff line change
Expand Up @@ -712,3 +712,59 @@ def get(url, version, **kwargs):
"spec": {"suspend": False, "startingDeadlineSeconds": 0},
}
assert json.loads(api.patch.call_args[1]["data"]) == patch_data


def test_scaler_downscale_period_no_error(monkeypatch, caplog):
api = MagicMock()
monkeypatch.setattr(
"kube_downscaler.scaler.helper.get_kube_api", MagicMock(return_value=api)
)

def get(url, version, **kwargs):
if url == "pods":
data = {"items": []}
elif url == "cronjobs":
data = {
"items": [
{
"metadata": {
"name": "cronjob-1",
"namespace": "default",
"creationTimestamp": "2019-03-01T16:38:00Z",
"annotations": {},
},
"spec": {"suspend": False},
},
]
}
elif url == "namespaces/default":
data = {"metadata": {}}
else:
raise Exception(f"unexpected call: {url}, {version}, {kwargs}")

response = MagicMock()
response.json.return_value = data
return response

api.get = get

include_resources = frozenset(["cronjobs"])
scale(
namespace=None,
upscale_period="never",
downscale_period="Mon-Tue 19:00-19:00 UTC",
default_uptime="always",
default_downtime="never",
include_resources=include_resources,
exclude_namespaces=[],
exclude_deployments=[],
exclude_statefulsets=[],
exclude_cronjobs=[],
dry_run=False,
grace_period=300,
downtime_replicas=0,
)

assert api.patch.call_count == 0
for record in caplog.records:
assert record.levelname != "ERROR"

0 comments on commit b2aad83

Please sign in to comment.