Skip to content

Commit 5d2e554

Browse files
committed
CachedResourceEndpointSlice reconciler shouldn't retry on success
On-behalf-of: @SAP [email protected] Signed-off-by: Robert Vasek <[email protected]>
1 parent 1b50cf7 commit 5d2e554

File tree

3 files changed

+17
-35
lines changed

3 files changed

+17
-35
lines changed

pkg/reconciler/cache/cachedresourceendpointslice/cachedresourceendpointslice_controller.go

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -253,30 +253,27 @@ func (c *controller) processNextWorkItem(ctx context.Context) bool {
253253
// other workers.
254254
defer c.queue.Done(key)
255255

256-
if requeue, err := c.process(ctx, key); err != nil {
256+
if err := c.process(ctx, key); err != nil {
257257
utilruntime.HandleError(fmt.Errorf("%q controller failed to sync %q, err: %w", ControllerName, key, err))
258258
c.queue.AddRateLimited(key)
259259
return true
260-
} else if requeue {
261-
c.queue.Add(key)
262-
return true
263260
}
264261
c.queue.Forget(key)
265262
return true
266263
}
267264

268-
func (c *controller) process(ctx context.Context, key string) (bool, error) {
265+
func (c *controller) process(ctx context.Context, key string) error {
269266
clusterName, _, name, err := kcpcache.SplitMetaClusterNamespaceKey(key)
270267
if err != nil {
271268
utilruntime.HandleError(err)
272-
return false, nil
269+
return nil
273270
}
274271
obj, err := c.getCachedResourceEndpointSlice(clusterName.Path(), name)
275272
if err != nil {
276273
if errors.IsNotFound(err) {
277-
return false, nil // object deleted before we handled it
274+
return nil // object deleted before we handled it
278275
}
279-
return false, err
276+
return err
280277
}
281278

282279
old := obj
@@ -286,7 +283,7 @@ func (c *controller) process(ctx context.Context, key string) (bool, error) {
286283
ctx = klog.NewContext(ctx, logger)
287284

288285
var errs []error
289-
requeue, err := c.reconcile(ctx, obj)
286+
err = c.reconcile(ctx, obj)
290287
if err != nil {
291288
errs = append(errs, err)
292289
}
@@ -302,7 +299,7 @@ func (c *controller) process(ctx context.Context, key string) (bool, error) {
302299
errs = append(errs, err)
303300
}
304301

305-
return requeue, utilerrors.NewAggregate(errs)
302+
return utilerrors.NewAggregate(errs)
306303
}
307304

308305
// InstallIndexers adds the additional indexers that this controller requires to the informers.

pkg/reconciler/cache/cachedresourceendpointslice/cachedresourceendpointslice_reconcile.go

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -27,25 +27,10 @@ import (
2727
cachev1alpha1 "github.com/kcp-dev/sdk/apis/cache/v1alpha1"
2828
conditionsv1alpha1 "github.com/kcp-dev/sdk/apis/third_party/conditions/apis/conditions/v1alpha1"
2929
"github.com/kcp-dev/sdk/apis/third_party/conditions/util/conditions"
30-
topologyv1alpha1 "github.com/kcp-dev/sdk/apis/topology/v1alpha1"
3130
)
3231

33-
func (c *controller) reconcile(ctx context.Context, endpoints *cachev1alpha1.CachedResourceEndpointSlice) (bool, error) {
34-
r := &endpointsReconciler{
35-
getCachedResource: c.getCachedResource,
36-
getPartition: c.getPartition,
37-
}
38-
39-
return r.reconcile(ctx, endpoints)
40-
}
41-
42-
type endpointsReconciler struct {
43-
getCachedResource func(path logicalcluster.Path, name string) (*cachev1alpha1.CachedResource, error)
44-
getPartition func(clusterName logicalcluster.Name, name string) (*topologyv1alpha1.Partition, error)
45-
}
46-
47-
func (r *endpointsReconciler) reconcile(ctx context.Context, endpoints *cachev1alpha1.CachedResourceEndpointSlice) (bool, error) {
48-
_, err := r.getCachedResource(logicalcluster.From(endpoints).Path(), endpoints.Spec.CachedResource.Name)
32+
func (c *controller) reconcile(ctx context.Context, endpoints *cachev1alpha1.CachedResourceEndpointSlice) error {
33+
_, err := c.getCachedResource(logicalcluster.From(endpoints).Path(), endpoints.Spec.CachedResource.Name)
4934
if err != nil {
5035
if apierrors.IsNotFound(err) {
5136
// Don't keep the endpoints if the CachedResource has been deleted.
@@ -60,7 +45,7 @@ func (r *endpointsReconciler) reconcile(ctx context.Context, endpoints *cachev1a
6045
endpoints.Spec.CachedResource.Name,
6146
)
6247
// No need to try again.
63-
return false, nil
48+
return nil
6449
} else {
6550
conditions.MarkFalse(
6651
endpoints,
@@ -71,15 +56,15 @@ func (r *endpointsReconciler) reconcile(ctx context.Context, endpoints *cachev1a
7156
logicalcluster.From(endpoints),
7257
endpoints.Spec.CachedResource.Name,
7358
)
74-
return true, err
59+
return err
7560
}
7661
}
7762
conditions.MarkTrue(endpoints, cachev1alpha1.CachedResourceValid)
7863

7964
// Check the partition selector.
8065
var selector labels.Selector
8166
if endpoints.Spec.Partition != "" {
82-
partition, err := r.getPartition(logicalcluster.From(endpoints), endpoints.Spec.Partition)
67+
partition, err := c.getPartition(logicalcluster.From(endpoints), endpoints.Spec.Partition)
8368
if err != nil {
8469
if apierrors.IsNotFound(err) {
8570
// Don't keep the endpoints if the Partition has been deleted and is still referenced.
@@ -93,7 +78,7 @@ func (r *endpointsReconciler) reconcile(ctx context.Context, endpoints *cachev1a
9378
err,
9479
)
9580
// No need to try again.
96-
return false, nil
81+
return nil
9782
} else {
9883
conditions.MarkFalse(
9984
endpoints,
@@ -103,7 +88,7 @@ func (r *endpointsReconciler) reconcile(ctx context.Context, endpoints *cachev1a
10388
"%v",
10489
err,
10590
)
106-
return true, err
91+
return err
10792
}
10893
}
10994
selector, err = metav1.LabelSelectorAsSelector(partition.Spec.Selector)
@@ -116,7 +101,7 @@ func (r *endpointsReconciler) reconcile(ctx context.Context, endpoints *cachev1a
116101
"%v",
117102
err,
118103
)
119-
return true, err
104+
return err
120105
}
121106
}
122107
if selector == nil {
@@ -127,5 +112,5 @@ func (r *endpointsReconciler) reconcile(ctx context.Context, endpoints *cachev1a
127112

128113
endpoints.Status.ShardSelector = selector.String()
129114

130-
return true, err
115+
return nil
131116
}

pkg/reconciler/cache/cachedresourceendpointslice/cachedresourceendpointslice_reconcile_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ func TestReconcile(t *testing.T) {
124124
Partition: "my-partition",
125125
},
126126
}
127-
_, err := c.reconcile(context.Background(), cachedResourceEndpointSlice)
127+
err := c.reconcile(context.Background(), cachedResourceEndpointSlice)
128128
if tc.wantError {
129129
require.Error(t, err, "expected an error")
130130
} else {

0 commit comments

Comments
 (0)