@@ -234,7 +234,20 @@ func (r *Runner) Run(ctx context.Context) error {
234234 return err
235235 }
236236
237- rawConfig , err := r .parseConfigurationPhaseOne (ctx )
237+ // ===================================================================
238+ // == Latency Predictor Integration
239+ // ===================================================================
240+ var predictor latencypredictor.PredictorInterface // Use the interface type
241+ if * enableLatencyPredictor {
242+ setupLog .Info ("Latency predictor is enabled. Initializing..." )
243+ predictor = latencypredictor .New (latencypredictor .ConfigFromEnv (), ctrl .Log .WithName ("latency-predictor" ))
244+ } else {
245+ setupLog .Info ("Latency predictor is disabled." )
246+ predictor = nil // This will be a true nil interface
247+ }
248+ // ===================================================================
249+
250+ rawConfig , err := r .parseConfigurationPhaseOne (ctx , predictor )
238251 if err != nil {
239252 setupLog .Error (err , "Failed to parse configuration" )
240253 return err
@@ -315,32 +328,6 @@ func (r *Runner) Run(ctx context.Context) error {
315328 runtime .SetBlockProfileRate (1 )
316329 }
317330
318- // ===================================================================
319- // == Latency Predictor Integration
320- // ===================================================================
321- var predictor latencypredictor.PredictorInterface // Use the interface type
322- if * enableLatencyPredictor {
323- setupLog .Info ("Latency predictor is enabled. Initializing..." )
324- predictor = latencypredictor .New (latencypredictor .ConfigFromEnv (), ctrl .Log .WithName ("latency-predictor" ))
325-
326- // For the runnable, you'll need to type assert back to the concrete type
327- concretePredictor := predictor .(* latencypredictor.Predictor )
328- if err := mgr .Add (runnable .NoLeaderElection (& predictorRunnable {predictor : concretePredictor })); err != nil {
329- setupLog .Error (err , "Failed to register latency predictor runnable" )
330- return err
331- }
332- } else {
333- setupLog .Info ("Latency predictor is disabled." )
334- predictor = nil // This will be a true nil interface
335- }
336- // ===================================================================
337-
338- err = r .parsePluginsConfiguration (ctx , predictor , datastore )
339- if err != nil {
340- setupLog .Error (err , "Failed to parse the configuration" )
341- return err
342- }
343-
344331 // --- Initialize Core EPP Components ---
345332 if r .schedulerConfig == nil {
346333 err := errors .New ("scheduler config must be set either by config api or through code" )
@@ -417,6 +404,12 @@ func (r *Runner) Run(ctx context.Context) error {
417404 return err
418405 }
419406
407+ if * enableLatencyPredictor && predictor != nil {
408+ if err := registerLatencyPredictorServer (mgr , predictor ); err != nil {
409+ return err
410+ }
411+ }
412+
420413 // --- Start Manager ---
421414 // This blocks until a signal is received.
422415 setupLog .Info ("Controller manager starting" )
@@ -473,7 +466,7 @@ func (r *Runner) registerLatencyPredictorPlugins(predictor latencypredictor.Pred
473466 plugins .Register (profile .SLOAwareProfileHandlerType , profile .SLOAwareProfileHandlerFactory )
474467}
475468
476- func (r * Runner ) parseConfigurationPhaseOne (ctx context.Context ) (* configapi.EndpointPickerConfig , error ) {
469+ func (r * Runner ) parseConfigurationPhaseOne (ctx context.Context , predictor latencypredictor. PredictorInterface ) (* configapi.EndpointPickerConfig , error ) {
477470 if * configText == "" && * configFile == "" {
478471 return nil , nil // configuring through code, not through file
479472 }
@@ -702,6 +695,18 @@ func registerHealthServer(mgr manager.Manager, logger logr.Logger, ds datastore.
702695 return nil
703696}
704697
698+ // registerLatencyPredictorServer adds the Latency Predictor server as a Runnable to the given manager.
699+ func registerLatencyPredictorServer (mgr manager.Manager , predictor latencypredictor.PredictorInterface ) error {
700+ // For the runnable, you'll need to type assert back to the concrete type
701+ concretePredictor := predictor .(* latencypredictor.Predictor )
702+ if err := mgr .Add (runnable .NoLeaderElection (& predictorRunnable {predictor : concretePredictor })); err != nil {
703+ setupLog .Error (err , "Failed to register latency predictor runnable" )
704+ return err
705+ }
706+ setupLog .Info ("Latency predictor runnable added to manager." )
707+ return nil
708+ }
709+
705710func validateFlags () error {
706711 if (* poolName != "" && * endpointSelector != "" ) || (* poolName == "" && * endpointSelector == "" ) {
707712 return errors .New ("either pool-name or endpoint-selector must be set" )
0 commit comments