Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

desiredReplicas ignored in scaledObject with trigger cron #5805

Closed
gerbil opened this issue May 15, 2024 · 4 comments
Closed

desiredReplicas ignored in scaledObject with trigger cron #5805

gerbil opened this issue May 15, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@gerbil
Copy link

gerbil commented May 15, 2024

Report

desiredReplicas is ignored completely when using trigger cron for CRD based deployment

ScaledObject:

apiVersion: keda.sh/v1alpha1
kind: ScaledObject
metadata:
  name: backend
  namespace: test
spec:
  scaleTargetRef:
    apiVersion: deployment.xxx.com/v1alpha1
    kind: ApplicationDeployment
    name: backend
  triggers:
    - metadata:
        desiredReplicas: '5'
        end: 30 * * * *
        start: 0 * * * *
        timezone: Europe/Riga
      type: cron

Expected Behavior

desiredReplicas should be respected by scaledObject cron based feature

triggers:
    - metadata:
        desiredReplicas: '5'

Actual Behavior

ScaledObject ref always restored to replicas: 1 ignoring desiredReplicas

2024-05-15T11:00:11Z	INFO	scaleexecutor	Successfully updated ScaleTarget	{"scaledobject.Name": "backend", "scaledObject.Namespace": "ivp-test", "scaleTarget.Name": "backend", "Original Replicas Count": 0, "New Replicas Count": 1}

Steps to Reproduce the Problem

  1. Create CRD based deployment with replicas = 5
  2. Create ScaledObject for the ref in step1 with triggers: -metadata: desiredReplicas: '5'
  3. Wait for scale down action
  4. Wait for scale up action

Logs from KEDA operator

2024-05-15T10:33:11Z	INFO	scaleexecutor	Successfully set ScaleTarget replicas count to ScaledObject minReplicaCount	{"scaledobject.Name": "backend", "scaledObject.Namespace": "ivp-test", "scaleTarget.Name": "backend", "Original Replicas Count": 5, "New Replicas Count": 0}
2024-05-15T11:00:11Z	INFO	scaleexecutor	Successfully updated ScaleTarget	{"scaledobject.Name": "backend", "scaledObject.Namespace": "ivp-test", "scaleTarget.Name": "backend", "Original Replicas Count": 0, "New Replicas Count": 1}

KEDA Version

2.14.0

Kubernetes Version

1.27

Platform

Microsoft Azure

Scaler Details

No response

Anything else?

No response

@gerbil gerbil added the bug Something isn't working label May 15, 2024
@tomkerkhove
Copy link
Member

This is by design, I believe, but I still think we should kill it in favor of #3566 @kedacore/keda-maintainers

@gerbil
Copy link
Author

gerbil commented May 17, 2024

What exactly is by design here? desiredReplicas is a part of ScaledObject/triggers spec and it's not working as expected.

@JorTurFer
Copy link
Member

Hello @gerbil
It's working as expected because the scaling to 5 is happening, as we can see here:

2024-05-15T10:33:11Z	INFO	scaleexecutor	Successfully set ScaleTarget replicas count to ScaledObject minReplicaCount	{"scaledobject.Name": "backend", "scaledObject.Namespace": "ivp-test", "scaleTarget.Name": "backend", "Original Replicas Count": 5, "New Replicas Count": 0}

KEDA is scaling from 0 to 1 because KEDA relies on the HPA to scaling from 1 to N, so the "usual" process is that KEDA scales from 0 to 1 when there is at least 1 active trigger, and then the HPA scales the workload from 1 to N. desiredReplicas is the value that the trigger will return to the HPA Controller. In the same way as with other scalers, if your queue returns 50, KEDA won't scale from 0 to 50 directly.
This is explained here: https://keda.sh/docs/2.14/concepts/scaling-deployments/#activating-and-scaling-thresholds

Given this, if you want to scale from 0 to 5 directly, it's doable. You can use idleReplicaCount option to allow scaling to 0 with min replicas 5, and then KEDA will scaling from 0 to 5 and from 5 to 0 without passing from 1 and the HPA:

apiVersion: keda.sh/v1alpha1
kind: ScaledObject
metadata:
  name: backend
  namespace: test
spec:
  minReplicaCount: 5
  idleReplicaCount: 0
  scaleTargetRef:
    apiVersion: deployment.xxx.com/v1alpha1
    kind: ApplicationDeployment
    name: backend
  triggers:
    - metadata:
        desiredReplicas: '5'
        end: 30 * * * *
        start: 0 * * * *
        timezone: Europe/Riga
      type: cron

@gerbil
Copy link
Author

gerbil commented May 28, 2024

Working fine, thank you!

@gerbil gerbil closed this as completed May 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants