Documentation
¶
Index ¶
- Constants
- Variables
- func BuildClusterLinkConfig(config *MigrationConfig, auth clusterlink.Authenticator) clusterlink.Config
- func RunAttributes(c *MigrationConfig) []attribute.KeyValue
- func WarnIfPausedOnExecuteFailure(config *MigrationConfig, execErr error)
- type ExecutionParams
- type MigrationActions
- func (s *MigrationActions) CheckLags(ctx context.Context, config *MigrationConfig, lagThreshold int64, ...) error
- func (s *MigrationActions) FenceGateway(ctx context.Context, config *MigrationConfig) error
- func (s *MigrationActions) Initialize(ctx context.Context, config *MigrationConfig, ...) error
- func (s *MigrationActions) PauseOffsetSync(ctx context.Context, config *MigrationConfig, ...) error
- func (s *MigrationActions) PromoteTopics(ctx context.Context, config *MigrationConfig, ...) error
- func (s *MigrationActions) ResolveGatewayCapability(ctx context.Context, config *MigrationConfig) error
- func (s *MigrationActions) RestoreOffsetSync(ctx context.Context, config *MigrationConfig, ...) error
- func (s *MigrationActions) SetHotReloadTimeout(d time.Duration)
- func (s *MigrationActions) SetPromoteBatchSize(n int)
- func (s *MigrationActions) SetRolloutTimeout(d time.Duration)
- func (s *MigrationActions) SwitchGateway(ctx context.Context, config *MigrationConfig) error
- func (s *MigrationActions) VerifyFence(ctx context.Context, config *MigrationConfig) error
- func (s *MigrationActions) VerifyHotReloadCapability(ctx context.Context, config *MigrationConfig) error
- type MigrationConfig
- type MigrationOrchestrator
- type WorkflowStep
Constants ¶
const ( StateUninitialized = "uninitialized" StateInitialized = "initialized" StateLagsOk = "lags_ok" StateFenced = "fenced" StateOffsetSyncPaused = "offset_sync_paused" StateFenceVerified = "fence_verified" StatePromoted = "promoted" StateSwitched = "switched" StateOffsetSyncRestored = "offset_sync_restored" )
FSM State constants
const ( EventInitialize = "initialize" EventWaitForLags = "wait_for_lags" EventFence = "fence" // EventPauseOffsetSync pauses cluster-link consumer offset sync // (spec.staticMigration.consumerOffsetSync.pause) immediately after fencing. Without the // opt-in the transition still fires as a pass-through so the forward // walk is identical either way. EventPauseOffsetSync = "pause_offset_sync" EventVerifyFence = "verify_fence" EventPromote = "promote" EventSwitch = "switch" // EventRestoreOffsetSync sets cluster-link consumer offset sync back to // the manifest's baseline after the switch, when the plan owes a restore. // Otherwise the transition still fires as a pass-through, like // pause_offset_sync. EventRestoreOffsetSync = "restore_offset_sync" // EventAbortFence rolls back to initialized when the pause_offset_sync // step fails (from fenced) or the verify_fence step detects unrouted // producers (from offset_sync_paused); the transition itself unfences // the gateway and restores any paused sync config (see onAbortFence in // orchestrator.go). EventAbortFence = "abort_fence" )
FSM Event constants
const ( RollbackPathAbortFence = "abort_fence" // this run's fence, undone along the FSM's abort_fence edge RollbackPathEarlierRunFence = "earlier_run_fence" // an interrupted run's fence, undone outside the FSM RollbackPathUnconfirmedFence = "unconfirmed_fence" // a fence that reached the CR but was never confirmed )
Rollback paths, recorded as kcp.rollback.path on migration.rollback.
Variables ¶
var ErrFenceUnconfirmed = errors.New("fence could not be confirmed on every gateway pod")
ErrFenceUnconfirmed marks a fence whose CR reached the cluster but whose effect on the serving pods was never confirmed. The orchestrator catches it to restore the initial CR — see restoreAfterUnconfirmedFence for why that is the right compensation even when the fence appears not to have landed at all.
var ErrUnroutedProducers = offset.ErrUnroutedProducers
ErrUnroutedProducers is returned when the post-fence check detects producers bypassing the gateway. The orchestrator catches this to trigger an EventAbortFence transition back to initialized state. Re-exported from offset.ErrUnroutedProducers (the package that actually detects and wraps it) so every existing errors.Is call site in this package keeps working unchanged.
Functions ¶
func BuildClusterLinkConfig ¶ added in v0.8.1
func BuildClusterLinkConfig(config *MigrationConfig, auth clusterlink.Authenticator) clusterlink.Config
BuildClusterLinkConfig assembles a clusterlink.Config from a migration config plus a runtime REST Authenticator, shared by the offset-sync pause, restore and rollback so none duplicates the field layout. auth carries whichever REST auth form the manifest resolved — basic, bearer or mtls — not only the api_key/api_secret pair BasicAuth wraps.
func RunAttributes ¶ added in v0.11.0
func RunAttributes(c *MigrationConfig) []attribute.KeyValue
RunAttributes are migration.run's plan-derived attributes. They are only meaningful once initialize has copied the reconcile plan onto c. Counts only: no topic names.
func WarnIfPausedOnExecuteFailure ¶ added in v0.8.1
func WarnIfPausedOnExecuteFailure(config *MigrationConfig, execErr error)
WarnIfPausedOnExecuteFailure prints a stderr remediation message when orchestrator.Execute returns an error and the operator opted into offset-sync pausing (config.PauseConsumerOffsetSync). The pause and restore steps are idempotent applies with nothing to branch on, so the guidance is a single generic reminder gated only on the manifest-declared intent: verify the cluster link matches the declared baseline before resuming normal operation.
Soft-fail: never returns an error — this is best-effort messaging on top of the underlying execute error.
Types ¶
type ExecutionParams ¶
type ExecutionParams struct {
LagThreshold int64
// RestAuth authenticates the destination cluster-link REST surface — the
// full resolved Authenticator (basic, bearer, or mtls), not only an
// api_key/api_secret pair.
RestAuth clusterlink.Authenticator
// ReconcileResult is the migplan.Result the command layer computed via
// migplan.Reconcile just before Execute — mirrors TBM's own
// ExecutionParams shape. onInitialize consumes it directly instead of
// running any validation of its own; migplan.Reconcile already did that.
ReconcileResult *migplan.Result
}
ExecutionParams holds the per-run runtime parameters a transition may need. It is passed to fsm.Event as the sole argument and read back by callbacks via execParamsFromEvent, rather than stashed on the orchestrator, so the values flow with the event instead of living as mutable orchestrator state.
type MigrationActions ¶ added in v0.8.9
type MigrationActions struct {
// contains filtered or unexported fields
}
func NewMigrationActions ¶ added in v0.8.9
func NewMigrationActions( gatewayService gateway.Service, clusterLinkService clusterlink.Service, ) *MigrationActions
func NewMigrationActionsWithOffsets ¶ added in v0.8.9
func NewMigrationActionsWithOffsets( gatewayService gateway.Service, clusterLinkService clusterlink.Service, sourceOffset offset.Provider, destinationOffset offset.Provider, ) *MigrationActions
func (*MigrationActions) CheckLags ¶ added in v0.8.9
func (s *MigrationActions) CheckLags( ctx context.Context, config *MigrationConfig, lagThreshold int64, restAuth clusterlink.Authenticator, ) error
CheckLags polls source and destination offsets until lag is below threshold
func (*MigrationActions) FenceGateway ¶ added in v0.8.9
func (s *MigrationActions) FenceGateway(ctx context.Context, config *MigrationConfig) error
FenceGateway applies the fenced gateway CR YAML to block traffic, confirms the Confluent operator accepted the new spec, then waits for it to report the gateway as Ready at that generation. The wait runs without a deadline by default — the operator drives convergence and the user can Ctrl-C if a rollout wedges. An optional per-workflow rolloutTimeout caps the wait when set (via SetRolloutTimeout).
func (*MigrationActions) Initialize ¶ added in v0.8.9
func (s *MigrationActions) Initialize( ctx context.Context, config *MigrationConfig, restAuth clusterlink.Authenticator, res *migplan.Result, ) error
Initialize captures the migplan-derived artifacts onto config. Mirrors TBMActions.Initialize's shape (check res.Refused, copy fields) — everything migplan.Reconcile already decided (staged-auth/secret existence, cluster-link topic classification, whether an offset-sync restore is owed) is NOT re-checked here.
func (*MigrationActions) PauseOffsetSync ¶ added in v0.8.9
func (s *MigrationActions) PauseOffsetSync( ctx context.Context, config *MigrationConfig, restAuth clusterlink.Authenticator, ) error
PauseOffsetSync runs the pause_offset_sync stage: with the operator's spec.staticMigration.consumerOffsetSync.pause opt-in, and only when this run has an actual cutover in flight (config.FenceYAML set by the plan), it applies an idempotent AlterConfigs SET disabling cluster-link consumer offset sync; otherwise it passes through so the FSM still records offset_sync_paused. Plan- and manifest-driven only: it never reads the live cluster link to decide anything, so re-running it (a resume, a retry) simply re-applies the same SET — safe whether or not a prior attempt already landed it.
func (*MigrationActions) PromoteTopics ¶ added in v0.8.9
func (s *MigrationActions) PromoteTopics(ctx context.Context, config *MigrationConfig, restAuth clusterlink.Authenticator) error
PromoteTopics polls offsets and promotes mirror topics that reach zero lag
func (*MigrationActions) ResolveGatewayCapability ¶ added in v0.11.0
func (s *MigrationActions) ResolveGatewayCapability(ctx context.Context, config *MigrationConfig) error
ResolveGatewayCapability determines how gateway state transitions will be verified on the live cluster and adopts it for this run. Called once per run, via ensureGatewayCapability.
func (*MigrationActions) RestoreOffsetSync ¶ added in v0.11.0
func (s *MigrationActions) RestoreOffsetSync(ctx context.Context, config *MigrationConfig, restAuth clusterlink.Authenticator) error
RestoreOffsetSync runs the restore_offset_sync stage, the last in the workflow: when reconcile found a restore owed (config.RestoreOffsetSync), it applies an idempotent AlterConfigs SET of consumer.offset.sync.enable to the declared baseline; otherwise it passes through so the FSM still records offset_sync_restored. Plan- and manifest-driven only: it never reads the live cluster link. A failed SET fails the step and leaves the FSM at switched. The switch has landed, so nothing rolls back; a re-run, whose reconcile still finds the restore owed, retries it.
func (*MigrationActions) SetHotReloadTimeout ¶ added in v0.11.0
func (s *MigrationActions) SetHotReloadTimeout(d time.Duration)
SetHotReloadTimeout sets the deadline for per-pod configId verification. A value of 0 falls back to gateway.DefaultHotReloadTimeout — unlike the rollout waits, this one is never allowed to run unbounded.
func (*MigrationActions) SetPromoteBatchSize ¶ added in v0.8.9
func (s *MigrationActions) SetPromoteBatchSize(n int)
SetPromoteBatchSize caps how many mirror topics are promoted per batch during PromoteTopics. A value of 0 (the default) means unlimited — all zero-lag topics are promoted at once. When set (>0), each batch is promoted and fully confirmed STOPPED before the next batch is submitted.
func (*MigrationActions) SetRolloutTimeout ¶ added in v0.8.9
func (s *MigrationActions) SetRolloutTimeout(d time.Duration)
SetRolloutTimeout sets the deadline applied to gateway-readiness waits. A value of 0 means no deadline.
func (*MigrationActions) SwitchGateway ¶ added in v0.8.9
func (s *MigrationActions) SwitchGateway(ctx context.Context, config *MigrationConfig) error
SwitchGateway derives the switch RoutePatch for config.Route (a whole-route replace of the captured route with the target streamingDomain — see deriveSwitchRoutePatch) — patches it in, confirms the operator accepted the new spec, then waits for it to report the gateway as Ready. The wait uses the same no-deadline-by-default behavior as FenceGateway.
Because the captured route is unfenced and already carries pre-staged ("redundant") auth for the target domain (checked by migplan.Reconcile's redundant-auth precondition), this one whole-route replace yields unfenced + target-domain + target-auth with no secret or auth change at cutover — it both drops the fence and flips the domain, and there is no separately-authored switchover CR to apply.
The acceptance check is what stops this reporting a completed migration for a switchover the operator refused — the failure mode described on waitForGatewayAccepted, hit on 2026-07-27 while setting up the live-cluster e2e test infrastructure.
func (*MigrationActions) VerifyFence ¶ added in v0.8.9
func (s *MigrationActions) VerifyFence(ctx context.Context, config *MigrationConfig) error
VerifyFence verifies the fence held: the source offsets of every topic the run migrates (config.MigrateTopics, already-promoted ones included) must be stable, because an increasing offset after fencing indicates a producer bypassing the gateway. An already-promoted topic's mirror no longer copies from the source, so a write straight to it would never reach the target. When detection is disabled (DetectUnroutedProducersDuration == 0) the step succeeds immediately so the FSM still records fence_verified.
detectUnroutedProducers wraps ErrUnroutedProducers only for a real detection; a network/fetch error propagates as-is. Either way we just return it — what happens next (a rollback, or keeping the fence when reconcile forbids one) is the orchestrator's handleStepFailure.
func (*MigrationActions) VerifyHotReloadCapability ¶ added in v0.11.0
func (s *MigrationActions) VerifyHotReloadCapability(ctx context.Context, config *MigrationConfig) error
VerifyHotReloadCapability proves the gateway really does apply config revisions, before any traffic-affecting change is made. See gateway.TransitionVerifier.VerifyHotReloadCapability's doc comment for why this matters and why patching only spec.configId — touching no other field — makes it safe to call at any point, including a resume.
type MigrationConfig ¶ added in v0.8.4
type MigrationConfig struct {
MigrationId string
// Destination cluster configuration
ClusterId string
ClusterRestEndpoint string
ClusterLinkName string
Topics []string
// MigrateTopics is every topic this run migrates — Topics plus the
// already-promoted ones — set each run from the reconcile result. The fence
// check watches their source offsets: an already-promoted topic's mirror no
// longer copies from the source, so a write straight to it would be lost.
MigrateTopics []string
// AwaitStopped is the subset of Topics that reconcile found already
// mid-promotion (PENDING_STOPPED) on this run — resume-derived, so it is
// (re)populated fresh from the reconcile Result every run. The promote
// stage seeds these straight into its awaiting-STOPPED set: it waits for
// them to reach STOPPED and never re-issues a promote on an already-
// promoting mirror. Empty on a first run (nothing promoted yet).
AwaitStopped []string
// PauseConsumerOffsetSync is the operator's opt-in (manifest
// spec.staticMigration.consumerOffsetSync.pause, read each run) to pause
// cluster-link consumer offset sync for the duration of execute.
PauseConsumerOffsetSync bool
// ConsumerOffsetSyncBaseline is the declared pre-migration state of
// consumer.offset.sync.enable on the cluster link (manifest
// spec.staticMigration.consumerOffsetSync.baseline: "enabled" or "disabled"),
// read from the manifest each run — never from the live cluster link. The
// restore_offset_sync step and the abort_fence rollback apply this value
// as an idempotent AlterConfigs SET.
ConsumerOffsetSyncBaseline string
// RestoreOffsetSync is set each run from the reconcile result: true when
// the restore_offset_sync step must set consumer.offset.sync.enable back
// to ConsumerOffsetSyncBaseline after the switch.
RestoreOffsetSync bool
// DetectUnroutedProducersDuration is the monitoring window for the post-fence
// safety check that verifies source offsets are not still increasing before
// promoting mirror topics. A value of 0 skips the check. An increasing offset
// after fencing indicates a producer that bypassed the gateway and is writing
// directly to the source cluster.
DetectUnroutedProducersDuration time.Duration
// ConsumerOffsetSyncDrainDuration is how long the pause_offset_sync stage
// waits after fencing before disabling the cluster link's
// consumer.offset.sync.enable. The fence freezes source consumer offsets
// (clients can no longer commit), so holding here lets the link run one or
// more further sync cycles and propagate those final committed offsets to
// the destination, minimising messages reprocessed after switchover. Only
// has effect when PauseConsumerOffsetSync is set. Best-effort: offset sync
// is asynchronous, so this reduces but does not eliminate duplicate
// processing. A value of 0 (the default) skips the wait — the link is
// disabled immediately after fencing, the prior behaviour.
ConsumerOffsetSyncDrainDuration time.Duration
// Gateway CR configuration
InitialCrName string
K8sNamespace string
// GatewayYAML is the whole gateway CR migplan pulled and cleaned (see
// migplan/gatewayfile.go's cleanGatewayDoc), set each run from the reconcile
// result — the fence/switch derivation base.
GatewayYAML string
// GatewayConfigPort is the port the gateway's GET /config endpoint is served
// on. Configurable because the contract requires it to be; nothing fronts
// this port, so kcp dials pod IPs on it directly.
GatewayConfigPort int
// Route is the single spec.route.name this migration fences and
// switches, read from the manifest each run. AAO, like TBM, only ever
// operates on one route per migration.
Route string
// FenceYAML, SwitchoverYAML and RollbackFenceYAML are the route shapes
// migplan.Reconcile returns, set each run from the reconcile result and
// applied as given. For a static route: FenceYAML is a {fence: …} block set
// on Route; SwitchoverYAML (the switched route) and RollbackFenceYAML (the
// route as a rollback leaves it, the start-of-run route with the fence
// taken out) are whole {route: …} documents that replace Route. For a
// dynamic route each is a whole rules: block set on Route's rules.
FenceYAML string
SwitchoverYAML string
RollbackFenceYAML string
// RollbackAllowed is set each run from the reconcile result: true when a
// pre-promote failure may roll back (unfence), i.e. no topic in the batch
// is promoted or promoting yet.
RollbackAllowed bool
// FencedAtStart is set each run from the reconcile result: true when the
// route already carried kcp's fence for this migration at the start of the
// run, left by an earlier, interrupted run.
FencedAtStart bool
}
MigrationConfig holds all domain configuration for a migration: pure data, built from the manifest and the run's reconcile result.
type MigrationOrchestrator ¶
type MigrationOrchestrator struct {
// contains filtered or unexported fields
}
MigrationOrchestrator manages the FSM lifecycle and coordinates workflow execution
func NewMigrationOrchestrator ¶
func NewMigrationOrchestrator( config *MigrationConfig, actions *MigrationActions, ) *MigrationOrchestrator
NewMigrationOrchestrator creates a new migration orchestrator with injected dependencies
func (*MigrationOrchestrator) CurrentState ¶ added in v0.11.0
func (o *MigrationOrchestrator) CurrentState() string
CurrentState returns the FSM's current state — the single source of truth for where this run's machine sits, now that no config field mirrors it.
func (*MigrationOrchestrator) Execute ¶
func (o *MigrationOrchestrator) Execute(ctx context.Context, lagThreshold int64, restAuth clusterlink.Authenticator, res *migplan.Result) (err error)
Execute runs the full migration workflow, always from StateUninitialized (see NewMigrationOrchestrator). res is the migplan.Result the command layer (cmd/migration/cutover/execute) computes live via migplan.Reconcile on every invocation — not only the first — and is now non-nil on every call; onInitialize consumes it directly.
type WorkflowStep ¶
WorkflowStep defines a single step in the migration workflow. It is pure FSM topology plus an ops-facing Description; user-facing presentation lives in stepHeaders, keyed by event, so the edge definitions stay presentation-free.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package d2s implements the FSM-driven orchestrator for a dynamic-to-static route conversion (spec.dynamicToStaticConversion): fence the dynamic route, re-check the conversion on post-fence data, copy the in-scope consumer groups' committed offsets to the destination, and switch the route to static.
|
Package d2s implements the FSM-driven orchestrator for a dynamic-to-static route conversion (spec.dynamicToStaticConversion): fence the dynamic route, re-check the conversion on post-fence data, copy the in-scope consumer groups' committed offsets to the destination, and switch the route to static. |
|
Package killpoint holds the migration FSMs' two test-only seams.
|
Package killpoint holds the migration FSMs' two test-only seams. |
|
Package tbm implements the FSM-driven orchestrator for the Topic-Batch Migration (TBM) workflow.
|
Package tbm implements the FSM-driven orchestrator for the Topic-Batch Migration (TBM) workflow. |