feat: Use informer cache for ReplicaSet replica count lookups#7466
feat: Use informer cache for ReplicaSet replica count lookups#7466mattshep wants to merge 4 commits intokedacore:mainfrom
Conversation
|
Thank you for your contribution! 🙏 Please understand that we will do our best to review your PR and give you feedback as soon as possible, but please bear with us if it takes a little longer as expected. While you are waiting, make sure to:
Once the initial tests are successful, a KEDA member will ensure that the e2e tests are run. Once the e2e tests have been successfully completed, the PR may be merged at a later date. Please be patient. Learn more about our contribution guide. |
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
JorTurFer
left a comment
There was a problem hiding this comment.
I think that there isn't any way to test this with unit tests, could you tell us something about the use case where you need to scale replicasets directly? We can cover it using e2e tests adding one case where KEDA scales the rs directly, ensuring that this code works
|
We run a platform where users deploy workloads that scale based on a Redis queue (pending session requests). When a user pushes a new version, we want the old version to remain independently scalable — for example, to handle traffic surges if the new version is broken. With Deployment-targeted ScaledObjects, only the current ReplicaSet scales; old ReplicaSets are stuck at their replica count. We create ReplicaSets directly (rather than one Deployment per revision) because ReplicaSets are the natural primitive — Deployments add rollout logic we don't need since we manage revision lifecycle ourselves. Happy to help with e2e test scenarios if useful. |
With this in mind, I'd take some test like https://github.com/kedacore/keda/tree/main/tests/internals/subresource_scale as inspiration and write another specific for replicaset directly. The main goal is to have this new use case covered to avoid breaking it in the future. Does it make sense? |
|
/run-e2e replicaset |
Syncs RBAC changes with core: kedacore/keda#7466 This adds list/watch permissions for ReplicaSets to enable the informer cache optimization when targeting ReplicaSets directly with ScaledObjects. Signed-off-by: Matt Sheppard <matthewlouissheppard@gmail.com>
GetCurrentReplicas() has special handling for Deployments and StatefulSets that uses the controller-runtime client (backed by informer cache) instead of the scale subresource API. This avoids live API calls on every poll. ReplicaSets were missing this optimization and always used the scale subresource, causing a live API call every polling interval. With many ScaledObjects targeting ReplicaSets, this creates significant API server load. This change adds ReplicaSet to the list of resource types that use the informer cache, reducing API calls for ReplicaSet-targeted ScaledObjects. Signed-off-by: Matt Sheppard <matt.sheppard@daily.co>
Signed-off-by: Matt Sheppard <matt.sheppard@daily.co>
Signed-off-by: Matt Sheppard <matt.sheppard@daily.co>
- Add replicasets to ClusterRole for informer cache list/watch - Move WaitForReplicaSetReplicaReadyCount to tests/helper package - Update e2e test to use shared helper function Signed-off-by: Matt Sheppard <matt.sheppard@daily.co>
5b08cfb to
740515e
Compare
|
/run-e2e replicaset |
GetCurrentReplicas()has special handling for Deployments and StatefulSets that uses the controller-runtime client (backed by informer cache) instead of the scale subresource API. This avoids live API calls on every poll.ReplicaSets were missing this optimization and always used the scale subresource, causing a live API call every polling interval. With many ScaledObjects targeting ReplicaSets, this creates significant API server load.
This change adds ReplicaSet to the list of resource types that use the informer cache, reducing API calls for ReplicaSet-targeted ScaledObjects.
Validated in a staging environment with 67 ScaledObjects targeting ReplicaSets:
/apis/apps/v1/.../replicasets/.../scaleNo unit tests found for existing case statements.
Checklist
make generate-scalers-schemahas been run to update any outdated generated files