Skip to content

Commit

Permalink
Merge pull request #1880 from kube-logging/sync-period-flag
Browse files Browse the repository at this point in the history
feat: add sync-period to control resync if needed
  • Loading branch information
pepov authored Dec 16, 2024
2 parents 14b7276 + b2c9852 commit 72257f5
Show file tree
Hide file tree
Showing 2 changed files with 15 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 @@ -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.
Expand Down
15 changes: 13 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"runtime/coverage"
"strings"
"syscall"
"time"

"emperror.dev/errors"
prometheusOperator "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
Expand Down Expand Up @@ -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,
Expand All @@ -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()
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 72257f5

Please sign in to comment.