Skip to content

Commit

Permalink
Merge pull request #203 from turkenh/tweak-poll-and-max-reconcile-rate
Browse files Browse the repository at this point in the history
Use better defaults for poll interval and max reconcile rate
  • Loading branch information
turkenh authored Feb 20, 2024
2 parents 74fc861 + c73c4bc commit cc17d12
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
4 changes: 2 additions & 2 deletions cmd/provider/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ func main() {
app = kingpin.New(filepath.Base(os.Args[0]), "Template support for Crossplane.").DefaultEnvars()
debug = app.Flag("debug", "Run with debug logging.").Short('d').Bool()
syncInterval = app.Flag("sync", "Controller manager sync period such as 300ms, 1.5h, or 2h45m").Short('s').Default("1h").Duration()
pollInterval = app.Flag("poll", "Poll interval controls how often an individual resource should be checked for drift.").Default("1m").Duration()
pollInterval = app.Flag("poll", "Poll interval controls how often an individual resource should be checked for drift.").Default("10m").Duration()
pollJitterPercentage = app.Flag("poll-jitter-percentage", "Percentage of jitter to apply to poll interval. It cannot be negative, and must be less than 100.").Default("10").Uint()
leaderElection = app.Flag("leader-election", "Use leader election for the controller manager.").Short('l').Default("false").Envar("LEADER_ELECTION").Bool()
maxReconcileRate = app.Flag("max-reconcile-rate", "The number of concurrent reconciliations that may be running at one time.").Default("10").Int()
maxReconcileRate = app.Flag("max-reconcile-rate", "The number of concurrent reconciliations that may be running at one time.").Default("100").Int()
enableManagementPolicies = app.Flag("enable-management-policies", "Enable support for Management Policies.").Default("true").Envar("ENABLE_MANAGEMENT_POLICIES").Bool()
sanitizeSecrets = app.Flag("sanitize-secrets", "when enabled, redacts Secret data from Object status").Default("false").Envar("SANITIZE_SECRETS").Bool()
)
Expand Down
11 changes: 10 additions & 1 deletion internal/controller/object/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"context"
"encoding/base64"
"fmt"
"math/rand"
"strings"
"time"

Expand Down Expand Up @@ -113,7 +114,15 @@ func Setup(mgr ctrl.Manager, o controller.Options, sanitizeSecrets bool, pollJit
}),
managed.WithFinalizer(&objFinalizer{client: mgr.GetClient()}),
managed.WithPollInterval(o.PollInterval),
managed.WithPollJitterHook(pollJitter),
managed.WithPollIntervalHook(func(mg resource.Managed, pollInterval time.Duration) time.Duration {
if mg.GetCondition(xpv1.TypeReady).Status != v1.ConditionTrue {
// If the resource is not ready, we should poll more frequently not to delay time to readiness.
pollInterval = 30 * time.Second
}
// 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
}),
managed.WithLogger(o.Logger.WithValues("controller", name)),
managed.WithRecorder(event.NewAPIRecorder(mgr.GetEventRecorderFor(name))),
managed.WithConnectionPublishers(cps...),
Expand Down

0 comments on commit cc17d12

Please sign in to comment.