controllerutils

package
v0.0.0-...-204f69e 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: 32 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ReconcileTotal counts the total number of reconciliations per controller.
	ReconcileTotal = promauto.With(legacyregistry.Registerer()).NewCounterVec(
		prometheus.CounterOpts{
			Name: "backend_controller_reconcile_total",
			Help: "Total number of reconciliations per controller.",
		},
		[]string{"controller"},
	)
)

Functions

func AddLoggerValues

func AddLoggerValues(logger logr.Logger, key any) logr.Logger

func DegradedControllerPanicHandler

func DegradedControllerPanicHandler(ctx context.Context, controllerCRUD database.ResourceCRUD[api.Controller], controllerName string, initialControllerFn InitialControllerFunc) func(interface{})

func DeleteRecursively

func DeleteRecursively(ctx context.Context, resourcesDBClient database.ResourcesDBClient, rootResourceID *azcorearm.ResourceID) error

func GetOrCreateController

func GetOrCreateController(
	ctx context.Context, resourcesDBClient database.ResourcesDBClient, parentResourceID *azcorearm.ResourceID,
	controllerName string, initialControllerFn InitialControllerFunc,
) (*api.Controller, error)

GetOrCreateController gets the named Controller document under the given parent resource (cluster, node pool, or external auth). If it does not exist, it creates one using initialControllerFn. On create conflict (HTTP 409), it re-reads and returns the existing document (same pattern as database.GetOrCreateServiceProviderCluster).

func ManagementClusterContentResourceIDFromParentResourceID

func ManagementClusterContentResourceIDFromParentResourceID(parentResourceID *azcorearm.ResourceID, maestroBundleInternalName api.MaestroBundleInternalName) *azcorearm.ResourceID

ManagementClusterContentResourceIDFromParentResourceID returns the resource ID for the ManagementClusterContent nested under parentResourceID with the given maestro bundle internal name.

func MarkBillingDocumentDeleted

func MarkBillingDocumentDeleted(ctx context.Context, billingDBClient database.BillingDBClient, resourceID *azcorearm.ResourceID, deletionTime time.Time) error

MarkBillingDocumentDeleted patches a Cosmos DB document in the Billing container to add a deletion timestamp.

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 NewInitialManagementClusterContent

func NewInitialManagementClusterContent(managementClusterContentResourceID *azcorearm.ResourceID) *api.ManagementClusterContent

NewInitialManagementClusterContent returns a new ManagementClusterContent with the given full managementClusterContents ARM resource ID. The returned value can be used to consistently initialize a new ManagementClusterContent

func ReportSyncError

func ReportSyncError(syncErr error) controllerMutationFunc

func WriteController

func WriteController(ctx context.Context, controllerCRUD database.ResourceCRUD[api.Controller], controllerName string, initialControllerFn InitialControllerFunc, mutationFns ...controllerMutationFunc) error

WriteController will read the existing value, call the mutations in order, then write the result. It only tries *once*. If it fails, then the an error is returned. This detail is important, it doesn't even retry conflicts. This is so that if a failure happens the control-loop will re-run and restablish the information it was trying to write as valid. This prevents accidental recreation of controller instances in cosmos during a delete.

Types

type ActiveOperationBasedChecker

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

func DefaultActiveOperationPrioritizingCooldown

func DefaultActiveOperationPrioritizingCooldown(activeOperationLister listers.ActiveOperationLister) *ActiveOperationBasedChecker

func NewActiveOperationPrioritizingCooldown

func NewActiveOperationPrioritizingCooldown(activeOperationLister listers.ActiveOperationLister, activeOperationCooldown, inactiveOperationCooldown time.Duration) *ActiveOperationBasedChecker

func (*ActiveOperationBasedChecker) CanSync

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

type ClusterSyncer

type ClusterSyncer interface {
	SyncOnce(ctx context.Context, keyObj HCPClusterKey) error
	CooldownChecker() controllerutil.CooldownChecker
}

type Controller

type Controller interface {
	SyncOnce(ctx context.Context, keyObj any) error
	Run(ctx context.Context, threadiness int)
}

func NewClusterWatchingController

func NewClusterWatchingController(
	name string,
	resourcesDBClient database.ResourcesDBClient,
	informers informers.BackendInformers,
	resyncDuration time.Duration,
	syncer ClusterSyncer,
) Controller

NewClusterWatchingController periodically looks up all clusters and queues them cooldownDuration is how long to wait before allowing a new notification to fire the controller. Since our detection of change is coarse, we are being triggered every few second without new information. Until we get a changefeed, the cooldownDuration value is effectively the min resync time. This does NOT prevent us from re-executing on errors, so errors will continue to trigger fast checks as expected.

func NewExternalAuthWatchingController

func NewExternalAuthWatchingController(
	name string,
	resourcesDBClient database.ResourcesDBClient,
	informers informers.BackendInformers,
	resyncDuration time.Duration,
	syncer ExternalAuthSyncer,
) Controller

NewExternalAuthWatchingController periodically looks up all ExternalAuths and queues them cooldownDuration is how long to wait before allowing a new notification to fire the controller. Since our detection of change is coarse, we are being triggered every few second without new information. Until we get a changefeed, the cooldownDuration value is effectively the min resync time. This does NOT prevent us from re-executing on errors, so errors will continue to trigger fast checks as expected.

func NewManagementClusterWatchingController

func NewManagementClusterWatchingController(
	name string,
	fleetDBClient database.FleetDBClient,
	fleetInformers dbinformers.FleetInformers,
	resyncDuration time.Duration,
	syncer ManagementClusterSyncer,
) Controller

