@@ -173,14 +173,17 @@ func NewPolicyHandler(config HandlerConfig) (*Handler, error) {
173
173
}
174
174
175
175
func (h * Handler ) configureHorizontalPolicy () error {
176
+ return h .updateHorizontalPolicy (h .policy )
177
+ }
176
178
179
+ func (h * Handler ) updateHorizontalPolicy (up * sdk.ScalingPolicy ) error {
177
180
err := h .loadCheckRunners ()
178
181
if err != nil {
179
182
return fmt .Errorf ("failed to load check handlers: %w" , err )
180
183
}
181
184
182
- h .minCount = h . policy .Min
183
- h .maxCount = h . policy .Max
185
+ h .minCount = up .Min
186
+ h .maxCount = up .Max
184
187
185
188
h .calculateNewCount = h .calculateHorizontalNewCount
186
189
return nil
@@ -211,6 +214,7 @@ func (h *Handler) loadCheckRunners() error {
211
214
runners = append (runners , runner )
212
215
}
213
216
217
+ // Do the update as a single operation to avoid partial updates.
214
218
h .checkRunners = runners
215
219
return nil
216
220
}
@@ -397,24 +401,22 @@ func (h *Handler) updateHandler(updatedPolicy *sdk.ScalingPolicy) {
397
401
398
402
switch updatedPolicy .Type {
399
403
case sdk .ScalingPolicyTypeCluster , sdk .ScalingPolicyTypeHorizontal :
400
- h .log .Debug ("updating check handlers" , "old_checks" , len (h .policy .Checks ),
401
- "new_checks" , len (updatedPolicy .Checks ))
402
- err := h .configureHorizontalPolicy ()
404
+ err := h .updateHorizontalPolicy (updatedPolicy )
403
405
if err != nil {
404
- h .errChn <- fmt .Errorf ("unable to update horizontal policy: %w" , err )
406
+ h .errChn <- fmt .Errorf ("unable to update horizontal policy %w" , err )
405
407
return
406
408
}
407
409
408
410
default :
409
- err := h .configureVerticalPolicy ( )
411
+ err := h .updateVerticalPolicy ( updatedPolicy )
410
412
if err != nil {
411
- h .errChn <- fmt .Errorf ("unable to update vertical policy: %w" , err )
413
+ h .errChn <- fmt .Errorf ("unable to update vertical policy %w" , err )
414
+ return
412
415
}
413
416
}
414
417
415
- h .log .Debug ("policy successfully updated" )
416
418
h .policy = updatedPolicy
417
-
419
+ h . log . Debug ( "policy successfully updated" )
418
420
}
419
421
420
422
// applyMutators applies the mutators registered with the handler in order and
0 commit comments