orkestra

package
v0.7.9 Latest Latest
Warning

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

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

README

pkg/orkestra

orkestra is the process lifecycle manager. It registers domain.Komponent services, starts them in registration order, and shuts them down in reverse order on SIGINT or SIGTERM.

ork := orkestra.NewOrkestra(30*time.Second, logLevel)
ork.Register([]domain.Komponent{kubeclient, event, konductor, health})
ork.Start(ctx)

Komponent contract

Any service that participates in the lifecycle implements domain.Komponent:

type Komponent interface {
    Name() string
    Start(ctx context.Context) error
    Shutdown(ctx context.Context)
    Started() bool
}

Start order matches registration order. Shutdown order is reversed — the last-started service is the first to stop. The event handler is always shut down last, regardless of registration position, so that other services can still emit events during their shutdown.

Post-start hooks

Some services must start only after the full komponent list is running (e.g. leader election, which needs the kube client up first):

ork.AddPostStartHook(konductorComp, func(ctx context.Context) {
    ko.Start(ctx)
})

Post-start hooks run in goroutines after all Start calls succeed.

Shutdown hooks

Cleanup that must happen after all komponents have stopped (TLS cert deletion, webhook configuration removal, RBAC cleanup) registers via OnShutdown:

ork.OnShutdown(func(ctx context.Context) {
    certmanager.DeleteCertificateAndSecret(ctx, ...)
})

Hooks run sequentially in registration order, within the shutdown timeout. If the timeout is exceeded mid-way, remaining hooks are skipped and the process exits.

Graceful shutdown timeout

NewOrkestra(timeout, logLevel) sets the maximum time allowed for all komponents and hooks to finish shutting down. If exceeded at any point, Orkestra stops waiting and closes the done channel. The main goroutine calls ork.Wait() which blocks on this channel.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Orkestra

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

func NewOrkestra

func NewOrkestra(instance string, timeout time.Duration, logLevel string) *Orkestra

func (*Orkestra) AddPostStartHook

func (o *Orkestra) AddPostStartHook(comp domain.Komponent, hook func(context.Context))

AddPostStartHook: for services that need to start after Orkestra has started

func (*Orkestra) GetKomponent

func (o *Orkestra) GetKomponent(name string) domain.Komponent

GetKomponent returns a komponent if present

func (*Orkestra) OnShutdown

func (o *Orkestra) OnShutdown(fn func(context.Context))

OnShutdown registers a function to be called after all komponents have stopped, within the graceful shutdown timeout.

Use this for cleanup that must happen after the operator stops processing but before the process exits:

  • RBAC deletion (security.rbac.cleanupOnShutdown: true)
  • Deletion protection webhook removal
  • Temp file cleanup (generated TLS certs)

Hooks are called in registration order, sequentially. If the shutdown timeout is exceeded before all hooks run, remaining hooks are skipped — the process is exiting regardless.

func (*Orkestra) Register

func (o *Orkestra) Register(c []domain.Komponent)

Register all komponents

func (*Orkestra) Shutdown

func (o *Orkestra) Shutdown(ctx context.Context)

func (*Orkestra) Start

func (o *Orkestra) Start(ctx context.Context) error

func (*Orkestra) Wait

func (o *Orkestra) Wait()

Listening to done channel

Jump to

Keyboard shortcuts

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