controllerutils

package
v0.0.0-...-2776c19 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2026 License: Apache-2.0 Imports: 11 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

func NeedsUpdate

func NeedsUpdate(existing, desired any) bool

NeedsUpdate reports whether `desired` differs from `existing` in any way that should cause us to write `desired` back to Cosmos. It is a strict-but-server-managed-fields-aware semantic equality check: all the fields that actually persist must match, but cosmos-managed values like the document etag are ignored, as are Go-level representation differences (RawExtension Raw vs Object, parent pointer chains in ResourceID, etc.).

func ResourceIDsEqual

func ResourceIDsEqual(a, b *azcorearm.ResourceID) bool

ResourceIDsEqual compares two *azcorearm.ResourceID for equality by their canonical string form. Both may be nil; non-nil values are compared by String(), so independently-parsed instances with different parent pointer chains still compare equal when they represent the same ARM ID.

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