Skip to content

fix: preserve autoscaled deployment replicas - #226

Closed
Kevin Rudde (kevinrudde) wants to merge 1 commit into
mainfrom
preserve-autoscaled-deployments
Closed

fix: preserve autoscaled deployment replicas#226
Kevin Rudde (kevinrudde) wants to merge 1 commit into
mainfrom
preserve-autoscaled-deployments

Conversation

@kevinrudde

Copy link
Copy Markdown
Member

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 EnsureDeployment and HasDeploymentChanged functions 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, and deploymentHashObject ensures the hash used for change detection ignores the replica count when autoscaled.

  • The StoreReconciler now uses HasDeploymentChanged instead of the generic HasObjectChanged to benefit from the autoscaling-aware logic.

RBAC Permissions:

  • The RBAC rules in store_controller.go are updated to include permissions for managing horizontalpodautoscalers in the default namespace, ensuring the controller can list and watch HPAs.

Testing:

  • New unit tests in internal/k8s/utils_test.go verify that:
    • For autoscaled Deployments, the replica count is preserved during reconciliation.
    • For non-autoscaled Deployments, the replica count is updated as configured.

@kevinrudde
Kevin Rudde (kevinrudde) force-pushed the preserve-autoscaled-deployments branch from 7a36f0f to 209ada5 Compare July 22, 2026 13:26
@kevinrudde

Copy link
Copy Markdown
Member Author

Okay maybe this is not really needed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant