controllerutils

package
v0.0.0-...-c81c1b6 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2026 License: Apache-2.0 Imports: 33 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 DegradedControllerPanicHandler

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

func DeleteRecursively

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

func GetOrCreateController

func GetOrCreateController(
	ctx context.Context, resourcesDBClient corecosmosstorage.ResourcesDBClient, parentResourceID *azcorearm.ResourceID,
	controllerName string, initialControllerFn InitialControllerFunc,
) (*coreapi.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 corecosmosstorage.GetOrCreateServiceProviderCluster).

func HostedClusterNamespace

func HostedClusterNamespace(envIdentifier, csClusterID string) string

HostedClusterNamespace returns the management-cluster namespace that hosts a given HCP's HostedCluster / NodePool objects. Cluster Service names it "ocm-<envIdentifier>-<csClusterID>" and we must mirror that exactly so the kube-applier targets the right namespace.

func HostedControlPlaneNamespace

func HostedControlPlaneNamespace(envIdentifier, csClusterID, csClusterDomainPrefix string) string

HostedControlPlaneNamespace returns the management-cluster namespace that hosts a given HCP's control plane workloads (including ControlPlaneComponent CRs). Hypershift names it "ocm-<envIdentifier>-<csClusterID>-<csClusterDomainPrefix>".

func ManagementClusterContentResourceIDFromParentResourceID

func ManagementClusterContentResourceIDFromParentResourceID(parentResourceID *azcorearm.ResourceID, maestroBundleInternalName coreapi.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 billingcosmosstorage.BillingDBClient, resourceID *azcorearm.ResourceID, deletionTime time.Time) error

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

func NewInitialManagementClusterContent

func NewInitialManagementClusterContent(managementClusterContentResourceID *azcorearm.ResourceID) *coreapi.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 cosmosstorageutils.ResourceCRUD[coreapi.Controller, *coreapi.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 corelisters.ActiveOperationLister) *ActiveOperationBasedChecker

func NewActiveOperationPrioritizingCooldown

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

func (*ActiveOperationBasedChecker) CanSync

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

type AfterEnqueuer

type AfterEnqueuer = controllerutil.AfterEnqueuer

Type aliases re-export types from internal/controllerutils so that existing backend callers continue to compile without import changes.

type ClusterSyncer

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

type Controller

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

func NewClusterWatchingController

