mirror of
https://github.com/optim-enterprises-bv/kubernetes.git
synced 2025-11-01 18:58:18 +00:00
Split k8s.io/component-base/registry and add into k8s.io/component-base/version and k8s.io/component-base/featuregate
This commit is contained in:
@@ -38,7 +38,7 @@ import (
|
||||
"k8s.io/component-base/featuregate"
|
||||
"k8s.io/component-base/logs"
|
||||
"k8s.io/component-base/metrics"
|
||||
utilversion "k8s.io/component-base/registry"
|
||||
utilversion "k8s.io/component-base/version"
|
||||
kapi "k8s.io/kubernetes/pkg/apis/core"
|
||||
controlplaneapiserver "k8s.io/kubernetes/pkg/controlplane/apiserver/options"
|
||||
"k8s.io/kubernetes/pkg/controlplane/reconcilers"
|
||||
@@ -48,7 +48,7 @@ import (
|
||||
)
|
||||
|
||||
func TestAddFlags(t *testing.T) {
|
||||
componentGlobalsRegistry := utilversion.DefaultComponentGlobalsRegistry
|
||||
componentGlobalsRegistry := featuregate.DefaultComponentGlobalsRegistry
|
||||
t.Cleanup(func() {
|
||||
componentGlobalsRegistry.Reset()
|
||||
})
|
||||
@@ -149,7 +149,7 @@ func TestAddFlags(t *testing.T) {
|
||||
JSONPatchMaxCopyBytes: int64(3 * 1024 * 1024),
|
||||
MaxRequestBodyBytes: int64(3 * 1024 * 1024),
|
||||
ComponentGlobalsRegistry: componentGlobalsRegistry,
|
||||
ComponentName: utilversion.DefaultKubeComponent,
|
||||
ComponentName: featuregate.DefaultKubeComponent,
|
||||
},
|
||||
Admission: &kubeoptions.AdmissionOptions{
|
||||
GenericAdmission: &apiserveroptions.AdmissionOptions{
|
||||
|
||||
@@ -24,7 +24,7 @@ import (
|
||||
|
||||
genericoptions "k8s.io/apiserver/pkg/server/options"
|
||||
utilfeature "k8s.io/apiserver/pkg/util/feature"
|
||||
utilversion "k8s.io/component-base/registry"
|
||||
utilversion "k8s.io/component-base/version"
|
||||
netutils "k8s.io/utils/net"
|
||||
|
||||
controlplaneapiserver "k8s.io/kubernetes/pkg/controlplane/apiserver/options"
|
||||
|
||||
@@ -36,17 +36,17 @@ import (
|
||||
serverstorage "k8s.io/apiserver/pkg/server/storage"
|
||||
utilfeature "k8s.io/apiserver/pkg/util/feature"
|
||||
"k8s.io/apiserver/pkg/util/notfoundhandler"
|
||||
utilversion "k8s.io/apiserver/pkg/util/version"
|
||||
"k8s.io/apiserver/pkg/util/webhook"
|
||||
clientgoinformers "k8s.io/client-go/informers"
|
||||
"k8s.io/client-go/rest"
|
||||
cliflag "k8s.io/component-base/cli/flag"
|
||||
"k8s.io/component-base/cli/globalflag"
|
||||
"k8s.io/component-base/featuregate"
|
||||
"k8s.io/component-base/logs"
|
||||
logsapi "k8s.io/component-base/logs/api/v1"
|
||||
_ "k8s.io/component-base/metrics/prometheus/workqueue"
|
||||
"k8s.io/component-base/term"
|
||||
"k8s.io/component-base/version"
|
||||
utilversion "k8s.io/component-base/version"
|
||||
"k8s.io/component-base/version/verflag"
|
||||
"k8s.io/klog/v2"
|
||||
aggregatorapiserver "k8s.io/kube-aggregator/pkg/apiserver"
|
||||
@@ -64,8 +64,8 @@ func init() {
|
||||
|
||||
// NewAPIServerCommand creates a *cobra.Command object with default parameters
|
||||
func NewAPIServerCommand() *cobra.Command {
|
||||
_, featureGate := utilversion.DefaultComponentGlobalsRegistry.ComponentGlobalsOrRegister(
|
||||
utilversion.DefaultKubeComponent, utilversion.DefaultBuildEffectiveVersion(), utilfeature.DefaultMutableFeatureGate)
|
||||
_, featureGate := featuregate.DefaultComponentGlobalsRegistry.ComponentGlobalsOrRegister(
|
||||
featuregate.DefaultKubeComponent, utilversion.DefaultBuildEffectiveVersion(), utilfeature.DefaultMutableFeatureGate)
|
||||
s := options.NewServerRunOptions()
|
||||
|
||||
cmd := &cobra.Command{
|
||||
@@ -78,7 +78,7 @@ cluster's shared state through which all other components interact.`,
|
||||
// stop printing usage when the command errors
|
||||
SilenceUsage: true,
|
||||
PersistentPreRunE: func(*cobra.Command, []string) error {
|
||||
if err := utilversion.DefaultComponentGlobalsRegistry.Set(); err != nil {
|
||||
if err := featuregate.DefaultComponentGlobalsRegistry.Set(); err != nil {
|
||||
return err
|
||||
}
|
||||
// silence client-go warnings.
|
||||
@@ -139,7 +139,7 @@ cluster's shared state through which all other components interact.`,
|
||||
// Run runs the specified APIServer. This should never exit.
|
||||
func Run(ctx context.Context, opts options.CompletedOptions) error {
|
||||
// To help debugging, immediately log version
|
||||
klog.Infof("Version: %+v", version.Get())
|
||||
klog.Infof("Version: %+v", utilversion.Get())
|
||||
|
||||
klog.InfoS("Golang settings", "GOGC", os.Getenv("GOGC"), "GOMAXPROCS", os.Getenv("GOMAXPROCS"), "GOTRACEBACK", os.Getenv("GOTRACEBACK"))
|
||||
|
||||
|
||||
@@ -55,9 +55,10 @@ import (
|
||||
clientgotransport "k8s.io/client-go/transport"
|
||||
"k8s.io/client-go/util/cert"
|
||||
"k8s.io/client-go/util/keyutil"
|
||||
"k8s.io/component-base/featuregate"
|
||||
featuregatetesting "k8s.io/component-base/featuregate/testing"
|
||||
logsapi "k8s.io/component-base/logs/api/v1"
|
||||
utilversion "k8s.io/component-base/registry"
|
||||
utilversion "k8s.io/component-base/version"
|
||||
"k8s.io/klog/v2"
|
||||
"k8s.io/kube-aggregator/pkg/apiserver"
|
||||
"k8s.io/kubernetes/pkg/features"
|
||||
@@ -204,8 +205,8 @@ func StartTestServer(t ktesting.TB, instanceOptions *TestServerInstanceOptions,
|
||||
}
|
||||
// need to call SetFeatureGateEmulationVersionDuringTest to reset the feature gate emulation version at the end of the test.
|
||||
featuregatetesting.SetFeatureGateEmulationVersionDuringTest(t, featureGate, effectiveVersion.EmulationVersion())
|
||||
utilversion.DefaultComponentGlobalsRegistry.Reset()
|
||||
utilruntime.Must(utilversion.DefaultComponentGlobalsRegistry.Register(utilversion.DefaultKubeComponent, effectiveVersion, featureGate))
|
||||
featuregate.DefaultComponentGlobalsRegistry.Reset()
|
||||
utilruntime.Must(featuregate.DefaultComponentGlobalsRegistry.Register(featuregate.DefaultKubeComponent, effectiveVersion, featureGate))
|
||||
|
||||
s := options.NewServerRunOptions()
|
||||
if instanceOptions.RequestTimeout > 0 {
|
||||
@@ -373,7 +374,7 @@ func StartTestServer(t ktesting.TB, instanceOptions *TestServerInstanceOptions,
|
||||
s.Authentication.RequestHeader.ExtraHeaderPrefixes = extraHeaders
|
||||
}
|
||||
|
||||
if err := utilversion.DefaultComponentGlobalsRegistry.Set(); err != nil {
|
||||
if err := featuregate.DefaultComponentGlobalsRegistry.Set(); err != nil {
|
||||
return result, err
|
||||
}
|
||||
|
||||
|
||||
@@ -62,9 +62,8 @@ import (
|
||||
metricsfeatures "k8s.io/component-base/metrics/features"
|
||||
controllersmetrics "k8s.io/component-base/metrics/prometheus/controllers"
|
||||
"k8s.io/component-base/metrics/prometheus/slis"
|
||||
utilversion "k8s.io/component-base/registry"
|
||||
"k8s.io/component-base/term"
|
||||
"k8s.io/component-base/version"
|
||||
utilversion "k8s.io/component-base/version"
|
||||
"k8s.io/component-base/version/verflag"
|
||||
genericcontrollermanager "k8s.io/controller-manager/app"
|
||||
"k8s.io/controller-manager/controller"
|
||||
@@ -107,8 +106,8 @@ const (
|
||||
|
||||
// NewControllerManagerCommand creates a *cobra.Command object with default parameters
|
||||
func NewControllerManagerCommand() *cobra.Command {
|
||||
_, _ = utilversion.DefaultComponentGlobalsRegistry.ComponentGlobalsOrRegister(
|
||||
utilversion.DefaultKubeComponent, utilversion.DefaultBuildEffectiveVersion(), utilfeature.DefaultMutableFeatureGate)
|
||||
_, _ = featuregate.DefaultComponentGlobalsRegistry.ComponentGlobalsOrRegister(
|
||||
featuregate.DefaultKubeComponent, utilversion.DefaultBuildEffectiveVersion(), utilfeature.DefaultMutableFeatureGate)
|
||||
|
||||
s, err := options.NewKubeControllerManagerOptions()
|
||||
if err != nil {
|
||||
@@ -150,7 +149,7 @@ controller, and serviceaccounts controller.`,
|
||||
}
|
||||
|
||||
// add feature enablement metrics
|
||||
fg := s.ComponentGlobalsRegistry.FeatureGateFor(utilversion.DefaultKubeComponent)
|
||||
fg := s.ComponentGlobalsRegistry.FeatureGateFor(featuregate.DefaultKubeComponent)
|
||||
fg.(featuregate.MutableFeatureGate).AddMetrics()
|
||||
return Run(context.Background(), c.Complete())
|
||||
},
|
||||
@@ -194,7 +193,7 @@ func Run(ctx context.Context, c *config.CompletedConfig) error {
|
||||
stopCh := ctx.Done()
|
||||
|
||||
// To help debugging, immediately log version
|
||||
logger.Info("Starting", "version", version.Get())
|
||||
logger.Info("Starting", "version", utilversion.Get())
|
||||
|
||||
logger.Info("Golang settings", "GOGC", os.Getenv("GOGC"), "GOMAXPROCS", os.Getenv("GOMAXPROCS"), "GOTRACEBACK", os.Getenv("GOTRACEBACK"))
|
||||
|
||||
@@ -293,11 +292,11 @@ func Run(ctx context.Context, c *config.CompletedConfig) error {
|
||||
}
|
||||
|
||||
if utilfeature.DefaultFeatureGate.Enabled(kubefeatures.CoordinatedLeaderElection) {
|
||||
binaryVersion, err := semver.ParseTolerant(utilversion.DefaultComponentGlobalsRegistry.EffectiveVersionFor(utilversion.DefaultKubeComponent).BinaryVersion().String())
|
||||
binaryVersion, err := semver.ParseTolerant(featuregate.DefaultComponentGlobalsRegistry.EffectiveVersionFor(featuregate.DefaultKubeComponent).BinaryVersion().String())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
emulationVersion, err := semver.ParseTolerant(utilversion.DefaultComponentGlobalsRegistry.EffectiveVersionFor(utilversion.DefaultKubeComponent).EmulationVersion().String())
|
||||
emulationVersion, err := semver.ParseTolerant(featuregate.DefaultComponentGlobalsRegistry.EffectiveVersionFor(featuregate.DefaultKubeComponent).EmulationVersion().String())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ import (
|
||||
"k8s.io/component-base/logs"
|
||||
logsapi "k8s.io/component-base/logs/api/v1"
|
||||
"k8s.io/component-base/metrics"
|
||||
utilversion "k8s.io/component-base/registry"
|
||||
utilversion "k8s.io/component-base/version"
|
||||
cmoptions "k8s.io/controller-manager/options"
|
||||
"k8s.io/klog/v2"
|
||||
kubectrlmgrconfigv1alpha1 "k8s.io/kube-controller-manager/config/v1alpha1"
|
||||
@@ -104,7 +104,7 @@ type KubeControllerManagerOptions struct {
|
||||
ShowHiddenMetricsForVersion string
|
||||
|
||||
// ComponentGlobalsRegistry is the registry where the effective versions and feature gates for all components are stored.
|
||||
ComponentGlobalsRegistry utilversion.ComponentGlobalsRegistry
|
||||
ComponentGlobalsRegistry featuregate.ComponentGlobalsRegistry
|
||||
}
|
||||
|
||||
// NewKubeControllerManagerOptions creates a new KubeControllerManagerOptions with a default config.
|
||||
@@ -114,10 +114,10 @@ func NewKubeControllerManagerOptions() (*KubeControllerManagerOptions, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if utilversion.DefaultComponentGlobalsRegistry.EffectiveVersionFor(utilversion.DefaultKubeComponent) == nil {
|
||||
if featuregate.DefaultComponentGlobalsRegistry.EffectiveVersionFor(featuregate.DefaultKubeComponent) == nil {
|
||||
featureGate := utilfeature.DefaultMutableFeatureGate
|
||||
effectiveVersion := utilversion.DefaultKubeEffectiveVersion()
|
||||
utilruntime.Must(utilversion.DefaultComponentGlobalsRegistry.Register(utilversion.DefaultKubeComponent, effectiveVersion, featureGate))
|
||||
utilruntime.Must(featuregate.DefaultComponentGlobalsRegistry.Register(featuregate.DefaultKubeComponent, effectiveVersion, featureGate))
|
||||
}
|
||||
|
||||
s := KubeControllerManagerOptions{
|
||||
@@ -209,7 +209,7 @@ func NewKubeControllerManagerOptions() (*KubeControllerManagerOptions, error) {
|
||||
Authorization: apiserveroptions.NewDelegatingAuthorizationOptions(),
|
||||
Metrics: metrics.NewOptions(),
|
||||
Logs: logs.NewOptions(),
|
||||
ComponentGlobalsRegistry: utilversion.DefaultComponentGlobalsRegistry,
|
||||
ComponentGlobalsRegistry: featuregate.DefaultComponentGlobalsRegistry,
|
||||
}
|
||||
|
||||
s.Authentication.RemoteKubeConfigFileOptional = true
|
||||
@@ -450,7 +450,7 @@ func (s *KubeControllerManagerOptions) Validate(allControllers []string, disable
|
||||
errs = append(errs, s.Authentication.Validate()...)
|
||||
errs = append(errs, s.Authorization.Validate()...)
|
||||
errs = append(errs, s.Metrics.Validate()...)
|
||||
errs = append(errs, utilversion.ValidateKubeEffectiveVersion(s.ComponentGlobalsRegistry.EffectiveVersionFor(utilversion.DefaultKubeComponent)))
|
||||
errs = append(errs, utilversion.ValidateKubeEffectiveVersion(s.ComponentGlobalsRegistry.EffectiveVersionFor(featuregate.DefaultKubeComponent)))
|
||||
|
||||
// TODO: validate component config, master and kubeconfig
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ import (
|
||||
|
||||
"k8s.io/apiserver/pkg/apis/apiserver"
|
||||
apiserveroptions "k8s.io/apiserver/pkg/server/options"
|
||||
utilversion "k8s.io/component-base/registry"
|
||||
utilversion "k8s.io/component-base/version"
|
||||
|
||||
componentbaseconfig "k8s.io/component-base/config"
|
||||
"k8s.io/component-base/featuregate"
|
||||
@@ -449,7 +449,7 @@ func TestAddFlags(t *testing.T) {
|
||||
Master: "192.168.4.20",
|
||||
Metrics: &metrics.Options{},
|
||||
Logs: logs.NewOptions(),
|
||||
ComponentGlobalsRegistry: utilversion.DefaultComponentGlobalsRegistry,
|
||||
ComponentGlobalsRegistry: featuregate.DefaultComponentGlobalsRegistry,
|
||||
}
|
||||
|
||||
// Sort GCIgnoredResources because it's built from a map, which means the
|
||||
@@ -659,7 +659,7 @@ func TestApplyTo(t *testing.T) {
|
||||
|
||||
func TestEmulatedVersion(t *testing.T) {
|
||||
var cleanupAndSetupFunc = func() featuregate.FeatureGate {
|
||||
componentGlobalsRegistry := utilversion.DefaultComponentGlobalsRegistry
|
||||
componentGlobalsRegistry := featuregate.DefaultComponentGlobalsRegistry
|
||||
componentGlobalsRegistry.Reset() // make sure this test have a clean state
|
||||
t.Cleanup(func() {
|
||||
componentGlobalsRegistry.Reset() // make sure this test doesn't leak a dirty state
|
||||
@@ -676,7 +676,7 @@ func TestEmulatedVersion(t *testing.T) {
|
||||
{Version: version.MustParse("1.31"), Default: false, PreRelease: featuregate.Alpha},
|
||||
},
|
||||
}))
|
||||
utilruntime.Must(componentGlobalsRegistry.Register(utilversion.DefaultKubeComponent, verKube, fg))
|
||||
utilruntime.Must(componentGlobalsRegistry.Register(featuregate.DefaultKubeComponent, verKube, fg))
|
||||
return fg
|
||||
}
|
||||
|
||||
|
||||
@@ -41,10 +41,11 @@ import (
|
||||
cliflag "k8s.io/component-base/cli/flag"
|
||||
componentbaseconfig "k8s.io/component-base/config"
|
||||
"k8s.io/component-base/config/options"
|
||||
"k8s.io/component-base/featuregate"
|
||||
"k8s.io/component-base/logs"
|
||||
logsapi "k8s.io/component-base/logs/api/v1"
|
||||
"k8s.io/component-base/metrics"
|
||||
utilversion "k8s.io/component-base/registry"
|
||||
utilversion "k8s.io/component-base/version"
|
||||
"k8s.io/klog/v2"
|
||||
schedulerappconfig "k8s.io/kubernetes/cmd/kube-scheduler/app/config"
|
||||
"k8s.io/kubernetes/pkg/scheduler"
|
||||
@@ -75,7 +76,7 @@ type Options struct {
|
||||
Master string
|
||||
|
||||
// ComponentGlobalsRegistry is the registry where the effective versions and feature gates for all components are stored.
|
||||
ComponentGlobalsRegistry utilversion.ComponentGlobalsRegistry
|
||||
ComponentGlobalsRegistry featuregate.ComponentGlobalsRegistry
|
||||
|
||||
// Flags hold the parsed CLI flags.
|
||||
Flags *cliflag.NamedFlagSets
|
||||
@@ -84,10 +85,10 @@ type Options struct {
|
||||
// NewOptions returns default scheduler app options.
|
||||
func NewOptions() *Options {
|
||||
// make sure DefaultKubeComponent is registered in the DefaultComponentGlobalsRegistry.
|
||||
if utilversion.DefaultComponentGlobalsRegistry.EffectiveVersionFor(utilversion.DefaultKubeComponent) == nil {
|
||||
if featuregate.DefaultComponentGlobalsRegistry.EffectiveVersionFor(featuregate.DefaultKubeComponent) == nil {
|
||||
featureGate := utilfeature.DefaultMutableFeatureGate
|
||||
effectiveVersion := utilversion.DefaultKubeEffectiveVersion()
|
||||
utilruntime.Must(utilversion.DefaultComponentGlobalsRegistry.Register(utilversion.DefaultKubeComponent, effectiveVersion, featureGate))
|
||||
utilruntime.Must(featuregate.DefaultComponentGlobalsRegistry.Register(featuregate.DefaultKubeComponent, effectiveVersion, featureGate))
|
||||
}
|
||||
o := &Options{
|
||||
SecureServing: apiserveroptions.NewSecureServingOptions().WithLoopback(),
|
||||
@@ -107,7 +108,7 @@ func NewOptions() *Options {
|
||||
},
|
||||
Metrics: metrics.NewOptions(),
|
||||
Logs: logs.NewOptions(),
|
||||
ComponentGlobalsRegistry: utilversion.DefaultComponentGlobalsRegistry,
|
||||
ComponentGlobalsRegistry: featuregate.DefaultComponentGlobalsRegistry,
|
||||
}
|
||||
|
||||
o.Authentication.TolerateInClusterLookupFailure = true
|
||||
@@ -279,7 +280,7 @@ func (o *Options) Validate() []error {
|
||||
errs = append(errs, o.Authorization.Validate()...)
|
||||
errs = append(errs, o.Metrics.Validate()...)
|
||||
|
||||
effectiveVersion := o.ComponentGlobalsRegistry.EffectiveVersionFor(utilversion.DefaultKubeComponent)
|
||||
effectiveVersion := o.ComponentGlobalsRegistry.EffectiveVersionFor(featuregate.DefaultKubeComponent)
|
||||
if err := utilversion.ValidateKubeEffectiveVersion(effectiveVersion); err != nil {
|
||||
errs = append(errs, err)
|
||||
}
|
||||
|
||||
@@ -33,8 +33,8 @@ import (
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
apiserveroptions "k8s.io/apiserver/pkg/server/options"
|
||||
componentbaseconfig "k8s.io/component-base/config"
|
||||
"k8s.io/component-base/featuregate"
|
||||
"k8s.io/component-base/logs"
|
||||
utilversion "k8s.io/component-base/registry"
|
||||
"k8s.io/klog/v2/ktesting"
|
||||
v1 "k8s.io/kube-scheduler/config/v1"
|
||||
kubeschedulerconfig "k8s.io/kubernetes/pkg/scheduler/apis/config"
|
||||
@@ -323,7 +323,7 @@ profiles:
|
||||
AlwaysAllowGroups: []string{"system:masters"},
|
||||
},
|
||||
Logs: logs.NewOptions(),
|
||||
ComponentGlobalsRegistry: utilversion.DefaultComponentGlobalsRegistry,
|
||||
ComponentGlobalsRegistry: featuregate.DefaultComponentGlobalsRegistry,
|
||||
},
|
||||
expectedUsername: "config",
|
||||
expectedConfig: kubeschedulerconfig.KubeSchedulerConfiguration{
|
||||
@@ -375,7 +375,7 @@ profiles:
|
||||
return cfg
|
||||
}(),
|
||||
Logs: logs.NewOptions(),
|
||||
ComponentGlobalsRegistry: utilversion.DefaultComponentGlobalsRegistry,
|
||||
ComponentGlobalsRegistry: featuregate.DefaultComponentGlobalsRegistry,
|
||||
},
|
||||
expectedError: "no kind \"KubeSchedulerConfiguration\" is registered for version \"componentconfig/v1alpha1\"",
|
||||
},
|
||||
@@ -384,7 +384,7 @@ profiles:
|
||||
options: &Options{
|
||||
ConfigFile: unknownVersionConfig,
|
||||
Logs: logs.NewOptions(),
|
||||
ComponentGlobalsRegistry: utilversion.DefaultComponentGlobalsRegistry,
|
||||
ComponentGlobalsRegistry: featuregate.DefaultComponentGlobalsRegistry,
|
||||
},
|
||||
expectedError: "no kind \"KubeSchedulerConfiguration\" is registered for version \"kubescheduler.config.k8s.io/unknown\"",
|
||||
},
|
||||
@@ -393,7 +393,7 @@ profiles:
|
||||
options: &Options{
|
||||
ConfigFile: noVersionConfig,
|
||||
Logs: logs.NewOptions(),
|
||||
ComponentGlobalsRegistry: utilversion.DefaultComponentGlobalsRegistry,
|
||||
ComponentGlobalsRegistry: featuregate.DefaultComponentGlobalsRegistry,
|
||||
},
|
||||
expectedError: "Object 'apiVersion' is missing",
|
||||
},
|
||||
@@ -430,7 +430,7 @@ profiles:
|
||||
AlwaysAllowGroups: []string{"system:masters"},
|
||||
},
|
||||
Logs: logs.NewOptions(),
|
||||
ComponentGlobalsRegistry: utilversion.DefaultComponentGlobalsRegistry,
|
||||
ComponentGlobalsRegistry: featuregate.DefaultComponentGlobalsRegistry,
|
||||
},
|
||||
expectedUsername: "flag",
|
||||
expectedConfig: kubeschedulerconfig.KubeSchedulerConfiguration{
|
||||
@@ -503,7 +503,7 @@ profiles:
|
||||
AlwaysAllowGroups: []string{"system:masters"},
|
||||
},
|
||||
Logs: logs.NewOptions(),
|
||||
ComponentGlobalsRegistry: utilversion.DefaultComponentGlobalsRegistry,
|
||||
ComponentGlobalsRegistry: featuregate.DefaultComponentGlobalsRegistry,
|
||||
},
|
||||
expectedConfig: kubeschedulerconfig.KubeSchedulerConfiguration{
|
||||
TypeMeta: metav1.TypeMeta{
|
||||
@@ -548,7 +548,7 @@ profiles:
|
||||
options: &Options{
|
||||
ConfigFile: pluginConfigFile,
|
||||
Logs: logs.NewOptions(),
|
||||
ComponentGlobalsRegistry: utilversion.DefaultComponentGlobalsRegistry,
|
||||
ComponentGlobalsRegistry: featuregate.DefaultComponentGlobalsRegistry,
|
||||
},
|
||||
expectedUsername: "config",
|
||||
expectedConfig: kubeschedulerconfig.KubeSchedulerConfiguration{
|
||||
@@ -669,7 +669,7 @@ profiles:
|
||||
options: &Options{
|
||||
ConfigFile: multiProfilesConfig,
|
||||
Logs: logs.NewOptions(),
|
||||
ComponentGlobalsRegistry: utilversion.DefaultComponentGlobalsRegistry,
|
||||
ComponentGlobalsRegistry: featuregate.DefaultComponentGlobalsRegistry,
|
||||
},
|
||||
expectedUsername: "config",
|
||||
expectedConfig: kubeschedulerconfig.KubeSchedulerConfiguration{
|
||||
@@ -784,7 +784,7 @@ profiles:
|
||||
name: "no config",
|
||||
options: &Options{
|
||||
Logs: logs.NewOptions(),
|
||||
ComponentGlobalsRegistry: utilversion.DefaultComponentGlobalsRegistry,
|
||||
ComponentGlobalsRegistry: featuregate.DefaultComponentGlobalsRegistry,
|
||||
},
|
||||
expectedError: "no configuration has been provided",
|
||||
},
|
||||
@@ -793,7 +793,7 @@ profiles:
|
||||
options: &Options{
|
||||
ConfigFile: unknownFieldConfig,
|
||||
Logs: logs.NewOptions(),
|
||||
ComponentGlobalsRegistry: utilversion.DefaultComponentGlobalsRegistry,
|
||||
ComponentGlobalsRegistry: featuregate.DefaultComponentGlobalsRegistry,
|
||||
},
|
||||
expectedError: `unknown field "foo"`,
|
||||
checkErrFn: runtime.IsStrictDecodingError,
|
||||
@@ -803,7 +803,7 @@ profiles:
|
||||
options: &Options{
|
||||
ConfigFile: duplicateFieldConfig,
|
||||
Logs: logs.NewOptions(),
|
||||
ComponentGlobalsRegistry: utilversion.DefaultComponentGlobalsRegistry,
|
||||
ComponentGlobalsRegistry: featuregate.DefaultComponentGlobalsRegistry,
|
||||
},
|
||||
expectedError: `key "leaderElect" already set`,
|
||||
checkErrFn: runtime.IsStrictDecodingError,
|
||||
@@ -813,7 +813,7 @@ profiles:
|
||||
options: &Options{
|
||||
ConfigFile: highThroughputProfileConfig,
|
||||
Logs: logs.NewOptions(),
|
||||
ComponentGlobalsRegistry: utilversion.DefaultComponentGlobalsRegistry,
|
||||
ComponentGlobalsRegistry: featuregate.DefaultComponentGlobalsRegistry,
|
||||
},
|
||||
expectedUsername: "config",
|
||||
expectedConfig: kubeschedulerconfig.KubeSchedulerConfiguration{
|
||||
|
||||
@@ -53,9 +53,8 @@ import (
|
||||
"k8s.io/component-base/metrics/features"
|
||||
"k8s.io/component-base/metrics/legacyregistry"
|
||||
"k8s.io/component-base/metrics/prometheus/slis"
|
||||
utilversion "k8s.io/component-base/registry"
|
||||
"k8s.io/component-base/term"
|
||||
"k8s.io/component-base/version"
|
||||
utilversion "k8s.io/component-base/version"
|
||||
"k8s.io/component-base/version/verflag"
|
||||
"k8s.io/klog/v2"
|
||||
schedulerserverconfig "k8s.io/kubernetes/cmd/kube-scheduler/app/config"
|
||||
@@ -81,8 +80,8 @@ type Option func(runtime.Registry) error
|
||||
func NewSchedulerCommand(registryOptions ...Option) *cobra.Command {
|
||||
// explicitly register (if not already registered) the kube effective version and feature gate in DefaultComponentGlobalsRegistry,
|
||||
// which will be used in NewOptions.
|
||||
_, _ = utilversion.DefaultComponentGlobalsRegistry.ComponentGlobalsOrRegister(
|
||||
utilversion.DefaultKubeComponent, utilversion.DefaultBuildEffectiveVersion(), utilfeature.DefaultMutableFeatureGate)
|
||||
_, _ = featuregate.DefaultComponentGlobalsRegistry.ComponentGlobalsOrRegister(
|
||||
featuregate.DefaultKubeComponent, utilversion.DefaultBuildEffectiveVersion(), utilfeature.DefaultMutableFeatureGate)
|
||||
opts := options.NewOptions()
|
||||
|
||||
cmd := &cobra.Command{
|
||||
@@ -133,7 +132,7 @@ for more information about scheduling and the kube-scheduler component.`,
|
||||
// runCommand runs the scheduler.
|
||||
func runCommand(cmd *cobra.Command, opts *options.Options, registryOptions ...Option) error {
|
||||
verflag.PrintAndExitIfRequested()
|
||||
fg := opts.ComponentGlobalsRegistry.FeatureGateFor(utilversion.DefaultKubeComponent)
|
||||
fg := opts.ComponentGlobalsRegistry.FeatureGateFor(featuregate.DefaultKubeComponent)
|
||||
// Activate logging as soon as possible, after that
|
||||
// show flags with the final logging configuration.
|
||||
if err := logsapi.ValidateAndApply(opts.Logs, fg); err != nil {
|
||||
@@ -164,7 +163,7 @@ func Run(ctx context.Context, cc *schedulerserverconfig.CompletedConfig, sched *
|
||||
logger := klog.FromContext(ctx)
|
||||
|
||||
// To help debugging, immediately log version
|
||||
logger.Info("Starting Kubernetes Scheduler", "version", version.Get())
|
||||
logger.Info("Starting Kubernetes Scheduler", "version", utilversion.Get())
|
||||
|
||||
logger.Info("Golang settings", "GOGC", os.Getenv("GOGC"), "GOMAXPROCS", os.Getenv("GOMAXPROCS"), "GOTRACEBACK", os.Getenv("GOTRACEBACK"))
|
||||
|
||||
@@ -211,11 +210,11 @@ func Run(ctx context.Context, cc *schedulerserverconfig.CompletedConfig, sched *
|
||||
readyzChecks = append(readyzChecks, handlerSyncCheck)
|
||||
|
||||
if cc.LeaderElection != nil && utilfeature.DefaultFeatureGate.Enabled(kubefeatures.CoordinatedLeaderElection) {
|
||||
binaryVersion, err := semver.ParseTolerant(utilversion.DefaultComponentGlobalsRegistry.EffectiveVersionFor(utilversion.DefaultKubeComponent).BinaryVersion().String())
|
||||
binaryVersion, err := semver.ParseTolerant(featuregate.DefaultComponentGlobalsRegistry.EffectiveVersionFor(featuregate.DefaultKubeComponent).BinaryVersion().String())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
emulationVersion, err := semver.ParseTolerant(utilversion.DefaultComponentGlobalsRegistry.EffectiveVersionFor(utilversion.DefaultKubeComponent).EmulationVersion().String())
|
||||
emulationVersion, err := semver.ParseTolerant(featuregate.DefaultComponentGlobalsRegistry.EffectiveVersionFor(featuregate.DefaultKubeComponent).EmulationVersion().String())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ import (
|
||||
componentbaseconfig "k8s.io/component-base/config"
|
||||
"k8s.io/component-base/featuregate"
|
||||
featuregatetesting "k8s.io/component-base/featuregate/testing"
|
||||
utilversion "k8s.io/component-base/registry"
|
||||
utilversion "k8s.io/component-base/version"
|
||||
configv1 "k8s.io/kube-scheduler/config/v1"
|
||||
"k8s.io/kubernetes/cmd/kube-scheduler/app/options"
|
||||
"k8s.io/kubernetes/pkg/features"
|
||||
@@ -437,7 +437,7 @@ leaderElection:
|
||||
for k, v := range tc.restoreFeatures {
|
||||
featuregatetesting.SetFeatureGateDuringTest(t, feature.DefaultFeatureGate, k, v)
|
||||
}
|
||||
componentGlobalsRegistry := utilversion.DefaultComponentGlobalsRegistry
|
||||
componentGlobalsRegistry := featuregate.DefaultComponentGlobalsRegistry
|
||||
t.Cleanup(func() {
|
||||
componentGlobalsRegistry.Reset()
|
||||
})
|
||||
@@ -453,7 +453,7 @@ leaderElection:
|
||||
{Version: version.MustParse("1.31"), Default: false, PreRelease: featuregate.Alpha},
|
||||
},
|
||||
}))
|
||||
utilruntime.Must(componentGlobalsRegistry.Register(utilversion.DefaultKubeComponent, verKube, fg))
|
||||
utilruntime.Must(componentGlobalsRegistry.Register(featuregate.DefaultKubeComponent, verKube, fg))
|
||||
|
||||
fs := pflag.NewFlagSet("test", pflag.PanicOnError)
|
||||
opts := options.NewOptions()
|
||||
|
||||
@@ -37,13 +37,13 @@ import (
|
||||
"k8s.io/component-base/featuregate"
|
||||
"k8s.io/component-base/logs"
|
||||
"k8s.io/component-base/metrics"
|
||||
utilversion "k8s.io/component-base/registry"
|
||||
utilversion "k8s.io/component-base/version"
|
||||
kubeoptions "k8s.io/kubernetes/pkg/kubeapiserver/options"
|
||||
netutils "k8s.io/utils/net"
|
||||
)
|
||||
|
||||
func TestAddFlags(t *testing.T) {
|
||||
componentGlobalsRegistry := utilversion.DefaultComponentGlobalsRegistry
|
||||
componentGlobalsRegistry := featuregate.DefaultComponentGlobalsRegistry
|
||||
t.Cleanup(func() {
|
||||
componentGlobalsRegistry.Reset()
|
||||
})
|
||||
@@ -133,7 +133,7 @@ func TestAddFlags(t *testing.T) {
|
||||
JSONPatchMaxCopyBytes: int64(3 * 1024 * 1024),
|
||||
MaxRequestBodyBytes: int64(3 * 1024 * 1024),
|
||||
ComponentGlobalsRegistry: componentGlobalsRegistry,
|
||||
ComponentName: utilversion.DefaultKubeComponent,
|
||||
ComponentName: featuregate.DefaultKubeComponent,
|
||||
},
|
||||
Admission: &kubeoptions.AdmissionOptions{
|
||||
GenericAdmission: &apiserveroptions.AdmissionOptions{
|
||||
|
||||
@@ -25,7 +25,6 @@ import (
|
||||
utilfeature "k8s.io/apiserver/pkg/util/feature"
|
||||
"k8s.io/component-base/featuregate"
|
||||
basemetrics "k8s.io/component-base/metrics"
|
||||
utilversion "k8s.io/component-base/registry"
|
||||
"k8s.io/kubernetes/pkg/features"
|
||||
|
||||
peerreconcilers "k8s.io/apiserver/pkg/reconcilers"
|
||||
@@ -201,7 +200,7 @@ func TestValidateOptions(t *testing.T) {
|
||||
name: "validate master count equal 0",
|
||||
expectErrors: true,
|
||||
options: &Options{
|
||||
GenericServerRunOptions: &genericoptions.ServerRunOptions{ComponentGlobalsRegistry: utilversion.DefaultComponentGlobalsRegistry},
|
||||
GenericServerRunOptions: &genericoptions.ServerRunOptions{ComponentGlobalsRegistry: featuregate.DefaultComponentGlobalsRegistry},
|
||||
Etcd: &genericoptions.EtcdOptions{},
|
||||
SecureServing: &genericoptions.SecureServingOptionsWithLoopback{},
|
||||
Audit: &genericoptions.AuditOptions{},
|
||||
@@ -228,7 +227,7 @@ func TestValidateOptions(t *testing.T) {
|
||||
name: "validate token request enable not attempted",
|
||||
expectErrors: true,
|
||||
options: &Options{
|
||||
GenericServerRunOptions: &genericoptions.ServerRunOptions{ComponentGlobalsRegistry: utilversion.DefaultComponentGlobalsRegistry},
|
||||
GenericServerRunOptions: &genericoptions.ServerRunOptions{ComponentGlobalsRegistry: featuregate.DefaultComponentGlobalsRegistry},
|
||||
Etcd: &genericoptions.EtcdOptions{},
|
||||
SecureServing: &genericoptions.SecureServingOptionsWithLoopback{},
|
||||
Audit: &genericoptions.AuditOptions{},
|
||||
|
||||
@@ -60,8 +60,7 @@ import (
|
||||
"k8s.io/client-go/informers"
|
||||
"k8s.io/client-go/kubernetes"
|
||||
restclient "k8s.io/client-go/rest"
|
||||
utilversion "k8s.io/component-base/registry"
|
||||
kubeversion "k8s.io/component-base/version"
|
||||
utilversion "k8s.io/component-base/version"
|
||||
aggregatorscheme "k8s.io/kube-aggregator/pkg/apiserver/scheme"
|
||||
netutils "k8s.io/utils/net"
|
||||
|
||||
@@ -241,7 +240,7 @@ func TestVersion(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
expectedInfo := kubeversion.Get()
|
||||
expectedInfo := utilversion.Get()
|
||||
kubeVersion := utilversion.DefaultKubeEffectiveVersion().BinaryVersion()
|
||||
expectedInfo.Major = fmt.Sprintf("%d", kubeVersion.Major())
|
||||
expectedInfo.Minor = fmt.Sprintf("%d", kubeVersion.Minor())
|
||||
|
||||
@@ -25,7 +25,7 @@ import (
|
||||
"k8s.io/apiserver/pkg/server/resourceconfig"
|
||||
serverstorage "k8s.io/apiserver/pkg/server/storage"
|
||||
"k8s.io/apiserver/pkg/storage/storagebackend"
|
||||
version "k8s.io/component-base/registry"
|
||||
version "k8s.io/component-base/version"
|
||||
"k8s.io/kubernetes/pkg/api/legacyscheme"
|
||||
"k8s.io/kubernetes/pkg/apis/apps"
|
||||
"k8s.io/kubernetes/pkg/apis/certificates"
|
||||
|
||||
@@ -24,7 +24,7 @@ import (
|
||||
|
||||
"k8s.io/apiextensions-apiserver/pkg/cmd/server/options"
|
||||
genericapiserver "k8s.io/apiserver/pkg/server"
|
||||
utilversion "k8s.io/component-base/registry"
|
||||
"k8s.io/component-base/featuregate"
|
||||
)
|
||||
|
||||
func NewServerCommand(ctx context.Context, out, errOut io.Writer) *cobra.Command {
|
||||
@@ -34,7 +34,7 @@ func NewServerCommand(ctx context.Context, out, errOut io.Writer) *cobra.Command
|
||||
Short: "Launch an API extensions API server",
|
||||
Long: "Launch an API extensions API server",
|
||||
PersistentPreRunE: func(*cobra.Command, []string) error {
|
||||
return utilversion.DefaultComponentGlobalsRegistry.Set()
|
||||
return featuregate.DefaultComponentGlobalsRegistry.Set()
|
||||
},
|
||||
RunE: func(c *cobra.Command, args []string) error {
|
||||
if err := o.Complete(); err != nil {
|
||||
|
||||
@@ -40,8 +40,9 @@ import (
|
||||
"k8s.io/apiserver/pkg/util/openapi"
|
||||
"k8s.io/client-go/kubernetes"
|
||||
restclient "k8s.io/client-go/rest"
|
||||
"k8s.io/component-base/featuregate"
|
||||
logsapi "k8s.io/component-base/logs/api/v1"
|
||||
utilversion "k8s.io/component-base/registry"
|
||||
utilversion "k8s.io/component-base/version"
|
||||
"k8s.io/klog/v2"
|
||||
)
|
||||
|
||||
@@ -129,8 +130,8 @@ func StartTestServer(t Logger, _ *TestServerInstanceOptions, customFlags []strin
|
||||
effectiveVersion := utilversion.DefaultKubeEffectiveVersion()
|
||||
effectiveVersion.SetEmulationVersion(featureGate.EmulationVersion())
|
||||
|
||||
utilversion.DefaultComponentGlobalsRegistry.Reset()
|
||||
utilruntime.Must(utilversion.DefaultComponentGlobalsRegistry.Register(utilversion.DefaultKubeComponent, effectiveVersion, featureGate))
|
||||
featuregate.DefaultComponentGlobalsRegistry.Reset()
|
||||
utilruntime.Must(featuregate.DefaultComponentGlobalsRegistry.Register(featuregate.DefaultKubeComponent, effectiveVersion, featureGate))
|
||||
s := options.NewCustomResourceDefinitionsServerOptions(os.Stdout, os.Stderr)
|
||||
s.AddFlags(fs)
|
||||
|
||||
@@ -154,7 +155,7 @@ func StartTestServer(t Logger, _ *TestServerInstanceOptions, customFlags []strin
|
||||
|
||||
fs.Parse(customFlags)
|
||||
|
||||
if err := utilversion.DefaultComponentGlobalsRegistry.Set(); err != nil {
|
||||
if err := featuregate.DefaultComponentGlobalsRegistry.Set(); err != nil {
|
||||
return result, err
|
||||
}
|
||||
|
||||
|
||||
@@ -33,7 +33,8 @@ import (
|
||||
"k8s.io/apiserver/pkg/cel/library"
|
||||
genericfeatures "k8s.io/apiserver/pkg/features"
|
||||
utilfeature "k8s.io/apiserver/pkg/util/feature"
|
||||
utilversion "k8s.io/component-base/registry"
|
||||
"k8s.io/component-base/featuregate"
|
||||
utilversion "k8s.io/component-base/version"
|
||||
)
|
||||
|
||||
// DefaultCompatibilityVersion returns a default compatibility version for use with EnvSet
|
||||
@@ -49,7 +50,7 @@ import (
|
||||
// A default version number equal to the current Kubernetes major.minor version
|
||||
// indicates fast forward CEL features that can be used when rollback is no longer needed.
|
||||
func DefaultCompatibilityVersion() *version.Version {
|
||||
effectiveVer := utilversion.DefaultComponentGlobalsRegistry.EffectiveVersionFor(utilversion.DefaultKubeComponent)
|
||||
effectiveVer := featuregate.DefaultComponentGlobalsRegistry.EffectiveVersionFor(featuregate.DefaultKubeComponent)
|
||||
if effectiveVer == nil {
|
||||
effectiveVer = utilversion.DefaultKubeEffectiveVersion()
|
||||
}
|
||||
|
||||
@@ -77,8 +77,8 @@ import (
|
||||
"k8s.io/component-base/logs"
|
||||
"k8s.io/component-base/metrics/features"
|
||||
"k8s.io/component-base/metrics/prometheus/slis"
|
||||
utilversion "k8s.io/component-base/registry"
|
||||
"k8s.io/component-base/tracing"
|
||||
utilversion "k8s.io/component-base/version"
|
||||
"k8s.io/klog/v2"
|
||||
openapicommon "k8s.io/kube-openapi/pkg/common"
|
||||
"k8s.io/kube-openapi/pkg/spec3"
|
||||
|
||||
@@ -45,8 +45,8 @@ import (
|
||||
"k8s.io/client-go/informers"
|
||||
"k8s.io/client-go/kubernetes/fake"
|
||||
"k8s.io/client-go/rest"
|
||||
utilversion "k8s.io/component-base/registry"
|
||||
"k8s.io/component-base/tracing"
|
||||
utilversion "k8s.io/component-base/version"
|
||||
"k8s.io/klog/v2/ktesting"
|
||||
netutils "k8s.io/utils/net"
|
||||
)
|
||||
|
||||
@@ -53,7 +53,7 @@ import (
|
||||
"k8s.io/apiserver/pkg/storageversion"
|
||||
restclient "k8s.io/client-go/rest"
|
||||
"k8s.io/component-base/featuregate"
|
||||
utilversion "k8s.io/component-base/registry"
|
||||
utilversion "k8s.io/component-base/version"
|
||||
"k8s.io/klog/v2"
|
||||
openapibuilder3 "k8s.io/kube-openapi/pkg/builder3"
|
||||
openapicommon "k8s.io/kube-openapi/pkg/common"
|
||||
|
||||
@@ -52,7 +52,7 @@ import (
|
||||
"k8s.io/client-go/informers"
|
||||
"k8s.io/client-go/kubernetes/fake"
|
||||
restclient "k8s.io/client-go/rest"
|
||||
utilversion "k8s.io/component-base/registry"
|
||||
utilversion "k8s.io/component-base/version"
|
||||
"k8s.io/klog/v2/ktesting"
|
||||
kubeopenapi "k8s.io/kube-openapi/pkg/common"
|
||||
"k8s.io/kube-openapi/pkg/validation/spec"
|
||||
|
||||
@@ -28,7 +28,8 @@ import (
|
||||
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
|
||||
"k8s.io/apiserver/pkg/server"
|
||||
utilfeature "k8s.io/apiserver/pkg/util/feature"
|
||||
utilversion "k8s.io/component-base/registry"
|
||||
"k8s.io/component-base/featuregate"
|
||||
utilversion "k8s.io/component-base/version"
|
||||
|
||||
"github.com/spf13/pflag"
|
||||
)
|
||||
@@ -94,22 +95,22 @@ type ServerRunOptions struct {
|
||||
ShutdownWatchTerminationGracePeriod time.Duration
|
||||
|
||||
// ComponentGlobalsRegistry is the registry where the effective versions and feature gates for all components are stored.
|
||||
ComponentGlobalsRegistry utilversion.ComponentGlobalsRegistry
|
||||
ComponentGlobalsRegistry featuregate.ComponentGlobalsRegistry
|
||||
// ComponentName is name under which the server's global variabled are registered in the ComponentGlobalsRegistry.
|
||||
ComponentName string
|
||||
}
|
||||
|
||||
func NewServerRunOptions() *ServerRunOptions {
|
||||
if utilversion.DefaultComponentGlobalsRegistry.EffectiveVersionFor(utilversion.DefaultKubeComponent) == nil {
|
||||
if featuregate.DefaultComponentGlobalsRegistry.EffectiveVersionFor(featuregate.DefaultKubeComponent) == nil {
|
||||
featureGate := utilfeature.DefaultMutableFeatureGate
|
||||
effectiveVersion := utilversion.DefaultKubeEffectiveVersion()
|
||||
utilruntime.Must(utilversion.DefaultComponentGlobalsRegistry.Register(utilversion.DefaultKubeComponent, effectiveVersion, featureGate))
|
||||
utilruntime.Must(featuregate.DefaultComponentGlobalsRegistry.Register(featuregate.DefaultKubeComponent, effectiveVersion, featureGate))
|
||||
}
|
||||
|
||||
return NewServerRunOptionsForComponent(utilversion.DefaultKubeComponent, utilversion.DefaultComponentGlobalsRegistry)
|
||||
return NewServerRunOptionsForComponent(featuregate.DefaultKubeComponent, featuregate.DefaultComponentGlobalsRegistry)
|
||||
}
|
||||
|
||||
func NewServerRunOptionsForComponent(componentName string, componentGlobalsRegistry utilversion.ComponentGlobalsRegistry) *ServerRunOptions {
|
||||
func NewServerRunOptionsForComponent(componentName string, componentGlobalsRegistry featuregate.ComponentGlobalsRegistry) *ServerRunOptions {
|
||||
defaults := server.NewConfig(serializer.CodecFactory{})
|
||||
return &ServerRunOptions{
|
||||
MaxRequestsInFlight: defaults.MaxRequestsInFlight,
|
||||
|
||||
@@ -26,12 +26,13 @@ import (
|
||||
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
|
||||
"k8s.io/apimachinery/pkg/util/version"
|
||||
utilfeature "k8s.io/apiserver/pkg/util/feature"
|
||||
utilversion "k8s.io/component-base/registry"
|
||||
"k8s.io/component-base/featuregate"
|
||||
utilversion "k8s.io/component-base/version"
|
||||
netutils "k8s.io/utils/net"
|
||||
)
|
||||
|
||||
func TestServerRunOptionsValidate(t *testing.T) {
|
||||
testRegistry := utilversion.NewComponentGlobalsRegistry()
|
||||
testRegistry := featuregate.NewComponentGlobalsRegistry()
|
||||
featureGate := utilfeature.DefaultFeatureGate.DeepCopy()
|
||||
effectiveVersion := utilversion.NewEffectiveVersion("1.30")
|
||||
effectiveVersion.SetEmulationVersion(version.MajorMinor(1, 32))
|
||||
@@ -54,7 +55,7 @@ func TestServerRunOptionsValidate(t *testing.T) {
|
||||
MinRequestTimeout: 1800,
|
||||
JSONPatchMaxCopyBytes: 10 * 1024 * 1024,
|
||||
MaxRequestBodyBytes: 10 * 1024 * 1024,
|
||||
ComponentGlobalsRegistry: utilversion.DefaultComponentGlobalsRegistry,
|
||||
ComponentGlobalsRegistry: featuregate.DefaultComponentGlobalsRegistry,
|
||||
},
|
||||
expectErr: "--max-requests-inflight can not be negative value",
|
||||
},
|
||||
@@ -69,7 +70,7 @@ func TestServerRunOptionsValidate(t *testing.T) {
|
||||
MinRequestTimeout: 1800,
|
||||
JSONPatchMaxCopyBytes: 10 * 1024 * 1024,
|
||||
MaxRequestBodyBytes: 10 * 1024 * 1024,
|
||||
ComponentGlobalsRegistry: utilversion.DefaultComponentGlobalsRegistry,
|
||||
ComponentGlobalsRegistry: featuregate.DefaultComponentGlobalsRegistry,
|
||||
},
|
||||
expectErr: "--max-mutating-requests-inflight can not be negative value",
|
||||
},
|
||||
@@ -84,7 +85,7 @@ func TestServerRunOptionsValidate(t *testing.T) {
|
||||
MinRequestTimeout: 1800,
|
||||
JSONPatchMaxCopyBytes: 10 * 1024 * 1024,
|
||||
MaxRequestBodyBytes: 10 * 1024 * 1024,
|
||||
ComponentGlobalsRegistry: utilversion.DefaultComponentGlobalsRegistry,
|
||||
ComponentGlobalsRegistry: featuregate.DefaultComponentGlobalsRegistry,
|
||||
},
|
||||
expectErr: "--request-timeout can not be negative value",
|
||||
},
|
||||
@@ -99,7 +100,7 @@ func TestServerRunOptionsValidate(t *testing.T) {
|
||||
MinRequestTimeout: -1800,
|
||||
JSONPatchMaxCopyBytes: 10 * 1024 * 1024,
|
||||
MaxRequestBodyBytes: 10 * 1024 * 1024,
|
||||
ComponentGlobalsRegistry: utilversion.DefaultComponentGlobalsRegistry,
|
||||
ComponentGlobalsRegistry: featuregate.DefaultComponentGlobalsRegistry,
|
||||
},
|
||||
expectErr: "--min-request-timeout can not be negative value",
|
||||
},
|
||||
@@ -114,7 +115,7 @@ func TestServerRunOptionsValidate(t *testing.T) {
|
||||
MinRequestTimeout: 1800,
|
||||
JSONPatchMaxCopyBytes: -10 * 1024 * 1024,
|
||||
MaxRequestBodyBytes: 10 * 1024 * 1024,
|
||||
ComponentGlobalsRegistry: utilversion.DefaultComponentGlobalsRegistry,
|
||||
ComponentGlobalsRegistry: featuregate.DefaultComponentGlobalsRegistry,
|
||||
},
|
||||
expectErr: "ServerRunOptions.JSONPatchMaxCopyBytes can not be negative value",
|
||||
},
|
||||
@@ -129,7 +130,7 @@ func TestServerRunOptionsValidate(t *testing.T) {
|
||||
MinRequestTimeout: 1800,
|
||||
JSONPatchMaxCopyBytes: 10 * 1024 * 1024,
|
||||
MaxRequestBodyBytes: -10 * 1024 * 1024,
|
||||
ComponentGlobalsRegistry: utilversion.DefaultComponentGlobalsRegistry,
|
||||
ComponentGlobalsRegistry: featuregate.DefaultComponentGlobalsRegistry,
|
||||
},
|
||||
expectErr: "ServerRunOptions.MaxRequestBodyBytes can not be negative value",
|
||||
},
|
||||
@@ -145,7 +146,7 @@ func TestServerRunOptionsValidate(t *testing.T) {
|
||||
JSONPatchMaxCopyBytes: 10 * 1024 * 1024,
|
||||
MaxRequestBodyBytes: 10 * 1024 * 1024,
|
||||
LivezGracePeriod: -time.Second,
|
||||
ComponentGlobalsRegistry: utilversion.DefaultComponentGlobalsRegistry,
|
||||
ComponentGlobalsRegistry: featuregate.DefaultComponentGlobalsRegistry,
|
||||
},
|
||||
expectErr: "--livez-grace-period can not be a negative value",
|
||||
},
|
||||
@@ -161,7 +162,7 @@ func TestServerRunOptionsValidate(t *testing.T) {
|
||||
JSONPatchMaxCopyBytes: 10 * 1024 * 1024,
|
||||
MaxRequestBodyBytes: 10 * 1024 * 1024,
|
||||
ShutdownDelayDuration: -time.Second,
|
||||
ComponentGlobalsRegistry: utilversion.DefaultComponentGlobalsRegistry,
|
||||
ComponentGlobalsRegistry: featuregate.DefaultComponentGlobalsRegistry,
|
||||
},
|
||||
expectErr: "--shutdown-delay-duration can not be negative value",
|
||||
},
|
||||
@@ -177,7 +178,7 @@ func TestServerRunOptionsValidate(t *testing.T) {
|
||||
MinRequestTimeout: 1800,
|
||||
JSONPatchMaxCopyBytes: 10 * 1024 * 1024,
|
||||
MaxRequestBodyBytes: 10 * 1024 * 1024,
|
||||
ComponentGlobalsRegistry: utilversion.DefaultComponentGlobalsRegistry,
|
||||
ComponentGlobalsRegistry: featuregate.DefaultComponentGlobalsRegistry,
|
||||
},
|
||||
expectErr: "--strict-transport-security-directives invalid, allowed values: max-age=expireTime, includeSubDomains, preload. see https://tools.ietf.org/html/rfc6797#section-6.1 for more information",
|
||||
},
|
||||
@@ -210,7 +211,7 @@ func TestServerRunOptionsValidate(t *testing.T) {
|
||||
MinRequestTimeout: 1800,
|
||||
JSONPatchMaxCopyBytes: 10 * 1024 * 1024,
|
||||
MaxRequestBodyBytes: 10 * 1024 * 1024,
|
||||
ComponentGlobalsRegistry: utilversion.DefaultComponentGlobalsRegistry,
|
||||
ComponentGlobalsRegistry: featuregate.DefaultComponentGlobalsRegistry,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ import (
|
||||
"k8s.io/client-go/discovery"
|
||||
restclient "k8s.io/client-go/rest"
|
||||
cliflag "k8s.io/component-base/cli/flag"
|
||||
utilversion "k8s.io/component-base/registry"
|
||||
utilversion "k8s.io/component-base/version"
|
||||
"k8s.io/klog/v2/ktesting"
|
||||
netutils "k8s.io/utils/net"
|
||||
)
|
||||
|
||||
@@ -22,7 +22,7 @@ import (
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
apimachineryversion "k8s.io/apimachinery/pkg/util/version"
|
||||
version "k8s.io/component-base/registry"
|
||||
version "k8s.io/component-base/version"
|
||||
)
|
||||
|
||||
type ResourceEncodingConfig interface {
|
||||
|
||||
@@ -33,7 +33,7 @@ import (
|
||||
"k8s.io/apiserver/pkg/apis/example2"
|
||||
example2install "k8s.io/apiserver/pkg/apis/example2/install"
|
||||
"k8s.io/apiserver/pkg/storage/storagebackend"
|
||||
version "k8s.io/component-base/registry"
|
||||
version "k8s.io/component-base/version"
|
||||
)
|
||||
|
||||
var (
|
||||
|
||||
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package version
|
||||
package featuregate
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@@ -26,7 +26,7 @@ import (
|
||||
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
|
||||
"k8s.io/apimachinery/pkg/util/version"
|
||||
cliflag "k8s.io/component-base/cli/flag"
|
||||
"k8s.io/component-base/featuregate"
|
||||
baseversion "k8s.io/component-base/version"
|
||||
"k8s.io/klog/v2"
|
||||
)
|
||||
|
||||
@@ -67,8 +67,8 @@ type VersionMapping func(from *version.Version) *version.Version
|
||||
|
||||
// ComponentGlobals stores the global variables for a component for easy access.
|
||||
type ComponentGlobals struct {
|
||||
effectiveVersion MutableEffectiveVersion
|
||||
featureGate featuregate.MutableVersionedFeatureGate
|
||||
effectiveVersion baseversion.MutableEffectiveVersion
|
||||
featureGate MutableVersionedFeatureGate
|
||||
|
||||
// emulationVersionMapping contains the mapping from the emulation version of this component
|
||||
// to the emulation version of another component.
|
||||
@@ -87,16 +87,16 @@ type ComponentGlobals struct {
|
||||
type ComponentGlobalsRegistry interface {
|
||||
// EffectiveVersionFor returns the EffectiveVersion registered under the component.
|
||||
// Returns nil if the component is not registered.
|
||||
EffectiveVersionFor(component string) EffectiveVersion
|
||||
EffectiveVersionFor(component string) baseversion.EffectiveVersion
|
||||
// FeatureGateFor returns the FeatureGate registered under the component.
|
||||
// Returns nil if the component is not registered.
|
||||
FeatureGateFor(component string) featuregate.FeatureGate
|
||||
FeatureGateFor(component string) 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
|
||||
Register(component string, effectiveVersion baseversion.MutableEffectiveVersion, 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)
|
||||
ComponentGlobalsOrRegister(component string, effectiveVersion baseversion.MutableEffectiveVersion, featureGate MutableVersionedFeatureGate) (baseversion.MutableEffectiveVersion, 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.
|
||||
@@ -143,7 +143,7 @@ func (r *componentGlobalsRegistry) Reset() {
|
||||
r.set = false
|
||||
}
|
||||
|
||||
func (r *componentGlobalsRegistry) EffectiveVersionFor(component string) EffectiveVersion {
|
||||
func (r *componentGlobalsRegistry) EffectiveVersionFor(component string) baseversion.EffectiveVersion {
|
||||
r.mutex.RLock()
|
||||
defer r.mutex.RUnlock()
|
||||
globals, ok := r.componentGlobals[component]
|
||||
@@ -153,7 +153,7 @@ func (r *componentGlobalsRegistry) EffectiveVersionFor(component string) Effecti
|
||||
return globals.effectiveVersion
|
||||
}
|
||||
|
||||
func (r *componentGlobalsRegistry) FeatureGateFor(component string) featuregate.FeatureGate {
|
||||
func (r *componentGlobalsRegistry) FeatureGateFor(component string) FeatureGate {
|
||||
r.mutex.RLock()
|
||||
defer r.mutex.RUnlock()
|
||||
globals, ok := r.componentGlobals[component]
|
||||
@@ -163,7 +163,7 @@ func (r *componentGlobalsRegistry) FeatureGateFor(component string) featuregate.
|
||||
return globals.featureGate
|
||||
}
|
||||
|
||||
func (r *componentGlobalsRegistry) unsafeRegister(component string, effectiveVersion MutableEffectiveVersion, featureGate featuregate.MutableVersionedFeatureGate) error {
|
||||
func (r *componentGlobalsRegistry) unsafeRegister(component string, effectiveVersion baseversion.MutableEffectiveVersion, featureGate MutableVersionedFeatureGate) error {
|
||||
if _, ok := r.componentGlobals[component]; ok {
|
||||
return fmt.Errorf("component globals of %s already registered", component)
|
||||
}
|
||||
@@ -182,7 +182,7 @@ func (r *componentGlobalsRegistry) unsafeRegister(component string, effectiveVer
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *componentGlobalsRegistry) Register(component string, effectiveVersion MutableEffectiveVersion, featureGate featuregate.MutableVersionedFeatureGate) error {
|
||||
func (r *componentGlobalsRegistry) Register(component string, effectiveVersion baseversion.MutableEffectiveVersion, featureGate MutableVersionedFeatureGate) error {
|
||||
if effectiveVersion == nil {
|
||||
return fmt.Errorf("cannot register nil effectiveVersion")
|
||||
}
|
||||
@@ -191,7 +191,7 @@ func (r *componentGlobalsRegistry) Register(component string, effectiveVersion M
|
||||
return r.unsafeRegister(component, effectiveVersion, featureGate)
|
||||
}
|
||||
|
||||
func (r *componentGlobalsRegistry) ComponentGlobalsOrRegister(component string, effectiveVersion MutableEffectiveVersion, featureGate featuregate.MutableVersionedFeatureGate) (MutableEffectiveVersion, featuregate.MutableVersionedFeatureGate) {
|
||||
func (r *componentGlobalsRegistry) ComponentGlobalsOrRegister(component string, effectiveVersion baseversion.MutableEffectiveVersion, featureGate MutableVersionedFeatureGate) (baseversion.MutableEffectiveVersion, MutableVersionedFeatureGate) {
|
||||
r.mutex.Lock()
|
||||
defer r.mutex.Unlock()
|
||||
globals, ok := r.componentGlobals[component]
|
||||
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package version
|
||||
package featuregate
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@@ -24,7 +24,7 @@ import (
|
||||
"github.com/spf13/pflag"
|
||||
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
|
||||
"k8s.io/apimachinery/pkg/util/version"
|
||||
"k8s.io/component-base/featuregate"
|
||||
baseversion "k8s.io/component-base/version"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -33,8 +33,8 @@ const (
|
||||
|
||||
func TestEffectiveVersionRegistry(t *testing.T) {
|
||||
r := NewComponentGlobalsRegistry()
|
||||
ver1 := NewEffectiveVersion("1.31")
|
||||
ver2 := NewEffectiveVersion("1.28")
|
||||
ver1 := baseversion.NewEffectiveVersion("1.31")
|
||||
ver2 := baseversion.NewEffectiveVersion("1.28")
|
||||
|
||||
if r.EffectiveVersionFor(testComponent) != nil {
|
||||
t.Fatalf("expected nil EffectiveVersion initially")
|
||||
@@ -56,40 +56,40 @@ func TestEffectiveVersionRegistry(t *testing.T) {
|
||||
|
||||
func testRegistry(t *testing.T) *componentGlobalsRegistry {
|
||||
r := NewComponentGlobalsRegistry()
|
||||
verKube := NewEffectiveVersion("1.31")
|
||||
fgKube := featuregate.NewVersionedFeatureGate(version.MustParse("0.0"))
|
||||
err := fgKube.AddVersioned(map[featuregate.Feature]featuregate.VersionedSpecs{
|
||||
verKube := baseversion.NewEffectiveVersion("1.31")
|
||||
fgKube := NewVersionedFeatureGate(version.MustParse("0.0"))
|
||||
err := fgKube.AddVersioned(map[Feature]VersionedSpecs{
|
||||
"kubeA": {
|
||||
{Version: version.MustParse("1.31"), Default: true, LockToDefault: true, PreRelease: featuregate.GA},
|
||||
{Version: version.MustParse("1.28"), Default: false, PreRelease: featuregate.Beta},
|
||||
{Version: version.MustParse("1.27"), Default: false, PreRelease: featuregate.Alpha},
|
||||
{Version: version.MustParse("1.31"), Default: true, LockToDefault: true, PreRelease: GA},
|
||||
{Version: version.MustParse("1.28"), Default: false, PreRelease: Beta},
|
||||
{Version: version.MustParse("1.27"), Default: false, PreRelease: Alpha},
|
||||
},
|
||||
"kubeB": {
|
||||
{Version: version.MustParse("1.30"), Default: false, PreRelease: featuregate.Alpha},
|
||||
{Version: version.MustParse("1.30"), Default: false, PreRelease: Alpha},
|
||||
},
|
||||
"commonC": {
|
||||
{Version: version.MustParse("1.29"), Default: true, PreRelease: featuregate.Beta},
|
||||
{Version: version.MustParse("1.27"), Default: false, PreRelease: featuregate.Alpha},
|
||||
{Version: version.MustParse("1.29"), Default: true, PreRelease: Beta},
|
||||
{Version: version.MustParse("1.27"), Default: false, PreRelease: Alpha},
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
verTest := NewEffectiveVersion("2.8")
|
||||
fgTest := featuregate.NewVersionedFeatureGate(version.MustParse("0.0"))
|
||||
err = fgTest.AddVersioned(map[featuregate.Feature]featuregate.VersionedSpecs{
|
||||
verTest := baseversion.NewEffectiveVersion("2.8")
|
||||
fgTest := NewVersionedFeatureGate(version.MustParse("0.0"))
|
||||
err = fgTest.AddVersioned(map[Feature]VersionedSpecs{
|
||||
"testA": {
|
||||
{Version: version.MustParse("2.10"), Default: true, PreRelease: featuregate.GA},
|
||||
{Version: version.MustParse("2.8"), Default: false, PreRelease: featuregate.Beta},
|
||||
{Version: version.MustParse("2.7"), Default: false, PreRelease: featuregate.Alpha},
|
||||
{Version: version.MustParse("2.10"), Default: true, PreRelease: GA},
|
||||
{Version: version.MustParse("2.8"), Default: false, PreRelease: Beta},
|
||||
{Version: version.MustParse("2.7"), Default: false, PreRelease: Alpha},
|
||||
},
|
||||
"testB": {
|
||||
{Version: version.MustParse("2.9"), Default: false, PreRelease: featuregate.Alpha},
|
||||
{Version: version.MustParse("2.9"), Default: false, PreRelease: Alpha},
|
||||
},
|
||||
"commonC": {
|
||||
{Version: version.MustParse("2.9"), Default: true, PreRelease: featuregate.Beta},
|
||||
{Version: version.MustParse("2.7"), Default: false, PreRelease: featuregate.Alpha},
|
||||
{Version: version.MustParse("2.9"), Default: true, PreRelease: Beta},
|
||||
{Version: version.MustParse("2.7"), Default: false, PreRelease: Alpha},
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
@@ -130,7 +130,7 @@ func TestVersionFlagOptionsWithMapping(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestVersionedFeatureGateFlag(t *testing.T) {
|
||||
func TestVersionedFeatureGateFlags(t *testing.T) {
|
||||
r := testRegistry(t)
|
||||
known := strings.Join(r.unsafeKnownFeatures(), "\n")
|
||||
expectedKnown := "kube:AllAlpha=true|false (ALPHA - default=false)\n" +
|
||||
@@ -153,8 +153,8 @@ func TestFlags(t *testing.T) {
|
||||
parseError string
|
||||
expectedKubeEmulationVersion string
|
||||
expectedTestEmulationVersion string
|
||||
expectedKubeFeatureValues map[featuregate.Feature]bool
|
||||
expectedTestFeatureValues map[featuregate.Feature]bool
|
||||
expectedKubeFeatureValues map[Feature]bool
|
||||
expectedTestFeatureValues map[Feature]bool
|
||||
}{
|
||||
{
|
||||
name: "setting kube emulation version",
|
||||
@@ -213,8 +213,8 @@ func TestFlags(t *testing.T) {
|
||||
},
|
||||
expectedKubeEmulationVersion: "1.31",
|
||||
expectedTestEmulationVersion: "2.7",
|
||||
expectedKubeFeatureValues: map[featuregate.Feature]bool{"kubeA": true, "kubeB": false, "commonC": true},
|
||||
expectedTestFeatureValues: map[featuregate.Feature]bool{"testA": true, "testB": false, "commonC": false},
|
||||
expectedKubeFeatureValues: map[Feature]bool{"kubeA": true, "kubeB": false, "commonC": true},
|
||||
expectedTestFeatureValues: map[Feature]bool{"testA": true, "testB": false, "commonC": false},
|
||||
},
|
||||
{
|
||||
name: "setting future test feature flag",
|
||||
@@ -234,8 +234,8 @@ func TestFlags(t *testing.T) {
|
||||
},
|
||||
expectedKubeEmulationVersion: "1.30",
|
||||
expectedTestEmulationVersion: "2.7",
|
||||
expectedKubeFeatureValues: map[featuregate.Feature]bool{"kubeA": false, "kubeB": true, "commonC": false},
|
||||
expectedTestFeatureValues: map[featuregate.Feature]bool{"testA": false, "testB": false, "commonC": true},
|
||||
expectedKubeFeatureValues: map[Feature]bool{"kubeA": false, "kubeB": true, "commonC": false},
|
||||
expectedTestFeatureValues: map[Feature]bool{"testA": false, "testB": false, "commonC": true},
|
||||
},
|
||||
{
|
||||
name: "setting kube feature flag with different prefix",
|
||||
@@ -312,9 +312,9 @@ func TestFlags(t *testing.T) {
|
||||
|
||||
func TestVersionMapping(t *testing.T) {
|
||||
r := NewComponentGlobalsRegistry()
|
||||
ver1 := NewEffectiveVersion("0.58")
|
||||
ver2 := NewEffectiveVersion("1.28")
|
||||
ver3 := NewEffectiveVersion("2.10")
|
||||
ver1 := baseversion.NewEffectiveVersion("0.58")
|
||||
ver2 := baseversion.NewEffectiveVersion("1.28")
|
||||
ver3 := baseversion.NewEffectiveVersion("2.10")
|
||||
|
||||
utilruntime.Must(r.Register("test1", ver1, nil))
|
||||
utilruntime.Must(r.Register("test2", ver2, nil))
|
||||
@@ -354,9 +354,9 @@ func TestVersionMapping(t *testing.T) {
|
||||
|
||||
func TestVersionMappingWithMultipleDependency(t *testing.T) {
|
||||
r := NewComponentGlobalsRegistry()
|
||||
ver1 := NewEffectiveVersion("0.58")
|
||||
ver2 := NewEffectiveVersion("1.28")
|
||||
ver3 := NewEffectiveVersion("2.10")
|
||||
ver1 := baseversion.NewEffectiveVersion("0.58")
|
||||
ver2 := baseversion.NewEffectiveVersion("1.28")
|
||||
ver3 := baseversion.NewEffectiveVersion("2.10")
|
||||
|
||||
utilruntime.Must(r.Register("test1", ver1, nil))
|
||||
utilruntime.Must(r.Register("test2", ver2, nil))
|
||||
@@ -381,9 +381,9 @@ func TestVersionMappingWithMultipleDependency(t *testing.T) {
|
||||
|
||||
func TestVersionMappingWithCyclicDependency(t *testing.T) {
|
||||
r := NewComponentGlobalsRegistry()
|
||||
ver1 := NewEffectiveVersion("0.58")
|
||||
ver2 := NewEffectiveVersion("1.28")
|
||||
ver3 := NewEffectiveVersion("2.10")
|
||||
ver1 := baseversion.NewEffectiveVersion("0.58")
|
||||
ver2 := baseversion.NewEffectiveVersion("1.28")
|
||||
ver3 := baseversion.NewEffectiveVersion("2.10")
|
||||
|
||||
utilruntime.Must(r.Register("test1", ver1, nil))
|
||||
utilruntime.Must(r.Register("test2", ver2, nil))
|
||||
@@ -1,180 +0,0 @@
|
||||
/*
|
||||
Copyright 2024 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package version
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sync/atomic"
|
||||
|
||||
"k8s.io/apimachinery/pkg/util/version"
|
||||
baseversion "k8s.io/component-base/version"
|
||||
)
|
||||
|
||||
type EffectiveVersion interface {
|
||||
BinaryVersion() *version.Version
|
||||
EmulationVersion() *version.Version
|
||||
MinCompatibilityVersion() *version.Version
|
||||
EqualTo(other EffectiveVersion) bool
|
||||
String() string
|
||||
Validate() []error
|
||||
}
|
||||
|
||||
type MutableEffectiveVersion interface {
|
||||
EffectiveVersion
|
||||
Set(binaryVersion, emulationVersion, minCompatibilityVersion *version.Version)
|
||||
SetEmulationVersion(emulationVersion *version.Version)
|
||||
SetMinCompatibilityVersion(minCompatibilityVersion *version.Version)
|
||||
}
|
||||
|
||||
type effectiveVersion struct {
|
||||
// When true, BinaryVersion() returns the current binary version
|
||||
useDefaultBuildBinaryVersion atomic.Bool
|
||||
// Holds the last binary version stored in Set()
|
||||
binaryVersion atomic.Pointer[version.Version]
|
||||
// If the emulationVersion is set by the users, it could only contain major and minor versions.
|
||||
// In tests, emulationVersion could be the same as the binary version, or set directly,
|
||||
// which can have "alpha" as pre-release to continue serving expired apis while we clean up the test.
|
||||
emulationVersion atomic.Pointer[version.Version]
|
||||
// minCompatibilityVersion could only contain major and minor versions.
|
||||
minCompatibilityVersion atomic.Pointer[version.Version]
|
||||
}
|
||||
|
||||
func (m *effectiveVersion) BinaryVersion() *version.Version {
|
||||
if m.useDefaultBuildBinaryVersion.Load() {
|
||||
return defaultBuildBinaryVersion()
|
||||
}
|
||||
return m.binaryVersion.Load()
|
||||
}
|
||||
|
||||
func (m *effectiveVersion) EmulationVersion() *version.Version {
|
||||
ver := m.emulationVersion.Load()
|
||||
if ver != nil {
|
||||
// Emulation version can have "alpha" as pre-release to continue serving expired apis while we clean up the test.
|
||||
// The pre-release should not be accessible to the users.
|
||||
return ver.WithPreRelease(m.BinaryVersion().PreRelease())
|
||||
}
|
||||
return ver
|
||||
}
|
||||
|
||||
func (m *effectiveVersion) MinCompatibilityVersion() *version.Version {
|
||||
return m.minCompatibilityVersion.Load()
|
||||
}
|
||||
|
||||
func (m *effectiveVersion) EqualTo(other EffectiveVersion) bool {
|
||||
return m.BinaryVersion().EqualTo(other.BinaryVersion()) && m.EmulationVersion().EqualTo(other.EmulationVersion()) && m.MinCompatibilityVersion().EqualTo(other.MinCompatibilityVersion())
|
||||
}
|
||||
|
||||
func (m *effectiveVersion) String() string {
|
||||
if m == nil {
|
||||
return "<nil>"
|
||||
}
|
||||
return fmt.Sprintf("{BinaryVersion: %s, EmulationVersion: %s, MinCompatibilityVersion: %s}",
|
||||
m.BinaryVersion().String(), m.EmulationVersion().String(), m.MinCompatibilityVersion().String())
|
||||
}
|
||||
|
||||
func majorMinor(ver *version.Version) *version.Version {
|
||||
if ver == nil {
|
||||
return ver
|
||||
}
|
||||
return version.MajorMinor(ver.Major(), ver.Minor())
|
||||
}
|
||||
|
||||
func (m *effectiveVersion) Set(binaryVersion, emulationVersion, minCompatibilityVersion *version.Version) {
|
||||
m.binaryVersion.Store(binaryVersion)
|
||||
m.useDefaultBuildBinaryVersion.Store(false)
|
||||
m.emulationVersion.Store(majorMinor(emulationVersion))
|
||||
m.minCompatibilityVersion.Store(majorMinor(minCompatibilityVersion))
|
||||
}
|
||||
|
||||
func (m *effectiveVersion) SetEmulationVersion(emulationVersion *version.Version) {
|
||||
m.emulationVersion.Store(majorMinor(emulationVersion))
|
||||
}
|
||||
|
||||
func (m *effectiveVersion) SetMinCompatibilityVersion(minCompatibilityVersion *version.Version) {
|
||||
m.minCompatibilityVersion.Store(majorMinor(minCompatibilityVersion))
|
||||
}
|
||||
|
||||
func (m *effectiveVersion) Validate() []error {
|
||||
var errs []error
|
||||
// Validate only checks the major and minor versions.
|
||||
binaryVersion := m.BinaryVersion().WithPatch(0)
|
||||
emulationVersion := m.emulationVersion.Load()
|
||||
minCompatibilityVersion := m.minCompatibilityVersion.Load()
|
||||
|
||||
// emulationVersion can only be 1.{binaryMinor-1}...1.{binaryMinor}.
|
||||
maxEmuVer := binaryVersion
|
||||
minEmuVer := binaryVersion.SubtractMinor(1)
|
||||
if emulationVersion.GreaterThan(maxEmuVer) || emulationVersion.LessThan(minEmuVer) {
|
||||
errs = append(errs, fmt.Errorf("emulation version %s is not between [%s, %s]", emulationVersion.String(), minEmuVer.String(), maxEmuVer.String()))
|
||||
}
|
||||
// minCompatibilityVersion can only be 1.{binaryMinor-1} for alpha.
|
||||
maxCompVer := binaryVersion.SubtractMinor(1)
|
||||
minCompVer := binaryVersion.SubtractMinor(1)
|
||||
if minCompatibilityVersion.GreaterThan(maxCompVer) || minCompatibilityVersion.LessThan(minCompVer) {
|
||||
errs = append(errs, fmt.Errorf("minCompatibilityVersion version %s is not between [%s, %s]", minCompatibilityVersion.String(), minCompVer.String(), maxCompVer.String()))
|
||||
}
|
||||
return errs
|
||||
}
|
||||
|
||||
func newEffectiveVersion(binaryVersion *version.Version, useDefaultBuildBinaryVersion bool) MutableEffectiveVersion {
|
||||
effective := &effectiveVersion{}
|
||||
compatVersion := binaryVersion.SubtractMinor(1)
|
||||
effective.Set(binaryVersion, binaryVersion, compatVersion)
|
||||
effective.useDefaultBuildBinaryVersion.Store(useDefaultBuildBinaryVersion)
|
||||
return effective
|
||||
}
|
||||
|
||||
func NewEffectiveVersion(binaryVer string) MutableEffectiveVersion {
|
||||
if binaryVer == "" {
|
||||
return &effectiveVersion{}
|
||||
}
|
||||
binaryVersion := version.MustParse(binaryVer)
|
||||
return newEffectiveVersion(binaryVersion, false)
|
||||
}
|
||||
|
||||
func defaultBuildBinaryVersion() *version.Version {
|
||||
verInfo := baseversion.Get()
|
||||
return version.MustParse(verInfo.String()).WithInfo(verInfo)
|
||||
}
|
||||
|
||||
// DefaultBuildEffectiveVersion returns the MutableEffectiveVersion based on the
|
||||
// current build information.
|
||||
func DefaultBuildEffectiveVersion() MutableEffectiveVersion {
|
||||
binaryVersion := defaultBuildBinaryVersion()
|
||||
if binaryVersion.Major() == 0 && binaryVersion.Minor() == 0 {
|
||||
return DefaultKubeEffectiveVersion()
|
||||
}
|
||||
return newEffectiveVersion(binaryVersion, true)
|
||||
}
|
||||
|
||||
// DefaultKubeEffectiveVersion returns the MutableEffectiveVersion based on the
|
||||
// latest K8s release.
|
||||
func DefaultKubeEffectiveVersion() MutableEffectiveVersion {
|
||||
binaryVersion := version.MustParse(baseversion.DefaultKubeBinaryVersion).WithInfo(baseversion.Get())
|
||||
return newEffectiveVersion(binaryVersion, false)
|
||||
}
|
||||
|
||||
// ValidateKubeEffectiveVersion validates the EmulationVersion is equal to the binary version at 1.31 for kube components.
|
||||
// emulationVersion is introduced in 1.31, so it is only allowed to be equal to the binary version at 1.31.
|
||||
func ValidateKubeEffectiveVersion(effectiveVersion EffectiveVersion) error {
|
||||
binaryVersion := version.MajorMinor(effectiveVersion.BinaryVersion().Major(), effectiveVersion.BinaryVersion().Minor())
|
||||
if binaryVersion.EqualTo(version.MajorMinor(1, 31)) && !effectiveVersion.EmulationVersion().EqualTo(binaryVersion) {
|
||||
return fmt.Errorf("emulation version needs to be equal to binary version(%s) in compatibility-version alpha, got %s",
|
||||
binaryVersion.String(), effectiveVersion.EmulationVersion().String())
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -19,10 +19,41 @@ package version
|
||||
import (
|
||||
"fmt"
|
||||
"runtime"
|
||||
"sync/atomic"
|
||||
|
||||
"k8s.io/apimachinery/pkg/util/version"
|
||||
apimachineryversion "k8s.io/apimachinery/pkg/version"
|
||||
)
|
||||
|
||||
type EffectiveVersion interface {
|
||||
BinaryVersion() *version.Version
|
||||
EmulationVersion() *version.Version
|
||||
MinCompatibilityVersion() *version.Version
|
||||
EqualTo(other EffectiveVersion) bool
|
||||
String() string
|
||||
Validate() []error
|
||||
}
|
||||
|
||||
type MutableEffectiveVersion interface {
|
||||
EffectiveVersion
|
||||
Set(binaryVersion, emulationVersion, minCompatibilityVersion *version.Version)
|
||||
SetEmulationVersion(emulationVersion *version.Version)
|
||||
SetMinCompatibilityVersion(minCompatibilityVersion *version.Version)
|
||||
}
|
||||
|
||||
type effectiveVersion struct {
|
||||
// When true, BinaryVersion() returns the current binary version
|
||||
useDefaultBuildBinaryVersion atomic.Bool
|
||||
// Holds the last binary version stored in Set()
|
||||
binaryVersion atomic.Pointer[version.Version]
|
||||
// If the emulationVersion is set by the users, it could only contain major and minor versions.
|
||||
// In tests, emulationVersion could be the same as the binary version, or set directly,
|
||||
// which can have "alpha" as pre-release to continue serving expired apis while we clean up the test.
|
||||
emulationVersion atomic.Pointer[version.Version]
|
||||
// minCompatibilityVersion could only contain major and minor versions.
|
||||
minCompatibilityVersion atomic.Pointer[version.Version]
|
||||
}
|
||||
|
||||
// Get returns the overall codebase version. It's for detecting
|
||||
// what code a binary was built from.
|
||||
func Get() apimachineryversion.Info {
|
||||
@@ -40,3 +71,129 @@ func Get() apimachineryversion.Info {
|
||||
Platform: fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH),
|
||||
}
|
||||
}
|
||||
|
||||
func (m *effectiveVersion) BinaryVersion() *version.Version {
|
||||
if m.useDefaultBuildBinaryVersion.Load() {
|
||||
return defaultBuildBinaryVersion()
|
||||
}
|
||||
return m.binaryVersion.Load()
|
||||
}
|
||||
|
||||
func (m *effectiveVersion) EmulationVersion() *version.Version {
|
||||
ver := m.emulationVersion.Load()
|
||||
if ver != nil {
|
||||
// Emulation version can have "alpha" as pre-release to continue serving expired apis while we clean up the test.
|
||||
// The pre-release should not be accessible to the users.
|
||||
return ver.WithPreRelease(m.BinaryVersion().PreRelease())
|
||||
}
|
||||
return ver
|
||||
}
|
||||
|
||||
func (m *effectiveVersion) MinCompatibilityVersion() *version.Version {
|
||||
return m.minCompatibilityVersion.Load()
|
||||
}
|
||||
|
||||
func (m *effectiveVersion) EqualTo(other EffectiveVersion) bool {
|
||||
return m.BinaryVersion().EqualTo(other.BinaryVersion()) && m.EmulationVersion().EqualTo(other.EmulationVersion()) && m.MinCompatibilityVersion().EqualTo(other.MinCompatibilityVersion())
|
||||
}
|
||||
|
||||
func (m *effectiveVersion) String() string {
|
||||
if m == nil {
|
||||
return "<nil>"
|
||||
}
|
||||
return fmt.Sprintf("{BinaryVersion: %s, EmulationVersion: %s, MinCompatibilityVersion: %s}",
|
||||
m.BinaryVersion().String(), m.EmulationVersion().String(), m.MinCompatibilityVersion().String())
|
||||
}
|
||||
|
||||
func majorMinor(ver *version.Version) *version.Version {
|
||||
if ver == nil {
|
||||
return ver
|
||||
}
|
||||
return version.MajorMinor(ver.Major(), ver.Minor())
|
||||
}
|
||||
|
||||
func (m *effectiveVersion) Set(binaryVersion, emulationVersion, minCompatibilityVersion *version.Version) {
|
||||
m.binaryVersion.Store(binaryVersion)
|
||||
m.useDefaultBuildBinaryVersion.Store(false)
|
||||
m.emulationVersion.Store(majorMinor(emulationVersion))
|
||||
m.minCompatibilityVersion.Store(majorMinor(minCompatibilityVersion))
|
||||
}
|
||||
|
||||
func (m *effectiveVersion) SetEmulationVersion(emulationVersion *version.Version) {
|
||||
m.emulationVersion.Store(majorMinor(emulationVersion))
|
||||
}
|
||||
|
||||
func (m *effectiveVersion) SetMinCompatibilityVersion(minCompatibilityVersion *version.Version) {
|
||||
m.minCompatibilityVersion.Store(majorMinor(minCompatibilityVersion))
|
||||
}
|
||||
|
||||
func (m *effectiveVersion) Validate() []error {
|
||||
var errs []error
|
||||
// Validate only checks the major and minor versions.
|
||||
binaryVersion := m.BinaryVersion().WithPatch(0)
|
||||
emulationVersion := m.emulationVersion.Load()
|
||||
minCompatibilityVersion := m.minCompatibilityVersion.Load()
|
||||
|
||||
// emulationVersion can only be 1.{binaryMinor-1}...1.{binaryMinor}.
|
||||
maxEmuVer := binaryVersion
|
||||
minEmuVer := binaryVersion.SubtractMinor(1)
|
||||
if emulationVersion.GreaterThan(maxEmuVer) || emulationVersion.LessThan(minEmuVer) {
|
||||
errs = append(errs, fmt.Errorf("emulation version %s is not between [%s, %s]", emulationVersion.String(), minEmuVer.String(), maxEmuVer.String()))
|
||||
}
|
||||
// minCompatibilityVersion can only be 1.{binaryMinor-1} for alpha.
|
||||
maxCompVer := binaryVersion.SubtractMinor(1)
|
||||
minCompVer := binaryVersion.SubtractMinor(1)
|
||||
if minCompatibilityVersion.GreaterThan(maxCompVer) || minCompatibilityVersion.LessThan(minCompVer) {
|
||||
errs = append(errs, fmt.Errorf("minCompatibilityVersion version %s is not between [%s, %s]", minCompatibilityVersion.String(), minCompVer.String(), maxCompVer.String()))
|
||||
}
|
||||
return errs
|
||||
}
|
||||
|
||||
func newEffectiveVersion(binaryVersion *version.Version, useDefaultBuildBinaryVersion bool) MutableEffectiveVersion {
|
||||
effective := &effectiveVersion{}
|
||||
compatVersion := binaryVersion.SubtractMinor(1)
|
||||
effective.Set(binaryVersion, binaryVersion, compatVersion)
|
||||
effective.useDefaultBuildBinaryVersion.Store(useDefaultBuildBinaryVersion)
|
||||
return effective
|
||||
}
|
||||
|
||||
func NewEffectiveVersion(binaryVer string) MutableEffectiveVersion {
|
||||
if binaryVer == "" {
|
||||
return &effectiveVersion{}
|
||||
}
|
||||
binaryVersion := version.MustParse(binaryVer)
|
||||
return newEffectiveVersion(binaryVersion, false)
|
||||
}
|
||||
|
||||
func defaultBuildBinaryVersion() *version.Version {
|
||||
verInfo := Get()
|
||||
return version.MustParse(verInfo.String()).WithInfo(verInfo)
|
||||
}
|
||||
|
||||
// DefaultBuildEffectiveVersion returns the MutableEffectiveVersion based on the
|
||||
// current build information.
|
||||
func DefaultBuildEffectiveVersion() MutableEffectiveVersion {
|
||||
binaryVersion := defaultBuildBinaryVersion()
|
||||
if binaryVersion.Major() == 0 && binaryVersion.Minor() == 0 {
|
||||
return DefaultKubeEffectiveVersion()
|
||||
}
|
||||
return newEffectiveVersion(binaryVersion, true)
|
||||
}
|
||||
|
||||
// DefaultKubeEffectiveVersion returns the MutableEffectiveVersion based on the
|
||||
// latest K8s release.
|
||||
func DefaultKubeEffectiveVersion() MutableEffectiveVersion {
|
||||
binaryVersion := version.MustParse(DefaultKubeBinaryVersion).WithInfo(Get())
|
||||
return newEffectiveVersion(binaryVersion, false)
|
||||
}
|
||||
|
||||
// ValidateKubeEffectiveVersion validates the EmulationVersion is equal to the binary version at 1.31 for kube components.
|
||||
// emulationVersion is introduced in 1.31, so it is only allowed to be equal to the binary version at 1.31.
|
||||
func ValidateKubeEffectiveVersion(effectiveVersion EffectiveVersion) error {
|
||||
binaryVersion := version.MajorMinor(effectiveVersion.BinaryVersion().Major(), effectiveVersion.BinaryVersion().Minor())
|
||||
if binaryVersion.EqualTo(version.MajorMinor(1, 31)) && !effectiveVersion.EmulationVersion().EqualTo(binaryVersion) {
|
||||
return fmt.Errorf("emulation version needs to be equal to binary version(%s) in compatibility-version alpha, got %s",
|
||||
binaryVersion.String(), effectiveVersion.EmulationVersion().String())
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -44,6 +44,7 @@ require (
|
||||
github.com/google/gofuzz v1.2.0 // indirect
|
||||
github.com/google/uuid v1.6.0 // indirect
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 // indirect
|
||||
github.com/inconshreveable/mousetrap v1.1.0 // indirect
|
||||
github.com/josharian/intern v1.0.0 // indirect
|
||||
github.com/json-iterator/go v1.1.12 // indirect
|
||||
github.com/mailru/easyjson v0.7.7 // indirect
|
||||
@@ -55,6 +56,7 @@ require (
|
||||
github.com/prometheus/client_model v0.6.1 // indirect
|
||||
github.com/prometheus/common v0.55.0 // indirect
|
||||
github.com/prometheus/procfs v0.15.1 // indirect
|
||||
github.com/spf13/cobra v1.8.1 // indirect
|
||||
github.com/spf13/pflag v1.0.5 // indirect
|
||||
github.com/x448/float16 v0.8.4 // indirect
|
||||
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.53.0 // indirect
|
||||
|
||||
4
staging/src/k8s.io/cri-client/go.sum
generated
4
staging/src/k8s.io/cri-client/go.sum
generated
@@ -19,6 +19,7 @@ github.com/census-instrumentation/opencensus-proto v0.4.1/go.mod h1:4T9NM4+4Vw91
|
||||
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
|
||||
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
|
||||
github.com/cncf/xds/go v0.0.0-20240423153145-555b57ec207b/go.mod h1:W+zGtBO5Y1IgJhy4+A9GOqVhqLpfZi+vwmdNXUehLA8=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
|
||||
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
@@ -73,6 +74,7 @@ github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/ad
|
||||
github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA=
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0 h1:bkypFPDjIYGfCYD5mRBvpqxfYX1YCS1PXdKYWi8FsN0=
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0/go.mod h1:P+Lt/0by1T8bfcF3z737NnSbmxQAppXMRziHUxPOC8k=
|
||||
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
|
||||
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
|
||||
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
|
||||
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
|
||||
@@ -120,7 +122,9 @@ github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoG
|
||||
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
|
||||
github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8=
|
||||
github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4=
|
||||
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
|
||||
github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM=
|
||||
github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y=
|
||||
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
|
||||
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
||||
|
||||
@@ -31,7 +31,7 @@ import (
|
||||
genericapiserver "k8s.io/apiserver/pkg/server"
|
||||
"k8s.io/apiserver/pkg/server/filters"
|
||||
genericoptions "k8s.io/apiserver/pkg/server/options"
|
||||
utilversion "k8s.io/component-base/registry"
|
||||
"k8s.io/component-base/featuregate"
|
||||
"k8s.io/kube-aggregator/pkg/apis/apiregistration/v1beta1"
|
||||
"k8s.io/kube-aggregator/pkg/apiserver"
|
||||
aggregatorscheme "k8s.io/kube-aggregator/pkg/apiserver/scheme"
|
||||
@@ -63,7 +63,7 @@ func NewCommandStartAggregator(ctx context.Context, defaults *AggregatorOptions)
|
||||
Short: "Launch a API aggregator and proxy server",
|
||||
Long: "Launch a API aggregator and proxy server",
|
||||
PersistentPreRunE: func(*cobra.Command, []string) error {
|
||||
return utilversion.DefaultComponentGlobalsRegistry.Set()
|
||||
return featuregate.DefaultComponentGlobalsRegistry.Set()
|
||||
},
|
||||
RunE: func(c *cobra.Command, args []string) error {
|
||||
if err := o.Complete(); err != nil {
|
||||
|
||||
@@ -35,8 +35,7 @@ import (
|
||||
genericoptions "k8s.io/apiserver/pkg/server/options"
|
||||
utilfeature "k8s.io/apiserver/pkg/util/feature"
|
||||
"k8s.io/component-base/featuregate"
|
||||
utilversion "k8s.io/component-base/registry"
|
||||
baseversion "k8s.io/component-base/version"
|
||||
utilversion "k8s.io/component-base/version"
|
||||
"k8s.io/sample-apiserver/pkg/admission/plugin/banflunder"
|
||||
"k8s.io/sample-apiserver/pkg/admission/wardleinitializer"
|
||||
"k8s.io/sample-apiserver/pkg/apis/wardle/v1alpha1"
|
||||
@@ -97,7 +96,7 @@ func NewCommandStartWardleServer(ctx context.Context, defaults *WardleServerOpti
|
||||
Short: "Launch a wardle API server",
|
||||
Long: "Launch a wardle API server",
|
||||
PersistentPreRunE: func(*cobra.Command, []string) error {
|
||||
return utilversion.DefaultComponentGlobalsRegistry.Set()
|
||||
return featuregate.DefaultComponentGlobalsRegistry.Set()
|
||||
},
|
||||
RunE: func(c *cobra.Command, args []string) error {
|
||||
if err := o.Complete(); err != nil {
|
||||
@@ -133,7 +132,7 @@ func NewCommandStartWardleServer(ctx context.Context, defaults *WardleServerOpti
|
||||
// Register the "Wardle" component with the global component registry,
|
||||
// associating it with its effective version and feature gate configuration.
|
||||
// Will skip if the component has been registered, like in the integration test.
|
||||
_, wardleFeatureGate := utilversion.DefaultComponentGlobalsRegistry.ComponentGlobalsOrRegister(
|
||||
_, wardleFeatureGate := featuregate.DefaultComponentGlobalsRegistry.ComponentGlobalsOrRegister(
|
||||
apiserver.WardleComponentName, utilversion.NewEffectiveVersion(defaultWardleVersion),
|
||||
featuregate.NewVersionedFeatureGate(version.MustParse(defaultWardleVersion)))
|
||||
|
||||
@@ -148,14 +147,14 @@ func NewCommandStartWardleServer(ctx context.Context, defaults *WardleServerOpti
|
||||
}))
|
||||
|
||||
// Register the default kube component if not already present in the global registry.
|
||||
_, _ = utilversion.DefaultComponentGlobalsRegistry.ComponentGlobalsOrRegister(utilversion.DefaultKubeComponent,
|
||||
utilversion.NewEffectiveVersion(baseversion.DefaultKubeBinaryVersion), utilfeature.DefaultMutableFeatureGate)
|
||||
_, _ = featuregate.DefaultComponentGlobalsRegistry.ComponentGlobalsOrRegister(featuregate.DefaultKubeComponent,
|
||||
utilversion.NewEffectiveVersion(utilversion.DefaultKubeBinaryVersion), utilfeature.DefaultMutableFeatureGate)
|
||||
|
||||
// Set the emulation version mapping from the "Wardle" component to the kube component.
|
||||
// This ensures that the emulation version of the latter is determined by the emulation version of the former.
|
||||
utilruntime.Must(utilversion.DefaultComponentGlobalsRegistry.SetEmulationVersionMapping(apiserver.WardleComponentName, utilversion.DefaultKubeComponent, WardleVersionToKubeVersion))
|
||||
utilruntime.Must(featuregate.DefaultComponentGlobalsRegistry.SetEmulationVersionMapping(apiserver.WardleComponentName, featuregate.DefaultKubeComponent, WardleVersionToKubeVersion))
|
||||
|
||||
utilversion.DefaultComponentGlobalsRegistry.AddFlags(flags)
|
||||
featuregate.DefaultComponentGlobalsRegistry.AddFlags(flags)
|
||||
|
||||
return cmd
|
||||
}
|
||||
@@ -164,13 +163,13 @@ func NewCommandStartWardleServer(ctx context.Context, defaults *WardleServerOpti
|
||||
func (o WardleServerOptions) Validate(args []string) error {
|
||||
errors := []error{}
|
||||
errors = append(errors, o.RecommendedOptions.Validate()...)
|
||||
errors = append(errors, utilversion.DefaultComponentGlobalsRegistry.Validate()...)
|
||||
errors = append(errors, featuregate.DefaultComponentGlobalsRegistry.Validate()...)
|
||||
return utilerrors.NewAggregate(errors)
|
||||
}
|
||||
|
||||
// Complete fills in fields required to have valid data
|
||||
func (o *WardleServerOptions) Complete() error {
|
||||
if utilversion.DefaultComponentGlobalsRegistry.FeatureGateFor(apiserver.WardleComponentName).Enabled("BanFlunder") {
|
||||
if featuregate.DefaultComponentGlobalsRegistry.FeatureGateFor(apiserver.WardleComponentName).Enabled("BanFlunder") {
|
||||
// register admission plugins
|
||||
banflunder.Register(o.RecommendedOptions.Admission.Plugins)
|
||||
|
||||
@@ -207,8 +206,8 @@ func (o *WardleServerOptions) Config() (*apiserver.Config, error) {
|
||||
serverConfig.OpenAPIV3Config.Info.Title = "Wardle"
|
||||
serverConfig.OpenAPIV3Config.Info.Version = "0.1"
|
||||
|
||||
serverConfig.FeatureGate = utilversion.DefaultComponentGlobalsRegistry.FeatureGateFor(utilversion.DefaultKubeComponent)
|
||||
serverConfig.EffectiveVersion = utilversion.DefaultComponentGlobalsRegistry.EffectiveVersionFor(apiserver.WardleComponentName)
|
||||
serverConfig.FeatureGate = featuregate.DefaultComponentGlobalsRegistry.FeatureGateFor(featuregate.DefaultKubeComponent)
|
||||
serverConfig.EffectiveVersion = featuregate.DefaultComponentGlobalsRegistry.EffectiveVersionFor(apiserver.WardleComponentName)
|
||||
|
||||
if err := o.RecommendedOptions.ApplyTo(serverConfig); err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -20,7 +20,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"k8s.io/apimachinery/pkg/util/version"
|
||||
utilversion "k8s.io/component-base/registry"
|
||||
utilversion "k8s.io/component-base/version"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
@@ -64,7 +64,7 @@ import (
|
||||
restclient "k8s.io/client-go/rest"
|
||||
"k8s.io/client-go/restmapper"
|
||||
"k8s.io/client-go/tools/pager"
|
||||
utilversion "k8s.io/component-base/registry"
|
||||
utilversion "k8s.io/component-base/version"
|
||||
"k8s.io/klog/v2"
|
||||
"k8s.io/kubernetes/cmd/kube-apiserver/app/options"
|
||||
kubeapiservertesting "k8s.io/kubernetes/cmd/kube-apiserver/app/testing"
|
||||
|
||||
@@ -48,8 +48,7 @@ import (
|
||||
clientset "k8s.io/client-go/kubernetes"
|
||||
"k8s.io/utils/pointer"
|
||||
|
||||
utilversion "k8s.io/component-base/registry"
|
||||
"k8s.io/component-base/version"
|
||||
utilversion "k8s.io/component-base/version"
|
||||
kubeapiservertesting "k8s.io/kubernetes/cmd/kube-apiserver/app/testing"
|
||||
"k8s.io/kubernetes/pkg/api/legacyscheme"
|
||||
"k8s.io/kubernetes/test/integration/framework"
|
||||
@@ -66,7 +65,7 @@ func TestClient(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
expectedInfo := version.Get()
|
||||
expectedInfo := utilversion.Get()
|
||||
kubeVersion := utilversion.DefaultKubeEffectiveVersion().BinaryVersion()
|
||||
expectedInfo.Major = fmt.Sprintf("%d", kubeVersion.Major())
|
||||
expectedInfo.Minor = fmt.Sprintf("%d", kubeVersion.Minor())
|
||||
|
||||
@@ -54,7 +54,7 @@ import (
|
||||
"k8s.io/client-go/transport"
|
||||
"k8s.io/client-go/util/cert"
|
||||
"k8s.io/component-base/featuregate"
|
||||
utilversion "k8s.io/component-base/registry"
|
||||
utilversion "k8s.io/component-base/version"
|
||||
apiregistrationv1 "k8s.io/kube-aggregator/pkg/apis/apiregistration/v1"
|
||||
aggregatorclient "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset"
|
||||
"k8s.io/kubernetes/cmd/kube-apiserver/app"
|
||||
@@ -702,7 +702,7 @@ func prepareAggregatedWardleAPIServer(ctx context.Context, t *testing.T, namespa
|
||||
framework.SharedEtcd())
|
||||
t.Cleanup(func() { testServer.TearDownFn() })
|
||||
|
||||
_, _ = utilversion.DefaultComponentGlobalsRegistry.ComponentGlobalsOrRegister(
|
||||
_, _ = featuregate.DefaultComponentGlobalsRegistry.ComponentGlobalsOrRegister(
|
||||
apiserver.WardleComponentName, utilversion.NewEffectiveVersion(wardleBinaryVersion),
|
||||
featuregate.NewVersionedFeatureGate(version.MustParse(wardleBinaryVersion)))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user