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

Add jitter to poll interval #198

Merged
merged 2 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 9 additions & 1 deletion cmd/provider/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@ func main() {
ctrl.SetLogger(zl)
}

// configure the jitter to be the 10% of the poll interval
lsviben marked this conversation as resolved.
Show resolved Hide resolved
pollJitter := time.Duration(float64(*pollInterval) * 0.1)
log.Debug("Starting",
"sync-interval", syncInterval.String(),
"poll-interval", pollInterval.String(),
"poll-jitter", pollJitter.String(),
"max-reconcile-rate", *maxReconcileRate)

cfg, err := ctrl.GetConfig()
kingpin.FatalIfError(err, "Cannot get API server rest config")

Expand Down Expand Up @@ -130,7 +138,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), "Cannot setup controller")
kingpin.FatalIfError(object.Setup(mgr, o, *sanitizeSecrets, pollJitter), "Cannot setup controller")
kingpin.FatalIfError(mgr.Start(ctrl.SetupSignalHandler()), "Cannot start controller manager")
}

Expand Down
6 changes: 4 additions & 2 deletions internal/controller/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ limitations under the License.
package controller

import (
"time"

ctrl "sigs.k8s.io/controller-runtime"

"github.com/crossplane/crossplane-runtime/pkg/controller"
Expand All @@ -27,11 +29,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) error {
func Setup(mgr ctrl.Manager, o controller.Options, sanitizeSecrets bool, pollJitter time.Duration) error {
if err := config.Setup(mgr, o); err != nil {
return err
}
if err := object.Setup(mgr, o, sanitizeSecrets); err != nil {
if err := object.Setup(mgr, o, sanitizeSecrets, pollJitter); err != nil {
return err
}
return nil
Expand Down
4 changes: 3 additions & 1 deletion internal/controller/object/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"encoding/base64"
"fmt"
"strings"
"time"

"github.com/pkg/errors"
v1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -91,7 +92,7 @@ const (
)

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

cps := []managed.ConnectionPublisher{managed.NewAPISecretPublisher(mgr.GetClient(), mgr.GetScheme())}
Expand All @@ -112,6 +113,7 @@ func Setup(mgr ctrl.Manager, o controller.Options, sanitizeSecrets bool) error {
}),
managed.WithFinalizer(&objFinalizer{client: mgr.GetClient()}),
managed.WithPollInterval(o.PollInterval),
managed.WithPollJitterHook(pollJitter),
managed.WithLogger(o.Logger.WithValues("controller", name)),
managed.WithRecorder(event.NewAPIRecorder(mgr.GetEventRecorderFor(name))),
managed.WithConnectionPublishers(cps...),
Expand Down
Loading