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

operator

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2026 License: MIT Imports: 24 Imported by: 0

Documentation

Overview

Package operator implements the Kubernetes controller for Berth lease resources.

BerthLeaseReconciler watches for BerthLease custom resources and reconciles their state. It is built on controller-runtime and registers itself with a ctrl.Manager via BerthLeaseReconciler.SetupWithManager.

The reconciler is responsible for observing lease state transitions and, in future phases, applying workload actions (suspend/resume) to target resources referenced by the lease.

Index

Constants

View Source
const (
	StateHeld     = "held"
	StateWaiting  = "waiting"
	StateReleased = "released"
)

LeaseState values written to BerthLease.status.leaseState.

View Source
const (
	ConditionAcquired         = "Acquired"
	ConditionHeartbeatHealthy = "HeartbeatHealthy"
)

Condition types written to BerthLease.status.conditions.

View Source
const (
	ManagedLease   = "berth.skaphos.io/managed-lease"
	ManagedUID     = "berth.skaphos.io/managed-lease-uid"
	SchedulingGate = "berth.skaphos.io/lease-held"
	PhaseActive    = "Active"
	PhaseStopping  = "Stopping"
)
View Source
const FinalizerName = "berth.skaphos.io/lease-release"

FinalizerName is the finalizer applied to BerthLease objects so the reconciler can stop managed Pods and release ownership before garbage collection.

Variables

This section is empty.

Functions

func SetupWorkloadAdmission added in v0.4.1

func SetupWorkloadAdmission(mgr ctrl.Manager, c ctrlclient.Client, operatorUser string) error

Types

type BerthLeaseReconciler

type BerthLeaseReconciler struct {
	ctrlclient.Client

	// Log is the reconciler's logger.
	Log logr.Logger

	// LeaseClient is the central API server client. Required.
	LeaseClient LeaseClient

	// ClusterIdentity, when non-empty, is used as the holder identity for
	// every Acquire / Release call, overriding spec.HolderIdentity on the
	// BerthLease. Set this to a cluster-distinct value (typically via the
	// operator's --cluster-id flag) to enable the cross-cluster singleton
	// pattern: the same BerthLease applied to multiple clusters competes
	// for the lease rather than co-renewing under a shared identity.
	//
	// When empty, the reconciler falls back to spec.HolderIdentity. That
	// path supports the original use case where an external client manages
	// its own holder identity directly against the Berth API server.
	ClusterIdentity string

	// ManagedWorkloads requires the separate fail-closed admission installation.
	ManagedWorkloads  bool
	OperatorNamespace string
}

BerthLeaseReconciler reconciles BerthLease resources by holding (or renewing) a lease against the central API server and applying the configured workload actions in response to lease state.

func (*BerthLeaseReconciler) Reconcile

func (r *BerthLeaseReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error)

Reconcile bounds both central calls and local cleanup operations. The client supplied by main bypasses the informer cache for security-sensitive reads.

func (*BerthLeaseReconciler) SetupWithManager

func (r *BerthLeaseReconciler) SetupWithManager(mgr ctrl.Manager) error

SetupWithManager registers the reconciler with the controller-runtime manager.

type LeaseClient

type LeaseClient interface {
	Acquire(ctx context.Context, namespace, name, holder string, ttl time.Duration) (client.AcquireResult, error)
	Renew(ctx context.Context, namespace, name, holder string, fencingToken int32, ttl time.Duration) (client.AcquireResult, error)
	Release(ctx context.Context, namespace, name, holder string, fencingToken int32) error
}

LeaseClient is the subset of [client.Client] consumed by the reconciler. Defined as an interface so tests can inject a fake.

type WorkloadAdmission added in v0.4.1

type WorkloadAdmission struct {
	Client       ctrlclient.Client
	OperatorUser string
	Mutate       bool
}

WorkloadAdmission is independent of opt-in helper injection. Its registrations must use failurePolicy=Fail without caller-controlled selectors.

func (*WorkloadAdmission) Handle added in v0.4.1

Jump to

Keyboard shortcuts

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