Skip to content

Commit d7b6e45

Browse files
Add manager filter for generation changed (#41)
Fixes: aws-controllers-k8s/community#886 The reconciler will indefinitely requeue even when there have been no changes made to the `spec` or `status`. This is happening in both the adoption and resource reconciler types. The root cause comes from `controller-runtime` requeue-ing the resource when we patch the `status` subresource - see [this issue](kubernetes-sigs/kubebuilder#618) for details. This bug was introduced for the resource reconciler as part of #39 , since we now call `patchResourceStatus` on every reconcile loop. This fix adds an event filter to each manager, with a predicate that the resource must have changed generation. The generation is not changed unless there has been a modification to the `spec`.
1 parent 0cc4433 commit d7b6e45

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

pkg/runtime/adoption_reconciler.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
ctrlrt "sigs.k8s.io/controller-runtime"
2626
"sigs.k8s.io/controller-runtime/pkg/client"
2727
k8sctrlutil "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
28+
"sigs.k8s.io/controller-runtime/pkg/predicate"
2829

2930
ackv1alpha1 "github.com/aws-controllers-k8s/runtime/apis/core/v1alpha1"
3031
ackcfg "github.com/aws-controllers-k8s/runtime/pkg/config"
@@ -57,6 +58,8 @@ func (r *adoptionReconciler) BindControllerManager(mgr ctrlrt.Manager) error {
5758
).For(
5859
// Read only adopted resource objects
5960
&ackv1alpha1.AdoptedResource{},
61+
).WithEventFilter(
62+
predicate.GenerationChangedPredicate{},
6063
).Complete(r)
6164
}
6265

pkg/runtime/reconciler.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2525
ctrlrt "sigs.k8s.io/controller-runtime"
2626
"sigs.k8s.io/controller-runtime/pkg/client"
27+
"sigs.k8s.io/controller-runtime/pkg/predicate"
2728

2829
ackv1alpha1 "github.com/aws-controllers-k8s/runtime/apis/core/v1alpha1"
2930
ackcompare "github.com/aws-controllers-k8s/runtime/pkg/compare"
@@ -80,6 +81,8 @@ func (r *resourceReconciler) BindControllerManager(mgr ctrlrt.Manager) error {
8081
mgr,
8182
).For(
8283
rd.EmptyRuntimeObject(),
84+
).WithEventFilter(
85+
predicate.GenerationChangedPredicate{},
8386
).Complete(r)
8487
}
8588

0 commit comments

Comments
 (0)