Documentation ¶
Index ¶
Constants ¶
const (
DefaultKubeComponent = "kube"
)
Variables ¶
This section is empty.
Functions ¶
func NewComponentGlobalsRegistry ¶
func NewComponentGlobalsRegistry() *componentGlobalsRegistry
func ValidateKubeEffectiveVersion ¶
func ValidateKubeEffectiveVersion(effectiveVersion EffectiveVersion) error
ValidateKubeEffectiveVersion validates the EmulationVersion is equal to the binary version at 1.31 for kube components. TODO: remove in 1.32 emulationVersion is introduced in 1.31, so it is only allowed to be equal to the binary version at 1.31.
Types ¶
type ComponentGlobals ¶
type ComponentGlobals struct {
// contains filtered or unexported fields
}
ComponentGlobals stores the global variables for a component for easy access.
type ComponentGlobalsRegistry ¶
type ComponentGlobalsRegistry interface { // EffectiveVersionFor returns the EffectiveVersion registered under the component. // Returns nil if the component is not registered. EffectiveVersionFor(component string) EffectiveVersion // FeatureGateFor returns the FeatureGate registered under the component. // Returns nil if the component is not registered. FeatureGateFor(component string) featuregate.FeatureGate // Register registers the EffectiveVersion and FeatureGate for a component. // returns error if the component is already registered. Register(component string, effectiveVersion MutableEffectiveVersion, featureGate featuregate.MutableVersionedFeatureGate) error // ComponentGlobalsOrRegister would return the registered global variables for the component if it already exists in the registry. // Otherwise, the provided variables would be registered under the component, and the same variables would be returned. ComponentGlobalsOrRegister(component string, effectiveVersion MutableEffectiveVersion, featureGate featuregate.MutableVersionedFeatureGate) (MutableEffectiveVersion, featuregate.MutableVersionedFeatureGate) // AddFlags adds flags of "--emulated-version" and "--feature-gates" AddFlags(fs *pflag.FlagSet) // Set sets the flags for all global variables for all components registered. Set() error // SetFallback calls Set() if it has never been called. SetFallback() error // Validate calls the Validate() function for all the global variables for all components registered. Validate() []error // Reset removes all stored ComponentGlobals, configurations, and version mappings. Reset() // SetEmulationVersionMapping sets the mapping from the emulation version of one component // to the emulation version of another component. // Once set, the emulation version of the toComponent will be determined by the emulation version of the fromComponent, // and cannot be set from cmd flags anymore. // For a given component, its emulation version can only depend on one other component, no multiple dependency is allowed. SetEmulationVersionMapping(fromComponent, toComponent string, f VersionMapping) error }
var DefaultComponentGlobalsRegistry ComponentGlobalsRegistry = NewComponentGlobalsRegistry()
DefaultComponentGlobalsRegistry is the global var to store the effective versions and feature gates for all components for easy access. Example usage: // register the component effective version and feature gate first _, _ = utilversion.DefaultComponentGlobalsRegistry.ComponentGlobalsOrRegister(utilversion.DefaultKubeComponent, utilversion.DefaultKubeEffectiveVersion(), utilfeature.DefaultMutableFeatureGate) wardleEffectiveVersion := utilversion.NewEffectiveVersion("1.2") wardleFeatureGate := featuregate.NewFeatureGate() utilruntime.Must(utilversion.DefaultComponentGlobalsRegistry.Register(apiserver.WardleComponentName, wardleEffectiveVersion, wardleFeatureGate, false))
cmd := &cobra.Command{ ... // call DefaultComponentGlobalsRegistry.Set() in PersistentPreRunE PersistentPreRunE: func(*cobra.Command, []string) error { if err := utilversion.DefaultComponentGlobalsRegistry.Set(); err != nil { return err } ... }, RunE: func(c *cobra.Command, args []string) error { // call utilversion.DefaultComponentGlobalsRegistry.Validate() somewhere }, }
flags := cmd.Flags() // add flags utilversion.DefaultComponentGlobalsRegistry.AddFlags(flags)
type EffectiveVersion ¶
type MutableEffectiveVersion ¶
type MutableEffectiveVersion interface { EffectiveVersion Set(binaryVersion, emulationVersion, minCompatibilityVersion *version.Version) SetEmulationVersion(emulationVersion *version.Version) SetMinCompatibilityVersion(minCompatibilityVersion *version.Version) }
func DefaultBuildEffectiveVersion ¶
func DefaultBuildEffectiveVersion() MutableEffectiveVersion
DefaultBuildEffectiveVersion returns the MutableEffectiveVersion based on the current build information.
func DefaultKubeEffectiveVersion ¶
func DefaultKubeEffectiveVersion() MutableEffectiveVersion
DefaultKubeEffectiveVersion returns the MutableEffectiveVersion based on the latest K8s release.
func NewEffectiveVersion ¶
func NewEffectiveVersion(binaryVer string) MutableEffectiveVersion