feat(controller): change replicas through the scale subresource - #75
Merged
Merged
Conversation
A full-object update is the wrong tool for a replica change on a
workload something else also manages. A HorizontalPodAutoscaler writes
through /scale, so a narrow write competes with it cleanly, whereas a
full update replays the entire spec on a conflict retry.
Deployment and StatefulSet now go through client.SubResource("scale").
CronJob is unchanged: it has no scale subresource and spec.suspend
remains the mechanism.
The two branches were near-identical, so they collapse into one helper.
The annotations are written before the scale call on purpose: if the
scale then fails the workload is still running and the next evaluation
retries it, whereas the other order could leave a stopped workload with
no record of its previous replica count, and the zero-replica guard
would stop the operator ever revisiting it.
Adds deployments/scale and statefulsets/scale with get and update.
Narrow and explicit; the generic variant was considered and rejected,
with the reasoning recorded on the issue.
Closes #68
Signed-off-by: Simon Lauger <simon@lauger.de>
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.
Summary
A full-object update is the wrong tool for a replica change on a workload that something else also manages. A HorizontalPodAutoscaler writes through
/scale, so a narrow write competes with it cleanly, whereas a full-object update replays the entire spec on a conflict retry.Deployment and StatefulSet now change replicas through
client.SubResource("scale"). CronJob is unchanged: it has no scale subresource, andspec.suspendremains the mechanism.The two branches were near-identical, so they collapse into one helper.
The write order is deliberate and is the part worth reviewing. Annotations are written first, then the scale call. If the scale fails, the workload is still running and the next evaluation retries it, so the state corrects itself. In the other order, a failed annotation write would leave a workload stopped with no record of its previous replica count, and the zero-replica guard at the top would stop the operator ever revisiting it, making the loss permanent. There is a test for this with an injected scale failure.
RBAC gains
deployments/scaleandstatefulsets/scalewithgetandupdate. Narrow and explicit;make check-rbacconfirms the chart and the markers agree.The generic "any kind implementing /scale" variant remains rejected, with the three blockers recorded on #68 so the question is not reopened without them.
Closes #68
Test plan
make cipasses; existing scale-down tests continue to assertreplicas == 0, so the subresource path is genuinely exercised rather than silently skipped.