Skip to content

Commit bc7e7b0

Browse files
committed
Updated config loading to support FeatureGates as a map[string]bool
Signed-off-by: Shmuel Kallner <[email protected]>
1 parent 98e766d commit bc7e7b0

File tree

1 file changed

+28
-4
lines changed

1 file changed

+28
-4
lines changed

pkg/epp/config/loader/configloader.go

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ func LoadConfig(configBytes []byte, handle plugins.Handle, logger logr.Logger) (
5151

5252
logger.Info("Loaded configuration", "config", rawConfig)
5353

54+
if err = validateFeatureGates(rawConfig.FeatureGates); err != nil {
55+
return nil, fmt.Errorf("failed to validate feature gates - %w", err)
56+
}
57+
5458
setDefaultsPhaseOne(rawConfig)
5559

5660
// instantiate loaded plugins
@@ -121,11 +125,18 @@ func loadSchedulerConfig(configProfiles []configapi.SchedulingProfile, handle pl
121125
return scheduling.NewSchedulerConfig(profileHandler, profiles), nil
122126
}
123127

124-
func loadFeatureConfig(featureGates *configapi.FeatureGates) config.FeatureConfig {
125-
featureConfig := config.FeatureConfig{}
128+
func loadFeatureConfig(featureGates *configapi.FeatureGates) map[string]bool {
129+
featureConfig := map[string]bool{}
126130

127-
featureConfig.EnableDataLayer = featureGates.EnableDataLayer
128-
featureConfig.EnableFlowControl = featureGates.EnableFlowControl
131+
for gate := range registeredFeatureGates {
132+
featureConfig[gate] = false
133+
}
134+
135+
if featureGates != nil {
136+
for gate, enabled := range *featureGates {
137+
featureConfig[gate] = enabled
138+
}
139+
}
129140

130141
return featureConfig
131142
}
@@ -215,3 +226,16 @@ func RegisterFeatureGate(gate string) {
215226
registeredFeatureGates[gate] = struct{}{}
216227
}
217228

229+
func validateFeatureGates(fg *configapi.FeatureGates) error {
230+
if fg == nil {
231+
return nil
232+
}
233+
234+
for gate := range *fg {
235+
if _, ok := registeredFeatureGates[gate]; !ok {
236+
return errors.New(gate + " is an unregistered Feature Gate")
237+
}
238+
}
239+
240+
return nil
241+
}

0 commit comments

Comments
 (0)