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 ¶
- Variables
- type Backend
- type Config
- type NoopBackend
- type SDK
- func (s *SDK) ActiveSessions() int
- func (s *SDK) Drain(ctx context.Context) error
- func (s *SDK) EndSession(ctx context.Context, sessionID string) error
- func (s *SDK) Ready(ctx context.Context) error
- func (s *SDK) Run(ctx context.Context) error
- func (s *SDK) Shutdown(ctx context.Context) error
- func (s *SDK) StartSession(ctx context.Context, sessionID string, token []byte) error
Constants ¶
This section is empty.
Variables ¶
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) SetCapacity ¶
func (b *NoopBackend) SetCapacity(_ context.Context, n int) 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 (*SDK) ActiveSessions ¶
ActiveSessions returns the current session count.
func (*SDK) Drain ¶
Drain refuses new sessions and runs OnDrain. Existing sessions continue until they EndSession themselves.
func (*SDK) EndSession ¶
EndSession releases a session slot. Returns ErrSessionUnknown if the session was never started.
func (*SDK) Run ¶
Run drives the health heartbeat until ctx is cancelled. It returns ctx.Err() on exit.