NewManagementClusterWatchingController periodically looks up all management clusters and queues them.

func NewNodePoolWatchingController

func NewNodePoolWatchingController(
	name string,
	resourcesDBClient database.ResourcesDBClient,
	informers informers.BackendInformers,
	resyncDuration time.Duration,
	syncer NodePoolSyncer,
) Controller

NewNodePoolWatchingController periodically looks up all NodePools and queues them cooldownDuration is how long to wait before allowing a new notification to fire the controller. Since our detection of change is coarse, we are being triggered every few second without new information. Until we get a changefeed, the cooldownDuration value is effectively the min resync time. This does NOT prevent us from re-executing on errors, so errors will continue to trigger fast checks as expected.

func NewSubscriptionWatchingController

func NewSubscriptionWatchingController(
	name string,
	informers informers.BackendInformers,
	resyncDuration time.Duration,
	syncer SubscriptionSyncer,
) Controller

NewSubscriptionWatchingController periodically looks up all subscriptions and queues them. cooldownDuration is how long to wait before allowing a new notification to fire the controller. Since our detection of change is coarse, we are being triggered every few second without new information. Until we get a changefeed, the cooldownDuration value is effectively the min resync time. This does NOT prevent us from re-executing on errors, so errors will continue to trigger fast checks as expected.

type ExternalAuthSyncer

type ExternalAuthSyncer interface {
	SyncOnce(ctx context.Context, keyObj HCPExternalAuthKey) error
	CooldownChecker() controllerutil.CooldownChecker
}

type GenericSyncer

type GenericSyncer[T comparable] interface {
	SyncOnce(ctx context.Context, keyObj T) error
	CooldownChecker() controllerutil.CooldownChecker
	MakeKey(resourceID *azcorearm.ResourceID) T
}

type HCPClusterKey

type HCPClusterKey struct {
	SubscriptionID    string `json:"subscriptionID"`
	ResourceGroupName string `json:"resourceGroupName"`
	HCPClusterName    string `json:"hcpClusterName"`
}

HCPClusterKey is for driving workqueues keyed for clusters

func (HCPClusterKey) AddLoggerValues

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

func (HCPClusterKey) GetResourceID

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

func (HCPClusterKey) InitialController

func (k HCPClusterKey) InitialController(controllerName string) *api.Controller

type HCPExternalAuthKey

type HCPExternalAuthKey struct {
	SubscriptionID      string `json:"subscriptionID"`
	ResourceGroupName   string `json:"resourceGroupName"`
	HCPClusterName      string `json:"hcpClusterName"`
	HCPExternalAuthName string `json:"hcpExternalAuthName"`
}

func (*HCPExternalAuthKey) AddLoggerValues

func (k *HCPExternalAuthKey) AddLoggerValues(logger logr.Logger) logr.Logger

func (*HCPExternalAuthKey) GetResourceID

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

func (*HCPExternalAuthKey) InitialController

func (k *HCPExternalAuthKey) InitialController(controllerName string) *api.Controller

type HCPNodePoolKey

type HCPNodePoolKey struct {
	SubscriptionID    string `json:"subscriptionID"`
	ResourceGroupName string `json:"resourceGroupName"`
	HCPClusterName    string `json:"hcpClusterName"`
	HCPNodePoolName   string `json:"hcpNodePoolName"`
}

HCPNodePoolKey is for driving workqueus keyed for nodepools

func (HCPNodePoolKey) AddLoggerValues

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

func (HCPNodePoolKey) GetResourceID

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

func (HCPNodePoolKey) InitialController

func (k HCPNodePoolKey) InitialController(controllerName string) *api.Controller

type InitialControllerFunc

type InitialControllerFunc func(controllerName string) *api.Controller

InitialControllerFunc builds a new api.Controller for the given logical controller name (for example HCPClusterKey.InitialController).

type LoggableKey

type LoggableKey interface {
	AddLoggerValues(logger logr.Logger) logr.Logger
}

type ManagementClusterKey

type ManagementClusterKey struct {
	StampIdentifier string `json:"stampIdentifier"`
}

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) *api.Controller

type ManagementClusterSyncer

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

type NodePoolSyncer

type NodePoolSyncer interface {
	SyncOnce(ctx context.Context, keyObj HCPNodePoolKey) error
	CooldownChecker() controllerutil.CooldownChecker
}

type Notifier

type Notifier interface {
	AddEventHandlerWithOptions(handler cache.ResourceEventHandler, options cache.HandlerOptions) (cache.ResourceEventHandlerRegistration, error)
}

type OperationKey

type OperationKey struct {
	SubscriptionID   string `json:"subscriptionID"`
	OperationName    string `json:"operationName"`
	ParentResourceID string `json:"parentResourceID"`
}

OperationKey is for driving workqueues keyed for operations

func (OperationKey) AddLoggerValues

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

func (OperationKey) GetParentResourceID

func (k OperationKey) GetParentResourceID() *azcorearm.ResourceID

func (OperationKey) InitialController

func (k OperationKey) InitialController(controllerName string) *api.Controller

type SubscriptionKey

type SubscriptionKey struct {
	SubscriptionID string `json:"subscriptionID"`
}

SubscriptionKey is for driving workqueues keyed for subscriptions

func (SubscriptionKey) AddLoggerValues

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

func (SubscriptionKey) GetResourceID

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

type SubscriptionSyncer

type SubscriptionSyncer interface {
	SyncOnce(ctx context.Context, keyObj SubscriptionKey) error
	CooldownChecker() controllerutil.CooldownChecker
}

Jump to

Keyboard shortcuts

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