-
Notifications
You must be signed in to change notification settings - Fork 586
/
types_feature.go
313 lines (274 loc) · 10.9 KB
/
types_feature.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
package v1
import (
"fmt"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
// +genclient
// +genclient:nonNamespaced
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// Feature holds cluster-wide information about feature gates. The canonical name is `cluster`
//
// Compatibility level 1: Stable within a major release for a minimum of 12 months or 3 minor releases (whichever is longer).
// +openshift:compatibility-gen:level=1
type FeatureGate struct {
metav1.TypeMeta `json:",inline"`
// metadata is the standard object's metadata.
// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
metav1.ObjectMeta `json:"metadata,omitempty"`
// spec holds user settable values for configuration
// +kubebuilder:validation:Required
// +required
Spec FeatureGateSpec `json:"spec"`
// status holds observed values from the cluster. They may not be overridden.
// +optional
Status FeatureGateStatus `json:"status"`
}
type FeatureSet string
var (
// Default feature set that allows upgrades.
Default FeatureSet = ""
// TechPreviewNoUpgrade turns on tech preview features that are not part of the normal supported platform. Turning
// this feature set on CANNOT BE UNDONE and PREVENTS UPGRADES.
TechPreviewNoUpgrade FeatureSet = "TechPreviewNoUpgrade"
// CustomNoUpgrade allows the enabling or disabling of any feature. Turning this feature set on IS NOT SUPPORTED, CANNOT BE UNDONE, and PREVENTS UPGRADES.
// Because of its nature, this setting cannot be validated. If you have any typos or accidentally apply invalid combinations
// your cluster may fail in an unrecoverable way.
CustomNoUpgrade FeatureSet = "CustomNoUpgrade"
// TopologyManager enables ToplogyManager support. Upgrades are enabled with this feature.
LatencySensitive FeatureSet = "LatencySensitive"
)
type FeatureGateSpec struct {
FeatureGateSelection `json:",inline"`
}
// +union
type FeatureGateSelection struct {
// featureSet changes the list of features in the cluster. The default is empty. Be very careful adjusting this setting.
// Turning on or off features may cause irreversible changes in your cluster which cannot be undone.
// +unionDiscriminator
// +optional
FeatureSet FeatureSet `json:"featureSet,omitempty"`
// customNoUpgrade allows the enabling or disabling of any feature. Turning this feature set on IS NOT SUPPORTED, CANNOT BE UNDONE, and PREVENTS UPGRADES.
// Because of its nature, this setting cannot be validated. If you have any typos or accidentally apply invalid combinations
// your cluster may fail in an unrecoverable way. featureSet must equal "CustomNoUpgrade" must be set to use this field.
// +optional
// +nullable
CustomNoUpgrade *CustomFeatureGates `json:"customNoUpgrade,omitempty"`
}
type CustomFeatureGates struct {
// enabled is a list of all feature gates that you want to force on
// +optional
Enabled []FeatureGateName `json:"enabled,omitempty"`
// disabled is a list of all feature gates that you want to force off
// +optional
Disabled []FeatureGateName `json:"disabled,omitempty"`
}
// FeatureGateName is a string to enforce patterns on the name of a FeatureGate
// +kubebuilder:validation:Pattern=`^([A-Za-z0-9-]+\.)*[A-Za-z0-9-]+\.?$`
type FeatureGateName string
type FeatureGateStatus struct {
// conditions represent the observations of the current state.
// Known .status.conditions.type are: "DeterminationDegraded"
// +listType=map
// +listMapKey=type
Conditions []metav1.Condition `json:"conditions,omitempty"`
// featureGates contains a list of enabled and disabled featureGates that are keyed by payloadVersion.
// Operators other than the CVO and cluster-config-operator, must read the .status.featureGates, locate
// the version they are managing, find the enabled/disabled featuregates and make the operand and operator match.
// The enabled/disabled values for a particular version may change during the life of the cluster as various
// .spec.featureSet values are selected.
// Operators may choose to restart their processes to pick up these changes, but remembering past enable/disable
// lists is beyond the scope of this API and is the responsibility of individual operators.
// Only featureGates with .version in the ClusterVersion.status will be present in this list.
// +listType=map
// +listMapKey=version
FeatureGates []FeatureGateDetails `json:"featureGates"`
}
type FeatureGateDetails struct {
// version matches the version provided by the ClusterVersion and in the ClusterOperator.Status.Versions field.
// +kubebuilder:validation:Required
// +required
Version string `json:"version"`
// enabled is a list of all feature gates that are enabled in the cluster for the named version.
// +optional
Enabled []FeatureGateAttributes `json:"enabled"`
// disabled is a list of all feature gates that are disabled in the cluster for the named version.
// +optional
Disabled []FeatureGateAttributes `json:"disabled"`
}
type FeatureGateAttributes struct {
// name is the name of the FeatureGate.
// +kubebuilder:validation:Required
Name FeatureGateName `json:"name"`
// possible (probable?) future additions include
// 1. support level (Stable, ServiceDeliveryOnly, TechPreview, DevPreview)
// 2. description
}
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// Compatibility level 1: Stable within a major release for a minimum of 12 months or 3 minor releases (whichever is longer).
// +openshift:compatibility-gen:level=1
type FeatureGateList struct {
metav1.TypeMeta `json:",inline"`
// metadata is the standard list's metadata.
// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
metav1.ListMeta `json:"metadata"`
Items []FeatureGate `json:"items"`
}
type FeatureGateEnabledDisabled struct {
Enabled []FeatureGateDescription
Disabled []FeatureGateDescription
}
// FeatureSets Contains a map of Feature names to Enabled/Disabled Feature.
//
// NOTE: The caller needs to make sure to check for the existence of the value
// using golang's existence field. A possible scenario is an upgrade where new
// FeatureSets are added and a controller has not been upgraded with a newer
// version of this file. In this upgrade scenario the map could return nil.
//
// example:
//
// if featureSet, ok := FeatureSets["SomeNewFeature"]; ok { }
//
// If you put an item in either of these lists, put your area and name on it so we can find owners.
var FeatureSets = map[FeatureSet]*FeatureGateEnabledDisabled{
Default: defaultFeatures,
CustomNoUpgrade: {
Enabled: []FeatureGateDescription{},
Disabled: []FeatureGateDescription{
disableKubeletCloudCredentialProviders, // We do not currently ship the correct config to use the external credentials provider.
},
},
TechPreviewNoUpgrade: newDefaultFeatures().
with(validatingAdmissionPolicy).
with(csiDriverSharedResource).
with(nodeSwap).
with(machineAPIProviderOpenStack).
with(insightsConfigAPI).
with(dynamicResourceAllocation).
with(gateGatewayAPI).
with(maxUnavailableStatefulSet).
with(eventedPleg).
with(sigstoreImageVerification).
with(gcpLabelsTags).
with(gcpClusterHostedDNS).
with(vSphereStaticIPs).
with(routeExternalCertificate).
with(automatedEtcdBackup).
with(vSphereControlPlaneMachineset).
without(machineAPIOperatorDisableMachineHealthCheckController).
with(adminNetworkPolicy).
with(dnsNameResolver).
with(machineConfigNodes).
with(metricsServer).
with(installAlternateInfrastructureAWS).
without(clusterAPIInstall).
with(sdnLiveMigration).
with(mixedCPUsAllocation).
with(managedBootImages).
without(disableKubeletCloudCredentialProviders).
with(onClusterBuild).
with(signatureStores).
with(pinnedImages).
with(upgradeStatus).
with(translateStreamCloseWebsocketRequests).
toFeatures(defaultFeatures),
LatencySensitive: newDefaultFeatures().
toFeatures(defaultFeatures),
}
var defaultFeatures = &FeatureGateEnabledDisabled{
Enabled: []FeatureGateDescription{
openShiftPodSecurityAdmission,
alibabaPlatform, // This is a bug, it should be TechPreviewNoUpgrade. This must be downgraded before 4.14 is shipped.
azureWorkloadIdentity,
cloudDualStackNodeIPs,
externalCloudProvider,
externalCloudProviderAzure,
externalCloudProviderGCP,
externalCloudProviderExternal,
privateHostedZoneAWS,
buildCSIVolumes,
kmsv1,
eventedPleg,
},
Disabled: []FeatureGateDescription{
disableKubeletCloudCredentialProviders, // We do not currently ship the correct config to use the external credentials provider.
},
}
type featureSetBuilder struct {
forceOn []FeatureGateDescription
forceOff []FeatureGateDescription
}
func newDefaultFeatures() *featureSetBuilder {
return &featureSetBuilder{}
}
func (f *featureSetBuilder) with(forceOn FeatureGateDescription) *featureSetBuilder {
for _, curr := range f.forceOn {
if curr.FeatureGateAttributes.Name == forceOn.FeatureGateAttributes.Name {
panic(fmt.Errorf("coding error: %q enabled twice", forceOn.FeatureGateAttributes.Name))
}
}
f.forceOn = append(f.forceOn, forceOn)
return f
}
func (f *featureSetBuilder) without(forceOff FeatureGateDescription) *featureSetBuilder {
for _, curr := range f.forceOff {
if curr.FeatureGateAttributes.Name == forceOff.FeatureGateAttributes.Name {
panic(fmt.Errorf("coding error: %q disabled twice", forceOff.FeatureGateAttributes.Name))
}
}
f.forceOff = append(f.forceOff, forceOff)
return f
}
func (f *featureSetBuilder) isForcedOff(needle FeatureGateDescription) bool {
for _, forcedOff := range f.forceOff {
if needle.FeatureGateAttributes.Name == forcedOff.FeatureGateAttributes.Name {
return true
}
}
return false
}
func (f *featureSetBuilder) isForcedOn(needle FeatureGateDescription) bool {
for _, forceOn := range f.forceOn {
if needle.FeatureGateAttributes.Name == forceOn.FeatureGateAttributes.Name {
return true
}
}
return false
}
func (f *featureSetBuilder) toFeatures(defaultFeatures *FeatureGateEnabledDisabled) *FeatureGateEnabledDisabled {
finalOn := []FeatureGateDescription{}
finalOff := []FeatureGateDescription{}
// only add the default enabled features if they haven't been explicitly set off
for _, defaultOn := range defaultFeatures.Enabled {
if !f.isForcedOff(defaultOn) {
finalOn = append(finalOn, defaultOn)
}
}
for _, currOn := range f.forceOn {
if f.isForcedOff(currOn) {
panic("coding error, you can't have features both on and off")
}
found := false
for _, alreadyOn := range finalOn {
if alreadyOn.FeatureGateAttributes.Name == currOn.FeatureGateAttributes.Name {
found = true
}
}
if found {
continue
}
finalOn = append(finalOn, currOn)
}
// only add the default disabled features if they haven't been explicitly set on
for _, defaultOff := range defaultFeatures.Disabled {
if !f.isForcedOn(defaultOff) {
finalOff = append(finalOff, defaultOff)
}
}
for _, currOff := range f.forceOff {
finalOff = append(finalOff, currOff)
}
return &FeatureGateEnabledDisabled{
Enabled: finalOn,
Disabled: finalOff,
}
}