Beispiel #1
0
def run_loop(run_once, namespace, kinds, upscale_period, downscale_period,
             default_uptime, default_downtime, exclude_namespaces,
             exclude_deployments, exclude_statefulsets, grace_period, interval,
             dry_run, downtime_replicas):
    handler = shutdown.GracefulShutdown()
    while True:
        try:
            scale(namespace,
                  upscale_period,
                  downscale_period,
                  default_uptime,
                  default_downtime,
                  kinds=frozenset(kinds),
                  exclude_namespaces=frozenset(exclude_namespaces.split(',')),
                  exclude_deployments=frozenset(
                      exclude_deployments.split(',')),
                  exclude_statefulsets=frozenset(
                      exclude_statefulsets.split(',')),
                  dry_run=dry_run,
                  grace_period=grace_period,
                  downtime_replicas=downtime_replicas)
        except Exception as e:
            logger.exception('Failed to autoscale : %s', e)
        if run_once or handler.shutdown_now:
            return
        with handler.safe_exit():
            time.sleep(interval)
Beispiel #2
0
def run_loop(
    run_once,
    namespace,
    include_resources,
    upscale_period,
    downscale_period,
    default_uptime,
    default_downtime,
    exclude_namespaces,
    exclude_deployments,
    grace_period,
    interval,
    dry_run,
    downtime_replicas,
    deployment_time_annotation=None,
    enable_events=False,
    upscale_step_size=0,
):
    handler = shutdown.GracefulShutdown()
    while True:
        try:
            scale(
                namespace,
                upscale_period,
                downscale_period,
                default_uptime,
                default_downtime,
                include_resources=frozenset(include_resources.split(",")),
                exclude_namespaces=frozenset(
                    re.compile(pattern)
                    for pattern in exclude_namespaces.split(",")),
                exclude_deployments=frozenset(exclude_deployments.split(",")),
                dry_run=dry_run,
                grace_period=grace_period,
                downtime_replicas=downtime_replicas,
                deployment_time_annotation=deployment_time_annotation,
                enable_events=enable_events,
                upscale_step_size=upscale_step_size,
            )
        except Exception as e:
            logger.exception(f"Failed to autoscale: {e}")
        if run_once or handler.shutdown_now:
            return
        with handler.safe_exit():
            time.sleep(interval)
Beispiel #3
0
def run_loop(
    run_once,
    namespace,
    include_resources,
    upscale_period,
    downscale_period,
    default_uptime,
    default_downtime,
    exclude_namespaces,
    exclude_deployments,
    exclude_statefulsets,
    exclude_cronjobs,
    grace_period,
    interval,
    dry_run,
    downtime_replicas,
    deployment_time_annotation=None,
):
    handler = shutdown.GracefulShutdown()
    while True:
        try:
            scale(
                namespace,
                upscale_period,
                downscale_period,
                default_uptime,
                default_downtime,
                include_resources=frozenset(include_resources.split(",")),
                exclude_namespaces=frozenset(exclude_namespaces.split(",")),
                exclude_deployments=frozenset(exclude_deployments.split(",")),
                exclude_statefulsets=frozenset(
                    exclude_statefulsets.split(",")),
                exclude_cronjobs=frozenset(exclude_cronjobs.split(",")),
                dry_run=dry_run,
                grace_period=grace_period,
                downtime_replicas=downtime_replicas,
                deployment_time_annotation=deployment_time_annotation,
            )
        except Exception as e:
            logger.exception("Failed to autoscale : %s", e)
        if run_once or handler.shutdown_now:
            return
        with handler.safe_exit():
            time.sleep(interval)