Documentation
¶
Overview ¶
Package controller contains controller utilities.
Index ¶
- Variables
- func AddAnnotations(o client.Object, annotations map[string]string)
- func CtrlResultForErr(err error) (ctrl.Result, error)
- func IsDelete(o client.Object) bool
- func IsUpsert(o client.Object) bool
- type BaseController
- func (self *BaseController[T]) NewEnqueueRequestForMapFunc(f func(ctx context.Context, obj client.Object) []reconcile.Request) handler.EventHandler
- func (self *BaseController[T]) Reconcile(ctx context.Context, req ctrl.Request, obj T) (ctrl.Result, error)
- func (self *BaseController[T]) ReconcileStatus(ctx context.Context, obj T, origErr error) error
- type BaseControllerOp
- type DrainState
- type StatusError
Constants ¶
This section is empty.
Variables ¶
var IsDraining = drain.IsDraining
Functions ¶
func AddAnnotations ¶
AddAnnotations adds the given annotations to the object.
func CtrlResultForErr ¶
CtrlResultForErr is a helper function to convert an error into a ctrl.Result passing through ngrok error mappings
Types ¶
type BaseController ¶
type BaseController[T client.Object] struct { // Kube is the base client for interacting with the Kubernetes API Kube client.Client // Log is the logger for the controller Log logr.Logger // Recorder is the event recorder for the controller Recorder events.EventRecorder // Namespace is optional for controllers Namespace *string // DrainState is used to check if the operator is draining. // If draining, non-delete reconciles are skipped to prevent new finalizers. DrainState DrainState StatusID func(obj T) string Create func(ctx context.Context, obj T) error Update func(ctx context.Context, obj T) error Delete func(ctx context.Context, obj T) error ErrResult func(op BaseControllerOp, obj T, err error) (ctrl.Result, error) }
BaseController is our standard pattern for writing controllers
Note: Non-provided methods are not called during reconcile
func (*BaseController[T]) NewEnqueueRequestForMapFunc ¶
func (self *BaseController[T]) NewEnqueueRequestForMapFunc(f func(ctx context.Context, obj client.Object) []reconcile.Request) handler.EventHandler
NewEnqueueRequestForMapFunc wraps a map function to be used as an event handler. It also takes care to make sure that the controllers logger is passed through to the map function, so that we can use our common pattern of getting the logger from the context.
func (*BaseController[T]) Reconcile ¶
func (self *BaseController[T]) Reconcile(ctx context.Context, req ctrl.Request, obj T) (ctrl.Result, error)
reconcile is the primary function that a manager calls for this controller to reconcile an event for the give client.Object
func (*BaseController[T]) ReconcileStatus ¶
func (self *BaseController[T]) ReconcileStatus(ctx context.Context, obj T, origErr error) error
ReconcileStatus reconciles the status of an object, retrying on conflict.
Status update conflicts are common because the object's resourceVersion can change between the initial Get() and this call (e.g., from the finalizer Patch earlier in the reconcile, or from an external spec mutation). On conflict, this method re-fetches the latest resourceVersion and retries.
This is safe for controllers where BaseController is the sole status writer for the resource (AgentEndpoint, CloudEndpoint, Domain, IPPolicy, etc.). For resources with multiple concurrent status writers (BoundEndpoint, Gateway), the callers manage their own retry/conflict logic and should not use this method.
type BaseControllerOp ¶
type BaseControllerOp int
BaseControllerOp is an enum for the different operations that can be performed by a BaseController
const ( // createOp is the operation for creating a resource CreateOp BaseControllerOp = iota // updateOp is the operation for updating a resource (upsert) UpdateOp // deleteOp is the operation for deleting a resource (and finalizers) DeleteOp )
type DrainState ¶
Re-export drain types for convenience so consumers can use controller.DrainState
type StatusError ¶
type StatusError struct {
// contains filtered or unexported fields
}
StatusError wraps .Status().*() errors returned from k8s client. err is the original reconcile error (may be nil if reconcile succeeded but status update failed). cause is the status update error.
func (StatusError) Error ¶
func (e StatusError) Error() string
func (StatusError) Unwrap ¶
func (e StatusError) Unwrap() error