diff --git a/internal/cmd/controller/gitops/reconciler/gitjob_controller.go b/internal/cmd/controller/gitops/reconciler/gitjob_controller.go index 0352e595cb..32fc27a544 100644 --- a/internal/cmd/controller/gitops/reconciler/gitjob_controller.go +++ b/internal/cmd/controller/gitops/reconciler/gitjob_controller.go @@ -211,7 +211,7 @@ func (r *GitJobReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctr // addJitter to the requeue time to avoid thundering herd // generate a random number between -10% and +10% of the duration func addJitter(d time.Duration) time.Duration { - return d + time.Duration(rand.Int64N(int64(d)/5)-int64(d)/10) + return d + time.Duration(rand.Int64N(int64(d)/5)-int64(d)/10) // nolint:gosec // gosec G404 false positive, not used for crypto } // manageGitJob is responsible for creating, updating and deleting the GitJob and setting the GitRepo's status accordingly diff --git a/internal/cmd/controller/operator.go b/internal/cmd/controller/operator.go index 73881c62a9..3442f38239 100644 --- a/internal/cmd/controller/operator.go +++ b/internal/cmd/controller/operator.go @@ -3,6 +3,7 @@ package controller import ( "context" "fmt" + "time" "github.com/reugn/go-quartz/quartz" @@ -18,6 +19,7 @@ import ( clientgoscheme "k8s.io/client-go/kubernetes/scheme" "k8s.io/client-go/rest" ctrl "sigs.k8s.io/controller-runtime" + "sigs.k8s.io/controller-runtime/pkg/cache" "sigs.k8s.io/controller-runtime/pkg/healthz" metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server" ) @@ -59,6 +61,8 @@ func start( leaderElectionSuffix = fmt.Sprintf("-%s", shardID) } + hour := 60 * time.Minute + mgr, err := ctrl.NewManager(config, ctrl.Options{ Scheme: scheme, Metrics: metricServerOptions, @@ -70,6 +74,11 @@ func start( LeaseDuration: leaderOpts.LeaseDuration, RenewDeadline: leaderOpts.RenewDeadline, RetryPeriod: leaderOpts.RetryPeriod, + + // resync to pick up lost gitrepos + Cache: cache.Options{ + SyncPeriod: &hour, + }, }) if err != nil { setupLog.Error(err, "unable to start manager")