Skip to content

Commit d48e9e0

Browse files
authored
Adds logic to the reconcile function to handle the optional infinite requeue (Issue #826) (#23)
This PR is one of two to implement [Issue #826](aws-controllers-k8s/community#826) [Link to the code-generator PR ](aws-controllers-k8s/code-generator#95) ### Testing I tested the change by enabling it for applicationAutoscaling (ScalableTarget) - [you can check the generated code on this branch just for reference. ](aws-controllers-k8s/applicationautoscaling-controller#21)
1 parent 932df41 commit d48e9e0

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

pkg/runtime/reconciler.go

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ package runtime
1515

1616
import (
1717
"context"
18-
18+
"time"
19+
1920
"github.com/go-logr/logr"
2021
"github.com/pkg/errors"
2122
corev1 "k8s.io/api/core/v1"
@@ -279,15 +280,21 @@ func (r *resourceReconciler) Sync(
279280
return err
280281
}
281282
for _, condition := range latest.Conditions() {
282-
if condition.Type == ackv1alpha1.ConditionTypeResourceSynced &&
283-
condition.Status != corev1.ConditionTrue {
284-
rlog.Debug(
285-
"requeueing resource after finding resource synced condition false",
286-
)
287-
return requeue.NeededAfter(
288-
ackerr.TemporaryOutOfSync,
289-
requeue.DefaultRequeueAfterDuration,
290-
)
283+
if condition.Type == ackv1alpha1.ConditionTypeResourceSynced {
284+
if condition.Status == corev1.ConditionTrue {
285+
if duration := r.rmf.RequeueOnSuccessSeconds(); duration > 0 {
286+
rlog.Debug(
287+
"requeueing resource after resource synced condition true",
288+
)
289+
return requeue.NeededAfter(nil, time.Duration(duration)*time.Second)
290+
}
291+
} else {
292+
rlog.Debug(
293+
"requeueing resource after finding resource synced condition false",
294+
)
295+
return requeue.NeededAfter(
296+
ackerr.TemporaryOutOfSync, requeue.DefaultRequeueAfterDuration)
297+
}
291298
}
292299
}
293300
return nil

pkg/types/aws_resource_manager.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ type AWSResourceManager interface {
7070

7171
// AWSResourceManagerFactory returns an AWSResourceManager that can be used to
7272
// manage AWS resources for a particular AWS account
73+
// TODO(jaypipes): Move AWSResourceManagerFactory into its own file
7374
type AWSResourceManagerFactory interface {
7475
// ResourceDescriptor returns an AWSResourceDescriptor that can be used by
7576
// the upstream controller-runtime to introspect the CRs that the resource
@@ -89,4 +90,7 @@ type AWSResourceManagerFactory interface {
8990
) (AWSResourceManager, error)
9091
// IsAdoptable returns true if the resource is able to be adopted
9192
IsAdoptable() bool
93+
// RequeueOnSuccessSeconds returns true if the resource should be requeued after specified seconds
94+
// Default is false which means resource will not be requeued after success.
95+
RequeueOnSuccessSeconds() int
9296
}

0 commit comments

Comments
 (0)