| 1 |
/* |
| 2 |
Copyright 2025 The Kubernetes Authors. |
| 3 |
|
| 4 |
Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 |
you may not use this file except in compliance with the License. |
| 6 |
You may obtain a copy of the License at |
| 7 |
|
| 8 |
http://www.apache.org/licenses/LICENSE-2.0 |
| 9 |
|
| 10 |
Unless required by applicable law or agreed to in writing, software |
| 11 |
distributed under the License is distributed on an "AS IS" BASIS, |
| 12 |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 |
See the License for the specific language governing permissions and |
| 14 |
limitations under the License. |
| 15 |
*/ |
| 16 |
|
| 17 |
package compatibility |
| 18 |
|
| 19 |
import ( |
| 20 |
utilruntime "k8s.io/apimachinery/pkg/util/runtime" |
| 21 |
utilfeature "k8s.io/apiserver/pkg/util/feature" |
| 22 |
basecompatibility "k8s.io/component-base/compatibility" |
| 23 |
) |
| 24 |
|
| 25 |
// DefaultComponentGlobalsRegistry is the global var to store the effective versions and feature gates for all components for easy access. |
| 26 |
// Example usage: |
| 27 |
// // register the component effective version and feature gate first |
| 28 |
// wardleEffectiveVersion := basecompatibility.NewEffectiveVersion("1.2") |
| 29 |
// wardleFeatureGate := featuregate.NewFeatureGate() |
| 30 |
// utilruntime.Must(compatibility.DefaultComponentGlobalsRegistry.Register(apiserver.WardleComponentName, wardleEffectiveVersion, wardleFeatureGate, false)) |
| 31 |
// |
| 32 |
// cmd := &cobra.Command{ |
| 33 |
// ... |
| 34 |
// // call DefaultComponentGlobalsRegistry.Set() in PersistentPreRunE to ensure the feature gates are set based on emulation version right after parsing the flags. |
| 35 |
// PersistentPreRunE: func(*cobra.Command, []string) error { |
| 36 |
// if err := compatibility.DefaultComponentGlobalsRegistry.Set(); err != nil { |
| 37 |
// return err |
| 38 |
// } |
| 39 |
// ... |
| 40 |
// }, |
| 41 |
// RunE: func(c *cobra.Command, args []string) error { |
| 42 |
// // call compatibility.DefaultComponentGlobalsRegistry.Validate() somewhere |
| 43 |
// }, |
| 44 |
// } |
| 45 |
// |
| 46 |
// flags := cmd.Flags() |
| 47 |
// // add flags |
| 48 |
// compatibility.DefaultComponentGlobalsRegistry.AddFlags(flags) |
| 49 |
var DefaultComponentGlobalsRegistry basecompatibility.ComponentGlobalsRegistry = basecompatibility.NewComponentGlobalsRegistry() |
| 50 |
|
| 51 |
func init() { |
| 52 |
utilruntime.Must(DefaultComponentGlobalsRegistry.Register(basecompatibility.DefaultKubeComponent, DefaultBuildEffectiveVersion(), utilfeature.DefaultMutableFeatureGate)) |
| 53 |
} |