@@ -172,20 +172,6 @@ func NewPolicyHandler(config HandlerConfig) (*Handler, error) {
172172 return h , nil
173173}
174174
175- func (h * Handler ) configureHorizontalPolicy () error {
176-
177- err := h .loadCheckRunners ()
178- if err != nil {
179- return fmt .Errorf ("failed to load check handlers: %w" , err )
180- }
181-
182- h .minCount = h .policy .Min
183- h .maxCount = h .policy .Max
184-
185- h .calculateNewCount = h .calculateHorizontalNewCount
186- return nil
187- }
188-
189175func (h * Handler ) loadCheckRunners () error {
190176 runners := []* checkRunner {}
191177
@@ -211,6 +197,7 @@ func (h *Handler) loadCheckRunners() error {
211197 runners = append (runners , runner )
212198 }
213199
200+ // Do the update as a single operation to avoid partial updates.
214201 h .checkRunners = runners
215202 return nil
216203}
@@ -397,24 +384,22 @@ func (h *Handler) updateHandler(updatedPolicy *sdk.ScalingPolicy) {
397384
398385 switch updatedPolicy .Type {
399386 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 ()
387+ err := h .updateHorizontalPolicy (updatedPolicy )
403388 if err != nil {
404- h .errChn <- fmt .Errorf ("unable to update horizontal policy: %w" , err )
389+ h .errChn <- fmt .Errorf ("unable to update horizontal policy %w" , err )
405390 return
406391 }
407392
408393 default :
409- err := h .configureVerticalPolicy ( )
394+ err := h .updateVerticalPolicy ( updatedPolicy )
410395 if err != nil {
411- h .errChn <- fmt .Errorf ("unable to update vertical policy: %w" , err )
396+ h .errChn <- fmt .Errorf ("unable to update vertical policy %w" , err )
397+ return
412398 }
413399 }
414400
415- h .log .Debug ("policy successfully updated" )
416401 h .policy = updatedPolicy
417-
402+ h . log . Debug ( "policy successfully updated" )
418403}
419404
420405// applyMutators applies the mutators registered with the handler in order and
0 commit comments