tenancy

package
v0.6.4 Latest Latest
Warning

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

Go to latest
Published: May 15, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

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

View Source
const (
	EventTypeCreated = "created"
	EventTypeDeleted = "deleted"
)

EventType constants for Event.EventType.

View Source
const (
	ResourceTypeOrg     = "org"
	ResourceTypeProject = "project"
)

ResourceType constants for Event.ResourceType.

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

func (Event) String

func (e Event) String() string

String returns a summary of the event for logging.

type Handler

type Handler interface {
	// HandleEvent is called for each event (both replay and incremental).
	// Must be idempotent -- replay on restart will re-deliver events for
	// all existing and soft-deleted resources.
	HandleEvent(ctx context.Context, event Event) error
}

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.

func (*Poller) Run

func (p *Poller) Run(ctx context.Context) error

Run executes replay (Phase 1), then enters steady-state polling (Phase 2). Blocks until ctx is cancelled. On restart, replays from scratch. Handlers must be idempotent.

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.

Jump to

Keyboard shortcuts

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