controller

package
v0.0.0-...-cf67981 Latest Latest
Warning

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

Go to latest
Published: May 13, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package controller contains controller utilities.

Index

Constants

This section is empty.

Variables

View Source
var IsDraining = drain.IsDraining

Functions

func AddAnnotations

func AddAnnotations(o client.Object, annotations map[string]string)

AddAnnotations adds the given annotations to the object.

func CtrlResultForErr

func CtrlResultForErr(err error) (ctrl.Result, error)

CtrlResultForErr is a helper function to convert an error into a ctrl.Result passing through ngrok error mappings

func IsDelete

func IsDelete(o client.Object) bool

IsDelete returns true if the object is being deleted. That is, if the deletion timestamp is set and non-zero.

func IsUpsert

func IsUpsert(o client.Object) bool

IsUpsert returns true if the object is being created or updated. That is, if the deletion timestamp is not set.

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

type DrainState = drain.State

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

Directories

Path Synopsis
MIT License
MIT License
MIT License
MIT License
MIT License
MIT License

Jump to

Keyboard shortcuts

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