Skip to content

Commit

Permalink
Merge pull request #274 from aerfio/aerfio/fix-poll-interval
Browse files Browse the repository at this point in the history
Fix poll jittering in Object controller
  • Loading branch information
turkenh authored Jul 26, 2024
2 parents a9c6ef8 + b654820 commit 80eeec3
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion cmd/provider/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func main() {
// notice and remove when we drop support for v1alpha1.
kingpin.FatalIfError(ctrl.NewWebhookManagedBy(mgr).For(&v1alpha1.Object{}).Complete(), "Cannot create Object webhook")

kingpin.FatalIfError(object.Setup(mgr, o, *sanitizeSecrets, pollJitter), "Cannot setup controller")
kingpin.FatalIfError(object.Setup(mgr, o, *sanitizeSecrets, pollJitter, *pollJitterPercentage), "Cannot setup controller")
kingpin.FatalIfError(mgr.Start(ctrl.SetupSignalHandler()), "Cannot start controller manager")
}

Expand Down
4 changes: 2 additions & 2 deletions internal/controller/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ import (

// Setup creates all Template controllers with the supplied logger and adds them to
// the supplied manager.
func Setup(mgr ctrl.Manager, o controller.Options, sanitizeSecrets bool, pollJitter time.Duration) error {
func Setup(mgr ctrl.Manager, o controller.Options, sanitizeSecrets bool, pollJitter time.Duration, pollJitterPercentage uint) error {
if err := config.Setup(mgr, o); err != nil {
return err
}
if err := object.Setup(mgr, o, sanitizeSecrets, pollJitter); err != nil {
if err := object.Setup(mgr, o, sanitizeSecrets, pollJitterPercentage); err != nil {
return err
}
if err := observedobjectcollection.Setup(mgr, o, pollJitter); err != nil {
Expand Down
3 changes: 2 additions & 1 deletion internal/controller/object/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ type KindObserver interface {
}

// Setup adds a controller that reconciles Object managed resources.
func Setup(mgr ctrl.Manager, o controller.Options, sanitizeSecrets bool, pollJitter time.Duration) error {
func Setup(mgr ctrl.Manager, o controller.Options, sanitizeSecrets bool, pollJitterPercentage uint) error {
name := managed.ControllerName(v1alpha2.ObjectGroupKind)
l := o.Logger.WithValues("controller", name)

Expand All @@ -132,6 +132,7 @@ func Setup(mgr ctrl.Manager, o controller.Options, sanitizeSecrets bool, pollJit
// If the resource is not ready, we should poll more frequently not to delay time to readiness.
pollInterval = 30 * time.Second
}
pollJitter := time.Duration(float64(pollInterval) * (float64(pollJitterPercentage) / 100.0))
// This is the same as runtime default poll interval with jitter, see:
// https://github.com/crossplane/crossplane-runtime/blob/7fcb8c5cad6fc4abb6649813b92ab92e1832d368/pkg/reconciler/managed/reconciler.go#L573
return pollInterval + time.Duration((rand.Float64()-0.5)*2*float64(pollJitter)) //nolint G404 // No need for secure randomness
Expand Down

0 comments on commit 80eeec3

Please sign in to comment.