Skip to content

Commit fe5dea3

Browse files
authored
Reintroduce Plugin.Name() (#1057)
* rename Factory function as FactoryFunc Signed-off-by: Etai Lev Ran <[email protected]> * Refactor field name from PluginName to Type JSON tags are not changed yet as it would impact all test files/sample YAML. Will be in a follow up commit. Signed-off-by: Etai Lev Ran <[email protected]> * Review test cases Added comments describing test beyond the already descriptive name (e.g., field Plugins was initially called PluginReference so names can be a little misleading when using PluginRef - it's not the scheduling profile's references). Removed redundant test case (coverage is still 100%). Signed-off-by: Etai Lev Ran <[email protected]> * Change pluginName to type in encoding Change the JSON tag on type Change test files and test cases' text to use type instead of pluginName Signed-off-by: Etai Lev Ran <[email protected]> * implement Name() for all plugins Signed-off-by: Etai Lev Ran <[email protected]> * Added WithName() to all plugins Plugins (except testing only plugins) now allow calling WithName() to assign their name. Facory functions work by calling New() to avoid code duplication and centralize parameter checking. When constructing an unnamed Plugin, its name defaults to Type() Signed-off-by: Etai Lev Ran <[email protected]> * implement review comments Set plugin name to its type explicitly in New() Remove empty name check from WithName() Refine error message in config loading (added plugin name for missing type) Signed-off-by: Etai Lev Ran <[email protected]> * change Name() comment Signed-off-by: Etai Lev Ran <[email protected]> --------- Signed-off-by: Etai Lev Ran <[email protected]>
1 parent 36175ba commit fe5dea3

File tree

22 files changed

+308
-133
lines changed

22 files changed

+308
-133
lines changed

api/config/v1alpha1/defaults.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ package v1alpha1
2323
func SetDefaults_EndpointPickerConfig(cfg *EndpointPickerConfig) {
2424
for idx, pluginConfig := range cfg.Plugins {
2525
if pluginConfig.Name == "" {
26-
cfg.Plugins[idx].Name = pluginConfig.PluginName
26+
cfg.Plugins[idx].Name = pluginConfig.Type
2727
}
2828
}
2929
}

api/config/v1alpha1/endpointpickerconfig_types.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,13 @@ type EndpointPickerConfig struct {
4646
type PluginSpec struct {
4747
// +optional
4848
// Name provides a name for plugin entries to reference. If
49-
// omitted, the value of the PluginName field will be used.
49+
// omitted, the value of the Plugin's Type field will be used.
5050
Name string `json:"name"`
5151

5252
// +required
5353
// +kubebuilder:validation:Required
54-
// PluginName specifies the plugin to be instantiated.
55-
PluginName string `json:"pluginName"`
54+
// Type specifies the plugin type to be instantiated.
55+
Type string `json:"type"`
5656

5757
// +optional
5858
// Parameters are the set of parameters to be passed to the plugin's

conformance/testing-epp/plugins/filter/request_header_based_filter.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ func (f *HeaderBasedTestingFilter) Type() string {
4949
return "header-based-testing"
5050
}
5151

52+
// Name returns the type of the filter.
53+
func (f *HeaderBasedTestingFilter) Name() string {
54+
return "header-based-testing-filter"
55+
}
56+
5257
// Filter selects pods that match the IP addresses specified in the request header.
5358
func (f *HeaderBasedTestingFilter) Filter(_ context.Context, _ *types.CycleState, request *types.LLMRequest, pods []types.Pod) []types.Pod {
5459
headerValue, ok := request.Headers[headerTestEppEndPointSelectionKey]

pkg/epp/common/config/loader/configloader.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,13 @@ func LoadSchedulerConfig(configProfiles []v1alpha1.SchedulingProfile, handle plu
120120
}
121121

122122
func instantiatePlugin(pluginSpec configapi.PluginSpec, handle plugins.Handle) (plugins.Plugin, error) {
123-
factory, ok := plugins.Registry[pluginSpec.PluginName]
123+
factory, ok := plugins.Registry[pluginSpec.Type]
124124
if !ok {
125-
return nil, fmt.Errorf("failed to instantiate the plugin. plugin %s not found", pluginSpec.PluginName)
125+
return nil, fmt.Errorf("failed to instantiate the plugin. plugin type %s not found", pluginSpec.Type)
126126
}
127127
thePlugin, err := factory(pluginSpec.Name, pluginSpec.Parameters, handle)
128128
if err != nil {
129-
return nil, fmt.Errorf("failed to instantiate the plugin %s. Error: %s", pluginSpec.PluginName, err)
129+
return nil, fmt.Errorf("failed to instantiate the plugin type %s. Error: %s", pluginSpec.Type, err)
130130
}
131131
return thePlugin, err
132132
}
@@ -135,18 +135,18 @@ func validateConfiguration(theConfig *configapi.EndpointPickerConfig) error {
135135
names := make(map[string]struct{})
136136

137137
for _, pluginConfig := range theConfig.Plugins {
138-
if pluginConfig.PluginName == "" {
139-
return errors.New("plugin reference definition missing a plugin name")
138+
if pluginConfig.Type == "" {
139+
return fmt.Errorf("plugin definition for %s is missing a type", pluginConfig.Name)
140140
}
141141

142142
if _, ok := names[pluginConfig.Name]; ok {
143-
return fmt.Errorf("the name %s has been specified for more than one plugin", pluginConfig.Name)
143+
return fmt.Errorf("plugin name %s used more than once", pluginConfig.Name)
144144
}
145145
names[pluginConfig.Name] = struct{}{}
146146

147-
_, ok := plugins.Registry[pluginConfig.PluginName]
147+
_, ok := plugins.Registry[pluginConfig.Type]
148148
if !ok {
149-
return fmt.Errorf("plugin %s is not found", pluginConfig.PluginName)
149+
return fmt.Errorf("plugin type %s is not found", pluginConfig.Type)
150150
}
151151
}
152152

0 commit comments

Comments
 (0)