multiinstance

package
v3.5.2 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2025 License: Apache-2.0 Imports: 11 Imported by: 2

Documentation

Index

Constants

View Source
const (
	// SchedulingQueueSize is the size of the scheduling queue for manager.Manager instances. It should be large enough
	// to handle all reasonable cases of manager.Manager instances being scheduled at the same time.
	SchedulingQueueSize = 100
)

Variables

This section is empty.

Functions

This section is empty.

Types

type DiagnosticsExposer

type DiagnosticsExposer interface {
	// RegisterInstance registers a new manager.Manager instance with the diagnostics exposer.
	RegisterInstance(manager.ID, http.Handler)

	// UnregisterInstance unregisters a manager.Manager instance with the diagnostics exposer.
	UnregisterInstance(manager.ID)
}

DiagnosticsExposer is an interface that represents an object that can expose diagnostics data of manager.Manager instances.

type DiagnosticsServer

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

DiagnosticsServer is a server that provides diagnostics information for multiple instances managed by the manager. Each instance exposes its own diagnostics endpoints on `/{instanceID}/debug/config/` prefix. On every call to RegisterInstance or UnregisterInstance, the server rebuilds its mux to include the latest set of handlers.

func NewDiagnosticsServer

func NewDiagnosticsServer(listenerPort int, opts ...DiagnosticsServerOption) *DiagnosticsServer

func (*DiagnosticsServer) RegisterInstance

func (s *DiagnosticsServer) RegisterInstance(instanceID manager.ID, instanceDiagnosticsHandler http.Handler)

RegisterInstance registers a new instance to the diagnostics server.

func (*DiagnosticsServer) ServeHTTP

func (s *DiagnosticsServer) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP serves the diagnostics server.

func (*DiagnosticsServer) Start

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

Start starts the diagnostics server.

func (*DiagnosticsServer) UnregisterInstance

func (s *DiagnosticsServer) UnregisterInstance(instanceID manager.ID)

UnregisterInstance unregisters an instance from the diagnostics server.

type DiagnosticsServerOption

type DiagnosticsServerOption func(*DiagnosticsServer)

DiagnosticsServerOption is a functional option for configuring the DiagnosticsServer.

func WithPprofHandler

func WithPprofHandler() DiagnosticsServerOption

type InstanceNotFoundError

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

InstanceNotFoundError is an error indicating that an instance with the given ID was not found in the manager. It can indicate that the instance was never scheduled or was stopped.

func NewInstanceNotFoundError

func NewInstanceNotFoundError(id manager.ID) InstanceNotFoundError

func (InstanceNotFoundError) Error

func (e InstanceNotFoundError) Error() string

type InstanceWithIDAlreadyScheduledError

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

InstanceWithIDAlreadyScheduledError is an error indicating that an instance with the same ID is already scheduled.

func NewInstanceWithIDAlreadyScheduledError

func NewInstanceWithIDAlreadyScheduledError(id manager.ID) InstanceWithIDAlreadyScheduledError

func (InstanceWithIDAlreadyScheduledError) Error

type Manager

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

Manager is able to dynamically run multiple instances of manager.Manager and manage their lifecycle. It is responsible for things like: - Making sure there's only one instance of a manager.Manager with a given ID. - Starting and stopping manager.Manager instances as needed. - Registering instances' diagnostic handlers in a DiagnosticsExposer when configured.

func NewManager

func NewManager(logger logr.Logger, opts ...ManagerOption) *Manager

NewManager creates a new multi-instance manager.

func (*Manager) GetInstanceConfigHash added in v3.5.0

func (m *Manager) GetInstanceConfigHash(id manager.ID) (string, error)

func (*Manager) IsInstanceReady

func (m *Manager) IsInstanceReady(id manager.ID) error

IsInstanceReady checks if a manager.Manager instance with the given ID is ready. If no instance with the given ID exists, it returns a InstanceNotFoundError error.

func (*Manager) ScheduleInstance

func (m *Manager) ScheduleInstance(in ManagerInstance) error

ScheduleInstance adds a new manager.Manager instance to the multi-instance manager and starts it immediately in a separate goroutine. If an instance with the same ID already exists, it returns a InstanceWithIDAlreadyScheduledError error.

func (*Manager) Start

func (m *Manager) Start(ctx context.Context) error

Start starts the multi-instance manager and blocks until the context is canceled. It should only be called once.

func (*Manager) StopInstance

func (m *Manager) StopInstance(instanceID manager.ID) error

StopInstance stops a manager.Manager instance with the given ID. If no instance with the given ID exists, it returns a InstanceNotFoundError error.

type ManagerInstance

type ManagerInstance interface {
	ID() manager.ID
	Run(context.Context) error
	Config() managercfg.Config
	IsReady() error
	DiagnosticsHandler() http.Handler
}

ManagerInstance is an interface that represents a single instance of a manager.Manager, exposing only the methods needed by the multi-instance manager.

type ManagerOption

type ManagerOption func(*Manager)

ManagerOption is a functional option that can be used to configure a new multi-instance manager.

func WithDiagnosticsExposer

func WithDiagnosticsExposer(exposer DiagnosticsExposer) ManagerOption

Jump to

Keyboard shortcuts

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