Skip to content

Commit a05f1e5

Browse files
committed
Deomonstrate GateSet composition
This commit demonstrate how libraries can define and expose Gates and GateSets, and compose GateSets into new GateSets. It also defines a small number of new-style gates, but does not use them yet.
1 parent 007e393 commit a05f1e5

File tree

4 files changed

+135
-0
lines changed

4 files changed

+135
-0
lines changed

pkg/features/kube_features.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ import (
2323
utilfeature "k8s.io/apiserver/pkg/util/feature"
2424
clientfeatures "k8s.io/client-go/features"
2525
"k8s.io/component-base/featuregate"
26+
kubeaggregatorfeatures "k8s.io/kube-aggregator/pkg/features"
27+
"k8s.io/utils/feature"
2628
)
2729

2830
const (
@@ -964,6 +966,31 @@ const (
964966
RecursiveReadOnlyMounts featuregate.Feature = "RecursiveReadOnlyMounts"
965967
)
966968

969+
var (
970+
// This is the composed set of gates that standard Kubernetes components
971+
// will expose. It starts with a few critical libs and then we will define
972+
// our own below.
973+
kubeGates = feature.MergeGateSets(
974+
clientfeatures.NewFeatureGates(),
975+
kubeaggregatorfeatures.FeatureGates(),
976+
apiextensionsfeatures.FeatureGates())
977+
978+
// owner: @AkihiroSuda
979+
// kep: https://kep.k8s.io/3857
980+
// alpha: v1.30
981+
//
982+
// Allows recursive read-only mounts.
983+
RecursiveReadOnlyMountsGate = kubeGates.AddOrDie(&feature.Gate{
984+
Name: "RecursiveReadOnlyMounts", Default: false, Release: feature.Alpha,
985+
})
986+
)
987+
988+
// KubernetesGates returns the set of feature gates that standard Kubernetes
989+
// components will expose.
990+
func KubernetesGates() *feature.GateSet {
991+
return kubeGates
992+
}
993+
967994
func init() {
968995
runtime.Must(utilfeature.DefaultMutableFeatureGate.Add(defaultKubernetesFeatureGates))
969996

staging/src/k8s.io/apiextensions-apiserver/pkg/features/kube_features.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package features
1919
import (
2020
utilfeature "k8s.io/apiserver/pkg/util/feature"
2121
"k8s.io/component-base/featuregate"
22+
"k8s.io/utils/feature"
2223
)
2324

2425
const (
@@ -47,6 +48,43 @@ func init() {
4748
utilfeature.DefaultMutableFeatureGate.Add(defaultKubernetesFeatureGates)
4849
}
4950

51+
var (
52+
libGates = &feature.GateSet{}
53+
54+
// Every feature gate should add method here following this template:
55+
//
56+
// // owner: @username
57+
// // alpha: v1.4
58+
// MyFeature() bool
59+
60+
// owner: @alexzielenski
61+
// alpha: v1.28
62+
//
63+
// Ignores errors raised on unchanged fields of Custom Resources
64+
// across UPDATE/PATCH requests.
65+
CRDValidationRatchetingGate = libGates.AddOrDie(&feature.Gate{
66+
Name: "CRDValidationRatcheting",
67+
Default: true,
68+
Release: feature.Beta,
69+
})
70+
71+
// owner: @jpbetz
72+
// alpha: v1.30
73+
//
74+
// CustomResourceDefinitions may include SelectableFields to declare which fields
75+
// may be used as field selectors.
76+
CustomResourceFieldSelectorsGate = libGates.AddOrDie(&feature.Gate{
77+
Name: "CustomResourceFieldSelectors",
78+
Default: false,
79+
Release: feature.Beta,
80+
})
81+
)
82+
83+
// FeatureGates returns the set of feature gates exposed by this library.
84+
func FeatureGates() *feature.GateSet {
85+
return libGates
86+
}
87+
5088
// defaultKubernetesFeatureGates consists of all known Kubernetes-specific feature keys.
5189
// To add a new feature, define a key for it above and add it here. The features will be
5290
// available throughout Kubernetes binaries.

staging/src/k8s.io/client-go/features/known_features.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ limitations under the License.
1616

1717
package features
1818

19+
import (
20+
"k8s.io/utils/feature"
21+
)
22+
1923
const (
2024
// Every feature gate should add method here following this template:
2125
//
@@ -43,6 +47,47 @@ const (
4347
InformerResourceVersion Feature = "InformerResourceVersion"
4448
)
4549

50+
var (
51+
libGates = &feature.GateSet{}
52+
53+
// Every feature gate should add method here following this template:
54+
//
55+
// // owner: @username
56+
// // alpha: v1.4
57+
// MyFeature featuregate.Feature = "MyFeature"
58+
//
59+
// Feature gates should be listed in alphabetical, case-sensitive
60+
// (upper before any lower case character) order. This reduces the risk
61+
// of code conflicts because changes are more likely to be scattered
62+
// across the file.
63+
64+
// owner: @p0lyn0mial
65+
// beta: v1.30
66+
//
67+
// Allow the client to get a stream of individual items instead of chunking from the server.
68+
//
69+
// NOTE:
70+
// The feature is disabled in Beta by default because
71+
// it will only be turned on for selected control plane component(s).
72+
WatchListClientGate = libGates.AddOrDie(&feature.Gate{
73+
Name: "WatchListClient",
74+
Release: feature.Beta,
75+
})
76+
77+
// owner: @nilekhc
78+
// alpha: v1.30
79+
InformerResourceVersionGate = libGates.AddOrDie(&feature.Gate{
80+
Name: "InformerResourceVersion",
81+
Release: feature.Alpha,
82+
})
83+
)
84+
85+
// NewFeatureGates returns the set of feature gates exposed by this library.
86+
// FIXME: Rename to FeatureGates once old-style function of same name is gone.
87+
func NewFeatureGates() *feature.GateSet {
88+
return libGates
89+
}
90+
4691
// defaultKubernetesFeatureGates consists of all known Kubernetes-specific feature keys.
4792
//
4893
// To add a new feature, define a key for it above and add it here.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package features
2+
3+
import (
4+
"k8s.io/utils/feature"
5+
)
6+
7+
var (
8+
libGates = &feature.GateSet{}
9+
10+
// Every feature gate should add method here following this template:
11+
//
12+
// // owner: @username
13+
// // alpha: v1.4
14+
// MyFeature featuregate.Feature = "MyFeature"
15+
//
16+
// Feature gates should be listed in alphabetical, case-sensitive
17+
// (upper before any lower case character) order. This reduces the risk
18+
// of code conflicts because changes are more likely to be scattered
19+
// across the file.
20+
)
21+
22+
// FeatureGates returns the set of feature gates exposed by this library.
23+
func FeatureGates() *feature.GateSet {
24+
return libGates
25+
}

0 commit comments

Comments
 (0)