diff --git a/controllers/logging/logging_controller.go b/controllers/logging/logging_controller.go index 091f2e2cb..a1b434eff 100644 --- a/controllers/logging/logging_controller.go +++ b/controllers/logging/logging_controller.go @@ -102,6 +102,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. diff --git a/main.go b/main.go index 1cb09ef14..77d32cc30 100644 --- a/main.go +++ b/main.go @@ -25,6 +25,7 @@ import ( "runtime/coverage" "strings" "syscall" + "time" "emperror.dev/errors" prometheusOperator "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1" @@ -81,6 +82,7 @@ func main() { var namespace string var loggingRef string 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, @@ -91,6 +93,7 @@ func main() { flag.BoolVar(&enableprofile, "pprof", false, "Enable pprof") flag.StringVar(&namespace, "watch-namespace", "", "Namespace to filter the list of watched objects") 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.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() @@ -142,7 +145,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) @@ -285,7 +288,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 }