Repository: kubernetes/kubernetes
File: staging/src/k8s.io/component-base/featuregate/feature_gate.go (Go)

Code before:
func (f *featureGate) Dependencies() map[Feature][]Feature {
	return maps.Clone(*f.dependencies.Load())
}

//logcheck:context // OverridedDefaultWithLogger must be used instead.
func (f *featureGate) OverrideDefault(name Feature, override bool) error {
	return f.OverrideDefaultWithLogger(klog.Background(), name, override)
}

func (f *featureGate) OverrideDefaultWithLogger(logger klog.Logger, name Feature, override bool) error {
	helper, logger := logger.WithCallStackHelper()
	helper()
	return f.overrideDefaultAtEmulationAndMinCompatVersion(logger, name, override, f.EmulationVersion(), f.MinCompatibilityVersion())
}

//logcheck:context // OverrideDefaultAtWithLogger must be used instead.
func (f *featureGate) OverrideDefaultAtVersion(name Feature, override bool, ver *version.Version) error {
	return f.OverrideDefaultAtVersionWithLogger(klog.Background(), name, override, ver)
}

func (f *featureGate) OverrideDefaultAtVersionWithLogger(logger klog.Logger, name Feature, override bool, ver *version.Version) error {
	helper, logger := logger.WithCallStackHelper()
	helper()
	return f.overrideDefaultAtEmulationAndMinCompatVersion(logger, name, override, ver, nil)
}

func (f *featureGate) overrideDefaultAtEmulationAndMinCompatVersion(logger klog.Logger, name Feature, override bool, emuVer, minCompatVer *version.Version) error {
	helper, logger := logger.WithCallStackHelper()
	helper()

	f.lock.Lock()
	defer f.lock.Unlock()

	if f.closed {
		return fmt.Errorf("cannot override default for feature %q: gates already added to a flag set", name)
	}

	// Copy existing state
	known := f.GetAllVersioned()

	specs, ok := known[name]
	if !ok {
		return fmt.Errorf("cannot override default: feature %q is not registered", name)
	}
	spec := featureSpecAtEmulationAndMinCompatVersion(specs, emuVer, minCompatVer)
	switch {
	case spec.LockToDefault:
		return fmt.Errorf("cannot override default: feature %q default is locked to %t", name, spec.Default)
	case spec.PreRelease == PreAlpha:
		return fmt.Errorf("cannot override default: feature %q is not available before version %s", name, emuVer)
	case spec.PreRelease == Deprecated:

Review comment (refactor):
Is making this a `helper()` correct once callers call this method directly and no longer call OverrideDefaultAtVersion?

The same question applies to other ___WithLogger() invocations of helper() ... I'm having a hard time understanding when we do and don't mark these as helpers

Code after:
	}
}

func (f *featureGate) Dependencies() map[Feature][]Feature {
	return maps.Clone(*f.dependencies.Load())
}

//logcheck:context // OverridedDefaultWithLogger must be used instead.
func (f *featureGate) OverrideDefault(name Feature, override bool) error {
	return f.OverrideDefaultWithLogger(klog.Background(), name, override)
}

func (f *featureGate) OverrideDefaultWithLogger(logger klog.Logger, name Feature, override bool) error {
	helper, logger := logger.WithCallStackHelper()
	helper()
	return f.overrideDefaultAtEmulationAndMinCompatVersion(logger, name, override, f.EmulationVersion(), f.MinCompatibilityVersion())
}

//logcheck:context // OverrideDefaultAtWithLogger must be used instead.
func (f *featureGate) OverrideDefaultAtVersion(name Feature, override bool, ver *version.Version) error {
	return f.OverrideDefaultAtVersionWithLogger(klog.Background(), name, override, ver)
}

func (f *featureGate) OverrideDefaultAtVersionWithLogger(logger klog.Logger, name Feature, override bool, ver *version.Version) error {
	helper, logger := logger.WithCallStackHelper()
	helper()
	return f.overrideDefaultAtEmulationAndMinCompatVersion(logger, name, override, ver, nil)
}

func (f *featureGate) overrideDefaultAtEmulationAndMinCompatVersion(logger klog.Logger, name Feature, override bool, emuVer, minCompatVer *version.Version) error {
	helper, logger := logger.WithCallStackHelper()
	helper()

	f.lock.Lock()
	defer f.lock.Unlock()

	if f.closed {
		return fmt.Errorf("cannot override default for feature %q: gates already added to a flag set", name)
	}

	// Copy existing state
	known := f.GetAllVersioned()

	specs, ok := known[name]
	if !ok {
		return fmt.Errorf("cannot override default: feature %q is not registered", name)
	}
	spec := featureSpecAtEmulationAndMinCompatVersion(specs, emuVer, minCompatVer)
	switch {
	case spec.LockToDefault:
		return fmt.Errorf("cannot override default: feature %q default is locked to %t", name, spec.Default)