controllerutils

package
v0.0.0-...-abfdb6c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 14, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package controllerutils holds controller helpers shared across services (backend, kube-applier, ...) that all build Cosmos-backed informer-driven controllers and want consistent cadence/gating behavior.

The cooldown gate exposed here was originally backend/pkg/controllers/controllerutils' TimeBasedCooldownChecker; it lives in internal/ so kube-applier can use the same implementation without re-importing the backend module.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CooldownChecker

type CooldownChecker interface {
	CanSync(ctx context.Context, key any) bool
}

CooldownChecker decides whether a key may be (re-)queued.

Implementations must be safe to call concurrently — informer event handlers, periodic resyncs, and worker goroutines may all consult the same checker.

CanSync takes a context so implementations may emit logs or use context-bound services; the time-based variant ignores it. A true return is taken as "the caller WILL sync this key" and the implementation is free to record state (e.g. stamp a next-allowed time) on that basis.

type TimeBasedCooldownChecker

type TimeBasedCooldownChecker struct {
	// contains filtered or unexported fields
}

TimeBasedCooldownChecker is a fixed-interval cooldown gate: after CanSync returns true for a key, subsequent calls for the same key return false until cooldownDuration has elapsed since the allowed call.

The next-exec map is an LRU rather than an unbounded map so that a long-running process whose keys come and go does not leak memory. 1M entries is far above any realistic management cluster's resource count.

func NewTimeBasedCooldownChecker

func NewTimeBasedCooldownChecker(cooldownDuration time.Duration) *TimeBasedCooldownChecker

NewTimeBasedCooldownChecker constructs a checker bound to the real wall-clock and a 1M-entry LRU. Tests should call SetClock to inject a fake clock.

func (*TimeBasedCooldownChecker) CanSync

func (c *TimeBasedCooldownChecker) CanSync(_ context.Context, key any) bool

CanSync stamps now+cooldownDuration on a true return so subsequent calls within the cooldown window return false. A key with no record is always allowed. ctx is part of the CooldownChecker interface but unused here.

func (*TimeBasedCooldownChecker) SetClock

SetClock substitutes the time source used to evaluate the cooldown. Intended for tests; production code should use the real clock from the constructor.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL