workloadintentworker

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 workloadintentworker runs River v0.51.0 workers in runtime-api for durable MCPServer apply/retirement, raw managed Deployment/Service sync, staged image publication, and fixed-token imperative component restarts.

Index

Constants

View Source
const (
	// QueueSchema must match Platform API's workload_intent River schema.
	QueueSchema = "workload_intent_queue"
	// QueueWorkloads handles bounded server, deployment, and restart jobs.
	QueueWorkloads = "workloads"
	// QueueRegistryPublication isolates long-running image archive publications.
	QueueRegistryPublication = "registry_publication"

	KindReconcileServer           = "reconcile_server"
	KindReconcileDeployment       = "reconcile_deployment"
	KindReconcileImagePublication = "reconcile_image_publication"
	KindReconcileComponentRestart = "reconcile_component_restart"
)

Variables

This section is empty.

Functions

func DeterministicHelperName

func DeterministicHelperName(publicationID string, attempt int) string

DeterministicHelperName derives a DNS-1123 compliant helper Pod name tied to publicationID and attempt so worker crash recovery can inspect and resume an existing helper instead of spawning duplicate helpers.

Types

type ApplyResult

type ApplyResult struct {
	UID        string
	Generation int64
}

ApplyResult captures the Kubernetes identity returned after applying a workload.

type Dependencies

type Dependencies struct {
	Server      *ServerWorker
	Deployment  *DeploymentWorker
	Publication *ImagePublicationWorker
	Restart     *RestartWorker
}

Dependencies bundles the four typed workers registered in the River runner.

type DeploymentExecutor

type DeploymentExecutor interface {
	ApplyDeploymentAndService(ctx context.Context, intent apikit.DeploymentIntent) (ApplyResult, error)
	DeleteDeploymentAndServiceByUID(ctx context.Context, namespace, name, targetUID string) error
}

DeploymentExecutor applies or UID-conditionally deletes raw Kubernetes Deployments and Services directly without passing through MCPServer operator.

type DeploymentPlatformClient

type DeploymentPlatformClient interface {
	ClaimDeploymentIntentFence(ctx context.Context, deploymentID, workerID string) (apikit.DeploymentIntentFenceResponse, error)
	RecordDeploymentIntentReceipt(ctx context.Context, deploymentID string, req apikit.DeploymentIntentReceiptRequest) (apikit.WorkloadExecutionReceipt, error)
}

DeploymentPlatformClient defines the Platform API operations for DeploymentWorker.

type DeploymentWorker

type DeploymentWorker struct {
	river.WorkerDefaults[ReconcileDeploymentJobArgs]
	// contains filtered or unexported fields
}

DeploymentWorker reconciles raw managed Deployment/Service intents.

func NewDeploymentWorker

func NewDeploymentWorker(platform DeploymentPlatformClient, exec DeploymentExecutor, workerID string) *DeploymentWorker

NewDeploymentWorker constructs a DeploymentWorker.

func (*DeploymentWorker) Reconcile

func (w *DeploymentWorker) Reconcile(ctx context.Context, deploymentID, jobRevisionID string, attempt int) error

Reconcile claims the fence and applies or UID-conditionally deletes the raw Deployment/Service.

func (*DeploymentWorker) Work

Work executes one River reconcile_deployment job.

type HelperState

type HelperState string

HelperState summarizes the observed phase of a deterministic push helper Pod.

const (
	HelperStateNotFound  HelperState = "NotFound"
	HelperStateRunning   HelperState = "Running"
	HelperStateSucceeded HelperState = "Succeeded"
	HelperStateFailed    HelperState = "Failed"
)

type ImagePublicationPlatformClient

type ImagePublicationPlatformClient interface {
	ClaimImagePublicationFence(ctx context.Context, publicationID, workerID string) (apikit.ImagePublicationFenceResponse, error)
	RecordImagePublicationReceipt(ctx context.Context, publicationID string, req apikit.ImagePublicationReceiptRequest) (apikit.WorkloadExecutionReceipt, error)
}

ImagePublicationPlatformClient defines Platform API calls for ImagePublicationWorker.

type ImagePublicationWorker

type ImagePublicationWorker struct {
	river.WorkerDefaults[ReconcileImagePublicationJobArgs]
	// contains filtered or unexported fields
}

ImagePublicationWorker reconciles finalized staged image archive publications on the dedicated registry_publication queue.

func NewImagePublicationWorker

func NewImagePublicationWorker(platform ImagePublicationPlatformClient, runner PublicationHelperRunner, workerID string) *ImagePublicationWorker

NewImagePublicationWorker constructs an ImagePublicationWorker.

func (*ImagePublicationWorker) Reconcile

func (w *ImagePublicationWorker) Reconcile(ctx context.Context, publicationID, jobRevisionID string, attempt int) error

Reconcile claims the fence, inspects/resumes or creates the deterministic helper Pod, verifies the target manifest digest at the registry, and records the fenced receipt.

func (*ImagePublicationWorker) Work

Work executes one River reconcile_image_publication job.

type KubeDeploymentExecutor

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

KubeDeploymentExecutor manages raw Kubernetes Deployments and Services.

func NewKubeDeploymentExecutor

func NewKubeDeploymentExecutor(clientset kubernetes.Interface) *KubeDeploymentExecutor

NewKubeDeploymentExecutor creates a Kubernetes-backed DeploymentExecutor.

func (*KubeDeploymentExecutor) ApplyDeploymentAndService

func (e *KubeDeploymentExecutor) ApplyDeploymentAndService(ctx context.Context, intent apikit.DeploymentIntent) (ApplyResult, error)

func (*KubeDeploymentExecutor) DeleteDeploymentAndServiceByUID

func (e *KubeDeploymentExecutor) DeleteDeploymentAndServiceByUID(ctx context.Context, namespace, name, targetUID string) error

type KubePublicationHelperRunner

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

KubePublicationHelperRunner runs deterministic skopeo helper Pods in the trusted helper namespace and verifies resulting manifest digests via HTTP HEAD.

func NewKubePublicationHelperRunner

func NewKubePublicationHelperRunner(cs kubernetes.Interface, helperNamespace, skopeoImage, stagingMount string) *KubePublicationHelperRunner

NewKubePublicationHelperRunner creates a Kubernetes-backed helper runner.

func (*KubePublicationHelperRunner) CreateHelper

func (r *KubePublicationHelperRunner) CreateHelper(ctx context.Context, intent apikit.ImagePublicationIntent, helperName string) error

func (*KubePublicationHelperRunner) InspectHelper

func (r *KubePublicationHelperRunner) InspectHelper(ctx context.Context, _ string, helperName string) (HelperState, error)

func (*KubePublicationHelperRunner) VerifyRegistryDigest

func (r *KubePublicationHelperRunner) VerifyRegistryDigest(ctx context.Context, intent apikit.ImagePublicationIntent) (string, error)

func (*KubePublicationHelperRunner) WaitHelperSucceeded

func (r *KubePublicationHelperRunner) WaitHelperSucceeded(ctx context.Context, _ string, helperName string) error

type KubeRestartPatcher

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

KubeRestartPatcher applies fixed restartedAt annotations to platform stack workloads.

func NewKubeRestartPatcher

func NewKubeRestartPatcher(clientset kubernetes.Interface) *KubeRestartPatcher

NewKubeRestartPatcher creates a Kubernetes-backed RestartPatcher.

func (*KubeRestartPatcher) PatchComponentRestart

func (p *KubeRestartPatcher) PatchComponentRestart(ctx context.Context, key, restartedAt string) (string, error)

type KubeServerExecutor

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

KubeServerExecutor implements ServerExecutor against Kubernetes dynamic/core clients and k8sstore.

func NewKubeServerExecutor

func NewKubeServerExecutor(dyn dynamic.Interface, cs kubernetes.Interface, accessMgr *k8sstore.Manager, sessions SessionRevoker) *KubeServerExecutor

NewKubeServerExecutor creates a Kubernetes-backed ServerExecutor.

func (*KubeServerExecutor) ApplyMCPServer

func (e *KubeServerExecutor) ApplyMCPServer(ctx context.Context, intent apikit.ServerIntent) (ApplyResult, error)

func (*KubeServerExecutor) CleanCredentials

func (e *KubeServerExecutor) CleanCredentials(ctx context.Context, namespace, name string) error

