Repository navigation
fix: keep MaxReplicas selected clusters when trimming a Set - #2107
Open
amalsaidov wants to merge 1 commit into
Open
amalsaidov wants to merge 1 commit into
amalsaidov wants to merge 1 commit into
Conversation
When a (Cluster)Set already has more selected clusters than MaxReplicas (for example after MaxReplicas is lowered), selectClusters trimmed the slice with currentSelectedClusters[:spec.MaxReplicas-1], leaving MaxReplicas-1 clusters selected instead of MaxReplicas. Slice to [:spec.MaxReplicas] so exactly MaxReplicas clusters remain, matching the behavior of the select-more path and the == MaxReplicas early return. Add a unit test covering the drop path, which fails before the fix (selects 1 instead of 2) and passes after. AI-assisted; directed, reviewed and tested by the author.
This branch has not been deployed
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.
Problem
In
selectClusters(controllers/set_utils.go), when a (Cluster)Set already has more selected clusters thanMaxReplicas, the extra clusters are dropped with:This keeps
MaxReplicas-1clusters instead ofMaxReplicas, so the Set ends up one cluster short of the requested replica count. This branch is reached wheneverlen(currentSelectedClusters) > MaxReplicas, for example after a user lowersMaxReplicason an existing Set that already had more clusters selected.The rest of the function treats exactly
MaxReplicasas the target: the early return fires onlen(currentSelectedClusters) == spec.MaxReplicas, andselectMoreClustersstops once the count reachesMaxReplicas. The drop path is inconsistent with that.Fix
Slice to
[:spec.MaxReplicas]so exactlyMaxReplicasclusters remain.Test
Added a unit test covering the drop path (4 selected clusters,
MaxReplicasof 2). It fails before the fix (selects 1) and passes after (selects 2).Verified locally:
go test ./controllers/(focused onSet utils) passesgofmtandgo vetcleanAI-assisted; directed, reviewed and tested by the author.