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

Commit

Permalink
Remove the original-replicas annotation on scale-up (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
aermakov-zalando authored and hjacobs committed Sep 20, 2018
1 parent 942e1ef commit 10eeae6
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions kube_downscaler/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

TIME_SPEC_PATTERN = re.compile(r'^([a-zA-Z]{3})-([a-zA-Z]{3}) (\d\d):(\d\d)-(\d\d):(\d\d) (?P<tz>[a-zA-Z/]+)$')

ORIGINAL_REPLICAS_ANNOTATION = 'downscaler/original-replicas'

logger = logging.getLogger('downscaler')


Expand Down Expand Up @@ -116,7 +118,7 @@ def autoscale_resource(resource: pykube.objects.NamespacedAPIObject,
downtime = resource.annotations.get('downscaler/downtime', default_downtime)
is_uptime = matches_time_spec(now, uptime) and not matches_time_spec(now, downtime)

original_replicas = resource.annotations.get('downscaler/original-replicas')
original_replicas = resource.annotations.get(ORIGINAL_REPLICAS_ANNOTATION)
logger.debug('%s %s/%s has %s replicas (original: %s, uptime: %s)',
resource.kind, resource.namespace, resource.name, replicas, original_replicas, uptime)
update_needed = False
Expand All @@ -125,6 +127,7 @@ def autoscale_resource(resource: pykube.objects.NamespacedAPIObject,
resource.kind, resource.namespace, resource.name, replicas, original_replicas,
uptime, downtime)
resource.obj['spec']['replicas'] = int(original_replicas)
resource.annotations[ORIGINAL_REPLICAS_ANNOTATION] = None
update_needed = True
elif not is_uptime and replicas > 0:
if within_grace_period(resource, grace_period):
Expand All @@ -135,7 +138,7 @@ def autoscale_resource(resource: pykube.objects.NamespacedAPIObject,
logger.info('Scaling down %s %s/%s from %s to %s replicas (uptime: %s, downtime: %s)',
resource.kind, resource.namespace, resource.name, replicas, target_replicas,
uptime, downtime)
resource.annotations['downscaler/original-replicas'] = str(replicas)
resource.annotations[ORIGINAL_REPLICAS_ANNOTATION] = str(replicas)
resource.obj['spec']['replicas'] = target_replicas
update_needed = True
if update_needed:
Expand Down

0 comments on commit 10eeae6

Please sign in to comment.