Skip to content

Commit e22b847

Browse files
committed
feat: add auto-scaling switch config parsing and apply, TargetResource support value all
1 parent c748df6 commit e22b847

File tree

4 files changed

+48
-4
lines changed

4 files changed

+48
-4
lines changed

internal/autoscaler/autoscaler.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,12 @@ func (s *Autoscaler) ProcessWorkloads(ctx context.Context) {
220220
rr := s.ResourceRecommender.GetRecommendedResources(workloadState)
221221
log.Info("recommend resources", "workload", workloadState.Name, "resources", rr)
222222

223+
// TODO: update recommmendation status of workload
224+
225+
if !workloadState.IsAutoScalingEnabled() {
226+
continue
227+
}
228+
223229
for _, worker := range podList.Items {
224230
if !worker.DeletionTimestamp.IsZero() {
225231
continue

internal/autoscaler/autoscaler_test.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ var _ = Describe("Autoscaler", func() {
184184
}).Should(Succeed())
185185
})
186186

187-
It("should update specific resources based on TargetResource", func() {
187+
It("should update resources based on auto scaling config", func() {
188188
tfEnv := NewTensorFusionEnvBuilder().
189189
AddPoolWithNodeCount(1).SetGpuCountPerNode(1).
190190
Build()
@@ -199,9 +199,22 @@ var _ = Describe("Autoscaler", func() {
199199
rr := scaler.ResourceRecommender.GetRecommendedResources(nil)
200200

201201
workloadState := scaler.WorkloadStates[workload.Name]
202-
workloadState.AutoScalingConfig.AutoSetResources.TargetResource = "tflops"
203-
204202
oldRes := workloadState.Resources
203+
204+
// verify IsAutoScalingEnabled
205+
workloadState.AutoScalingConfig.AutoSetResources.Enable = false
206+
scaler.ProcessWorkloads(ctx)
207+
Eventually(func(g Gomega) {
208+
tflopsRequest, tflopsLimit, vramRequest, vramLimit := parseResourceAnnotations(getWorkers(workload)[0])
209+
Expect(tflopsRequest.Equal(oldRes.Requests.Tflops)).To(BeTrue())
210+
Expect(tflopsLimit.Equal(oldRes.Limits.Tflops)).To(BeTrue())
211+
Expect(vramRequest.Equal(oldRes.Requests.Vram)).To(BeTrue())
212+
Expect(vramLimit.Equal(oldRes.Limits.Vram)).To(BeTrue())
213+
}).Should(Succeed())
214+
215+
// verify IsTargetResource
216+
workloadState.AutoScalingConfig.AutoSetResources.Enable = true
217+
workloadState.AutoScalingConfig.AutoSetResources.TargetResource = "tflops"
205218
scaler.ProcessWorkloads(ctx)
206219
Eventually(func(g Gomega) {
207220
tflopsRequest, tflopsLimit, vramRequest, vramLimit := parseResourceAnnotations(getWorkers(workload)[0])

internal/autoscaler/workloadstate.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package autoscaler
22

33
import (
44
"strconv"
5+
"strings"
56
"time"
67

78
tfv1 "github.com/NexusGPU/tensor-fusion/api/v1"
@@ -100,5 +101,9 @@ func (w *WorkloadState) GetResourceRecommenderConfig() *ResourceRecommenderConfi
100101

101102
func (w *WorkloadState) IsTargetResource(resourceName string) bool {
102103
target := w.AutoScalingConfig.AutoSetResources.TargetResource
103-
return target == "" || resourceName == target
104+
return target == "" || strings.EqualFold(target, "all") || strings.EqualFold(resourceName, target)
105+
}
106+
107+
func (w *WorkloadState) IsAutoScalingEnabled() bool {
108+
return w.AutoScalingConfig.AutoSetResources.Enable
104109
}

internal/autoscaler/workloadstate_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,13 @@ var _ = Describe("Workload State", func() {
8282
Expect(ws.IsTargetResource("tflops")).To(BeTrue())
8383
Expect(ws.IsTargetResource("vram")).To(BeTrue())
8484

85+
ws.AutoScalingConfig = tfv1.AutoScalingConfig{
86+
AutoSetResources: tfv1.AutoSetResources{TargetResource: "all"},
87+
}
88+
89+
Expect(ws.IsTargetResource("tflops")).To(BeTrue())
90+
Expect(ws.IsTargetResource("vram")).To(BeTrue())
91+
8592
ws.AutoScalingConfig = tfv1.AutoScalingConfig{
8693
AutoSetResources: tfv1.AutoSetResources{TargetResource: "tflops"},
8794
}
@@ -94,4 +101,17 @@ var _ = Describe("Workload State", func() {
94101
Expect(ws.IsTargetResource("tflops")).To(BeFalse())
95102
Expect(ws.IsTargetResource("vram")).To(BeTrue())
96103
})
104+
105+
It("should correctly determine if auto scaling is enabled based on config", func() {
106+
ws := NewWorkloadState("test")
107+
108+
ws.AutoScalingConfig = tfv1.AutoScalingConfig{
109+
AutoSetResources: tfv1.AutoSetResources{Enable: true},
110+
}
111+
Expect(ws.IsAutoScalingEnabled()).To(BeTrue())
112+
ws.AutoScalingConfig = tfv1.AutoScalingConfig{
113+
AutoSetResources: tfv1.AutoSetResources{Enable: false},
114+
}
115+
Expect(ws.IsAutoScalingEnabled()).To(BeFalse())
116+
})
97117
})

0 commit comments

Comments
 (0)