Help us shape the future of Go! Take the 2026 Go Developer Survey

controllerutils

package
v0.0.0-...-c4594f4 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: Apache-2.0 Imports: 36 Imported by: 2

Documentation

Index

Constants

View Source
const (
	// About 5x the observed read p99.9 of 3062ms; slow outliers can retry.
	CSReadTimeout = 15 * time.Second
	// Twice the observed write maximum of 7492ms, rounded up.
	CSWriteTimeout = 15 * time.Second
)

Default CS operation budgets. Callers should use local budgets when their operation's latency or upstream work requires a different bound.

View Source
const ServiceProviderDefaultIngressWildcardServingCertName = "service-provider-default-ingress-wildcard-serving-cert"

ServiceProviderDefaultIngressWildcardServingCertName is the Kubernetes Secret and SecretProviderClass name used for the default ingress wildcard serving certificate referenced by HostedCluster.Spec.OperatorConfiguration.IngressOperator.DefaultCertificate.

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 ClusterServiceIDForCluster

func ClusterServiceIDForCluster(cluster *coreapi.Cluster) string

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 NewControlPlaneVersionRolloutWatchingController

func NewControlPlaneVersionRolloutWatchingController(
	name string,
	fleetInformers fleetinformers.FleetInformers,
	resyncDuration time.Duration,
	syncer ControlPlaneVersionRolloutSyncer,
) *controllerutil.GenericWatchingController[ControlPlaneVersionRolloutKey]

NewControlPlaneVersionRolloutWatchingController watches ControlPlaneVersionRollout documents (and re-enqueues them on the resync interval) and drives the given syncer per rollout channel.

Unlike the cluster/management-cluster watching controllers, this one does not write a per-key Controller status document: ControlPlaneVersionRollout has no nested Controllers sub-resource, and rollout health is reported on the rollout's own Status.Conditions by the Normal assignment syncer.

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 ControlPlaneVersionRolloutKey

type ControlPlaneVersionRolloutKey struct {
	YStreamChannel string `json:"ystreamChannel"`
}

ControlPlaneVersionRolloutKey identifies a ControlPlaneVersionRollout by its y-stream channel (e.g. "stable-4.21"), which is the rollout's top-level resource name. All rollouts share a Cosmos partition keyed by the provider namespace.

func (ControlPlaneVersionRolloutKey) AddLoggerValues

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

func (ControlPlaneVersionRolloutKey) GetResourceID

type ControlPlaneVersionRolloutSyncer

type ControlPlaneVersionRolloutSyncer interface {
	SyncOnce(ctx context.Context, key ControlPlaneVersionRolloutKey) error
}

ControlPlaneVersionRolloutSyncer is the domain syncer driven by the ControlPlaneVersionRollout watching controller.

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 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.

type Enqueuer

type Enqueuer = controllerutil.Enqueuer

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

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.

type WatchingController

type WatchingController interface {
	Controller
	AddInterestingResource(resourceType azcorearm.ResourceType, resourceName string)
	// QueueForChildInformers maps direct child events (including deletion) to
	// this controller's owner key, respecting its resource-interest filter.
	QueueForChildInformers(resyncDuration time.Duration, notifiers ...Notifier) error
	QueueForDescendantInformers(time.Duration, int, ...Notifier) error
}

WatchingController exposes resource-event filtering on the underlying generic watching controller. With no interests registered, all events are accepted.

func NewClusterWatchingController

func NewClusterWatchingController(
	name string,
	resourcesDBClient corecosmosstorage.ResourcesDBClient,
	informers coreinformers.BackendInformers,
	kubeApplierInformers *unionkubeapplierinformers.UnionKubeApplierInformers,
	resyncDuration time.Duration,
	syncer ClusterSyncer,
) WatchingController

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 cluster-scoped ReadDesire and ApplyDesire events from the union kube-applier informer surface. The kube-applier writes per-desire status (including a Degraded condition) back onto these desires, so a desire update is how this controller learns "the kube-applier reported something new about a cluster" — the cluster Degraded aggregator folds cluster-scoped ApplyDesire/ReadDesire Degraded status into the cluster's Degraded condition. Only cluster-scoped desires are watched (node-pool-nested ones are ignored, see below). Delete desires are not wired in because their status does not carry cluster-state signal.

func NewExternalAuthWatchingController

func NewExternalAuthWatchingController(
	name string,
	resourcesDBClient corecosmosstorage.ResourcesDBClient,
	informers coreinformers.BackendInformers,
	resyncDuration time.Duration,
	syncer ExternalAuthSyncer,
) WatchingController

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 fleetcosmosstorage.FleetDBClient,
	fleetInformers fleetinformers.FleetInformers,
	resyncDuration time.Duration,
	syncer ManagementClusterSyncer,
) WatchingController

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,
) WatchingController

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 node-pool-scoped ReadDesire and ApplyDesire events from the union kube-applier informer surface. The kube-applier writes per-desire status (including a Degraded condition) back onto these desires, so a desire update is how this controller learns "the kube-applier reported something new about a node pool" — the node-pool Degraded aggregator folds node-pool-scoped ApplyDesire/ReadDesire Degraded status into the node pool's Degraded condition. Only node-pool-scoped desires are watched (cluster-scoped ones are ignored, see below). Delete desires are not wired in because their status does not carry node-pool-state signal.

func NewSubscriptionWatchingController

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

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,
) WatchingController

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 and ApplyDesire 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,
) WatchingController

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.

Jump to

Keyboard shortcuts

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