@@ -227,7 +227,20 @@ func (r *Runner) Run(ctx context.Context) error {
227227 return err
228228 }
229229
230- rawConfig , err := r .parseConfigurationPhaseOne (ctx )
230+ // ===================================================================
231+ // == Latency Predictor Integration
232+ // ===================================================================
233+ var predictor latencypredictor.PredictorInterface // Use the interface type
234+ if * enableLatencyPredictor {
235+ setupLog .Info ("Latency predictor is enabled. Initializing..." )
236+ predictor = latencypredictor .New (latencypredictor .ConfigFromEnv (), ctrl .Log .WithName ("latency-predictor" ))
237+ } else {
238+ setupLog .Info ("Latency predictor is disabled." )
239+ predictor = nil // This will be a true nil interface
240+ }
241+ // ===================================================================
242+
243+ rawConfig , err := r .parseConfigurationPhaseOne (ctx , predictor )
231244 if err != nil {
232245 setupLog .Error (err , "Failed to parse configuration" )
233246 return err
@@ -322,32 +335,6 @@ func (r *Runner) Run(ctx context.Context) error {
322335 runtime .SetBlockProfileRate (1 )
323336 }
324337
325- // ===================================================================
326- // == Latency Predictor Integration
327- // ===================================================================
328- var predictor latencypredictor.PredictorInterface // Use the interface type
329- if * enableLatencyPredictor {
330- setupLog .Info ("Latency predictor is enabled. Initializing..." )
331- predictor = latencypredictor .New (latencypredictor .ConfigFromEnv (), ctrl .Log .WithName ("latency-predictor" ))
332-
333- // For the runnable, you'll need to type assert back to the concrete type
334- concretePredictor := predictor .(* latencypredictor.Predictor )
335- if err := mgr .Add (runnable .NoLeaderElection (& predictorRunnable {predictor : concretePredictor })); err != nil {
336- setupLog .Error (err , "Failed to register latency predictor runnable" )
337- return err
338- }
339- } else {
340- setupLog .Info ("Latency predictor is disabled." )
341- predictor = nil // This will be a true nil interface
342- }
343- // ===================================================================
344-
345- err = r .parsePluginsConfiguration (ctx , predictor , datastore )
346- if err != nil {
347- setupLog .Error (err , "Failed to parse the configuration" )
348- return err
349- }
350-
351338 // --- Initialize Core EPP Components ---
352339 if r .schedulerConfig == nil {
353340 err := errors .New ("scheduler config must be set either by config api or through code" )
@@ -420,6 +407,12 @@ func (r *Runner) Run(ctx context.Context) error {
420407 return err
421408 }
422409
410+ if * enableLatencyPredictor && predictor != nil {
411+ if err := registerLatencyPredictorServer (mgr , predictor ); err != nil {
412+ return err
413+ }
414+ }
415+
423416 // --- Start Manager ---
424417 // This blocks until a signal is received.
425418 setupLog .Info ("Controller manager starting" )
@@ -454,7 +447,7 @@ func (r *Runner) registerLatencyPredictorPlugins(predictor latencypredictor.Pred
454447 plugins .Register (profile .SLOAwareProfileHandlerType , profile .SLOAwareProfileHandlerFactory )
455448}
456449
457- func (r * Runner ) parseConfigurationPhaseOne (ctx context.Context ) (* configapi.EndpointPickerConfig , error ) {
450+ func (r * Runner ) parseConfigurationPhaseOne (ctx context.Context , predictor latencypredictor. PredictorInterface ) (* configapi.EndpointPickerConfig , error ) {
458451 if * configText == "" && * configFile == "" {
459452 return nil , nil // configuring through code, not through file
460453 }
@@ -683,6 +676,18 @@ func registerHealthServer(mgr manager.Manager, logger logr.Logger, ds datastore.
683676 return nil
684677}
685678
679+ // registerLatencyPredictorServer adds the Latency Predictor server as a Runnable to the given manager.
680+ func registerLatencyPredictorServer (mgr manager.Manager , predictor latencypredictor.PredictorInterface ) error {
681+ // For the runnable, you'll need to type assert back to the concrete type
682+ concretePredictor := predictor .(* latencypredictor.Predictor )
683+ if err := mgr .Add (runnable .NoLeaderElection (& predictorRunnable {predictor : concretePredictor })); err != nil {
684+ setupLog .Error (err , "Failed to register latency predictor runnable" )
685+ return err
686+ }
687+ setupLog .Info ("Latency predictor runnable added to manager." )
688+ return nil
689+ }
690+
686691func validateFlags () error {
687692 if * poolName == "" {
688693 return fmt .Errorf ("required %q flag not set" , "poolName" )
0 commit comments