Fix scale-to-zero bug when spec.replicas is nil#515
Merged
Conversation
This fixes a critical regression introduced in PR #511 (commit c53f570) where an EDS could scale to 0 replicas despite having minReplicas set. Bug Scenario: 1. kubectl patch clears spec.replicas to nil 2. edsReplicas() returns 0 (per c53f570 change) 3. scaleEDS() writes eds.Spec.Replicas = &0 at line 935 4. Autoscaler returns no-op (e.g., excludeSystemIndices filters all indices) 5. No-op means scalingOperation.NodeReplicas = nil 6. Line 945 condition fails, so line 959 doesn't execute 7. Result: spec.replicas stays at 0, violating minReplicas Root Cause: The c53f570 change made edsReplicas() return 0 for autoscaling-enabled EDS with nil replicas, intending to let the autoscaler calculate the initial value. However, when the autoscaler returns a no-op (nil NodeReplicas), there's no fallback to prevent spec.replicas from being set to 0. Fix: Add defensive check in scaleEDS() before writing to spec.replicas: - When currentReplicas == 0 and minReplicas > 0: - First try status.replicas (reflects actual StatefulSet state) - Fall back to minReplicas for new/uninitialized EDS - This prevents writing 0 when it would violate bounds Test Coverage: - Added TestScaleToZeroPrevention with 3 test cases - Validates the defensive logic for all scenarios - All existing tests continue to pass Signed-off-by: Oliver Trosien <oliver.trosien@zalando.de>
53f996f to
e03eda8
Compare
|
Member
Author
|
We don't support scaling down to 0 pods, and shouldn't support it without additional safeguarding considerations. See this ticket for a some old discussion: #68 Regarding the second question, system indices can/should be treated special in most cases, see |
Collaborator
|
👍 |
1 similar comment
Contributor
|
👍 |
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 fixes a critical regression introduced in PR #511 (commit c53f570) where an EDS could scale to 0 replicas despite having minReplicas set.
Bug Scenario:
Root Cause:
The c53f570 change made edsReplicas() return 0 for autoscaling-enabled EDS with nil replicas, intending to let the autoscaler calculate the initial value. However, when the autoscaler returns a no-op (nil NodeReplicas), there's no fallback to prevent spec.replicas from being set to 0.
Fix:
Add defensive check in scaleEDS() before writing to spec.replicas:
Test Coverage: