fix: preserve autoscaled deployment replicas - #226
Closed
Kevin Rudde (kevinrudde) wants to merge 1 commit into
Closed
fix: preserve autoscaled deployment replicas#226Kevin Rudde (kevinrudde) wants to merge 1 commit into
Kevin Rudde (kevinrudde) wants to merge 1 commit into
Conversation
Kevin Rudde (kevinrudde)
force-pushed
the
preserve-autoscaled-deployments
branch
from
July 22, 2026 13:26
7a36f0f to
209ada5
Compare
Member
Author
|
Okay maybe this is not really needed |
Kevin Rudde (kevinrudde)
marked this pull request as draft
July 23, 2026 07:05
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This pull request introduces improved handling for Kubernetes Deployments that are managed by HorizontalPodAutoscalers (HPAs). The main goal is to ensure that when a Deployment is autoscaled, the controller preserves the replica count set by the HPA rather than overwriting it during reconciliation. The changes also add targeted unit tests to verify this behavior.
Deployment & Autoscaling Logic Improvements:
The
EnsureDeploymentandHasDeploymentChangedfunctions now detect if a Deployment is managed by an HPA. If so, they preserve the current replica count and only reconcile other changes, preventing the controller from fighting with the autoscaler. [1] [2] [3] [4]A new helper function,
isDeploymentAutoscaled, checks for HPAs targeting a Deployment, anddeploymentHashObjectensures the hash used for change detection ignores the replica count when autoscaled.The
StoreReconcilernow usesHasDeploymentChangedinstead of the genericHasObjectChangedto benefit from the autoscaling-aware logic.RBAC Permissions:
store_controller.goare updated to include permissions for managinghorizontalpodautoscalersin the default namespace, ensuring the controller can list and watch HPAs.Testing:
internal/k8s/utils_test.goverify that: