caas-team / py-kube-downscaler

Scale down / "pause" Kubernetes workload (Deployments, StatefulSets, and/or HorizontalPodAutoscalers and CronJobs too !) during non-work hours.
GNU General Public License v3.0
36 stars 14 forks source link

ScaledObject downscaling breaks due to missing autoscaling.keda.sh/paused-replicas annotation #86

Closed runningman84 closed 3 months ago

runningman84 commented 3 months ago

Issue

We use the downscaler to downscale all of our dev pods in the nights. Therefore the deployments and the scaledobjects have annotations look like these

apiVersion: apps/v1
kind: Deployment
metadata:
  annotations:
    downscaler/uptime: Mon-Fri 07:00-20:00 Europe/Berlin
    meta.helm.sh/release-name: wp-bedrock-sample
    meta.helm.sh/release-namespace: wp-bedrock-sample
---
apiVersion: keda.sh/v1alpha1
kind: ScaledObject
metadata:
  annotations:
    downscaler/uptime: Mon-Fri 19:00-20:00 Europe/Berlin
    meta.helm.sh/release-name: wp-bedrock-sample
    meta.helm.sh/release-namespace: wp-bedrock-sample

This used to work just fine in the past using the original kube downscaler. Somehow the latest version does not work anymore because it expects a autoscaling.keda.sh/paused-replicas key.

Problem to solve

│ 2024-08-21 14:36:44,549 ERROR: Failed to process ScaledObject wp-bedrock-sample/wp-bedrock-sample-wordpress-bedrock: 'autoscaling.keda.sh/paused-replicas'                                                                   │
│ Traceback (most recent call last):                                                                                                                                                                                           │
│   File "/kube_downscaler/scaler.py", line 940, in autoscale_resource                                                                                                                                                         │
│     scale_down(                                                                                                                                                                                                              │
│   File "/kube_downscaler/scaler.py", line 651, in scale_down                                                                                                                                                                 │
│     if resource.annotations[ScaledObject.keda_pause_annotation] is not None:                                                                                                                                                 │
│ KeyError: 'autoscaling.keda.sh/paused-replicas'

Further details

Proposal

Assume that autoscaling.keda.sh/paused-replicas is 0 if it is not present.

Who can address the issue

Other links/references

samuel-esp commented 3 months ago

The error was correctly fixed in #87 and #88