xds

package
v0.0.0-...-c46dd35 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2026 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Server

type Server struct {
	Log *slog.Logger
	// contains filtered or unexported fields
}

Server is a gRPC server that manages lifecycle and provides health checks. It supports both TCP and Unix domain socket transports and implements graceful shutdown.

Server is safe for concurrent use.

func NewServer

func NewServer(cfg *ServerConfig, log *slog.Logger, opts ...ServerOption) Server

NewServer creates a new Server with the given configuration and logger. The server is not started until Start is called.

func (*Server) AddCallback

func (s *Server) AddCallback(callback ServerCallback)

AddCallback registers a ServerCallback to be invoked before the server starts listening.

func (*Server) HealthzCheck

func (s *Server) HealthzCheck(req *http.Request) error

HealthzCheck is a liveness probe handler for health check endpoints. It returns an error when the server is not live, indicating the process should be restarted by the container runtime.

func (*Server) NeedLeaderElection

func (s *Server) NeedLeaderElection() bool

NeedLeaderElection returns false so the server runs on all replicas, not just the leader. This is required for HA deployments where every replica must serve gRPC traffic independently.

func (*Server) ReadyzCheck

func (s *Server) ReadyzCheck(req *http.Request) error

ReadyzCheck is a readiness probe handler for health check endpoints. It returns an error when the server is not ready to accept client requests, causing the pod to be removed from service endpoints until it becomes ready.

func (*Server) Start

func (s *Server) Start(ctx context.Context) error

Start starts the gRPC server and blocks until the context is cancelled or the server errors. It invokes the PreListen callback before starting to listen if a callback is registered. For Unix domain sockets, it sets appropriate permissions on the socket file. The server will attempt graceful shutdown when the context is cancelled.

type ServerCallback

type ServerCallback interface {
	// PreListen is called before the server starts listening on the configured address.
	// It is called after the context is created but before net.Listen is invoked.
	// Implementations should return an error if setup fails; the server will not start.
	PreListen(ctx context.Context) error
}

ServerCallback provides lifecycle hooks for the Server. Implementations can perform setup tasks before the server starts accepting connections.

type ServerConfig

type ServerConfig struct {
	// Network is the network type: "tcp" or "unix"
	Network string
	// Address is the address to bind to (e.g., ":50051" for TCP or "/tmp/server.sock" for Unix domain socket)
	Address string
	// ShutdownTimeout is the maximum time to wait for graceful shutdown
	ShutdownTimeout time.Duration
	// contains filtered or unexported fields
}

ServerConfig holds configuration for a Server.

Network and Address specify the network type and address for the server to bind to. For Unix domain sockets, use WithUDS. For TCP, the Address should be ":port" format. ShutdownTimeout specifies how long to wait for graceful shutdown before forcefully stopping the server.

func NewServerConfig

func NewServerConfig(opts ...ServerConfigOpt) *ServerConfig

NewServerConfig creates a new ServerConfig with default values. The default network is TCP on port 50051 with a 30-second shutdown timeout. Options can be provided to override defaults.

type ServerConfigOpt

type ServerConfigOpt func(*ServerConfig)

ServerConfigOpt is a functional option for configuring ServerConfig.

func WithUDS

func WithUDS(address string) ServerConfigOpt

WithUDS configures the server to use a Unix domain socket at the given address.

type ServerOption

type ServerOption func(*Server)

ServerOption is a functional option for configuring a Server.

func WithGRPCServer

func WithGRPCServer(srv *grpc.Server) ServerOption

WithGRPCServer sets a pre-configured gRPC server to be used by the Server. If not provided, a new gRPC server will be created with default settings.

type XdsServer

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

XdsServer is a gRPC server that implements Envoy's xDS discovery services. It embeds Server and registers discovery service handlers for LDS, CDS, EDS, RDS, and ADS with Envoy's go-control-plane server. The server uses a snapshot cache to manage versioned Envoy configurations.

XdsServer is configured with appropriate keepalive parameters for long-lived client connections and supports up to 1000 concurrent gRPC streams.

func NewXdsServer

func NewXdsServer(ctx context.Context, cfg *ServerConfig, cache cachev3.SnapshotCache, callbacks serverv3.Callbacks, log *slog.Logger) XdsServer

NewXdsServer creates a new XdsServer with Envoy discovery services registered. It configures the gRPC server with keepalive parameters suitable for long-lived client connections, registers all Envoy discovery services (LDS, CDS, EDS, RDS, ADS), and returns an XdsServer ready to be started.

Jump to

Keyboard shortcuts

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