Skip to content

Commit 46c5edb

Browse files
authored
Merge pull request kubernetes#107106 from tkashem/apf-comment
apf: clarify with comment
2 parents 9d2b361 + df41fe5 commit 46c5edb

File tree

6 files changed

+54
-38
lines changed

6 files changed

+54
-38
lines changed

pkg/registry/flowcontrol/ensurer/flowschema.go

+12-7
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,14 @@ type FlowSchemaEnsurer interface {
4141
Ensure([]*flowcontrolv1beta2.FlowSchema) error
4242
}
4343

44-
// FlowSchemaRemover removes the specified bootstrap configuration objects
44+
// FlowSchemaRemover is the interface that wraps the
45+
// RemoveAutoUpdateEnabledObjects method.
46+
//
47+
// RemoveAutoUpdateEnabledObjects removes a set of bootstrap FlowSchema
48+
// objects specified via their names. The function removes an object
49+
// only if automatic update of the spec is enabled for it.
4550
type FlowSchemaRemover interface {
46-
Remove([]string) error
51+
RemoveAutoUpdateEnabledObjects([]string) error
4752
}
4853

4954
// NewSuggestedFlowSchemaEnsurer returns a FlowSchemaEnsurer instance that
@@ -83,11 +88,11 @@ func NewFlowSchemaRemover(client flowcontrolclient.FlowSchemaInterface, lister f
8388
}
8489
}
8590

