Skip to content
This repository was archived by the owner on Dec 24, 2019. It is now read-only.

Commit 2381ffc

Browse files
wndhydrnthjacobs
authored andcommitted
Fix health state not recovering after a occured failure (#54)
When an exception is raised inside the method `autoscale`, the health endpoint indicates this by responding with status code "503". If kube-aws-autoscaler recovers on a subsequent run, the health endpoint still responds with status code "503". These changes fix this behaviour by setting the global variable `Healthy` to `True` after each run of autoscale if no exception occurred.
1 parent ae43506 commit 2381ffc

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

kube_aws_autoscaler/main.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,7 @@ def main():
460460
t = Thread(target=start_health_endpoint, daemon=True)
461461
t.start()
462462

463+
global Healthy
463464
while True:
464465
try:
465466
autoscale(buffer_percentage, buffer_fixed,
@@ -468,8 +469,8 @@ def main():
468469
buffer_spare_nodes=args.buffer_spare_nodes,
469470
include_master_nodes=args.include_master_nodes, dry_run=args.dry_run,
470471
disable_scale_down=args.no_scale_down)
472+
Healthy = True
471473
except Exception:
472-
global Healthy
473474
Healthy = False
474475
logger.exception('Failed to autoscale')
475476
if args.once:

tests/test_autoscaler.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
resize_auto_scaling_groups,
1111
scaling_activity_in_progress,
1212
slow_down_downscale, app)
13+
import kube_aws_autoscaler.main
1314

1415

1516
def test_parse_resource():
@@ -511,3 +512,11 @@ def test_start_health_endpoint():
511512
flask.testing = True
512513
response = flask.get('/healthz')
513514
assert response.status_code == 503
515+
516+
def test_endpoint_healthy_state(monkeypatch):
517+
kube_aws_autoscaler.main.Healthy = False
518+
autoscale = MagicMock()
519+
monkeypatch.setattr('kube_aws_autoscaler.main.autoscale', autoscale)
520+
monkeypatch.setattr('sys.argv', ['foo', '--once', '--dry-run'])
521+
main()
522+
assert kube_aws_autoscaler.main.Healthy == True

0 commit comments

Comments
 (0)