- .github
- applyconfigurations
- discovery
- dynamic
- examples
- features
- gentype
- informers
- kubernetes
- kubernetes_test
- listers
- metadata
- openapi
- openapi3
- pkg
- plugin
-
rest
-
fake
-
testdata
-
watch
- OWNERS
- client.go
- client_test.go
- config.go
- config_test.go
- connection_test.go
- exec.go
- exec_test.go
- plugin.go
- plugin_test.go
- request.go
- request_test.go
- request_watchlist_test.go
- transport.go
- transport_test.go
- url_utils.go
- url_utils_test.go
- urlbackoff.go
- urlbackoff_test.go
- warnings.go
- with_retry.go
- with_retry_test.go
- zz_generated.deepcopy.go
-
fake
- restmapper
- scale
- testing
- third_party
- tools
- transport
- util
- CHANGELOG.md
- CONTRIBUTING.md
- INSTALL.md
- LICENSE
- OWNERS
- README.md
- SECURITY_CONTACTS
- code-of-conduct.md
- doc.go
- go.mod
- go.sum
Explanation
This code defines a feature gate system within the k8s.io/client-go
library. Feature gates enable the control of experimental or unstable features within the Kubernetes client-go library. Here’s a breakdown:
Types:
prerelease
: Represents the maturity level of a feature (Alpha, Beta, GA, DEPRECATED).Feature
: Represents the name of a specific feature (e.g., “MyFeature”).FeatureSpec
: Stores information about a feature, including its default state (Default
), whether it’s locked to its default (LockToDefault
), and its maturity level (PreRelease
).
Interfaces:
Gates
: Defines a generic interface for feature gate management. Provides a single methodEnabled(key Feature)
to check if a feature is enabled.Registry
: An interface for external feature gate registries. Allows adding feature specifications to an existing registry.
Feature Gates Implementation:
FeatureGates()
: This function returns the currently activeGates
instance. By default, this is an implementation that reads feature state from environment variables.AddFeaturesToExistingFeatureGates(registry Registry)
: Adds the default Kubernetes feature gates to an existing registry. This is typically used in conjunction withReplaceFeatureGates
to gain control over the feature gate system.ReplaceFeatureGates(newFeatureGates Gates)
: Overwrites the default feature gate implementation with a custom one. This allows external code to manage feature gates via alternative mechanisms like command line flags.
Internal Implementation:
envVarFeatureGates
: A concrete implementation of theGates
interface that reads feature state from environment variables.featureGatesWrapper
: A thin wrapper forGates
to comply with theatomic.Value
type.featureGates
: An atomic value that stores the currentfeatureGatesWrapper
, providing thread-safe access to the global feature gate instance.
Key Points:
- Default Behavior: The library starts with a default set of feature gates, managed by environment variables.
- Control: The library provides mechanisms for external code to take control of the feature gate system and manage features through custom implementations.
- Warning: The code includes a warning mechanism that is triggered when the default feature gate implementation is overwritten after environment variables have been read, potentially leading to unexpected behavior.
Overall:
This code provides a flexible feature gate system that allows the Kubernetes client-go library to enable or disable experimental features and control their maturity levels. The system is designed to be extensible, allowing external code to manage feature gates according to its own needs.
Graph
The graph shows the usage of functions within the codebase.
Select a code symbol to view it's graph