@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
14
14
limitations under the License.
15
15
*/
16
16
17
- package config
17
+ package loader
18
18
19
19
import (
20
20
"errors"
@@ -25,8 +25,11 @@ import (
25
25
"k8s.io/apimachinery/pkg/runtime/serializer"
26
26
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
27
27
28
+ "sigs.k8s.io/gateway-api-inference-extension/api/config/v1alpha1"
28
29
configapi "sigs.k8s.io/gateway-api-inference-extension/api/config/v1alpha1"
29
30
"sigs.k8s.io/gateway-api-inference-extension/pkg/epp/plugins"
31
+ "sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling"
32
+ "sigs.k8s.io/gateway-api-inference-extension/pkg/epp/scheduling/framework"
30
33
)
31
34
32
35
var scheme = runtime .NewScheme ()
@@ -62,19 +65,61 @@ func LoadConfig(configText []byte, fileName string) (*configapi.EndpointPickerCo
62
65
return theConfig , nil
63
66
}
64
67
65
- func LoadPluginReferences (thePlugins []configapi.PluginSpec , handle plugins.Handle ) (map [string ]plugins.Plugin , error ) {
66
- references := map [string ]plugins.Plugin {}
68
+ func LoadPluginReferences (thePlugins []configapi.PluginSpec , handle plugins.Handle ) error {
67
69
for _ , pluginConfig := range thePlugins {
68
- thePlugin , err := InstantiatePlugin (pluginConfig , handle )
70
+ thePlugin , err := instantiatePlugin (pluginConfig , handle )
69
71
if err != nil {
70
- return nil , err
72
+ return err
71
73
}
72
- references [ pluginConfig .Name ] = thePlugin
74
+ handle . Plugins (). AddPlugin ( pluginConfig .Name , thePlugin )
73
75
}
74
- return references , nil
76
+ return nil
77
+ }
78
+
79
+ func LoadSchedulerConfig (configProfiles []v1alpha1.SchedulingProfile , handle plugins.Handle ) (* scheduling.SchedulerConfig , error ) {
80
+
81
+ var profiles = map [string ]* framework.SchedulerProfile {}
82
+
83
+ for _ , configProfile := range configProfiles {
84
+ profile := framework.SchedulerProfile {}
85
+
86
+ for _ , plugin := range configProfile .Plugins {
87
+ var err error
88
+ thePlugin := handle .Plugins ().Plugin (plugin .PluginRef )
89
+ if theScorer , ok := thePlugin .(framework.Scorer ); ok {
90
+ if plugin .Weight == nil {
91
+ return nil , fmt .Errorf ("scorer '%s' is missing a weight" , plugin .PluginRef )
92
+ }
93
+ thePlugin = framework .NewWeightedScorer (theScorer , * plugin .Weight )
94
+ }
95
+ err = profile .AddPlugins (thePlugin )
96
+ if err != nil {
97
+ return nil , err
98
+ }
99
+ }
100
+ profiles [configProfile .Name ] = & profile
101
+ }
102
+
103
+ var profileHandler framework.ProfileHandler
104
+ var profileHandlerName string
105
+
106
+ for pluginName , thePlugin := range handle .Plugins ().GetAllPluginsWithNames () {
107
+ if theProfileHandler , ok := thePlugin .(framework.ProfileHandler ); ok {
108
+ if profileHandler != nil {
109
+ return nil , fmt .Errorf ("only one profile handler is allowed. Both %s and %s are profile handlers" , profileHandlerName , pluginName )
110
+ }
111
+ profileHandler = theProfileHandler
112
+ profileHandlerName = pluginName
113
+ }
114
+ }
115
+ if profileHandler == nil {
116
+ return nil , errors .New ("no profile handler was specified" )
117
+ }
118
+
119
+ return scheduling .NewSchedulerConfig (profileHandler , profiles ), nil
75
120
}
76
121
77
- func InstantiatePlugin (pluginSpec configapi.PluginSpec , handle plugins.Handle ) (plugins.Plugin , error ) {
122
+ func instantiatePlugin (pluginSpec configapi.PluginSpec , handle plugins.Handle ) (plugins.Plugin , error ) {
78
123
factory , ok := plugins .Registry [pluginSpec .PluginName ]
79
124
if ! ok {
80
125
return nil , fmt .Errorf ("failed to instantiate the plugin. plugin %s not found" , pluginSpec .PluginName )
0 commit comments