@@ -30,6 +30,7 @@ import (
30
30
31
31
utilerrors "k8s.io/apimachinery/pkg/util/errors"
32
32
"k8s.io/apimachinery/pkg/util/naming"
33
+ "k8s.io/apimachinery/pkg/util/sets"
33
34
"k8s.io/apimachinery/pkg/util/version"
34
35
featuremetrics "k8s.io/component-base/metrics/prometheus/feature"
35
36
baseversion "k8s.io/component-base/version"
@@ -265,7 +266,7 @@ func NewVersionedFeatureGate(emulationVersion *version.Version) *featureGate {
265
266
f .enabled .Store (map [Feature ]bool {})
266
267
f .enabledRaw .Store (map [string ]bool {})
267
268
f .emulationVersion .Store (emulationVersion )
268
- f .queriedFeatures .Store (map [Feature ]struct {} {})
269
+ f .queriedFeatures .Store (sets. Set [Feature ]{})
269
270
klog .V (1 ).Infof ("new feature gate with emulationVersion=%s" , f .emulationVersion .Load ().String ())
270
271
return f
271
272
}
@@ -530,7 +531,7 @@ func (f *featureGate) SetEmulationVersion(emulationVersion *version.Version) err
530
531
enabled := map [Feature ]bool {}
531
532
errs := f .unsafeSetFromMap (enabled , enabledRaw , emulationVersion )
532
533
533
- queriedFeatures := f .queriedFeatures .Load ().(map [Feature ]struct {} )
534
+ queriedFeatures := f .queriedFeatures .Load ().(sets. Set [Feature ])
534
535
known := f .known .Load ().(map [Feature ]VersionedSpecs )
535
536
for feature := range queriedFeatures {
536
537
newVal := featureEnabled (feature , enabled , known , emulationVersion )
@@ -544,7 +545,7 @@ func (f *featureGate) SetEmulationVersion(emulationVersion *version.Version) err
544
545
// Persist changes
545
546
f .enabled .Store (enabled )
546
547
f .emulationVersion .Store (emulationVersion )
547
- f .queriedFeatures .Store (map [Feature ]struct {} {})
548
+ f .queriedFeatures .Store (sets. Set [Feature ]{})
548
549
}
549
550
return utilerrors .NewAggregate (errs )
550
551
}
@@ -564,15 +565,14 @@ func (f *featureGate) featureSpec(key Feature) (FeatureSpec, error) {
564
565
}
565
566
566
567
func (f * featureGate ) unsafeRecordQueried (key Feature ) {
567
- queriedFeatures := map [Feature ]struct {}{}
568
- for k := range f .queriedFeatures .Load ().(map [Feature ]struct {}) {
569
- queriedFeatures [k ] = struct {}{}
570
- }
568
+ queriedFeatures := f .queriedFeatures .Load ().(sets.Set [Feature ])
571
569
if _ , ok := queriedFeatures [key ]; ok {
572
570
return
573
571
}
574
- queriedFeatures [key ] = struct {}{}
575
- f .queriedFeatures .Store (queriedFeatures )
572
+ // Clone items from queriedFeatures before mutating it
573
+ newQueriedFeatures := queriedFeatures .Clone ()
574
+ newQueriedFeatures .Insert (key )
575
+ f .queriedFeatures .Store (newQueriedFeatures )
576
576
}
577
577
578
578
func featureEnabled (key Feature , enabled map [Feature ]bool , known map [Feature ]VersionedSpecs , emulationVersion * version.Version ) bool {
@@ -700,7 +700,7 @@ func (f *featureGate) DeepCopy() MutableVersionedFeatureGate {
700
700
fg .known .Store (known )
701
701
fg .enabled .Store (enabled )
702
702
fg .enabledRaw .Store (enabledRaw )
703
- fg .queriedFeatures .Store (map [Feature ]struct {} {})
703
+ fg .queriedFeatures .Store (sets. Set [Feature ]{})
704
704
return fg
705
705
}
706
706
0 commit comments