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

Commit 06b8fea

Browse files
committed
fix parameter passing
1 parent 8df25d8 commit 06b8fea

File tree

2 files changed

+25
-69
lines changed

2 files changed

+25
-69
lines changed

deploy/rbac.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ rules:
1818
- watch
1919
- list
2020
- apiGroups:
21-
- extensions
2221
- apps
2322
resources:
2423
- deployments

kube_downscaler/scaler.py

Lines changed: 25 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
DOWNTIME_ANNOTATION = "downscaler/downtime"
2222
DOWNTIME_REPLICAS_ANNOTATION = "downscaler/downtime-replicas"
2323

24+
RESOURCE_CLASSES = [Deployment, StatefulSet, Stack, CronJob]
25+
2426

2527
def parse_time(timestamp: str) -> datetime.datetime:
2628
return datetime.datetime.strptime(timestamp, "%Y-%m-%dT%H:%M:%SZ").replace(
@@ -293,6 +295,7 @@ def autoscale_resources(
293295
now: datetime.datetime,
294296
grace_period: int,
295297
downtime_replicas: int,
298+
deployment_time_annotation: Optional[str] = None,
296299
):
297300
for resource in kind.objects(api, namespace=(namespace or pykube.all)):
298301
if resource.namespace in exclude_namespaces or resource.name in exclude_names:
@@ -344,6 +347,7 @@ def autoscale_resources(
344347
grace_period,
345348
default_downtime_replicas_for_namespace,
346349
namespace_excluded=excluded,
350+
deployment_time_annotation=deployment_time_annotation,
347351
)
348352

349353

@@ -361,77 +365,30 @@ def scale(
361365
dry_run: bool,
362366
grace_period: int,
363367
downtime_replicas: int,
368+
deployment_time_annotation: Optional[str] = None,
364369
):
365370
api = helper.get_kube_api()
366371

367372
now = datetime.datetime.now(datetime.timezone.utc)
368373
forced_uptime = pods_force_uptime(api, namespace)
369374

370-
if "deployments" in include_resources:
371-
autoscale_resources(
372-
api,
373-
Deployment,
374-
namespace,
375-
exclude_namespaces,
376-
exclude_deployments,
377-
upscale_period,
378-
downscale_period,
379-
default_uptime,
380-
default_downtime,
381-
forced_uptime,
382-
dry_run,
383-
now,
384-
grace_period,
385-
downtime_replicas,
386-
)
387-
if "statefulsets" in include_resources:
388-
autoscale_resources(
389-
api,
390-
StatefulSet,
391-
namespace,
392-
exclude_namespaces,
393-
exclude_statefulsets,
394-
upscale_period,
395-
downscale_period,
396-
default_uptime,
397-
default_downtime,
398-
forced_uptime,
399-
dry_run,
400-
now,
401-
grace_period,
402-
downtime_replicas,
403-
)
404-
if "stacks" in include_resources:
405-
autoscale_resources(
406-
api,
407-
Stack,
408-
namespace,
409-
exclude_namespaces,
410-
exclude_statefulsets,
411-
upscale_period,
412-
downscale_period,
413-
default_uptime,
414-
default_downtime,
415-
forced_uptime,
416-
dry_run,
417-
now,
418-
grace_period,
419-
downtime_replicas,
420-
)
421-
if "cronjobs" in include_resources:
422-
autoscale_resources(
423-
api,
424-
CronJob,
425-
namespace,
426-
exclude_namespaces,
427-
exclude_cronjobs,
428-
upscale_period,
429-
downscale_period,
430-
default_uptime,
431-
default_downtime,
432-
forced_uptime,
433-
dry_run,
434-
now,
435-
grace_period,
436-
downtime_replicas,
437-
)
375+
for clazz in RESOURCE_CLASSES:
376+
plural = clazz.endpoint
377+
if plural in include_resources:
378+
autoscale_resources(
379+
api,
380+
clazz,
381+
namespace,
382+
exclude_namespaces,
383+
exclude_deployments,
384+
upscale_period,
385+
downscale_period,
386+
default_uptime,
387+
default_downtime,
388+
forced_uptime,
389+
dry_run,
390+
now,
391+
grace_period,
392+
downtime_replicas,
393+
deployment_time_annotation,
394+
)

0 commit comments

Comments
 (0)