Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport release-0.14] Fix poll jittering in Object controller #275

Merged
merged 1 commit into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading