Fix: Skip replica management when HPA is attached - #527
Fix: Skip replica management when HPA is attached#527niyomukiza-mechack wants to merge 3 commits into
Conversation
| return deleteDeployments | ||
| } | ||
|
|
||
| // hpaBuildIDSet returns a set of build IDs whose versions are managed by a |
There was a problem hiding this comment.
As of v1.8.1 of temporal-worker-controller, there is no ability to have a WorkerResourceTemplate per worker deployment version (i.e. "buildID"), so I don't see the need to return a map of buildIDs that are managed by an HPA. Just return true or false if an HPA is managing the scale for this WD.
| if spec.Replicas != nil { | ||
|
|
||
| // HPA exists — skip, don't touch replicas | ||
| if hpaBuildIDs[status.CurrentVersion.BuildID] { |
There was a problem hiding this comment.
See note above. This can just be a single boolean flag indicating whether HPA is managing the scaling or not for the WD as a whole.
There was a problem hiding this comment.
Hmh that makes sense, single boolean is much simpler
961aefe to
9ece780
Compare
The behavior that you describe above is intentional and exactly what is documented on the
|
|
Also, if we decide to merge this PR, it should not "close #350" The problem reported in #350 says:
which is different from the behavior that this PR describes and changes. (To be clear, I have not been able to reproduce the behavior described in #350, and the reporter hasn't gotten back to us with instructions to repro either, so I am not convinced we need to fix anything for #350) |
What was changed
When an HPA exists via
WorkerResourceTemplatethe controller now skips enforcing the deployment'sspec.Replicasof that version letting HPA manage the scaling.Changes
I added a wew helper function
hpaBuildIDSet()in planner.go It detects HPA-kind WRTs and marks all active build IDs as HPA managedI added
hpaBuildIDsparameter on getScaleDeployments. It skips spec.Replicas enforcement for versions in this setTarget version : gated on
!hasHPAforspec.Replicasenforcement, but preserves the 0 - >1 bootstrap since HPAs cannot scale a Deployment from zeroI added Logs warning when spec.Replicas is set alongside an HPA, so a developer see the conflicting config instead of a silent fight
Why?
A developer configured a WorkerResourceTemplate with an HPA (minReplicas: 3) on a WorkerDeployment that also had spec.replicas: 1
The controller enforced replicas: 1 every 15 seconds, the HPA scaled back to 3, creating an endless loop
The root cause was
getScaleDeploymentsenforced a WD'sspec.Replicason every reconcile without checking whether an HPA is already managing that Deployment's replica count.Checklist
Closes [Bug] HorizontalPodAutoscaler continuously rescales due to controller interference #350
How was this tested:
Unit tests
Local e2e test (Kind cluster + Temporal Cloud)
Reproduced the bug and verified the fix on a Kind cluster
Before the fix, when I edited the WorkerDeployment's spec.Replicas to 1, the Controller locked replicas at 1 even thought I had an HPA with a minimum of 3 replicas and max 10. HPA was only used when WorkerDeployment's spec.Replicas was nil.
After this fix: Same spec.replicas: 1. Replicas stayed at 3 (HPA's value).