mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-07-18 04:54:54 +00:00
Add CBOR feature gates.
For alpha, there is one apiserver feature gate and two client-go feature gates controlling CBOR. They were initially wired to separate test-only feature gate instances in order to prevent them from being configurable at runtime via command-line flags or environment variables (for client-go feature gates outside of Kubernetes components). All of the integration tests required by the KEP as alpha criteria have been implemented. This adds the feature gates to the usual feature gate instances and removes the temporary code to support separate test-only feature gate instances.
This commit is contained in:
@@ -31,53 +31,19 @@ import (
|
||||
"k8s.io/apimachinery/pkg/util/sets"
|
||||
"k8s.io/apiserver/pkg/features"
|
||||
utilfeature "k8s.io/apiserver/pkg/util/feature"
|
||||
clientfeatures "k8s.io/client-go/features"
|
||||
"k8s.io/client-go/transport"
|
||||
featuregatetesting "k8s.io/component-base/featuregate/testing"
|
||||
aggregatorscheme "k8s.io/kube-aggregator/pkg/apiserver/scheme"
|
||||
"k8s.io/kubernetes/pkg/api/legacyscheme"
|
||||
)
|
||||
|
||||
// SetTestOnlyCBORClientFeatureGatesForTest overrides the CBOR client feature gates in the test-only
|
||||
// client feature gate instance for the duration of a test. The CBOR client feature gates are
|
||||
// temporarily registered in their own feature gate instance that does not include runtime wiring to
|
||||
// command-line flags or environment variables in order to mitigate the risk of enabling a new
|
||||
// encoding before all integration tests have been demonstrated to pass.
|
||||
//
|
||||
// This will be removed as an alpha requirement. The client feature gates will be registered with
|
||||
// the existing feature gate instance and tests will use
|
||||
// k8s.io/client-go/features/testing.SetFeatureDuringTest (which unlike
|
||||
// k8s.io/component-base/featuregate/testing.SetFeatureGateDuringTest does not accept a feature gate
|
||||
// instance as a parameter).
|
||||
func SetTestOnlyCBORClientFeatureGatesForTest(tb testing.TB, allowed, preferred bool) {
|
||||
originalAllowed := clientfeatures.TestOnlyFeatureGates.Enabled(clientfeatures.TestOnlyClientAllowsCBOR)
|
||||
tb.Cleanup(func() {
|
||||
if err := clientfeatures.TestOnlyFeatureGates.Set(clientfeatures.TestOnlyClientAllowsCBOR, originalAllowed); err != nil {
|
||||
tb.Fatal(err)
|
||||
}
|
||||
})
|
||||
if err := clientfeatures.TestOnlyFeatureGates.Set(clientfeatures.TestOnlyClientAllowsCBOR, allowed); err != nil {
|
||||
tb.Fatal(err)
|
||||
}
|
||||
|
||||
originalPreferred := clientfeatures.TestOnlyFeatureGates.Enabled(clientfeatures.TestOnlyClientPrefersCBOR)
|
||||
tb.Cleanup(func() {
|
||||
if err := clientfeatures.TestOnlyFeatureGates.Set(clientfeatures.TestOnlyClientPrefersCBOR, originalPreferred); err != nil {
|
||||
tb.Fatal(err)
|
||||
}
|
||||
})
|
||||
if err := clientfeatures.TestOnlyFeatureGates.Set(clientfeatures.TestOnlyClientPrefersCBOR, preferred); err != nil {
|
||||
tb.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
// EnableCBORForTest patches global state to enable the CBOR serializer and reverses those changes
|
||||
// at the end of the test. As a risk mitigation, integration tests are initially written this way so
|
||||
// that integration tests can be implemented fully and incrementally before exposing options
|
||||
// (including feature gates) that can enable CBOR at runtime. After integration test coverage is
|
||||
// complete, feature gates will be introduced to completely supersede this mechanism.
|
||||
func EnableCBORServingAndStorageForTest(tb testing.TB) {
|
||||
featuregatetesting.SetFeatureGateDuringTest(tb, utilfeature.TestOnlyFeatureGate, features.TestOnlyCBORServingAndStorage, true)
|
||||
featuregatetesting.SetFeatureGateDuringTest(tb, utilfeature.DefaultFeatureGate, features.CBORServingAndStorage, true)
|
||||
|
||||
newCBORSerializerInfo := func(creater runtime.ObjectCreater, typer runtime.ObjectTyper) runtime.SerializerInfo {
|
||||
return runtime.SerializerInfo{
|
||||
|
||||
Reference in New Issue
Block a user