teamintentworker

package
v0.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2026 License: Apache-2.0 Imports: 0 Imported by: 0

Documentation

Overview

Package teamintentworker runs the durable River worker that reconciles Platform API team namespace intents against Kubernetes with fencing and incarnation ownership checks.

Index

Constants

View Source
const (
	// QueueName is the River queue for team namespace reconciliation jobs.
	QueueName = "team_namespace"
	// QueueSchema is the PostgreSQL schema owned by the team intent River queue.
	QueueSchema = "team_intent_queue"
	// JobKind matches services/platform-api/internal/teamintent/writer.go.
	JobKind = "reconcile_team_namespace"
)

Variables

View Source
var ErrInvalidConfig = errors.New("invalid team intent configuration")

ErrInvalidConfig indicates an unrecoverable team intent or reconciler configuration error (such as an empty or reserved platform namespace).

Functions

This section is empty.

Types

type K8sNamespaceReconciler

type K8sNamespaceReconciler struct {
	Client                   kubernetes.Interface
	EnsureRegistryPullSecret func(context.Context, kubernetes.Interface, string) error
	Traefik                  k8sprovision.TraefikWatchConfig
	IngressFromNamespaces    []string
}

K8sNamespaceReconciler provisions and cleans up Kubernetes team namespace prerequisites for durable team intents using ownership-checked operations.

func (*K8sNamespaceReconciler) CleanupDeleted

func (r *K8sNamespaceReconciler) CleanupDeleted(ctx context.Context, intent apikit.TeamNamespaceIntent) error

CleanupDeleted implements NamespaceReconciler by removing the Traefik watch for a deleted team incarnation while retaining its namespace.

func (*K8sNamespaceReconciler) CleanupDeletedTeamTraefikWatch

func (r *K8sNamespaceReconciler) CleanupDeletedTeamTraefikWatch(ctx context.Context, namespace, teamID string) error

CleanupDeletedTeamTraefikWatch inspects the target namespace's ownership label before touching Traefik. If the namespace is owned by a different team incarnation or is unmanaged, it returns ErrNamespaceOwnershipConflict without removing the Traefik watch. The namespace itself is always retained.

func (*K8sNamespaceReconciler) ReconcileActive

func (r *K8sNamespaceReconciler) ReconcileActive(ctx context.Context, intent apikit.TeamNamespaceIntent) (string, error)

ReconcileActive ensures the owned team namespace, its security/quota/RBAC prerequisites, registry pull secret, and Traefik watch entry exist.

type NamespaceReconciler

type NamespaceReconciler interface {
	ReconcileActive(ctx context.Context, intent apikit.TeamNamespaceIntent) (namespaceUID string, err error)
	CleanupDeleted(ctx context.Context, intent apikit.TeamNamespaceIntent) error
}

NamespaceReconciler performs ownership-checked Kubernetes namespace provisioning and deleted-team Traefik watch cleanup.

type PlatformClient

type PlatformClient interface {
	ClaimTeamIntentFence(ctx context.Context, teamID, workerID string) (apikit.TeamIntentFenceResponse, error)
	GetTeamIntent(ctx context.Context, teamID string) (apikit.TeamNamespaceIntent, bool, error)
	RecordTeamIntentReceipt(ctx context.Context, teamID string, req apikit.TeamIntentReceiptRequest) (apikit.TeamNamespaceReceipt, error)
}

PlatformClient is the subset of Platform API's internal team intent contract required by the worker.

type ReconcileJobArgs

type ReconcileJobArgs struct {
	TeamID      string `json:"teamId"`
	RevisionID  string `json:"revisionId"`
	OperationID string `json:"operationId,omitempty"`
	RequestID   string `json:"requestId,omitempty"`
	Traceparent string `json:"traceparent,omitempty"`
	Tracestate  string `json:"tracestate,omitempty"`
}

ReconcileJobArgs matches the JSON job payload inserted by Platform API's transactional team intent writer.

func (ReconcileJobArgs) Kind

func (ReconcileJobArgs) Kind() string

Kind returns the River job kind for team namespace reconciliation.

type RetryPolicy

type RetryPolicy struct {
	BaseDelay      time.Duration
	MaxDelay       time.Duration
	JitterFraction float64
	Now            func() time.Time
	RandFloat64    func() float64
}

RetryPolicy implements river.ClientRetryPolicy with capped exponential backoff and bounded jitter so transient Kubernetes outages back off cleanly without thundering herds or unbounded delays.

func NewRetryPolicy

func NewRetryPolicy() *RetryPolicy

NewRetryPolicy returns a capped exponential backoff retry policy with jitter.

func (*RetryPolicy) NextRetry

func (p *RetryPolicy) NextRetry(job *rivertype.JobRow) time.Time

NextRetry computes the next retry timestamp for job using capped exponential backoff with downward jitter in [(1-JitterFraction)*delay, delay].

type Runner

type Runner struct {
	// contains filtered or unexported fields
}

Runner owns the PostgreSQL pool and River client for team namespace reconciliation.

func NewRunner

func NewRunner(ctx context.Context, cfg RunnerConfig) (*Runner, error)

NewRunner connects to the River queue database on schema team_intent_queue and registers the fenced team namespace worker on queue team_namespace.

func (*Runner) RetryJob

func (r *Runner) RetryJob(ctx context.Context, jobID int64) (*rivertype.JobRow, error)

RetryJob marks an existing River job immediately eligible for retry.

func (*Runner) Start

func (r *Runner) Start(ctx context.Context) error

Start launches the River worker loop.

func (*Runner) Stop

func (r *Runner) Stop(ctx context.Context) error

Stop gracefully drains in-flight jobs within SoftStopTimeout and closes the PostgreSQL pool.

type RunnerConfig

type RunnerConfig struct {
	DatabaseURL          string
	WorkerID             string
	Platform             PlatformClient
	Reconciler           NamespaceReconciler
	MaxWorkers           int
	JobTimeout           time.Duration
	RescueStuckJobsAfter time.Duration
	FetchPollInterval    time.Duration
	MaxAttempts          int
	SoftStopTimeout      time.Duration
	Logger               *slog.Logger
	TestOnly             bool
}

RunnerConfig configures the pgxpool-backed River worker runner.

type Worker

type Worker struct {
	river.WorkerDefaults[ReconcileJobArgs]

	// BeforeMutate and AfterMutate are optional hooks used by tests to inject
	// concurrent state transitions during reconciliation.
	BeforeMutate func(ctx context.Context, intent apikit.TeamNamespaceIntent) error
	AfterMutate  func(ctx context.Context, intent apikit.TeamNamespaceIntent) error
	// contains filtered or unexported fields
}

Worker processes ReconcileJobArgs from River with per-team fencing, pre/post incarnation checks, and bounded execution receipts.

func NewWorker

func NewWorker(workerID string, platform PlatformClient, reconciler NamespaceReconciler) *Worker

NewWorker constructs a fenced team namespace reconciliation worker.

func (*Worker) Work

func (w *Worker) Work(ctx context.Context, job *river.Job[ReconcileJobArgs]) error

Work executes one durable reconciliation attempt for a team incarnation.

Jump to

Keyboard shortcuts

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