@@ -89,6 +89,7 @@ func (p RESTStorageProvider) GroupName() string {
89
89
return flowcontrol .GroupName
90
90
}
91
91
92
+ // PostStartHook returns the hook func that launches the config provider
92
93
func (p RESTStorageProvider ) PostStartHook () (string , genericapiserver.PostStartHookFunc , error ) {
93
94
return PostStartHookName , func (hookContext genericapiserver.PostStartHookContext ) error {
94
95
flowcontrolClientSet := flowcontrolclient .NewForConfigOrDie (hookContext .LoopbackClientConfig )
@@ -152,28 +153,30 @@ func lastMandatoryExists(flowcontrolClientSet flowcontrolclient.FlowcontrolV1alp
152
153
return false , nil
153
154
}
154
155
156
+ const thisFieldManager = "api-priority-and-fairness-config-producer"
157
+
155
158
func ensure (flowcontrolClientSet flowcontrolclient.FlowcontrolV1alpha1Interface , flowSchemas []* flowcontrolv1alpha1.FlowSchema , priorityLevels []* flowcontrolv1alpha1.PriorityLevelConfiguration ) error {
156
159
for _ , flowSchema := range flowSchemas {
157
- _ , err := flowcontrolClientSet .FlowSchemas ().Create (context .TODO (), flowSchema , metav1.CreateOptions {})
160
+ _ , err := flowcontrolClientSet .FlowSchemas ().Create (context .TODO (), flowSchema , metav1.CreateOptions {FieldManager : thisFieldManager })
158
161
if apierrors .IsAlreadyExists (err ) {
159
- klog .V (3 ).Infof ("system preset FlowSchema %s already exists, skipping creating" , flowSchema .Name )
162
+ klog .V (3 ).Infof ("Suggested FlowSchema %s already exists, skipping creating" , flowSchema .Name )
160
163
continue
161
164
}
162
165
if err != nil {
163
- return fmt .Errorf ("cannot create FlowSchema %s due to %v" , flowSchema .Name , err )
166
+ return fmt .Errorf ("cannot create suggested FlowSchema %s due to %v" , flowSchema .Name , err )
164
167
}
165
- klog .V (3 ).Infof ("created system preset FlowSchema %s" , flowSchema .Name )
168
+ klog .V (3 ).Infof ("Created suggested FlowSchema %s" , flowSchema .Name )
166
169
}
167
170
for _ , priorityLevelConfiguration := range priorityLevels {
168
- _ , err := flowcontrolClientSet .PriorityLevelConfigurations ().Create (context .TODO (), priorityLevelConfiguration , metav1.CreateOptions {})
171
+ _ , err := flowcontrolClientSet .PriorityLevelConfigurations ().Create (context .TODO (), priorityLevelConfiguration , metav1.CreateOptions {FieldManager : thisFieldManager })
169
172
if apierrors .IsAlreadyExists (err ) {
170
- klog .V (3 ).Infof ("system preset PriorityLevelConfiguration %s already exists, skipping creating" , priorityLevelConfiguration .Name )
173
+ klog .V (3 ).Infof ("Suggested PriorityLevelConfiguration %s already exists, skipping creating" , priorityLevelConfiguration .Name )
171
174
continue
172
175
}
173
176
if err != nil {
174
- return fmt .Errorf ("cannot create PriorityLevelConfiguration %s due to %v" , priorityLevelConfiguration .Name , err )
177
+ return fmt .Errorf ("cannot create suggested PriorityLevelConfiguration %s due to %v" , priorityLevelConfiguration .Name , err )
175
178
}
176
- klog .V (3 ).Infof ("created system preset PriorityLevelConfiguration %s" , priorityLevelConfiguration .Name )
179
+ klog .V (3 ).Infof ("Created suggested PriorityLevelConfiguration %s" , priorityLevelConfiguration .Name )
177
180
}
178
181
return nil
179
182
}
@@ -184,58 +187,60 @@ func upgrade(flowcontrolClientSet flowcontrolclient.FlowcontrolV1alpha1Interface
184
187
if err == nil {
185
188
// TODO(yue9944882): extract existing version from label and compare
186
189
// TODO(yue9944882): create w/ version string attached
187
- identical , err := flowSchemaHasWrongSpec (expectedFlowSchema , actualFlowSchema )
190
+ wrongSpec , err := flowSchemaHasWrongSpec (expectedFlowSchema , actualFlowSchema )
188
191
if err != nil {
189
192
return fmt .Errorf ("failed checking if mandatory FlowSchema %s is up-to-date due to %v, will retry later" , expectedFlowSchema .Name , err )
190
193
}
191
- if ! identical {
192
- if _ , err := flowcontrolClientSet .FlowSchemas ().Update (context .TODO (), expectedFlowSchema , metav1.UpdateOptions {}); err != nil {
194
+ if wrongSpec {
195
+ if _ , err := flowcontrolClientSet .FlowSchemas ().Update (context .TODO (), expectedFlowSchema , metav1.UpdateOptions {FieldManager : thisFieldManager }); err != nil {
193
196
return fmt .Errorf ("failed upgrading mandatory FlowSchema %s due to %v, will retry later" , expectedFlowSchema .Name , err )
194
197
}
198
+ klog .V (3 ).Infof ("Updated mandatory FlowSchema %s because its spec was %#+v but it must be %#+v" , expectedFlowSchema .Name , actualFlowSchema .Spec , expectedFlowSchema .Spec )
195
199
}
196
200
continue
197
201
}
198
202
if ! apierrors .IsNotFound (err ) {
199
- return fmt .Errorf ("failed getting FlowSchema %s due to %v, will retry later" , expectedFlowSchema .Name , err )
203
+ return fmt .Errorf ("failed getting mandatory FlowSchema %s due to %v, will retry later" , expectedFlowSchema .Name , err )
200
204
}
201
- _ , err = flowcontrolClientSet .FlowSchemas ().Create (context .TODO (), expectedFlowSchema , metav1.CreateOptions {})
205
+ _ , err = flowcontrolClientSet .FlowSchemas ().Create (context .TODO (), expectedFlowSchema , metav1.CreateOptions {FieldManager : thisFieldManager })
202
206
if apierrors .IsAlreadyExists (err ) {
203
- klog .V (3 ).Infof ("system preset FlowSchema %s already exists, skipping creating" , expectedFlowSchema .Name )
207
+ klog .V (3 ).Infof ("Mandatory FlowSchema %s already exists, skipping creating" , expectedFlowSchema .Name )
204
208
continue
205
209
}
206
210
if err != nil {
207
- return fmt .Errorf ("cannot create FlowSchema %s due to %v" , expectedFlowSchema .Name , err )
211
+ return fmt .Errorf ("cannot create mandatory FlowSchema %s due to %v" , expectedFlowSchema .Name , err )
208
212
}
209
- klog .V (3 ).Infof ("created system preset FlowSchema %s" , expectedFlowSchema .Name )
213
+ klog .V (3 ).Infof ("Created mandatory FlowSchema %s" , expectedFlowSchema .Name )
210
214
}
211
215
for _ , expectedPriorityLevelConfiguration := range priorityLevels {
212
216
actualPriorityLevelConfiguration , err := flowcontrolClientSet .PriorityLevelConfigurations ().Get (context .TODO (), expectedPriorityLevelConfiguration .Name , metav1.GetOptions {})
213
217
if err == nil {
214
218
// TODO(yue9944882): extract existing version from label and compare
215
219
// TODO(yue9944882): create w/ version string attached
216
- identical , err := priorityLevelHasWrongSpec (expectedPriorityLevelConfiguration , actualPriorityLevelConfiguration )
220
+ wrongSpec , err := priorityLevelHasWrongSpec (expectedPriorityLevelConfiguration , actualPriorityLevelConfiguration )
217
221
if err != nil {
218
222
return fmt .Errorf ("failed checking if mandatory PriorityLevelConfiguration %s is up-to-date due to %v, will retry later" , expectedPriorityLevelConfiguration .Name , err )
219
223
}
220
- if ! identical {
221
- if _ , err := flowcontrolClientSet .PriorityLevelConfigurations ().Update (context .TODO (), expectedPriorityLevelConfiguration , metav1.UpdateOptions {}); err != nil {
224
+ if wrongSpec {
225
+ if _ , err := flowcontrolClientSet .PriorityLevelConfigurations ().Update (context .TODO (), expectedPriorityLevelConfiguration , metav1.UpdateOptions {FieldManager : thisFieldManager }); err != nil {
222
226
return fmt .Errorf ("failed upgrading mandatory PriorityLevelConfiguration %s due to %v, will retry later" , expectedPriorityLevelConfiguration .Name , err )
223
227
}
228
+ klog .V (3 ).Infof ("Updated mandatory PriorityLevelConfiguration %s because its spec was %#+v but must be %#+v" , expectedPriorityLevelConfiguration .Name , actualPriorityLevelConfiguration .Spec , expectedPriorityLevelConfiguration .Spec )
224
229
}
225
230
continue
226
231
}
227
232
if ! apierrors .IsNotFound (err ) {
228
233
return fmt .Errorf ("failed getting PriorityLevelConfiguration %s due to %v, will retry later" , expectedPriorityLevelConfiguration .Name , err )
229
234
}
230
- _ , err = flowcontrolClientSet .PriorityLevelConfigurations ().Create (context .TODO (), expectedPriorityLevelConfiguration , metav1.CreateOptions {})
235
+ _ , err = flowcontrolClientSet .PriorityLevelConfigurations ().Create (context .TODO (), expectedPriorityLevelConfiguration , metav1.CreateOptions {FieldManager : thisFieldManager })
231
236
if apierrors .IsAlreadyExists (err ) {
232
- klog .V (3 ).Infof ("system preset PriorityLevelConfiguration %s already exists, skipping creating" , expectedPriorityLevelConfiguration .Name )
237
+ klog .V (3 ).Infof ("Mandatory PriorityLevelConfiguration %s already exists, skipping creating" , expectedPriorityLevelConfiguration .Name )
233
238
continue
234
239
}
235
240
if err != nil {
236
- return fmt .Errorf ("cannot create PriorityLevelConfiguration %s due to %v" , expectedPriorityLevelConfiguration .Name , err )
241
+ return fmt .Errorf ("cannot create mandatory PriorityLevelConfiguration %s due to %v" , expectedPriorityLevelConfiguration .Name , err )
237
242
}
238
- klog .V (3 ).Infof ("created system preset PriorityLevelConfiguration %s" , expectedPriorityLevelConfiguration .Name )
243
+ klog .V (3 ).Infof ("Created mandatory PriorityLevelConfiguration %s" , expectedPriorityLevelConfiguration .Name )
239
244
}
240
245
return nil
241
246
}
0 commit comments