Skip to content

Commit

Permalink
Gitops controller resyncs every hour
Browse files Browse the repository at this point in the history
If gitrepos are lost from requeueAfter polling, resync should add them
again.
  • Loading branch information
manno authored and Mario Manno committed Jan 7, 2025
1 parent 7759dd8 commit f33ef66
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,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
Expand Down
9 changes: 9 additions & 0 deletions internal/cmd/controller/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package controller
import (
"context"
"fmt"
"time"

"github.com/reugn/go-quartz/quartz"

Expand All @@ -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"
)
Expand Down Expand Up @@ -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,
Expand All @@ -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")
Expand Down

0 comments on commit f33ef66

Please sign in to comment.