core

package
v0.0.0-...-50251be Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2024 License: LGPL-3.0 Imports: 26 Imported by: 4

Documentation

Index

Constants

View Source
const (
	// Default - Set 0 weight to failed backend
	Default int16 = iota
	// ZeroToOne - Set weight 1 to all if all backends have StatusDown
	ZeroToOne
)

Fallback options

Variables

View Source
var (
	ErrIpvsSyscallFailed = errors.New("error while calling into IPVS")
	ErrObjectExists      = errors.New("specified object already exists")
	ErrObjectNotFound    = errors.New("unable to locate specified object")
	ErrIncompatibleAFs   = errors.New("incompatible address families")
)

Possible runtime errors.

View Source
var (
	ErrMissingEndpoint     = errors.New("endpoint information is missing")
	ErrUnknownMethod       = errors.New("specified forwarding method is unknown")
	ErrUnknownProtocol     = errors.New("specified protocol is unknown")
	ErrUnknownFlag         = errors.New("specified flag is unknown")
	ErrUnknownFallbackFlag = errors.New("specified fallback flag is unknown")
)

Possible validation errors.

Functions

func RegisterPrometheusExporter

func RegisterPrometheusExporter(ctx *Context)

Types

type Backend

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

Backend RS entity of gorb

func (*Backend) Cleanup

func (rs *Backend) Cleanup()

Cleanup backend, gracefully stops monitoring

func (*Backend) GetHealth

func (rs *Backend) GetHealth() float64

UpdateWeight save new weight and return prev

func (*Backend) UpdateWeight

func (rs *Backend) UpdateWeight(weight int32) int32

UpdateWeight save new weight and return prev

type BackendInfo

type BackendInfo struct {
	Options *BackendOptions `json:"options"`
	Metrics pulse.Metrics   `json:"metrics"`
}

BackendInfo contains information about backend options and pulse.

type BackendOptions

type BackendOptions struct {
	Host string `json:"host" yaml:"host"`
	Port uint16 `json:"port" yaml:"port"`
	// contains filtered or unexported fields
}

BackendOptions describe a virtual service backend.

func (*BackendOptions) CompareStoreOptions

func (o *BackendOptions) CompareStoreOptions(options *BackendOptions) bool

func (*BackendOptions) Validate

func (o *BackendOptions) Validate() error

Validate fills missing fields and validates backend configuration.

type Context

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

Context abstacts away the underlying IPVS bindings implementation.

func NewContext

func NewContext(options ContextOptions) (*Context, error)

NewContext creates a new Context and initializes IPVS.

func (*Context) Close

func (ctx *Context) Close()

Close shuts down IPVS and closes the Context.

func (*Context) CompareWith

func (ctx *Context) CompareWith(storeServices map[string]*ServiceConfig) *StoreSyncStatus

func (*Context) CreateBackend

func (ctx *Context) CreateBackend(vsID, rsID string, opts *BackendOptions) error

CreateBackend registers a new backend with a virtual service.

func (*Context) CreateService

func (ctx *Context) CreateService(vsID string, serviceConfig *ServiceConfig) error

CreateService registers a new virtual service with IPVS.

func (*Context) GetBackend

func (ctx *Context) GetBackend(vsID, rsID string) (*BackendInfo, error)

GetBackend returns information about a backend.

func (*Context) GetPoolForService

func (ctx *Context) GetPoolForService(svc gnl2go.Service) (gnl2go.Pool, error)

