Skip to content

Commit

Permalink
feat: add sync-period to control resync if needed, add debug log to s…
Browse files Browse the repository at this point in the history
…ee when resync happened (#1902)

Signed-off-by: Peter Wilcsinszky <[email protected]>
  • Loading branch information
pepov authored Jan 9, 2025
1 parent 06aca68 commit 6da8cda
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
2 changes: 2 additions & 0 deletions controllers/logging/logging_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ type LoggingReconciler struct {
func (r *LoggingReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
log := r.Log.WithValues("logging", req.Name)

log.V(1).Info("reconciling")

var logging loggingv1beta1.Logging
if err := r.Client.Get(ctx, req.NamespacedName, &logging); err != nil {
// If object is not found, return without error.
Expand Down
14 changes: 12 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ func main() {
var finalizerCleanup bool
var enableTelemetryControllerRoute bool
var klogLevel int
var syncPeriod string

flag.StringVar(&metricsAddr, "metrics-addr", ":8080", "The address the metric endpoint binds to.")
flag.BoolVar(&enableLeaderElection, "enable-leader-election", false,
Expand All @@ -99,6 +100,7 @@ func main() {
flag.StringVar(&loggingRef, "watch-logging-name", "", "Logging resource name to optionally filter the list of watched objects based on which logging they belong to by checking the app.kubernetes.io/managed-by label")
flag.BoolVar(&finalizerCleanup, "finalizer-cleanup", false, "Remove finalizers from Logging resources during operator shutdown, useful for Helm uninstallation")
flag.BoolVar(&enableTelemetryControllerRoute, "enable-telemetry-controller-route", false, "Enable the Telemetry Controller route for Logging resources")
flag.StringVar(&syncPeriod, "sync-period", "", "SyncPeriod determines the minimum frequency at which watched resources are reconciled. Defaults to 10 hours. Parsed using time.ParseDuration.")
flag.Parse()

ctx := context.Background()
Expand Down Expand Up @@ -150,7 +152,7 @@ func main() {
mgrOptions.WebhookServer = webhookServer
}

customMgrOptions, err := setupCustomCache(&mgrOptions, namespace, loggingRef)
customMgrOptions, err := setupCustomCache(&mgrOptions, syncPeriod, namespace, loggingRef)
if err != nil {
setupLog.Error(err, "unable to set up custom cache settings")
os.Exit(1)
Expand Down Expand Up @@ -310,7 +312,15 @@ func detectContainerRuntime(ctx context.Context, c client.Reader) error {
return nil
}

func setupCustomCache(mgrOptions *ctrl.Options, namespace string, loggingRef string) (*ctrl.Options, error) {
func setupCustomCache(mgrOptions *ctrl.Options, syncPeriod string, namespace string, loggingRef string) (*ctrl.Options, error) {
if syncPeriod != "" {
duration, err := time.ParseDuration(syncPeriod)
if err != nil {
return mgrOptions, err
}
mgrOptions.Cache.SyncPeriod = &duration
}

if namespace == "" && loggingRef == "" {
return mgrOptions, nil
}
Expand Down

0 comments on commit 6da8cda

Please sign in to comment.