Skip to content

Commit 522d88f

Browse files
committed
Moved config validation into a separate file
Signed-off-by: Shmuel Kallner <[email protected]>
1 parent eb2fbc5 commit 522d88f

File tree

2 files changed

+55
-46
lines changed

2 files changed

+55
-46
lines changed

pkg/epp/config/loader/configloader.go

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -187,53 +187,7 @@ func instantiatePlugins(configuredPlugins []configapi.PluginSpec, handle plugins
187187
return nil
188188
}
189189

190-
func validateSchedulingProfiles(config *configapi.EndpointPickerConfig) error {
191-
profileNames := sets.New[string]()
192-
for _, profile := range config.SchedulingProfiles {
193-
if profile.Name == "" {
194-
return errors.New("SchedulingProfile must have a name")
195-
}
196-
197-
if profileNames.Has(profile.Name) {
198-
return fmt.Errorf("the name '%s' has been specified for more than one SchedulingProfile", profile.Name)
199-
}
200-
profileNames.Insert(profile.Name)
201-
202-
for _, plugin := range profile.Plugins {
203-
if len(plugin.PluginRef) == 0 {
204-
return fmt.Errorf("SchedulingProfile '%s' plugins must have a plugin reference", profile.Name)
205-
}
206-
207-
notFound := true
208-
for _, pluginConfig := range config.Plugins {
209-
if plugin.PluginRef == pluginConfig.Name {
210-
notFound = false
211-
break
212-
}
213-
}
214-
if notFound {
215-
return errors.New(plugin.PluginRef + " is a reference to an undefined Plugin")
216-
}
217-
}
218-
}
219-
return nil
220-
}
221-
222190
// RegisterFeatureGate registers feature gate keys for validation
223191
func RegisterFeatureGate(gate string) {
224192
registeredFeatureGates[gate] = struct{}{}
225193
}
226-
227-
func validateFeatureGates(fg configapi.FeatureGates) error {
228-
if fg == nil {
229-
return nil
230-
}
231-
232-
for gate := range fg {
233-
if _, ok := registeredFeatureGates[gate]; !ok {
234-
return errors.New(gate + " is an unregistered Feature Gate")
235-
}
236-
}
237-
238-
return nil
239-
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package loader
2+
3+
import (
4+
"errors"
5+
"fmt"
6+
7+
"k8s.io/apimachinery/pkg/util/sets"
8+
configapi "sigs.k8s.io/gateway-api-inference-extension/apix/config/v1alpha1"
9+
)
10+
11+
func validateSchedulingProfiles(config *configapi.EndpointPickerConfig) error {
12+
profileNames := sets.New[string]()
13+
for _, profile := range config.SchedulingProfiles {
14+
if profile.Name == "" {
15+
return errors.New("SchedulingProfile must have a name")
16+
}
17+
18+
if profileNames.Has(profile.Name) {
19+
return fmt.Errorf("the name '%s' has been specified for more than one SchedulingProfile", profile.Name)
20+
}
21+
profileNames.Insert(profile.Name)
22+
23+
for _, plugin := range profile.Plugins {
24+
if len(plugin.PluginRef) == 0 {
25+
return fmt.Errorf("SchedulingProfile '%s' plugins must have a plugin reference", profile.Name)
26+
}
27+
28+
notFound := true
29+
for _, pluginConfig := range config.Plugins {
30+
if plugin.PluginRef == pluginConfig.Name {
31+
notFound = false
32+
break
33+
}
34+
}
35+
if notFound {
36+
return errors.New(plugin.PluginRef + " is a reference to an undefined Plugin")
37+
}
38+
}
39+
}
40+
return nil
41+
}
42+
43+
func validateFeatureGates(fg configapi.FeatureGates) error {
44+
if fg == nil {
45+
return nil
46+
}
47+
48+
for _, gate := range fg {
49+
if _, ok := registeredFeatureGates[gate]; !ok {
50+
return errors.New(gate + " is an unregistered Feature Gate")
51+
}
52+
}
53+
54+
return nil
55+
}

0 commit comments

Comments
 (0)