@@ -25,7 +25,6 @@ import (
25
25
"k8s.io/apimachinery/pkg/runtime/schema"
26
26
"k8s.io/apimachinery/pkg/util/wait"
27
27
flowcontrolbootstrap "k8s.io/apiserver/pkg/apis/flowcontrol/bootstrap"
28
- "k8s.io/apiserver/pkg/features"
29
28
"k8s.io/apiserver/pkg/registry/generic"
30
29
"k8s.io/apiserver/pkg/registry/rest"
31
30
genericapiserver "k8s.io/apiserver/pkg/server"
@@ -58,6 +57,8 @@ const PostStartHookName = "priority-and-fairness-config-producer"
58
57
59
58
// NewRESTStorage creates a new rest storage for flow-control api models.
60
59
func (p RESTStorageProvider ) NewRESTStorage (apiResourceConfigSource serverstorage.APIResourceConfigSource , restOptionsGetter generic.RESTOptionsGetter ) (genericapiserver.APIGroupInfo , error ) {
60
+ fg := featuregate .NewFeatureGate ()
61
+ fg .Set ("foo=bar" )
61
62
apiGroupInfo := genericapiserver .NewDefaultAPIGroupInfo (flowcontrol .GroupName , legacyscheme .Scheme , legacyscheme .ParameterCodec , legacyscheme .Codecs )
62
63
63
64
if storageMap , err := p .storage (apiResourceConfigSource , restOptionsGetter , flowcontrolapisv1beta3 .SchemeGroupVersion ); err != nil {
@@ -109,7 +110,7 @@ func (p RESTStorageProvider) GroupName() string {
109
110
// PostStartHook returns the hook func that launches the config provider
110
111
func (p RESTStorageProvider ) PostStartHook () (string , genericapiserver.PostStartHookFunc , error ) {
111
112
bce := & bootstrapConfigurationEnsurer {
112
- v134Config : p .FeatureGate . Enabled ( features . APFv134Config ) ,
113
+ featureGate : p .FeatureGate ,
113
114
informersSynced : []cache.InformerSynced {
114
115
p .InformerFactory .Flowcontrol ().V1 ().PriorityLevelConfigurations ().Informer ().HasSynced ,
115
116
p .InformerFactory .Flowcontrol ().V1 ().FlowSchemas ().Informer ().HasSynced ,
@@ -121,7 +122,7 @@ func (p RESTStorageProvider) PostStartHook() (string, genericapiserver.PostStart
121
122
}
122
123
123
124
type bootstrapConfigurationEnsurer struct {
124
- v134Config bool
125
+ featureGate featuregate. FeatureGate
125
126
informersSynced []cache.InformerSynced
126
127
fsLister flowcontrollisters.FlowSchemaLister
127
128
plcLister flowcontrollisters.PriorityLevelConfigurationLister
@@ -145,7 +146,7 @@ func (bce *bootstrapConfigurationEnsurer) ensureAPFBootstrapConfiguration(hookCo
145
146
146
147
err = wait .PollUntilContextCancel (ctx , time .Second , true ,
147
148
func (context.Context ) (bool , error ) {
148
- if err := ensure (ctx , bce .v134Config , clientset , bce .fsLister , bce .plcLister ); err != nil {
149
+ if err := ensure (ctx , bce .featureGate , clientset , bce .fsLister , bce .plcLister ); err != nil {
149
150
klog .ErrorS (err , "APF bootstrap ensurer ran into error, will retry later" )
150
151
return false , nil
151
152
}
@@ -165,7 +166,7 @@ func (bce *bootstrapConfigurationEnsurer) ensureAPFBootstrapConfiguration(hookCo
165
166
go func () {
166
167
_ = wait .PollUntilContextCancel (hookContext , time .Minute , true ,
167
168
func (ctx context.Context ) (bool , error ) {
168
- if err := ensure (ctx , bce .v134Config , clientset , bce .fsLister , bce .plcLister ); err != nil {
169
+ if err := ensure (ctx , bce .featureGate , clientset , bce .fsLister , bce .plcLister ); err != nil {
169
170
klog .ErrorS (err , "APF bootstrap ensurer ran into error, will retry later" )
170
171
}
171
172
// always auto update both suggested and mandatory configuration
@@ -177,29 +178,29 @@ func (bce *bootstrapConfigurationEnsurer) ensureAPFBootstrapConfiguration(hookCo
177
178
return nil
178
179
}
179
180
180
- func ensure (ctx context.Context , v134Config bool , clientset flowcontrolclient.FlowcontrolV1Interface , fsLister flowcontrollisters.FlowSchemaLister , plcLister flowcontrollisters.PriorityLevelConfigurationLister ) error {
181
+ func ensure (ctx context.Context , featureGate featuregate. FeatureGate , clientset flowcontrolclient.FlowcontrolV1Interface , fsLister flowcontrollisters.FlowSchemaLister , plcLister flowcontrollisters.PriorityLevelConfigurationLister ) error {
181
182
182
- if err := ensureSuggestedConfiguration (ctx , v134Config , clientset , fsLister , plcLister ); err != nil {
183
+ if err := ensureSuggestedConfiguration (ctx , featureGate , clientset , fsLister , plcLister ); err != nil {
183
184
// We should not attempt creation of mandatory objects if ensuring the suggested
184
185
// configuration resulted in an error.
185
186
// This only happens when the stop channel is closed.
186
187
return fmt .Errorf ("failed ensuring suggested settings - %w" , err )
187
188
}
188
189
189
- if err := ensureMandatoryConfiguration (ctx , v134Config , clientset , fsLister , plcLister ); err != nil {
190
+ if err := ensureMandatoryConfiguration (ctx , featureGate , clientset , fsLister , plcLister ); err != nil {
190
191
return fmt .Errorf ("failed ensuring mandatory settings - %w" , err )
191
192
}
192
193
193
- if err := removeDanglingBootstrapConfiguration (ctx , v134Config , clientset , fsLister , plcLister ); err != nil {
194
+ if err := removeDanglingBootstrapConfiguration (ctx , featureGate , clientset , fsLister , plcLister ); err != nil {
194
195
return fmt .Errorf ("failed to delete removed settings - %w" , err )
195
196
}
196
197
197
198
return nil
198
199
}
199
200
200
- func ensureSuggestedConfiguration (ctx context.Context , v134Config bool , clientset flowcontrolclient.FlowcontrolV1Interface , fsLister flowcontrollisters.FlowSchemaLister , plcLister flowcontrollisters.PriorityLevelConfigurationLister ) error {
201
+ func ensureSuggestedConfiguration (ctx context.Context , featureGate featuregate. FeatureGate , clientset flowcontrolclient.FlowcontrolV1Interface , fsLister flowcontrollisters.FlowSchemaLister , plcLister flowcontrollisters.PriorityLevelConfigurationLister ) error {
201
202
plcOps := ensurer .NewPriorityLevelConfigurationOps (clientset .PriorityLevelConfigurations (), plcLister )
202
- config := flowcontrolbootstrap .GetV1ConfigCollection (v134Config ).Suggested
203
+ config := flowcontrolbootstrap .GetV1ConfigCollection (featureGate ).Suggested
203
204
if err := ensurer .EnsureConfigurations (ctx , plcOps , config .PriorityLevelConfigurations , ensurer .NewSuggestedEnsureStrategy [* flowcontrolv1.PriorityLevelConfiguration ]()); err != nil {
204
205
return err
205
206
}
@@ -208,9 +209,9 @@ func ensureSuggestedConfiguration(ctx context.Context, v134Config bool, clientse
208
209
return ensurer .EnsureConfigurations (ctx , fsOps , config .FlowSchemas , ensurer .NewSuggestedEnsureStrategy [* flowcontrolv1.FlowSchema ]())
209
210
}
210
211
211
- func ensureMandatoryConfiguration (ctx context.Context , v134Config bool , clientset flowcontrolclient.FlowcontrolV1Interface , fsLister flowcontrollisters.FlowSchemaLister , plcLister flowcontrollisters.PriorityLevelConfigurationLister ) error {
212
+ func ensureMandatoryConfiguration (ctx context.Context , featureGate featuregate. FeatureGate , clientset flowcontrolclient.FlowcontrolV1Interface , fsLister flowcontrollisters.FlowSchemaLister , plcLister flowcontrollisters.PriorityLevelConfigurationLister ) error {
212
213
plcOps := ensurer .NewPriorityLevelConfigurationOps (clientset .PriorityLevelConfigurations (), plcLister )
213
- config := flowcontrolbootstrap .GetV1ConfigCollection (v134Config ).Mandatory
214
+ config := flowcontrolbootstrap .GetV1ConfigCollection (featureGate ).Mandatory
214
215
if err := ensurer .EnsureConfigurations (ctx , plcOps , config .PriorityLevelConfigurations , ensurer .NewMandatoryEnsureStrategy [* flowcontrolv1.PriorityLevelConfiguration ]()); err != nil {
215
216
return err
216
217
}
@@ -219,22 +220,22 @@ func ensureMandatoryConfiguration(ctx context.Context, v134Config bool, clientse
219
220
return ensurer .EnsureConfigurations (ctx , fsOps , config .FlowSchemas , ensurer .NewMandatoryEnsureStrategy [* flowcontrolv1.FlowSchema ]())
220
221
}
221
222
222
- func removeDanglingBootstrapConfiguration (ctx context.Context , v134Config bool , clientset flowcontrolclient.FlowcontrolV1Interface , fsLister flowcontrollisters.FlowSchemaLister , plcLister flowcontrollisters.PriorityLevelConfigurationLister ) error {
223
- if err := removeDanglingBootstrapFlowSchema (ctx , v134Config , clientset , fsLister ); err != nil {
223
+ func removeDanglingBootstrapConfiguration (ctx context.Context , featureGate featuregate. FeatureGate , clientset flowcontrolclient.FlowcontrolV1Interface , fsLister flowcontrollisters.FlowSchemaLister , plcLister flowcontrollisters.PriorityLevelConfigurationLister ) error {
224
+ if err := removeDanglingBootstrapFlowSchema (ctx , featureGate , clientset , fsLister ); err != nil {
224
225
return err
225
226
}
226
227
227
- return removeDanglingBootstrapPriorityLevel (ctx , v134Config , clientset , plcLister )
228
+ return removeDanglingBootstrapPriorityLevel (ctx , featureGate , clientset , plcLister )
228
229
}
229
230
230
- func removeDanglingBootstrapFlowSchema (ctx context.Context , v134Config bool , clientset flowcontrolclient.FlowcontrolV1Interface , fsLister flowcontrollisters.FlowSchemaLister ) error {
231
+ func removeDanglingBootstrapFlowSchema (ctx context.Context , featureGate featuregate. FeatureGate , clientset flowcontrolclient.FlowcontrolV1Interface , fsLister flowcontrollisters.FlowSchemaLister ) error {
231
232
fsOps := ensurer .NewFlowSchemaOps (clientset .FlowSchemas (), fsLister )
232
- return ensurer .RemoveUnwantedObjects (ctx , fsOps , flowcontrolbootstrap .GetFlowSchemas (v134Config ))
233
+ return ensurer .RemoveUnwantedObjects (ctx , fsOps , flowcontrolbootstrap .GetFlowSchemas (featureGate ))
233
234
}
234
235
235
- func removeDanglingBootstrapPriorityLevel (ctx context.Context , v134Config bool , clientset flowcontrolclient.FlowcontrolV1Interface , plcLister flowcontrollisters.PriorityLevelConfigurationLister ) error {
236
+ func removeDanglingBootstrapPriorityLevel (ctx context.Context , featureGate featuregate. FeatureGate , clientset flowcontrolclient.FlowcontrolV1Interface , plcLister flowcontrollisters.PriorityLevelConfigurationLister ) error {
236
237
plcOps := ensurer .NewPriorityLevelConfigurationOps (clientset .PriorityLevelConfigurations (), plcLister )
237
- return ensurer .RemoveUnwantedObjects (ctx , plcOps , flowcontrolbootstrap .GetPrioritylevelConfigurations (v134Config ))
238
+ return ensurer .RemoveUnwantedObjects (ctx , plcOps , flowcontrolbootstrap .GetPrioritylevelConfigurations (featureGate ))
238
239
}
239
240
240
241
// contextFromChannelAndMaxWaitDuration returns a Context that is bound to the
0 commit comments