@@ -31,43 +31,40 @@ const DefaultScorerWeight = 1
3131
3232var defaultScorerWeight = DefaultScorerWeight
3333
34- // applyStaticDefaults standardizes the configuration object before plugin instantiation.
35- // It handles simple structural defaults that do not require knowledge of the plugin registry.
34+ // applyStaticDefaults sanitizes the configuration object before plugin instantiation.
35+ // It handles "Static" defaults: simple structural changes to the API object that do not require access to the plugin
36+ // registry.
3637func applyStaticDefaults (cfg * configapi.EndpointPickerConfig ) {
37- // Infer plugin names. If a plugin has a Type but no Name, the Type becomes the Name.
3838 for idx , pluginConfig := range cfg .Plugins {
3939 if pluginConfig .Name == "" {
4040 cfg .Plugins [idx ].Name = pluginConfig .Type
4141 }
4242 }
4343
44- // Initialize feature gates.
4544 if cfg .FeatureGates == nil {
4645 cfg .FeatureGates = configapi.FeatureGates {}
4746 }
4847}
4948
50- // applySystemDefaults injects required architectural components that were omitted from the config.
51- // It inspects the instantiated plugins (via the handle) and ensures the system graph is complete.
49+ // applySystemDefaults injects required components that were omitted from the config.
50+ // It handles "System" defaults: logic that requires inspecting instantiated plugins (via the handle) to ensure the
51+ // system graph is complete.
5252func applySystemDefaults (cfg * configapi.EndpointPickerConfig , handle plugins.Handle ) error {
5353 allPlugins := handle .GetAllPluginsWithNames ()
54-
55- // Ensure the scheduling layer has profiles, pickers, and handlers.
56- if err := ensureSchedulingArchitecture (cfg , handle , allPlugins ); err != nil {
54+ if err := ensureSchedulingLayer (cfg , handle , allPlugins ); err != nil {
5755 return fmt .Errorf ("failed to apply scheduling system defaults: %w" , err )
5856 }
59-
6057 return nil
6158}
6259
63- // ensureSchedulingArchitecture guarantees that a valid scheduling profile exists and that all profiles have valid
64- // Pickers and Handlers.
65- func ensureSchedulingArchitecture (
60+ // ensureSchedulingLayer guarantees that the scheduling subsystem is structurally complete.
61+ // It ensures a valid profile exists and injects missing architectural components (like Pickers and ProfileHandlers) if
62+ // they are not explicitly configured.
63+ func ensureSchedulingLayer (
6664 cfg * configapi.EndpointPickerConfig ,
6765 handle plugins.Handle ,
6866 allPlugins map [string ]plugins.Plugin ,
6967) error {
70- // Ensure at least one Scheduling Profile exists.
7168 if len (cfg .SchedulingProfiles ) == 0 {
7269 defaultProfile := configapi.SchedulingProfile {Name : "default" }
7370 // Auto-populate the default profile with all Filter, Scorer, and Picker plugins found.
@@ -80,7 +77,6 @@ func ensureSchedulingArchitecture(
8077 cfg .SchedulingProfiles = []configapi.SchedulingProfile {defaultProfile }
8178 }
8279
83- // Ensure profile handler.
8480 // If there is only 1 profile and no handler is explicitly configured, use the SingleProfileHandler.
8581 if len (cfg .SchedulingProfiles ) == 1 {
8682 hasHandler := false
@@ -91,13 +87,12 @@ func ensureSchedulingArchitecture(
9187 }
9288 }
9389 if ! hasHandler {
94- if err := registerDefaultPlugin (cfg , handle , profile .SingleProfileHandlerType , profile . SingleProfileHandlerType ); err != nil {
90+ if err := registerDefaultPlugin (cfg , handle , profile .SingleProfileHandlerType ); err != nil {
9591 return err
9692 }
9793 }
9894 }
9995
100- // Ensure Picker(s) and Scorer weights.
10196 // Find or Create a default MaxScorePicker to reuse across profiles.
10297 var maxScorePickerName string
10398 for name , p := range allPlugins {
@@ -106,32 +101,28 @@ func ensureSchedulingArchitecture(
106101 break
107102 }
108103 }
109- // If no Picker exists anywhere, create one.
104+
110105 if maxScorePickerName == "" {
111- if err := registerDefaultPlugin (cfg , handle , picker .MaxScorePickerType , picker . MaxScorePickerType ); err != nil {
106+ if err := registerDefaultPlugin (cfg , handle , picker .MaxScorePickerType ); err != nil {
112107 return err
113108 }
114109 maxScorePickerName = picker .MaxScorePickerType
115110 }
116111
117- // Update profiles.
118112 for i , prof := range cfg .SchedulingProfiles {
119113 hasPicker := false
120114 for j , pluginRef := range prof .Plugins {
121115 p := handle .Plugin (pluginRef .PluginRef )
122116
123- // Default Scorer weight.
124117 if _ , ok := p .(framework.Scorer ); ok && pluginRef .Weight == nil {
125118 cfg .SchedulingProfiles [i ].Plugins [j ].Weight = & defaultScorerWeight
126119 }
127120
128- // Check for Picker.
129121 if _ , ok := p .(framework.Picker ); ok {
130122 hasPicker = true
131123 }
132124 }
133125
134- // Inject default Picker if missing.
135126 if ! hasPicker {
136127 cfg .SchedulingProfiles [i ].Plugins = append (
137128 cfg .SchedulingProfiles [i ].Plugins ,
@@ -148,15 +139,14 @@ func ensureSchedulingArchitecture(
148139func registerDefaultPlugin (
149140 cfg * configapi.EndpointPickerConfig ,
150141 handle plugins.Handle ,
151- name string ,
152142 pluginType string ,
153143) error {
144+ name := pluginType
154145 factory , ok := plugins .Registry [pluginType ]
155146 if ! ok {
156147 return fmt .Errorf ("plugin type '%s' not found in registry" , pluginType )
157148 }
158149
159- // Instantiate with nil config (factory must handle defaults).
160150 plugin , err := factory (name , nil , handle )
161151 if err != nil {
162152 return fmt .Errorf ("failed to instantiate default plugin '%s': %w" , name , err )
0 commit comments