86-
// GetFlowSchemaRemoveCandidate returns a list of FlowSchema object
91+
// GetFlowSchemaRemoveCandidates returns a list of FlowSchema object
8792
// names that are candidates for deletion from the cluster.
8893
// bootstrap: a set of hard coded FlowSchema configuration objects
8994
// kube-apiserver maintains in-memory.
90-
func GetFlowSchemaRemoveCandidate(lister flowcontrollisters.FlowSchemaLister, bootstrap []*flowcontrolv1beta2.FlowSchema) ([]string, error) {
95+
func GetFlowSchemaRemoveCandidates(lister flowcontrollisters.FlowSchemaLister, bootstrap []*flowcontrolv1beta2.FlowSchema) ([]string, error) {
9196
fsList, err := lister.List(labels.Everything())
9297
if err != nil {
9398
return nil, fmt.Errorf("failed to list FlowSchema - %w", err)
@@ -103,7 +108,7 @@ func GetFlowSchemaRemoveCandidate(lister flowcontrollisters.FlowSchemaLister, bo
103108
currentObjects[i] = fsList[i]
104109
}
105110

106-
return getRemoveCandidate(bootstrapNames, currentObjects), nil
111+
return getDanglingBootstrapObjectNames(bootstrapNames, currentObjects), nil
107112
}
108113

109114
type fsEnsurer struct {
@@ -121,9 +126,9 @@ func (e *fsEnsurer) Ensure(flowSchemas []*flowcontrolv1beta2.FlowSchema) error {
121126
return nil
122127
}
123128

124-
func (e *fsEnsurer) Remove(flowSchemas []string) error {
129+
func (e *fsEnsurer) RemoveAutoUpdateEnabledObjects(flowSchemas []string) error {
125130
for _, flowSchema := range flowSchemas {
126-
if err := removeConfiguration(e.wrapper, flowSchema); err != nil {
131+
if err := removeAutoUpdateEnabledConfiguration(e.wrapper, flowSchema); err != nil {
127132
return err
128133
}
129134
}

pkg/registry/flowcontrol/ensurer/flowschema_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ func TestRemoveFlowSchema(t *testing.T) {
322322
}
323323

324324
remover := NewFlowSchemaRemover(client, flowcontrollisters.NewFlowSchemaLister(indexer))
325-
err := remover.Remove([]string{test.bootstrapName})
325+
err := remover.RemoveAutoUpdateEnabledObjects([]string{test.bootstrapName})
326326
if err != nil {
327327
t.Fatalf("Expected no error, but got: %v", err)
328328
}
@@ -410,7 +410,7 @@ func TestGetFlowSchemaRemoveCandidate(t *testing.T) {
410410
}
411411

412412
lister := flowcontrollisters.NewFlowSchemaLister(indexer)
413-
removeListGot, err := GetFlowSchemaRemoveCandidate(lister, test.bootstrap)
413+
removeListGot, err := GetFlowSchemaRemoveCandidates(lister, test.bootstrap)
414414
if err != nil {
415415
t.Fatalf("Expected no error, but got: %v", err)
416416
}

pkg/registry/flowcontrol/ensurer/prioritylevelconfiguration.go

+13-7
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,15 @@ type PriorityLevelEnsurer interface {
4141
Ensure([]*flowcontrolv1beta2.PriorityLevelConfiguration) error
4242
}
4343

44-
// PriorityLevelRemover removes the specified bootstrap configuration objects
44+
// PriorityLevelRemover is the interface that wraps the
45+
// RemoveAutoUpdateEnabledObjects method.
46+
//
47+
// RemoveAutoUpdateEnabledObjects removes a set of bootstrap
48+
// PriorityLevelConfiguration objects specified via their names.
49+
// The function removes an object only if automatic update
50+
// of the spec is enabled for it.
4551
type PriorityLevelRemover interface {
46-
Remove([]string) error
52+
RemoveAutoUpdateEnabledObjects([]string) error
4753
}
4854

4955
// NewSuggestedPriorityLevelEnsurerEnsurer returns a PriorityLevelEnsurer instance that
@@ -83,11 +89,11 @@ func NewPriorityLevelRemover(client flowcontrolclient.PriorityLevelConfiguration
8389
}
8490
}
8591

86-
// GetPriorityLevelRemoveCandidate returns a list of PriorityLevelConfiguration
92+
// GetPriorityLevelRemoveCandidates returns a list of PriorityLevelConfiguration
8793
// names that are candidates for removal from the cluster.
8894
// bootstrap: a set of hard coded PriorityLevelConfiguration configuration
8995
// objects kube-apiserver maintains in-memory.
90-
func GetPriorityLevelRemoveCandidate(lister flowcontrollisters.PriorityLevelConfigurationLister, bootstrap []*flowcontrolv1beta2.PriorityLevelConfiguration) ([]string, error) {
96+
func GetPriorityLevelRemoveCandidates(lister flowcontrollisters.PriorityLevelConfigurationLister, bootstrap []*flowcontrolv1beta2.PriorityLevelConfiguration) ([]string, error) {
9197
plList, err := lister.List(labels.Everything())
9298
if err != nil {
9399
return nil, fmt.Errorf("failed to list PriorityLevelConfiguration - %w", err)
@@ -103,7 +109,7 @@ func GetPriorityLevelRemoveCandidate(lister flowcontrollisters.PriorityLevelConf
103109
currentObjects[i] = plList[i]
104110
}
105111

106-
return getRemoveCandidate(bootstrapNames, currentObjects), nil
112+
return getDanglingBootstrapObjectNames(bootstrapNames, currentObjects), nil
107113
}
108114

109115
type plEnsurer struct {
@@ -121,9 +127,9 @@ func (e *plEnsurer) Ensure(priorityLevels []*flowcontrolv1beta2.PriorityLevelCon
121127
return nil
122128
}
123129

124-
func (e *plEnsurer) Remove(priorityLevels []string) error {
130+
func (e *plEnsurer) RemoveAutoUpdateEnabledObjects(priorityLevels []string) error {
125131
for _, priorityLevel := range priorityLevels {
126-
if err := removeConfiguration(e.wrapper, priorityLevel); err != nil {
132+
if err := removeAutoUpdateEnabledConfiguration(e.wrapper, priorityLevel); err != nil {
127133
return err
128134
}
129135
}

pkg/registry/flowcontrol/ensurer/prioritylevelconfiguration_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ func TestRemovePriorityLevelConfiguration(t *testing.T) {
338338
}
339339

340340
remover := NewPriorityLevelRemover(client, flowcontrollisters.NewPriorityLevelConfigurationLister(indexer))
341-
err := remover.Remove([]string{test.bootstrapName})
341+
err := remover.RemoveAutoUpdateEnabledObjects([]string{test.bootstrapName})
342342
if err != nil {
343343
t.Fatalf("Expected no error, but got: %v", err)
344344
}
@@ -426,7 +426,7 @@ func TestGetPriorityLevelRemoveCandidate(t *testing.T) {
426426
}
427427

428428
lister := flowcontrollisters.NewPriorityLevelConfigurationLister(indexer)
429-
removeListGot, err := GetPriorityLevelRemoveCandidate(lister, test.bootstrap)
429+
removeListGot, err := GetPriorityLevelRemoveCandidates(lister, test.bootstrap)
430430
if err != nil {
431431
t.Fatalf("Expected no error, but got: %v", err)
432432
}

pkg/registry/flowcontrol/ensurer/strategy.go

+15-10
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,9 @@ func ensureConfiguration(wrapper configurationWrapper, strategy ensureStrategy,
268268
return fmt.Errorf("failed to update the %s, will retry later type=%s name=%q error=%w", wrapper.TypeName(), configurationType, name, err)
269269
}
270270

271-
func removeConfiguration(wrapper configurationWrapper, name string) error {
271+
// removeAutoUpdateEnabledConfiguration makes an attempt to remove the given
272+
// configuration object if automatic update of the spec is enabled for this object.
273+
func removeAutoUpdateEnabledConfiguration(wrapper configurationWrapper, name string) error {
272274
current, err := wrapper.Get(name)
273275
if err != nil {
274276
if apierrors.IsNotFound(err) {
@@ -305,16 +307,17 @@ func removeConfiguration(wrapper configurationWrapper, name string) error {
305307
return nil
306308
}
307309

308-
// getRemoveCandidate returns a list of configuration objects we should delete
309-
// from the cluster given a set of bootstrap and current configuration.
310-
// bootstrap: a set of hard coded configuration kube-apiserver maintains in-memory.
311-
// current: a set of configuration objects that exist on the cluster
312-
// Any object present in current is a candidate for removal if both a and b are true:
310+
// getDanglingBootstrapObjectNames returns a list of names of bootstrap
311+
// configuration objects that are potentially candidates for deletion from
312+
// the cluster, given a set of bootstrap and current configuration.
313+
// - bootstrap: a set of hard coded configuration kube-apiserver maintains in-memory.
314+
// - current: a set of configuration objects that exist on the cluster
315+
// Any object present in current is added to the list if both a and b are true:
313316
// a. the object in current is missing from the bootstrap configuration
314317
// b. the object has the designated auto-update annotation key
315-
// This function shares the common logic for both FlowSchema and PriorityLevelConfiguration
316-
// type and hence it accepts metav1.Object only.
317-
func getRemoveCandidate(bootstrap sets.String, current []metav1.Object) []string {
318+
// This function shares the common logic for both FlowSchema and
319+
// PriorityLevelConfiguration type and hence it accepts metav1.Object only.
320+
func getDanglingBootstrapObjectNames(bootstrap sets.String, current []metav1.Object) []string {
318321
if len(current) == 0 {
319322
return nil
320323
}
@@ -323,7 +326,9 @@ func getRemoveCandidate(bootstrap sets.String, current []metav1.Object) []string
323326
for i := range current {
324327
object := current[i]
325328
if _, ok := object.GetAnnotations()[flowcontrolv1beta2.AutoUpdateAnnotationKey]; !ok {
326-
// the configuration object does not have the annotation key
329+
// the configuration object does not have the annotation key,
330+
// it's probably a user defined configuration object,
331+
// so we can skip it.
327332
continue
328333
}
329334

pkg/registry/flowcontrol/rest/storage_flowcontrol.go

+10-10
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ func ensure(clientset flowcontrolclient.FlowcontrolV1beta2Interface, fsLister fl
188188
return fmt.Errorf("failed ensuring mandatory settings - %w", err)
189189
}
190190

191-
if err := removeConfiguration(clientset, fsLister, plcLister); err != nil {
191+
if err := removeDanglingBootstrapConfiguration(clientset, fsLister, plcLister); err != nil {
192192
return fmt.Errorf("failed to delete removed settings - %w", err)
193193
}
194194

@@ -215,17 +215,17 @@ func ensureMandatoryConfiguration(clientset flowcontrolclient.FlowcontrolV1beta2
215215
return plEnsurer.Ensure(flowcontrolbootstrap.MandatoryPriorityLevelConfigurations)
216216
}
217217

218-
func removeConfiguration(clientset flowcontrolclient.FlowcontrolV1beta2Interface, fsLister flowcontrollisters.FlowSchemaLister, plcLister flowcontrollisters.PriorityLevelConfigurationLister) error {
219-
if err := removeFlowSchema(clientset.FlowSchemas(), fsLister); err != nil {
218+
func removeDanglingBootstrapConfiguration(clientset flowcontrolclient.FlowcontrolV1beta2Interface, fsLister flowcontrollisters.FlowSchemaLister, plcLister flowcontrollisters.PriorityLevelConfigurationLister) error {
219+
if err := removeDanglingBootstrapFlowSchema(clientset.FlowSchemas(), fsLister); err != nil {
220220
return err
221221
}
222222

223-
return removePriorityLevel(clientset.PriorityLevelConfigurations(), plcLister)
223+
return removeDanglingBootstrapPriorityLevel(clientset.PriorityLevelConfigurations(), plcLister)
224224
}
225225

226-
func removeFlowSchema(client flowcontrolclient.FlowSchemaInterface, lister flowcontrollisters.FlowSchemaLister) error {
226+
func removeDanglingBootstrapFlowSchema(client flowcontrolclient.FlowSchemaInterface, lister flowcontrollisters.FlowSchemaLister) error {
227227
bootstrap := append(flowcontrolbootstrap.MandatoryFlowSchemas, flowcontrolbootstrap.SuggestedFlowSchemas...)
228-
candidates, err := ensurer.GetFlowSchemaRemoveCandidate(lister, bootstrap)
228+
candidates, err := ensurer.GetFlowSchemaRemoveCandidates(lister, bootstrap)
229229
if err != nil {
230230
return err
231231
}
@@ -234,12 +234,12 @@ func removeFlowSchema(client flowcontrolclient.FlowSchemaInterface, lister flowc
234234
}
235235

236236
fsRemover := ensurer.NewFlowSchemaRemover(client, lister)
237-
return fsRemover.Remove(candidates)
237+
return fsRemover.RemoveAutoUpdateEnabledObjects(candidates)
238238
}
239239

240-
func removePriorityLevel(client flowcontrolclient.PriorityLevelConfigurationInterface, lister flowcontrollisters.PriorityLevelConfigurationLister) error {
240+
func removeDanglingBootstrapPriorityLevel(client flowcontrolclient.PriorityLevelConfigurationInterface, lister flowcontrollisters.PriorityLevelConfigurationLister) error {
241241
bootstrap := append(flowcontrolbootstrap.MandatoryPriorityLevelConfigurations, flowcontrolbootstrap.SuggestedPriorityLevelConfigurations...)
242-
candidates, err := ensurer.GetPriorityLevelRemoveCandidate(lister, bootstrap)
242+
candidates, err := ensurer.GetPriorityLevelRemoveCandidates(lister, bootstrap)
243243
if err != nil {
244244
return err
245245
}
@@ -248,7 +248,7 @@ func removePriorityLevel(client flowcontrolclient.PriorityLevelConfigurationInte
248248
}
249249

250250
plRemover := ensurer.NewPriorityLevelRemover(client, lister)
251-
return plRemover.Remove(candidates)
251+
return plRemover.RemoveAutoUpdateEnabledObjects(candidates)
252252
}
253253

254254
// contextFromChannelAndMaxWaitDuration returns a Context that is bound to the

0 commit comments

Comments
 (0)