@@ -1056,7 +1056,7 @@ def autoscale_resource(
10561056def autoscale_resources (
10571057 api ,
10581058 kind ,
1059- namespace : FrozenSet [Pattern ],
1059+ namespace : FrozenSet [str ],
10601060 exclude_namespaces : FrozenSet [Pattern ],
10611061 exclude_names : FrozenSet [str ],
10621062 matching_labels : FrozenSet [Pattern ],
@@ -1363,7 +1363,7 @@ def autoscale_jobs(
13631363 if len (namespaces ) >= 1 :
13641364 namespaces = namespaces
13651365 else :
1366- namespaces = list (Namespace .objects (api ).iterator ())
1366+ namespaces = frozenset (Namespace .objects (api ).iterator ())
13671367
13681368 excluded_jobs = []
13691369
@@ -1372,40 +1372,38 @@ def autoscale_jobs(
13721372
13731373 for current_namespace in namespaces :
13741374 if any (
1375- [
1376- pattern .fullmatch (current_namespace .name )
1377- for pattern in exclude_namespaces
1378- ]
1375+ [pattern .fullmatch (current_namespace ) for pattern in exclude_namespaces ]
13791376 ):
13801377 logger .debug (
1381- f"Namespace { current_namespace . name } was excluded from job scaling (exclusion list regex matches)"
1378+ f"Namespace { current_namespace } was excluded from job scaling (exclusion list regex matches)"
13821379 )
13831380 continue
13841381
1385- logger .debug (f"Processing { current_namespace .name } for job scaling.." )
1382+ logger .debug (f"Processing { current_namespace } for job scaling.." )
1383+
1384+ # Override defaults with (optional) annotations from Namespace
1385+ namespace_obj = Namespace .objects (api ).get_by_name (current_namespace )
13861386
13871387 excluded = ignore_resource (current_namespace , now )
13881388
1389- default_uptime_for_namespace = current_namespace .annotations .get (
1389+ default_uptime_for_namespace = namespace_obj .annotations .get (
13901390 UPTIME_ANNOTATION , default_uptime
13911391 )
1392- default_downtime_for_namespace = current_namespace .annotations .get (
1392+ default_downtime_for_namespace = namespace_obj .annotations .get (
13931393 DOWNTIME_ANNOTATION , default_downtime
13941394 )
13951395
1396- upscale_period_for_namespace = current_namespace .annotations .get (
1396+ upscale_period_for_namespace = namespace_obj .annotations .get (
13971397 UPSCALE_PERIOD_ANNOTATION , upscale_period
13981398 )
1399- downscale_period_for_namespace = current_namespace .annotations .get (
1399+ downscale_period_for_namespace = namespace_obj .annotations .get (
14001400 DOWNSCALE_PERIOD_ANNOTATION , downscale_period
14011401 )
14021402 forced_uptime_value_for_namespace = str (
1403- current_namespace .annotations .get (
1404- FORCE_UPTIME_ANNOTATION , forced_uptime
1405- )
1403+ namespace_obj .annotations .get (FORCE_UPTIME_ANNOTATION , forced_uptime )
14061404 )
14071405 forced_downtime_value_for_namespace = str (
1408- current_namespace .annotations .get (FORCE_DOWNTIME_ANNOTATION , False )
1406+ namespace_obj .annotations .get (FORCE_DOWNTIME_ANNOTATION , False )
14091407 )
14101408 if forced_uptime_value_for_namespace .lower () == "true" :
14111409 forced_uptime_for_namespace = True
0 commit comments