Fixed KubeDownscaler Ignoring Keda ScaledObjects if the "paused-replicas" annotation is already present #41
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
WIth this PR I fixed a bug that prevented ScaledObjects from being paused if the "paused-replicas" annotation was already present inside the object
Motivation
If, for some reason, the annotation
autoscaling.keda.sh/paused-replicas
is already present in the ScaledObject, the KubeDownscaler won't process the resourceThis bug can happen if the developers incorrectly put this annotation at object creation.
For example this object:
will be logged in this way inside the Kube-Downscaler
2024-01-31 13:21:44,135 DEBUG: ScaledObject default/cron-scaledobject-2 has 0 replicas (original: None, uptime: Mon-Sun 07:30-10:45 CET)
This is because the
keda.py
was defined as suchthe method "replicas" is called inside the "get_replicas" function of the
scaler.py
class and it always returns 0 with a ScaledObjects defined as the one aboveChanges
How the fix works: Each ScaledObjects will be scaled to 0 regardless of them having the annotation or not. However if the annotation
autoscaling.keda.sh/paused-replicas
was already present and with a value (like 2 or 3), during the next Cluster Uptime the ScaledObject will be restored at that configuration. The previous configuration "paused configuration" is saved inside a new annotation calleddownscaler/original-pause-replicas
Tests done
Built the image and followed the workflow described above
TODO