-
Notifications
You must be signed in to change notification settings - Fork 201
Add a set of configuration defaults #1223
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
41d77dc
49e3586
09ab296
c9f2e7a
3501801
3483f05
94b39bf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,6 +29,8 @@ import ( | |
| "sigs.k8s.io/gateway-api-inference-extension/pkg/epp/plugins" | ||
| "sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling" | ||
| "sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/framework" | ||
| "sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/framework/plugins/picker" | ||
| "sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/framework/plugins/profile" | ||
| ) | ||
|
|
||
| var scheme = runtime.NewScheme() | ||
|
|
@@ -64,18 +66,39 @@ func LoadSchedulerConfig(configProfiles []configapi.SchedulingProfile, handle pl | |
| profiles := map[string]*framework.SchedulerProfile{} | ||
| for _, namedProfile := range configProfiles { | ||
| profile := framework.NewSchedulerProfile() | ||
| pickerAdded := false | ||
| scorerAdded := false | ||
| for _, plugin := range namedProfile.Plugins { | ||
| referencedPlugin := handle.Plugin(plugin.PluginRef) | ||
| if scorer, ok := referencedPlugin.(framework.Scorer); ok { | ||
| if plugin.Weight == nil { | ||
| return nil, fmt.Errorf("scorer '%s' is missing a weight", plugin.PluginRef) | ||
| // Set default weight to 1 | ||
|
||
| weight := 1 | ||
| if plugin.Weight != nil { | ||
| weight = *plugin.Weight | ||
| } | ||
| referencedPlugin = framework.NewWeightedScorer(scorer, *plugin.Weight) | ||
| referencedPlugin = framework.NewWeightedScorer(scorer, weight) | ||
| scorerAdded = true | ||
| } | ||
| if _, ok := referencedPlugin.(framework.Picker); ok { | ||
| pickerAdded = true | ||
| } | ||
| if err := profile.AddPlugins(referencedPlugin); err != nil { | ||
| return nil, fmt.Errorf("failed to load scheduler config - %w", err) | ||
| } | ||
| } | ||
| if !pickerAdded { | ||
| // There isn't a picker in this profile, add one | ||
| var thePicker framework.Picker | ||
| if scorerAdded { | ||
| thePicker = picker.NewMaxScorePicker(picker.DefaultMaxNumOfEndpoints) | ||
| } else { | ||
| thePicker = picker.NewRandomPicker(picker.DefaultMaxNumOfEndpoints) | ||
| } | ||
|
|
||
| if err := profile.AddPlugins(thePicker); err != nil { | ||
| return nil, fmt.Errorf("failed to load scheduler config - %w", err) | ||
| } | ||
| } | ||
| profiles[namedProfile.Name] = profile | ||
| } | ||
|
|
||
|
|
@@ -89,7 +112,10 @@ func LoadSchedulerConfig(configProfiles []configapi.SchedulingProfile, handle pl | |
| } | ||
| } | ||
| if profileHandler == nil { | ||
| return nil, errors.New("no profile handler was specified") | ||
| if len(profiles) != 1 { | ||
| return nil, errors.New("no profile handler was specified") | ||
| } | ||
| profileHandler = profile.NewSingleProfileHandler() | ||
| } | ||
|
|
||
| return scheduling.NewSchedulerConfig(profileHandler, profiles), nil | ||
|
|
@@ -125,10 +151,6 @@ func instantiatePlugins(configuredPlugins []configapi.PluginSpec, handle plugins | |
| } | ||
|
|
||
| func validateSchedulingProfiles(config *configapi.EndpointPickerConfig) error { | ||
| if len(config.SchedulingProfiles) == 0 { | ||
| return errors.New("there must be at least one scheduling profile in the configuration") | ||
| } | ||
|
|
||
| profileNames := sets.New[string]() | ||
| for _, profile := range config.SchedulingProfiles { | ||
| if profile.Name == "" { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we only add the plugins that are applicable allowed in a scheduling profile? scorer, filter, picker?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At this point in time in the code, one doesn't know what the plugins are as they have not yet been instantiated.
If you want, I can move this code to the LoadSchedulingConfig function, with appropriate changes to the configuration validation code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I recommend consolidating validation in this pkg, this is the practice, validation is invoked after defaulting automatically. We can do that in a followup PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also the code in ScheculingProfile.AddPlugins, ignores any plugins that are of types other than filter, scorer, picker, or postCycle
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, but when we default and log the config, they will show up, silently ignoring them is not ideal.