Repository navigation
feat: Implement scale-to-zero support for BudAIScaler - #4
Conversation
The CRD now allows maxReplicas=0, but the controller had a redundant validation that rejected it. Removed to allow complete workload disable. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Summary of ChangesHello @dittops, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces comprehensive scale-to-zero functionality for the Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request implements scale-to-zero support for BudAIScaler, which is a valuable feature for resource optimization. The changes include updates to the CRD, status tracking, and scaling algorithms to handle zero-replica states. The modification in budaiscaler_controller.go correctly removes the validation that prevented maxReplicas: 0, enabling workloads to be manually disabled. However, my review identified a critical side-effect of this change: a potential division-by-zero panic in the cost metrics collection logic when a workload is scaled to zero. This must be addressed before merging.
I am having trouble creating individual review comments. Click here to see my feedback.
pkg/controller/budaiscaler/budaiscaler_controller.go (206-208)
While removing this validation is necessary to support maxReplicas: 0, it introduces a critical risk of a division-by-zero panic.
The collectCostMetrics function in pkg/controller/budaiscaler/autoscaler.go calculates perReplicaCost by dividing by currentReplicas. When a workload is scaled to zero as a result of this change, currentReplicas will be 0, causing the controller to panic.
This affects both the logging statement and the returned CostMetrics struct. You should add a check to handle the currentReplicas == 0 case.
Recommendation:
In pkg/controller/budaiscaler/autoscaler.go, update collectCostMetrics to safely handle zero replicas:
// in collectCostMetrics function
var perReplicaCost float64
if currentReplicas > 0 {
perReplicaCost = hourlyCost / float64(currentReplicas)
}
klog.V(4).InfoS("Cost metrics calculated",
"provider", provider,
"replicas", currentReplicas,
"hourlyCost", hourlyCost,
"budgetPerHour", budgetPerHour,
"perReplicaCost", perReplicaCost)
return &types.CostMetrics{
CurrentCostPerHour: hourlyCost,
BudgetPerHour: budgetPerHour,
PerReplicaCostPerHour: perReplicaCost,
}
Summary
ScaleToZeroConfigto CRD for configuring scale-to-zero behavior with grace period and activation scalemaxReplicas: 0to completely disable workloads and free resourcesZeroDemandSincein status for grace period calculationFeatures
scaleToZeroConfigwith grace period before scaling to 0maxReplicas: 0to immediately scale to 0Example Usage
Test plan
maxReplicas: 0in k3d cluster - deployment scales to 0minReplicas: 1🤖 Generated with Claude Code