mirror of
https://github.com/kubernetes/client-go.git
synced 2025-09-04 16:40:21 +00:00
Add test-only client feature gates for CBOR.
As with the apiserver feature gate for CBOR as a serving and storage encoding, the client feature gates for CBOR are being initially added through a test-only feature gate instance that is not wired to environment variables or to command-line flags and is intended only to be enabled programmatically from integration tests. The test-only instance will be removed as part of alpha graduation and replaced by conventional client feature gating. Kubernetes-commit: ea13190d8bd3a4bb3e82055b529aa7599ae5c6e1
This commit is contained in:
committed by
Kubernetes Publisher
parent
abe0e99c21
commit
1cca19dc02
@@ -18,9 +18,11 @@ package features
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
|
||||
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
|
||||
"sync/atomic"
|
||||
)
|
||||
|
||||
// NOTE: types Feature, FeatureSpec, prerelease (and its values)
|
||||
@@ -141,3 +143,43 @@ var (
|
||||
// should use AddFeaturesToExistingFeatureGates followed by ReplaceFeatureGates.
|
||||
featureGates = &atomic.Value{}
|
||||
)
|
||||
|
||||
// TestOnlyFeatureGates is a distinct registry of pre-alpha client features that must not be
|
||||
// included in runtime wiring to command-line flags or environment variables. It exists as a risk
|
||||
// mitigation to allow only programmatic enablement of CBOR serialization for integration testing
|
||||
// purposes.
|
||||
//
|
||||
// TODO: Once all required integration test coverage is complete, this will be deleted and the
|
||||
// test-only feature gates will be replaced by normal feature gates.
|
||||
var TestOnlyFeatureGates = &testOnlyFeatureGates{
|
||||
features: map[Feature]bool{
|
||||
TestOnlyClientAllowsCBOR: false,
|
||||
TestOnlyClientPrefersCBOR: false,
|
||||
},
|
||||
}
|
||||
|
||||
type testOnlyFeatureGates struct {
|
||||
lock sync.RWMutex
|
||||
features map[Feature]bool
|
||||
}
|
||||
|
||||
func (t *testOnlyFeatureGates) Enabled(feature Feature) bool {
|
||||
t.lock.RLock()
|
||||
defer t.lock.RUnlock()
|
||||
|
||||
enabled, ok := t.features[feature]
|
||||
if !ok {
|
||||
panic(fmt.Sprintf("test-only feature %q not recognized", feature))
|
||||
}
|
||||
return enabled
|
||||
}
|
||||
|
||||
func (t *testOnlyFeatureGates) Set(feature Feature, enabled bool) error {
|
||||
t.lock.Lock()
|
||||
defer t.lock.Unlock()
|
||||
if _, ok := t.features[feature]; !ok {
|
||||
return fmt.Errorf("test-only feature %q not recognized", feature)
|
||||
}
|
||||
t.features[feature] = enabled
|
||||
return nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user