sdk

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: May 30, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package sdk is the pod-side companion to kit/orchestration. It abstracts the per-pod lifecycle — readiness, health heartbeat, per-session enter/exit callbacks, and graceful shutdown — behind a small interface so the pod binary doesn't bind to a specific orchestrator (Agones, k8s, local).

A real Agones implementation lives behind a build tag / sub-package to keep the heavy SDK out of the core dependency graph.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrAtCapacity     = errors.New("orchestration/sdk: pod at capacity")
	ErrDraining       = errors.New("orchestration/sdk: pod is draining")
	ErrSessionUnknown = errors.New("orchestration/sdk: unknown session")
)

Errors surfaced by the SDK.

Functions

This section is empty.

Types

type Backend

type Backend interface {
	Ready(ctx context.Context) error
	Health(ctx context.Context) error
	SetCapacity(ctx context.Context, n int) error
	Shutdown(ctx context.Context) error
}

Backend is the contract a real orchestrator (Agones, k8s) implements.

type Config

type Config struct {
	// Capacity is the max number of concurrent sessions this pod will
	// host.
	Capacity int

	// HealthInterval is the cadence at which Health is reported to the
	// backend. Defaults to 2s.
	HealthInterval time.Duration

	// Backend wires the SDK to a specific orchestrator. Use
	// NewNoopBackend for tests / local dev.
	Backend Backend

	// OnSessionStart is invoked when a session slot is opened.
	OnSessionStart func(ctx context.Context, sessionID string, token []byte) error
	// OnSessionEnd is invoked when a session slot is released.
	OnSessionEnd func(ctx context.Context, sessionID string)
	// OnDrain is invoked when the orchestrator requests graceful
	// shutdown; the pod should refuse new sessions and let existing
	// ones finish.
	OnDrain func(ctx context.Context) error
}

Config configures a pod-side SDK instance.

type NoopBackend

type NoopBackend struct {
	Ready_   int
	Healths  int
	Capacity int
	Shut     int
	// contains filtered or unexported fields
}

NoopBackend is a Backend that records calls and never errors. Useful for tests and local development.

func (*NoopBackend) Health

func (b *NoopBackend) Health(_ context.Context) error

func (*NoopBackend) Ready

func (b *NoopBackend) Ready(_ context.Context) error

func (*NoopBackend) SetCapacity

func (b *NoopBackend) SetCapacity(_ context.Context, n int) error

func (*NoopBackend) Shutdown

func (b *NoopBackend) Shutdown(_ context.Context) error

type SDK

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

SDK is the pod-side coordinator. Construct with New, then call Ready once after warm-up and let it drive Health on a ticker until ctx is cancelled.

func New

func New(cfg Config) (*SDK, error)

New constructs an SDK. Backend is required; everything else has a sensible zero.

func (*SDK) ActiveSessions

func (s *SDK) ActiveSessions() int

ActiveSessions returns the current session count.

func (*SDK) Drain

func (s *SDK) Drain(ctx context.Context) error

Drain refuses new sessions and runs OnDrain. Existing sessions continue until they EndSession themselves.

func (*SDK) EndSession

func (s *SDK) EndSession(ctx context.Context, sessionID string) error

EndSession releases a session slot. Returns ErrSessionUnknown if the session was never started.

func (*SDK) Ready

func (s *SDK) Ready(ctx context.Context) error

Ready signals the orchestrator that the pod is accepting sessions.

func (*SDK) Run

func (s *SDK) Run(ctx context.Context) error

Run drives the health heartbeat until ctx is cancelled. It returns ctx.Err() on exit.

func (*SDK) Shutdown

func (s *SDK) Shutdown(ctx context.Context) error

Shutdown drains and tells the backend to terminate.

func (*SDK) StartSession

func (s *SDK) StartSession(ctx context.Context, sessionID string, token []byte) error

StartSession opens a session slot.

Jump to

Keyboard shortcuts

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