Skip to content

Commit a1030a9

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 fa4e118 commit a1030a9

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
@@ -28,25 +28,10 @@ import (
2828
cachev1alpha1 "github.com/kcp-dev/kcp/sdk/apis/cache/v1alpha1"
2929
conditionsv1alpha1 "github.com/kcp-dev/kcp/sdk/apis/third_party/conditions/apis/conditions/v1alpha1"
3030
"github.com/kcp-dev/kcp/sdk/apis/third_party/conditions/util/conditions"
31-
topologyv1alpha1 "github.com/kcp-dev/kcp/sdk/apis/topology/v1alpha1"
3231
)
3332

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

8065
// Check the partition selector.
8166
var selector labels.Selector
8267
if endpoints.Spec.Partition != "" {
83-
partition, err := r.getPartition(logicalcluster.From(endpoints), endpoints.Spec.Partition)
68+
partition, err := c.getPartition(logicalcluster.From(endpoints), endpoints.Spec.Partition)
8469
if err != nil {
8570
if apierrors.IsNotFound(err) {
8671
// Don't keep the endpoints if the Partition has been deleted and is still referenced.
@@ -94,7 +79,7 @@ func (r *endpointsReconciler) reconcile(ctx context.Context, endpoints *cachev1a
9479
err,
9580
)
9681
// No need to try again.
97-
return false, nil
82+
return nil
9883
} else {
9984
conditions.MarkFalse(
10085
endpoints,
@@ -104,7 +89,7 @@ func (r *endpointsReconciler) reconcile(ctx context.Context, endpoints *cachev1a
10489
"%v",
10590
err,
10691
)
107-
return true, err
92+
return err
10893
}
10994
}
11095
selector, err = metav1.LabelSelectorAsSelector(partition.Spec.Selector)
@@ -117,7 +102,7 @@ func (r *endpointsReconciler) reconcile(ctx context.Context, endpoints *cachev1a
117102
"%v",
118103
err,
119104
)
120-
return true, err
105+
return err
121106
}
122107
}
123108
if selector == nil {
@@ -128,5 +113,5 @@ func (r *endpointsReconciler) reconcile(ctx context.Context, endpoints *cachev1a
128113

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

131-
return true, err
116+
return nil
132117
}

pkg/reconciler/cache/cachedresourceendpointslice/cachedresourceendpointslice_reconcile_test.go

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

0 commit comments

Comments
 (0)