ipvs.GetPoolForService() not works =( impement via iteration

func (*Context) GetService

func (ctx *Context) GetService(vsID string) (*ServiceInfo, error)

GetService returns information about a virtual service.

func (*Context) ListServices

func (ctx *Context) ListServices() ([]string, error)

ListServices returns a list of all registered services.

func (*Context) RemoveBackend

func (ctx *Context) RemoveBackend(vsID, rsID string) (*BackendOptions, error)

RemoveBackend deregisters a backend.

func (*Context) RemoveService

func (ctx *Context) RemoveService(vsID string) (*ServiceOptions, error)

RemoveService deregisters a virtual service.

func (*Context) SetStore

func (ctx *Context) SetStore(store *Store)

SetStore if external kvstore exists, set store to context

func (*Context) StoreExist

func (ctx *Context) StoreExist() bool

StoreExist Checks if store set

func (*Context) Synchronize

func (ctx *Context) Synchronize(storeServicesConfig map[string]*ServiceConfig) error

func (*Context) UpdateBackend

func (ctx *Context) UpdateBackend(vsID, rsID string, weight int32) (int32, error)

UpdateBackend updates the specified backend's weight.

type ContextOptions

type ContextOptions struct {
	Disco        string
	Endpoints    []net.IP
	Flush        bool
	ListenPort   uint16
	VipInterface string
}

ContextOptions configure Context behavior.

type Exporter

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

func NewExporter

func NewExporter(ctx *Context) *Exporter

func (*Exporter) Collect

func (e *Exporter) Collect(ch chan<- prometheus.Metric)

func (*Exporter) Describe

func (e *Exporter) Describe(ch chan<- *prometheus.Desc)

type Ipvs

type Ipvs interface {
	Init() error
	Exit()
	Flush() error
	AddService(vip string, port uint16, protocol uint16, sched string) error
	AddServiceWithFlags(vip string, port uint16, protocol uint16, sched string, flags []byte) error
	DelService(vip string, port uint16, protocol uint16) error
	AddDestPort(vip string, vport uint16, rip string, rport uint16, protocol uint16, weight int32, fwd uint32) error
	UpdateDestPort(vip string, vport uint16, rip string, rport uint16, protocol uint16, weight int32, fwd uint32) error
	DelDestPort(vip string, vport uint16, rip string, rport uint16, protocol uint16) error
	// Unforture not work =(
	// GetPoolForService(svc gnl2go.Service) (gnl2go.Pool, error)
	GetPools() ([]gnl2go.Pool, error)
}

type Service

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

Service VS entity of gorb

func (*Service) BackendExist

func (vs *Service) BackendExist(rsID string) bool

func (*Service) CalcServiceStat

func (vs *Service) CalcServiceStat() *ServiceInfo

func (*Service) Cleanup

func (vs *Service) Cleanup()

Cleanup remove service backends, gracefully stops backend monitoring

func (*Service) CreateBackend

func (vs *Service) CreateBackend(rsID string, opts *BackendOptions) error

CreateBackend registers a new backend in the virtual service.

func (*Service) GetBackend

func (vs *Service) GetBackend(rsID string) (*Backend, bool)

func (*Service) RemoveBackend

func (vs *Service) RemoveBackend(rsID string) (*BackendOptions, error)

RemoveBackend deregister a backend in the virtual service.

type ServiceConfig

type ServiceConfig struct {
	ServiceOptions  *ServiceOptions            `yaml:"service_options"`
	ServiceBackends map[string]*BackendOptions `yaml:"service_backends"`
}

type ServiceInfo

type ServiceInfo struct {
	Options       *ServiceOptions `json:"options"`
	Health        float64         `json:"health"`
	Backends      []string        `json:"backends"`
	BackendsCount uint16          `json:"backends_count"`
	FallBack      string          `json:"fallback"`
}

ServiceInfo contains information about virtual service options, its backends and overall virtual service health.

type ServiceOptions

type ServiceOptions struct {
	//service settings
	Host       string `json:"host" yaml:"host"`
	Port       uint16 `json:"port" yaml:"port"`
	Protocol   string `json:"protocol" yaml:"protocol"`
	LbMethod   string `json:"lb_method" yaml:"lb_method"`
	ShFlags    string `json:"sh_flags" yaml:"sh_flags"`
	Persistent bool   `json:"persistent" yaml:"persistent"`
	Fallback   string `json:"fallback" yaml:"fallback"`

	// service backends settings
	FwdMethod string         `json:"fwd_method" yaml:"fwd_method"`
	Pulse     *pulse.Options `json:"pulse" yaml:"pulse"`
	MaxWeight int32          `json:"max_weight" yaml:"max_weight"`
	// contains filtered or unexported fields
}

ServiceOptions describe a virtual service.

func (*ServiceOptions) CompareStoreOptions

func (o *ServiceOptions) CompareStoreOptions(options *ServiceOptions) bool

func (*ServiceOptions) Validate

func (o *ServiceOptions) Validate(defaultHost net.IP) error

Validate fills missing fields and validates virtual service configuration.

type Store

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

func NewStore

func NewStore(storeURLs []string, storeServicePath, storeBackendPath string, syncTime int64, useTLS bool, context *Context) (*Store, error)

func (*Store) Close

func (s *Store) Close()

func (*Store) StartSyncWithStore

func (s *Store) StartSyncWithStore() error

StartSyncWithStore synchronize gorb with store

func (*Store) StoreSyncStatus

func (s *Store) StoreSyncStatus() (*StoreSyncStatus, error)

func (*Store) Sync

func (s *Store) Sync()

type StoreSyncStatus

type StoreSyncStatus struct {
	// RemovedServices list of services that can be removed
	RemovedServices []string `json:"removed_services,omitempty"`
	// RemovedBackends list of backends that can be removed
	RemovedBackends []string `json:"removed_backends,omitempty"`
	// UpdatedServices list of services that can be updated
	UpdatedServices []string `json:"updated_services,omitempty"`
	// UpdatedBackends list of backends that can be updated
	UpdatedBackends []string `json:"updated_backends,omitempty"`
	// NewServices list of services that can be added
	NewServices []string `json:"new_services,omitempty"`
	// NewBackends list of backends that can be added
	NewBackends []string `json:"new_backends,omitempty"`
	// Status show final info about sync. May be 'need sync', 'ok'
	Status string `json:"status"`
}

StoreSyncStatus info about synchronization with ext-store

func (*StoreSyncStatus) CheckStatus

func (sync *StoreSyncStatus) CheckStatus() string

Jump to

Keyboard shortcuts

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