server

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2026 License: BSD-3-Clause Imports: 18 Imported by: 0

Documentation

Overview

Package server orchestrates the load balancer, discovery, and health subsystems.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractAPIPort added in v0.2.0

func ExtractAPIPort(endpoints []string) string

ExtractAPIPort returns the port from the first endpoint, or "6443" as default.

Types

type Option added in v0.2.0

type Option func(*Server)

Option configures a Server.

func WithDiscoveryProviders added in v0.3.0

func WithDiscoveryProviders(providers ...discovery.EndpointProvider) Option

WithDiscoveryProviders overrides the discovery providers used by the server. Intended for testing the discovery pipeline exit path. Panics if no providers are given.

func WithHealthServer added in v0.3.0

func WithHealthServer(hs healthServer) Option

WithHealthServer injects a custom health server implementation (for testing).

func WithKubeClient added in v0.2.0

func WithKubeClient(client kubernetes.Interface) Option

WithKubeClient injects a pre-built Kubernetes client for endpoint discovery.

func WithLivenessConfig added in v0.3.0

func WithLivenessConfig(interval, threshold time.Duration) Option

WithLivenessConfig overrides the heartbeat interval and liveness threshold from Config.LivenessInterval and Config.LivenessThreshold. Intended for testing with sub-second intervals that would be rejected by config validation. Both values must be positive, and threshold must be greater than interval. Panics on invalid values.

func WithLivenessProbe added in v0.3.0

func WithLivenessProbe(probe func()) Option

WithLivenessProbe overrides the function the heartbeat goroutine uses to probe system health. The default probes the load balancer. Intended for testing deadlock detection with a blocking probe. Panics if probe is nil.

type Server

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

Server ties together the load balancer, endpoint discovery, and health checking.

func New

func New(cfg *config.Config, logger *zap.Logger, opts ...Option) (*Server, error)

New creates a Server from the given config. Config is expected to be pre-validated by the caller; ApplyDefaults and Validate are retained as defense-in-depth for direct callers and tests.

func (*Server) Alive added in v0.3.0

func (srv *Server) Alive() bool

Alive reports whether the server's Run loop is active and responsive. Returns false when:

  • Run has not been called yet (lastHeartbeat == 0)
  • Run has returned (lastHeartbeat reset to 0)
  • The heartbeat probe has not responded within the liveness threshold (indicating a deadlocked load balancer goroutine)
  • The discovery pipeline has exited unexpectedly

func (*Server) Healthy

func (srv *Server) Healthy() (bool, error)

Healthy delegates to the load balancer health status.

func (*Server) Run

func (srv *Server) Run(ctx context.Context) error

Run starts all subsystems and blocks until ctx is cancelled.

Jump to

Keyboard shortcuts

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