featuregates

package
v0.0.0-...-6018a90 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 18, 2024 License: Apache-2.0 Imports: 21 Imported by: 49

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FeatureGateNamesToStrings

func FeatureGateNamesToStrings(in []configv1.FeatureGateName) []string

func ForceExit

func ForceExit(featureChange FeatureChange)

func NewObserveFeatureFlagsFunc

func NewObserveFeatureFlagsFunc(featureWhitelist sets.Set[configv1.FeatureGateName], featureBlacklist sets.Set[configv1.FeatureGateName], configPath []string, featureGateAccess FeatureGateAccess) configobserver.ObserveConfigFunc

NewObserveFeatureFlagsFunc produces a configobserver for feature gates. If non-nil, the featureWhitelist filters feature gates to a known subset (instead of everything). The featureBlacklist will stop certain features from making it through the list. The featureBlacklist should be empty, but for a brief time, some featuregates may need to skipped. @smarterclayton will live forever in shame for being the first to require this for "IPv6DualStack".

func StringsToFeatureGateNames

func StringsToFeatureGateNames(in []string) []configv1.FeatureGateName

Types

type FeatureChange

type FeatureChange struct {
	Previous *Features
	New      Features
}

type FeatureGate

type FeatureGate interface {
	// Enabled returns true if the key is enabled.
	Enabled(key configv1.FeatureGateName) bool
	// KnownFeatures returns a slice of strings describing the FeatureGate's known features.
	KnownFeatures() []configv1.FeatureGateName
}

FeatureGate indicates whether a given feature is enabled or not This interface is heavily influenced by k8s.io/component-base, but not exactly compatible.

func NewFeatureGate

func NewFeatureGate(enabled, disabled []configv1.FeatureGateName) FeatureGate

type FeatureGateAccess

type FeatureGateAccess interface {
	// SetChangeHandler can only be called before Run.
	// The default change handler will exit 0 when the set of featuregates changes.
	// That is usually the easiest and simplest thing for an *operator* to do.
	// This also discourages direct operand reading since all operands restarting simultaneously is bad.
	// This function allows changing that default behavior to something else (perhaps a channel notification for
	// all impacted controllers in an operator.
	// I doubt this will be worth the effort in the majority of cases.
	SetChangeHandler(featureGateChangeHandlerFn FeatureGateChangeHandlerFunc)

	// Run starts a go func that continously watches the set of featuregates enabled in the cluster.
	Run(ctx context.Context)
	// InitialFeatureGatesObserved returns a channel that is closed once the featuregates have
	// been observed. Once closed, the CurrentFeatureGates method will return the current set of
	// featuregates and will never return a non-nil error.
	InitialFeatureGatesObserved() <-chan struct{}
	// CurrentFeatureGates returns the list of enabled and disabled featuregates.
	// It returns an error if the current set of featuregates is not known.
	CurrentFeatureGates() (FeatureGate, error)
	// AreInitialFeatureGatesObserved returns true if the initial featuregates have been observed.
	AreInitialFeatureGatesObserved() bool
}

FeatureGateAccess is used to get a list of enabled and disabled featuregates. Create a new instance using NewFeatureGateAccess. To create one for unit testing, use NewHardcodedFeatureGateAccess.

func NewFeatureGateAccess

func NewFeatureGateAccess(
	desiredVersion, missingVersionMarker string,
	clusterVersionInformer v1.ClusterVersionInformer,
	featureGateInformer v1.FeatureGateInformer,
	eventRecorder events.Recorder) FeatureGateAccess

NewFeatureGateAccess returns a controller that keeps the list of enabled/disabled featuregates up to date. desiredVersion is the version of this operator that would be set on the clusteroperator.status.versions. missingVersionMarker is the stub version provided by the operator. If that is also the desired version, then the most either the desired clusterVersion or most recent version will be used. clusterVersionInformer is used when desiredVersion and missingVersionMarker are the same to derive the "best" version of featuregates to use. featureGateInformer is used to track changes to the featureGates once they are initially set. By default, when the enabled/disabled list of featuregates changes, os.Exit is called. This behavior can be overridden by calling SetChangeHandler to whatever you wish the behavior to be. A common construct is:

go

featureGateAccessor := NewFeatureGateAccess(args) go featureGateAccessor.Run(ctx)

select{ case <- featureGateAccessor.InitialFeatureGatesObserved():

featureGates, _ := featureGateAccessor.CurrentFeatureGates()
klog.Infof("FeatureGates initialized: knownFeatureGates=%v", featureGates.KnownFeatures())

case <- time.After(1*time.Minute):

	klog.Errorf("timed out waiting for FeatureGate detection")
	return fmt.Errorf("timed out waiting for FeatureGate detection")
}

// whatever other initialization you have to do, at this point you have FeatureGates to drive your behavior.

That construct is easy. It is better to use the .spec.observedConfiguration construct common in library-go operators to avoid gating your general startup on FeatureGate determination, but if you haven't already got that mechanism this construct is easy.

func NewHardcodedFeatureGateAccess

func NewHardcodedFeatureGateAccess(enabled, disabled []configv1.FeatureGateName) FeatureGateAccess

NewHardcodedFeatureGateAccess returns a FeatureGateAccess that is always initialized and always returns the provided feature gates.

func NewHardcodedFeatureGateAccessForTesting

func NewHardcodedFeatureGateAccessForTesting(enabled, disabled []configv1.FeatureGateName, initialFeatureGatesObserved chan struct{}, readErr error) FeatureGateAccess

NewHardcodedFeatureGateAccessForTesting returns a FeatureGateAccess that returns stub responses using caller-supplied values.

func NewHardcodedFeatureGateAccessFromFeatureGate

func NewHardcodedFeatureGateAccessFromFeatureGate(featureGate *configv1.FeatureGate, desiredVersion string) (FeatureGateAccess, error)

NewHardcodedFeatureGateAccessFromFeatureGate returns a FeatureGateAccess that is static and initialised from a populated FeatureGate status. If the desired version is missing, this will return an error.

type FeatureGateChangeHandlerFunc

type FeatureGateChangeHandlerFunc func(featureChange FeatureChange)

type Features

type Features struct {
	Enabled  []configv1.FeatureGateName
	Disabled []configv1.FeatureGateName
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL