@@ -30,6 +30,7 @@ import (
3030
3131 utilerrors "k8s.io/apimachinery/pkg/util/errors"
3232 "k8s.io/apimachinery/pkg/util/naming"
33+ "k8s.io/apimachinery/pkg/util/sets"
3334 "k8s.io/apimachinery/pkg/util/version"
3435 featuremetrics "k8s.io/component-base/metrics/prometheus/feature"
3536 baseversion "k8s.io/component-base/version"
@@ -265,7 +266,7 @@ func NewVersionedFeatureGate(emulationVersion *version.Version) *featureGate {
265266 f .enabled .Store (map [Feature ]bool {})
266267 f .enabledRaw .Store (map [string ]bool {})
267268 f .emulationVersion .Store (emulationVersion )
268- f .queriedFeatures .Store (map [Feature ]struct {} {})
269+ f .queriedFeatures .Store (sets. Set [Feature ]{})
269270 klog .V (1 ).Infof ("new feature gate with emulationVersion=%s" , f .emulationVersion .Load ().String ())
270271 return f
271272}
@@ -530,7 +531,7 @@ func (f *featureGate) SetEmulationVersion(emulationVersion *version.Version) err
530531 enabled := map [Feature ]bool {}
531532 errs := f .unsafeSetFromMap (enabled , enabledRaw , emulationVersion )
532533
533- queriedFeatures := f .queriedFeatures .Load ().(map [Feature ]struct {} )
534+ queriedFeatures := f .queriedFeatures .Load ().(sets. Set [Feature ])
534535 known := f .known .Load ().(map [Feature ]VersionedSpecs )
535536 for feature := range queriedFeatures {
536537 newVal := featureEnabled (feature , enabled , known , emulationVersion )
@@ -544,7 +545,7 @@ func (f *featureGate) SetEmulationVersion(emulationVersion *version.Version) err
544545 // Persist changes
545546 f .enabled .Store (enabled )
546547 f .emulationVersion .Store (emulationVersion )
547- f .queriedFeatures .Store (map [Feature ]struct {} {})
548+ f .queriedFeatures .Store (sets. Set [Feature ]{})
548549 }
549550 return utilerrors .NewAggregate (errs )
550551}
@@ -564,15 +565,14 @@ func (f *featureGate) featureSpec(key Feature) (FeatureSpec, error) {
564565}
565566
566567func (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 ])
571569 if _ , ok := queriedFeatures [key ]; ok {
572570 return
573571 }
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 )
576576}
577577
578578func featureEnabled (key Feature , enabled map [Feature ]bool , known map [Feature ]VersionedSpecs , emulationVersion * version.Version ) bool {
@@ -700,7 +700,7 @@ func (f *featureGate) DeepCopy() MutableVersionedFeatureGate {
700700 fg .known .Store (known )
701701 fg .enabled .Store (enabled )
702702 fg .enabledRaw .Store (enabledRaw )
703- fg .queriedFeatures .Store (map [Feature ]struct {} {})
703+ fg .queriedFeatures .Store (sets. Set [Feature ]{})
704704 return fg
705705}
706706
0 commit comments