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
- Variables
- type K8sNamespaceReconciler
- func (r *K8sNamespaceReconciler) CleanupDeleted(ctx context.Context, intent apikit.TeamNamespaceIntent) error
- func (r *K8sNamespaceReconciler) CleanupDeletedTeamTraefikWatch(ctx context.Context, namespace, teamID string) error
- func (r *K8sNamespaceReconciler) ReconcileActive(ctx context.Context, intent apikit.TeamNamespaceIntent) (string, error)
- type NamespaceReconciler
- type PlatformClient
- type ReconcileJobArgs
- type RetryPolicy
- type Runner
- type RunnerConfig
- type Worker
Constants ¶
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 ¶
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.
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.
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.