func (*KubeServerExecutor) DeleteMCPServerByUID

func (e *KubeServerExecutor) DeleteMCPServerByUID(ctx context.Context, namespace, name, targetCRUID string) error

func (*KubeServerExecutor) FenceSessions

func (e *KubeServerExecutor) FenceSessions(ctx context.Context, namespace, name, targetCRUID string) error

func (*KubeServerExecutor) MarkRetiring

func (e *KubeServerExecutor) MarkRetiring(ctx context.Context, namespace, name, targetCRUID string) (string, error)

func (*KubeServerExecutor) RetireGrants

func (e *KubeServerExecutor) RetireGrants(ctx context.Context, namespace, name string) error

type PublicationHelperRunner

type PublicationHelperRunner interface {
	InspectHelper(ctx context.Context, namespace, helperName string) (HelperState, error)
	CreateHelper(ctx context.Context, intent apikit.ImagePublicationIntent, helperName string) error
	WaitHelperSucceeded(ctx context.Context, namespace, helperName string) error
	VerifyRegistryDigest(ctx context.Context, intent apikit.ImagePublicationIntent) (string, error)
}

PublicationHelperRunner manages resumable deterministic helper Pods and verifies the resulting target manifest digest directly against the registry.

type ReconcileComponentRestartJobArgs

type ReconcileComponentRestartJobArgs struct {
	OperationID       string `json:"operationId"`
	DesiredRevisionID string `json:"desiredRevisionId"`
	RequestID         string `json:"requestId,omitempty"`
	Traceparent       string `json:"traceparent,omitempty"`
	Tracestate        string `json:"tracestate,omitempty"`
}

ReconcileComponentRestartJobArgs mirrors Platform API's reconcile_component_restart payload.

func (ReconcileComponentRestartJobArgs) Kind

type ReconcileDeploymentJobArgs

type ReconcileDeploymentJobArgs struct {
	DeploymentID      string `json:"deploymentId"`
	DesiredRevisionID string `json:"desiredRevisionId"`
	RequestID         string `json:"requestId,omitempty"`
	Traceparent       string `json:"traceparent,omitempty"`
	Tracestate        string `json:"tracestate,omitempty"`
}

ReconcileDeploymentJobArgs mirrors Platform API's reconcile_deployment payload.

func (ReconcileDeploymentJobArgs) Kind

type ReconcileImagePublicationJobArgs

type ReconcileImagePublicationJobArgs struct {
	PublicationID     string `json:"publicationId"`
	DesiredRevisionID string `json:"desiredRevisionId"`
	RequestID         string `json:"requestId,omitempty"`
	Traceparent       string `json:"traceparent,omitempty"`
	Tracestate        string `json:"tracestate,omitempty"`
}

ReconcileImagePublicationJobArgs mirrors Platform API's reconcile_image_publication payload.

func (ReconcileImagePublicationJobArgs) Kind

type ReconcileServerJobArgs

type ReconcileServerJobArgs struct {
	ServerID          string `json:"serverId"`
	DesiredRevisionID string `json:"desiredRevisionId"`
	RequestID         string `json:"requestId,omitempty"`
	Traceparent       string `json:"traceparent,omitempty"`
	Tracestate        string `json:"tracestate,omitempty"`
}

ReconcileServerJobArgs mirrors Platform API's reconcile_server River payload.

func (ReconcileServerJobArgs) Kind

type RestartPatcher

type RestartPatcher interface {
	PatchComponentRestart(ctx context.Context, component, restartedAt string) (targetUID string, err error)
}

RestartPatcher applies an exact fixed restartedAt annotation token to one component.

type RestartPlatformClient

type RestartPlatformClient interface {
	ClaimRestartOperationFence(ctx context.Context, operationID, workerID string) (apikit.RestartOperationFenceResponse, error)
	RecordRestartComponentCheckpoint(ctx context.Context, operationID string, req apikit.RestartComponentCheckpointRequest) (apikit.RestartOperationIntent, error)
	RecordRestartOperationReceipt(ctx context.Context, operationID string, req apikit.RestartOperationReceiptRequest) (apikit.WorkloadExecutionReceipt, error)
}

RestartPlatformClient defines Platform API calls for RestartWorker.

