Add adds features to the featureGate.
(features map[Feature]FeatureSpec)
| 263 | |
| 264 | // Add adds features to the featureGate. |
| 265 | func (f *featureGate) Add(features map[Feature]FeatureSpec) error { |
| 266 | f.lock.Lock() |
| 267 | defer f.lock.Unlock() |
| 268 | |
| 269 | if f.closed { |
| 270 | return fmt.Errorf("cannot add a feature gate after adding it to the flag set") |
| 271 | } |
| 272 | |
| 273 | // Copy existing state |
| 274 | known := map[Feature]FeatureSpec{} |
| 275 | maps.Copy(known, f.known.Load().(map[Feature]FeatureSpec)) |
| 276 | |
| 277 | for name, spec := range features { |
| 278 | if existingSpec, found := known[name]; found { |
| 279 | if existingSpec == spec { |
| 280 | continue |
| 281 | } |
| 282 | return fmt.Errorf("feature gate %q with different spec already exists: %v", name, existingSpec) |
| 283 | } |
| 284 | |
| 285 | known[name] = spec |
| 286 | } |
| 287 | |
| 288 | // Persist updated state |
| 289 | f.known.Store(known) |
| 290 | |
| 291 | return nil |
| 292 | } |
| 293 | |
| 294 | func (f *featureGate) OverrideDefault(name Feature, override bool) error { |
| 295 | f.lock.Lock() |