@@ -99,7 +99,6 @@ func (s *Autoscaler) LoadWorkloads(ctx context.Context) {
99
99
100
100
observedWorkloads := map [string ]bool {}
101
101
for _ , workload := range workloadList .Items {
102
- autoScalingConfig := workload .Spec .AutoScalingConfig
103
102
if ! workload .DeletionTimestamp .IsZero () {
104
103
continue
105
104
}
@@ -111,7 +110,7 @@ func (s *Autoscaler) LoadWorkloads(ctx context.Context) {
111
110
}
112
111
workloadState .Namespace = workload .Namespace
113
112
workloadState .Resources = workload .Spec .Resources
114
- workloadState .AutoScalingConfig = autoScalingConfig
113
+ workloadState .AutoScalingConfig = workload . Spec . AutoScalingConfig
115
114
s .WorkloadStates [workloadName ] = workloadState
116
115
117
116
observedWorkloads [workloadName ] = true
@@ -218,44 +217,40 @@ func (s *Autoscaler) ProcessWorkloads(ctx context.Context) {
218
217
continue
219
218
}
220
219
221
- // TODO: apply config
222
- // asConfig := workloadState.AutoScalingConfig
223
- // NewResourceRecommenderFromAutoScalingConfig(ResouceRecomenderConfig{
224
- // }).GetRecommendedResources(workloadState)
225
220
rr := s .ResourceRecommender .GetRecommendedResources (workloadState )
226
- log .Info ("Autoscaler processWorkloads " , "recommended resources" , rr )
221
+ log .Info ("recommend resources " , "workload" , workloadState . Name , " resources" , rr )
227
222
228
223
for _ , worker := range podList .Items {
229
224
if ! worker .DeletionTimestamp .IsZero () {
230
225
continue
231
226
}
232
227
233
- if err := s .updateWorker (ctx , & worker , rr ); err != nil {
228
+ if err := s .updateWorkerResourcesIfNeeded (ctx , workloadState , & worker , rr ); err != nil {
234
229
log .Error (err , "failed to update worker" )
235
230
}
236
231
}
237
232
}
238
233
}
239
234
240
- func (s * Autoscaler ) updateWorker (ctx context.Context , worker * corev1.Pod , rr * RecommendedResources ) error {
241
- annotations := worker .GetAnnotations ()
242
- newAnnotations := map [string ]string {}
243
-
235
+ func (s * Autoscaler ) updateWorkerResourcesIfNeeded (ctx context.Context , workloadState * WorkloadState , worker * corev1.Pod , rr * RecommendedResources ) error {
244
236
resourcesInfo := []struct {
237
+ name string
245
238
requestKey string
246
239
limitKey string
247
240
lowerBound ResourceAmount
248
241
upperBound ResourceAmount
249
242
target ResourceAmount
250
243
}{
251
244
{
245
+ name : "tflops" ,
252
246
requestKey : constants .TFLOPSRequestAnnotation ,
253
247
limitKey : constants .TFLOPSLimitAnnotation ,
254
248
lowerBound : rr .LowerBoundTflops ,
255
249
upperBound : rr .UpperBoundTflops ,
256
250
target : rr .TargetTflops ,
257
251
},
258
252
{
253
+ name : "vram" ,
259
254
requestKey : constants .VRAMRequestAnnotation ,
260
255
limitKey : constants .VRAMLimitAnnotation ,
261
256
lowerBound : rr .LowerBoundVram ,
@@ -264,8 +259,13 @@ func (s *Autoscaler) updateWorker(ctx context.Context, worker *corev1.Pod, rr *R
264
259
},
265
260
}
266
261
262
+ annotations := worker .GetAnnotations ()
263
+ newAnnotations := map [string ]string {}
267
264
for _ , resInfo := range resourcesInfo {
268
- if err := updateResource (
265
+ if ! workloadState .IsTargetResource (resInfo .name ) {
266
+ continue
267
+ }
268
+ if err := detectResourceChanges (
269
269
annotations , newAnnotations ,
270
270
resInfo .requestKey , resInfo .limitKey ,
271
271
resInfo .lowerBound , resInfo .upperBound , resInfo .target ,
@@ -291,7 +291,7 @@ func (s *Autoscaler) updateWorker(ctx context.Context, worker *corev1.Pod, rr *R
291
291
return nil
292
292
}
293
293
294
- func updateResource (annotations , newAnnotations map [string ]string , requestKey , limitKey string , lowerBound , upperBound , target ResourceAmount ) error {
294
+ func detectResourceChanges (annotations , newAnnotations map [string ]string , requestKey , limitKey string , lowerBound , upperBound , target ResourceAmount ) error {
295
295
currentRequest , err := resource .ParseQuantity (annotations [requestKey ])
296
296
if err != nil {
297
297
return fmt .Errorf ("failed to parse %s: %v" , requestKey , err )
0 commit comments