migration

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package migration provides a Migrator that runs a set of migrations concurrently before allowing controller-runtime runnables to start. Use WrapManager to gate runnables behind migration completion: each runnable added via the wrapped manager will block until all migrations succeed, and will return an error without starting if any migration fails.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WrapManager

func WrapManager(migrator *Migrator, mgr manager.Manager) manager.Manager

WrapManager returns a manager.Manager that gates all runnables added via Add behind the given Migrator's completion. If the migration succeeds, the runnables start normally. If the migration fails, each runnable returns the migration error without starting. If the context is canceled before migration completes, each runnable exits with nil.

Types

type Migration

type Migration interface {
	Migrate(ctx context.Context) error
}

Migration is a single migration that can be run before controllers start.

type Migrator

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

Migrator manages a set of migrations and runs them concurrently when Start is called. The Done channel is closed after all migrations complete (whether or not they succeed).

func NewMigrator

func NewMigrator() *Migrator

NewMigrator creates a new Migrator with no registered migrations.

func (*Migrator) Add

func (m *Migrator) Add(migration Migration) error

Add registers a migration. It returns an error if the Migrator has already been started.

func (*Migrator) Done

func (m *Migrator) Done() <-chan struct{}

Done returns a channel that is closed once Start has finished running all migrations.

func (*Migrator) Err

func (m *Migrator) Err() error

Err returns the error produced by Start or nil if Done is not yet closed.

func (*Migrator) Start

func (m *Migrator) Start(ctx context.Context) error

Start runs all registered migrations concurrently. It blocks until every migration has completed and returns a joined error if any migration failed. Start may only be called once; subsequent calls return an error immediately.

Jump to

Keyboard shortcuts

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