base

package
v0.0.0-...-f7606f5 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2026 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultRegisteredCooldown   = 5 * time.Minute
	DefaultUnregisteredCooldown = 10 * time.Second
)
View Source
const DefaultInformerResyncPeriod = 5 * time.Minute
View Source
const DefaultStampCooldownPeriod = 10 * time.Minute

Variables

View Source
var ErrStampNotApproved = errors.New("parent stamp is not approved")
View Source
var (
	ReconcileTotal = promauto.With(legacyregistry.Registerer()).NewCounterVec(
		prometheus.CounterOpts{
			Name: "fleet_controller_reconcile_total",
			Help: "Total number of reconciliations per controller.",
		},
		[]string{"controller"},
	)
)

Functions

func DegradedControllerPanicHandler

func DegradedControllerPanicHandler(ctx context.Context, controllerCRUD cosmosstorageutils.ResourceCRUD[coreapi.Controller, *coreapi.Controller], controllerName string, initialControllerFn InitialControllerFunc) func(any)

DegradedControllerPanicHandler returns a panic handler that writes a Degraded condition to the controller document with the panic stack trace.

func SetRegistrationCondition

func SetRegistrationCondition(conditions *[]metav1.Condition, conditionType string, syncErr error)

SetRegistrationCondition updates a registration condition based on the reconcile result. Once True, the condition never regresses to False — errors after a successful registration are recorded as True/CheckFailed so operators can observe the problem without losing the registration state.

When the condition already carries the target Status and Reason, the update is skipped even if the Message differs. External API errors embed per-request fields (operation IDs, timestamps) that change on every call; writing a new Message each retry would bump the Cosmos etag, trigger an informer update event, and enqueue the key via Add() — bypassing the workqueue rate limiter and creating a hot retry loop. The full error is still logged by the workqueue error handler, so no debugging information is lost.

func WriteController

func WriteController(ctx context.Context, controllerCRUD cosmosstorageutils.ResourceCRUD[coreapi.Controller, *coreapi.Controller], controllerName string, initialControllerFn InitialControllerFunc, mutationFns ...ControllerMutationFunc) error

WriteController reads the existing controller document (creating it if missing), applies mutations in order, and writes back the result. It only tries once — on conflict the control loop will re-run.

Types

type Controller

type Controller interface {
	QueueForInformers(resyncDuration time.Duration, notifiers ...controllerutils.Notifier) error
	Run(ctx context.Context, threadiness int)
	EnqueueAfter(keyObj any, duration time.Duration)
}

Controller is the common interface for all fleet controllers.

func NewManagementClusterWatchingController

func NewManagementClusterWatchingController(
	name string,
	fleetDBClient fleetcosmosstorage.FleetDBClient,
	managementClusterInformer cache.SharedIndexInformer,
	resyncDuration time.Duration,
	syncer ManagementClusterSyncer,
) Controller

NewManagementClusterWatchingController creates a controller that watches management cluster informers and automatically writes a controller document under the management cluster after each sync.

func NewStampWatchingController

func NewStampWatchingController(
	name string,
	syncer StampSyncer,
	cfg StampWatchingControllerConfig,
) Controller

NewStampWatchingController creates a controller and delegates reconciliation to the syncer. Call QueueForInformers to register informers.

type ControllerMutationFunc

type ControllerMutationFunc func(controller *coreapi.Controller)

ControllerMutationFunc mutates a controller document in place. It should only perform short calls, not long lookups. It must not fail.

func ReportSyncError

func ReportSyncError(syncErr error) ControllerMutationFunc

ReportSyncError returns a mutation that sets the Degraded condition based on whether a sync error occurred.

type InitialControllerFunc

type InitialControllerFunc func(controllerName string) *coreapi.Controller

InitialControllerFunc builds a new coreapi.Controller for the given logical controller name.

type ManagementClusterKey

type ManagementClusterKey struct {
	StampIdentifier string
}

ManagementClusterKey identifies a management cluster in the workqueue.

func (ManagementClusterKey) AddLoggerValues

func (k ManagementClusterKey) AddLoggerValues(logger logr.Logger) logr.Logger

func (ManagementClusterKey) GetResourceID

func (k ManagementClusterKey) GetResourceID() *azcorearm.ResourceID

func (ManagementClusterKey) InitialController

func (k ManagementClusterKey) InitialController(controllerName string) *coreapi.Controller

type ManagementClusterSyncer

type ManagementClusterSyncer interface {
	SyncOnce(ctx context.Context, key ManagementClusterKey) error
	CooldownChecker() controllerutils.CooldownChecker
}

ManagementClusterSyncer is the interface that concrete management cluster controllers implement.

type RegistrationAwareCooldown

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

RegistrationAwareCooldown uses a shorter cooldown for management clusters that are not yet Ready, mirroring the backend's ActiveOperationBasedChecker pattern for clusters with active operations.

func DefaultRegistrationAwareCooldown

func DefaultRegistrationAwareCooldown(
	managementClusterLister fleetlisters.ManagementClusterLister,
) *RegistrationAwareCooldown

func NewRegistrationAwareCooldown

func NewRegistrationAwareCooldown(
	managementClusterLister fleetlisters.ManagementClusterLister,
	registeredCooldown, unregisteredCooldown time.Duration,
) *RegistrationAwareCooldown

func (*RegistrationAwareCooldown) CanSync

func (c *RegistrationAwareCooldown) CanSync(ctx context.Context, key any) bool

func (*RegistrationAwareCooldown) SetClock

type StampKey

type StampKey struct {
	StampIdentifier string
}

StampKey identifies a Stamp in the workqueue.

func (StampKey) AddLoggerValues

func (k StampKey) AddLoggerValues(logger logr.Logger) logr.Logger

func (StampKey) GetResourceID

func (k StampKey) GetResourceID() *azcorearm.ResourceID

func (StampKey) String

func (k StampKey) String() string

type StampSyncer

type StampSyncer interface {
	SyncOnce(ctx context.Context, key StampKey) error
}

StampSyncer is the interface that concrete stamp controllers implement.

type StampWatchingControllerConfig

type StampWatchingControllerConfig struct {
	// Cooldown overrides the default time-based cooldown checker.
	// When set, CooldownPeriod and Clock are ignored.
	Cooldown controllerutils.CooldownChecker

	CooldownPeriod time.Duration
	Clock          utilsclock.PassiveClock
}

StampWatchingControllerConfig tunes the controller's cooldown behavior.

Jump to

Keyboard shortcuts

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