type RestartWorker

type RestartWorker struct {
	river.WorkerDefaults[ReconcileComponentRestartJobArgs]
	// contains filtered or unexported fields
}

RestartWorker executes durable imperative component restart operations using the fixed acceptance-time RestartedAt token and per-component checkpoints.

func NewRestartWorker

func NewRestartWorker(platform RestartPlatformClient, patcher RestartPatcher, workerID string) *RestartWorker

NewRestartWorker constructs a RestartWorker.

func (*RestartWorker) Reconcile

func (w *RestartWorker) Reconcile(ctx context.Context, operationID, _ string, attempt int) error

Reconcile claims the fence and patches every uncheckpointed target component using the fixed RestartedAt token persisted at acceptance.

func (*RestartWorker) Work

Work executes one River reconcile_component_restart job.

type Runner

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

Runner owns the pgxpool and River worker client for workload intent queues.

func NewRunner

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

NewRunner creates a River v0.51.0 (riverpgxv5) worker runner on workload_intent_queue.

func (*Runner) Start

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

Start starts processing River queues asynchronously.

func (*Runner) Stop

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

Stop gracefully drains in-flight River jobs and closes the pool.

type RunnerConfig

type RunnerConfig struct {
	DSN                           string
	Schema                        string
	WorkerID                      string
	WorkloadsMaxWorkers           int
	RegistryPublicationMaxWorkers int
}

RunnerConfig controls the River worker client and separate queue budgets.

func DefaultRunnerConfig

func DefaultRunnerConfig() RunnerConfig

DefaultRunnerConfig returns safe separate budgets for workloads and publications.

func (RunnerConfig) RiverQueues

func (c RunnerConfig) RiverQueues() map[string]river.QueueConfig

RiverQueues returns the dedicated River queue configuration map so image publication transfers cannot starve server/deployment/restart reconciliation.

type ServerExecutor

type ServerExecutor interface {
	ApplyMCPServer(ctx context.Context, intent apikit.ServerIntent) (ApplyResult, error)
	MarkRetiring(ctx context.Context, namespace, name, targetCRUID string) (string, error)
	FenceSessions(ctx context.Context, namespace, name, targetCRUID string) error
	RetireGrants(ctx context.Context, namespace, name string) error
	CleanCredentials(ctx context.Context, namespace, name string) error
	DeleteMCPServerByUID(ctx context.Context, namespace, name, targetCRUID string) error
}

ServerExecutor performs bounded Kubernetes apply and ordered retirement steps.

type ServerPlatformClient

type ServerPlatformClient interface {
	ClaimServerIntentFence(ctx context.Context, serverID, workerID string) (apikit.ServerIntentFenceResponse, error)
	RecordServerRetirementCheckpoint(ctx context.Context, serverID string, req apikit.ServerRetirementCheckpointRequest) (apikit.ServerIntent, error)
	RecordServerIntentReceipt(ctx context.Context, serverID string, req apikit.ServerIntentReceiptRequest) (apikit.WorkloadExecutionReceipt, error)
	GetImagePublicationIntent(ctx context.Context, publicationID string) (apikit.ImagePublicationIntent, bool, error)
}

ServerPlatformClient defines the Platform API operations used by ServerWorker.

type ServerWorker

type ServerWorker struct {
	river.WorkerDefaults[ReconcileServerJobArgs]
	// contains filtered or unexported fields
}

ServerWorker reconciles MCPServer intents and ordered retirements.

func NewServerWorker

func NewServerWorker(platform ServerPlatformClient, exec ServerExecutor, workerID string) *ServerWorker

NewServerWorker constructs a ServerWorker.

func (*ServerWorker) Reconcile

func (w *ServerWorker) Reconcile(ctx context.Context, serverID, jobRevisionID string, attempt int) error

Reconcile claims the execution fence and runs bounded apply or ordered retirement checkpoints for one server intent.

func (*ServerWorker) Work

Work executes one River reconcile_server job.

type SessionRevoker

type SessionRevoker interface {
	RevokeSessions(ctx context.Context, filter sessionstate.Filter, cause string) (int64, error)
}

SessionRevoker revokes platform sessions during ordered server retirement.

Jump to

Keyboard shortcuts

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