func NewClusterWatchingController(
	name string,
	resourcesDBClient corecosmosstorage.ResourcesDBClient,
	informers coreinformers.BackendInformers,
	kubeApplierInformers *unionkubeapplierinformers.UnionKubeApplierInformers,
	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.

kubeApplierInformers is optional: when non-nil, the controller also enqueues on ReadDesire events from the union kube-applier informer surface. The status that the kube-applier writes back lives on the ReadDesire, so a ReadDesire update is how this controller learns "the kube-applier reported something new about a cluster". Apply/Delete desires are not wired in because their status doesn't carry cluster-state signal.

func NewExternalAuthWatchingController

func NewExternalAuthWatchingController(
	name string,
	resourcesDBClient corecosmosstorage.ResourcesDBClient,
	informers coreinformers.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 NewGenericOperationController

func NewGenericOperationController(
	name string,
	synchronizer OperationSynchronizer,
	activeOperationScanInterval time.Duration,
	activeOperationInformer cache.SharedIndexInformer,
	resourcesDBClient corecosmosstorage.ResourcesDBClient,
) Controller

NewGenericOperationController returns a Controller that updates Cosmos DB documents tracking ongoing asynchronous operations. Each Controller instance has a unique OperationSynchronizer that reconciles a particular type of asynchronous operation, like cluster creation or node pool deletion.

func NewManagementClusterWatchingController

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

NewManagementClusterWatchingController periodically looks up all management clusters and queues them.

func NewNodePoolWatchingController

func NewNodePoolWatchingController(
	name string,
	resourcesDBClient corecosmosstorage.ResourcesDBClient,
	informers coreinformers.BackendInformers,
	kubeApplierInformers *unionkubeapplierinformers.UnionKubeApplierInformers,
	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.

kubeApplierInformers is optional: when non-nil, the controller also enqueues on ReadDesire events from the union kube-applier informer surface. The status that the kube-applier writes back lives on the ReadDesire, so a ReadDesire update is how this controller learns "the kube-applier reported something new about a node pool". Apply/Delete desires are not wired in because their status doesn't carry node-pool-state signal.

func NewSubscriptionWatchingController

func NewSubscriptionWatchingController(
	name string,
	informers coreinformers.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.

func NewSystemAdminCredentialRequestWatchingController

func NewSystemAdminCredentialRequestWatchingController(
	name string,
	resourcesDBClient corecosmosstorage.ResourcesDBClient,
	backendInformers coreinformers.BackendInformers,
	kubeApplierInformers *unionkubeapplierinformers.UnionKubeApplierInformers,
	resyncDuration time.Duration,
	syncer SystemAdminCredentialRequestSyncer,
) Controller

NewSystemAdminCredentialRequestWatchingController creates a controller that fires on individual SystemAdminCredentialRequest informer events rather than cluster-level events. This ensures controllers react immediately when a credential request is created or updated, instead of relying on periodic cluster resync.

kubeApplierInformers is optional: when non-nil, the controller also enqueues on ReadDesire events from the union kube-applier informer surface (the same pattern as ClusterWatchingController, but walking up to the credential request resource type instead of the cluster type).

func NewSystemAdminCredentialRevocationWatchingController

func NewSystemAdminCredentialRevocationWatchingController(
	name string,
	resourcesDBClient corecosmosstorage.ResourcesDBClient,
	backendInformers coreinformers.BackendInformers,
	kubeApplierInformers *unionkubeapplierinformers.UnionKubeApplierInformers,
	resyncDuration time.Duration,
	syncer SystemAdminCredentialRevocationSyncer,
) Controller

NewSystemAdminCredentialRevocationWatchingController creates a controller that fires on individual SystemAdminCredentialRevocation informer events. Each revocation drives its own lifecycle (marking credential requests for deletion, managing the CRR desires, and final teardown), so keying on the revocation lets a small set of focused controllers react immediately to revocation changes and re-poll on resync.

type ExternalAuthSyncer

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

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

type InitialControllerFunc

type InitialControllerFunc func(controllerName string) *coreapi.Controller

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

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) *coreapi.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
}

type Notifier

type Notifier = controllerutil.Notifier

Type aliases re-export types from internal/controllerutils so that existing backend callers continue to compile without import changes.

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

type OperationSynchronizer

type OperationSynchronizer interface {
	ShouldProcess(ctx context.Context, operation *coreapi.Operation) bool
	SynchronizeOperation(ctx context.Context, key OperationKey) error
}

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
}

type SystemAdminCredentialRequestKey

type SystemAdminCredentialRequestKey struct {
	SubscriptionID    string `json:"subscriptionID"`
	ResourceGroupName string `json:"resourceGroupName"`
	HCPClusterName    string `json:"hcpClusterName"`
	CredentialName    string `json:"credentialName"`
}

SystemAdminCredentialRequestKey is for driving workqueues keyed for credential requests

func (SystemAdminCredentialRequestKey) AddLoggerValues

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

func (SystemAdminCredentialRequestKey) GetClusterResourceID

func (k SystemAdminCredentialRequestKey) GetClusterResourceID() *azcorearm.ResourceID

func (SystemAdminCredentialRequestKey) GetResourceID

func (SystemAdminCredentialRequestKey) InitialController

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

type SystemAdminCredentialRequestSyncer

type SystemAdminCredentialRequestSyncer interface {
	SyncOnce(ctx context.Context, keyObj SystemAdminCredentialRequestKey) error
}

SystemAdminCredentialRequestSyncer is the interface that credential-request-watching controllers must implement. It mirrors ClusterSyncer but is keyed on SystemAdminCredentialRequestKey.

type SystemAdminCredentialRevocationKey

type SystemAdminCredentialRevocationKey struct {
	SubscriptionID    string `json:"subscriptionID"`
	ResourceGroupName string `json:"resourceGroupName"`
	HCPClusterName    string `json:"hcpClusterName"`
	RevocationName    string `json:"revocationName"`
}

SystemAdminCredentialRevocationKey is for driving workqueues keyed for revocations

func (SystemAdminCredentialRevocationKey) AddLoggerValues

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

func (SystemAdminCredentialRevocationKey) GetClusterResourceID

func (k SystemAdminCredentialRevocationKey) GetClusterResourceID() *azcorearm.ResourceID

func (SystemAdminCredentialRevocationKey) GetResourceID

func (SystemAdminCredentialRevocationKey) InitialController

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

type SystemAdminCredentialRevocationSyncer

type SystemAdminCredentialRevocationSyncer interface {
	SyncOnce(ctx context.Context, keyObj SystemAdminCredentialRevocationKey) error
}

SystemAdminCredentialRevocationSyncer is the interface that revocation-watching controllers must implement. It mirrors ClusterSyncer but is keyed on SystemAdminCredentialRevocationKey.

Jump to

Keyboard shortcuts

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