@@ -35,16 +35,19 @@ def pods_force_uptime(api, namespace: str):
3535
3636def autoscale_resource (resource : pykube .objects .NamespacedAPIObject ,
3737 default_uptime : str , default_downtime : str , forced_uptime : bool , dry_run : bool ,
38- now : datetime .datetime , grace_period : int , downtime_replicas : int ):
38+ now : datetime .datetime , grace_period : int , downtime_replicas : int , namespace_excluded = False ):
3939 try :
4040 # any value different from "false" will ignore the resource (to be on the safe side)
41- exclude = resource .annotations .get (EXCLUDE_ANNOTATION , 'false' ).lower () != 'false'
42- if exclude :
41+ exclude = namespace_excluded or (resource .annotations .get (EXCLUDE_ANNOTATION , 'false' ).lower () != 'false' )
42+ original_replicas = resource .annotations .get (ORIGINAL_REPLICAS_ANNOTATION )
43+ downtime_replicas = resource .annotations .get (DOWNTIME_REPLICAS_ANNOTATION , downtime_replicas )
44+
45+ if exclude and not original_replicas :
4346 logger .debug ('%s %s/%s was excluded' , resource .kind , resource .namespace , resource .name )
4447 else :
4548 replicas = resource .replicas
4649
47- if forced_uptime :
50+ if forced_uptime or ( exclude and original_replicas ) :
4851 uptime = "forced"
4952 downtime = "ignored"
5053 is_uptime = True
@@ -53,8 +56,6 @@ def autoscale_resource(resource: pykube.objects.NamespacedAPIObject,
5356 downtime = resource .annotations .get (DOWNTIME_ANNOTATION , default_downtime )
5457 is_uptime = helper .matches_time_spec (now , uptime ) and not helper .matches_time_spec (now , downtime )
5558
56- original_replicas = resource .annotations .get (ORIGINAL_REPLICAS_ANNOTATION )
57- downtime_replicas = resource .annotations .get (DOWNTIME_REPLICAS_ANNOTATION , downtime_replicas )
5859 logger .debug ('%s %s/%s has %s replicas (original: %s, uptime: %s)' ,
5960 resource .kind , resource .namespace , resource .name , replicas , original_replicas , uptime )
6061 update_needed = False
@@ -94,21 +95,20 @@ def autoscale_resources(api, kind, namespace: str,
9495 now : datetime .datetime , grace_period : int , downtime_replicas : int ):
9596 for resource in kind .objects (api , namespace = (namespace or pykube .all )):
9697 if resource .namespace in exclude_namespaces or resource .name in exclude_names :
98+ logger .debug ('Resource %s was excluded (either resource itself or namespace %s are excluded)' , resource .name , namespace )
9799 continue
98100
99101 # Override defaults with (optional) annotations from Namespace
100102 namespace_obj = pykube .Namespace .objects (api ).get_by_name (resource .namespace )
101103
102- if namespace_obj .annotations .get (EXCLUDE_ANNOTATION , 'false' ).lower () != 'false' :
103- logger .debug ('Namespace %s was excluded (because of namespace annotation)' , namespace )
104- continue
104+ excluded = namespace_obj .annotations .get (EXCLUDE_ANNOTATION , 'false' ).lower () != 'false'
105105
106106 default_uptime_for_namespace = namespace_obj .annotations .get (UPTIME_ANNOTATION , default_uptime )
107107 default_downtime_for_namespace = namespace_obj .annotations .get (DOWNTIME_ANNOTATION , default_downtime )
108108 forced_uptime_for_namespace = namespace_obj .annotations .get (FORCE_UPTIME_ANNOTATION , forced_uptime )
109109
110110 autoscale_resource (resource , default_uptime_for_namespace , default_downtime_for_namespace ,
111- forced_uptime_for_namespace , dry_run , now , grace_period , downtime_replicas )
111+ forced_uptime_for_namespace , dry_run , now , grace_period , downtime_replicas , namespace_excluded = excluded )
112112
113113
114114def scale (namespace : str , default_uptime : str , default_downtime : str , kinds : FrozenSet [str ],
0 commit comments