Documentation
¶
Overview ¶
Package tenancy provides a shared client library for tenant controllers to consume tenancy events from the Tenant Manager REST API.
This package has no database or Ent dependencies -- it is a pure HTTP client. Controllers only need the Tenant Manager URL and their canonical controller name.
Index ¶
Constants ¶
const ( EventTypeCreated = "created" EventTypeDeleted = "deleted" )
EventType constants for Event.EventType.
const ( ResourceTypeOrg = "org" ResourceTypeProject = "project" )
ResourceType constants for Event.ResourceType.
const ( StatusInProgress = "in_progress" StatusCompleted = "completed" StatusError = "error" )
Status constants used in controller status reporting.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Event ¶
type Event struct {
// ID is the monotonically increasing event sequence number.
ID int64 `json:"id"`
// EventType is "created" or "deleted".
EventType string `json:"eventType"`
// ResourceType is "org" or "project".
ResourceType string `json:"resourceType"`
ResourceID uuid.UUID `json:"resourceId"`
ResourceName string `json:"resourceName"`
// OrgID is set for project events; nil for org events.
OrgID *uuid.UUID `json:"orgId"`
OrgName *string `json:"orgName"`
// FolderID is reserved for future hierarchical resource types.
FolderID *uuid.UUID `json:"folderId"`
CreatedAt time.Time `json:"createdAt"`
}
Event represents a tenancy lifecycle event. Both replay (synthesized from DB state) and incremental (from tenancy_events) events use the same structure. Handlers must be idempotent — replay on restart will re-deliver events for all existing and soft-deleted resources.
type Poller ¶
type Poller struct {
// contains filtered or unexported fields
}
Poller manages the full Watch lifecycle: replay on startup, then steady-state polling. It calls the Handler for each event and manages controller status updates automatically.
func NewPoller ¶
func NewPoller(tenantManagerURL, controllerName string, handler Handler, opts ...func(*PollerConfig)) (*Poller, error)
NewPoller creates a Poller. controllerName must be the canonical ID from the registered-controller config (e.g., "app-orch-tenant-controller"). The internal /v1/events and /v1/status endpoints require no auth token — they are ClusterIP-only and the Tenant Manager enforces in-cluster network policy rather than JWT validation on these routes.
Returns an error if tenantManagerURL or controllerName is empty, or if the resulting config is invalid.
type PollerConfig ¶
type PollerConfig struct {
// PollInterval is the steady-state polling interval (default 5s).
PollInterval time.Duration
// PollLimit is the max number of events per poll request (default 100).
PollLimit int
// InitialBackoff is the starting backoff when the Tenant Manager is
// unreachable (default 1s).
InitialBackoff time.Duration
// MaxBackoff caps the exponential backoff (default 30s).
MaxBackoff time.Duration
// Timeout for individual HTTP requests (default 30s).
HTTPTimeout time.Duration
// OnError is an optional callback invoked when a non-fatal error occurs
// (poll failure, event processing error, status update failure).
OnError func(err error, msg string)
}
PollerConfig controls Poller behavior.
func DefaultPollerConfig ¶
func DefaultPollerConfig() PollerConfig
DefaultPollerConfig returns sensible defaults.