gossip

package
v0.0.40 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2024 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultLeaveTimeout is the time to wait during while leaving cluster
	DefaultLeaveTimeout = 5 * time.Second
	// DefaultReadyTimeout is the time to wait during ready status update
	DefaultReadyTimeout = 2 * time.Second
)
View Source
const (
	// NodeJoin represents an event about a node join.
	NodeJoin memberlist.NodeEventType = iota << 1
	// NodeLeave represents an event about a node leave.
	NodeLeave
	// NodeUpdate represents an event about a node update.
	NodeUpdate
	// NodeMessage represents an event about a user message.
	NodeMessage
	// NodeError represents an event about a node error.
	NodeError
)
View Source
const (
	GossipLabelKey = "go.ciq.dev/beskar-gossip"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BeskarMeta

type BeskarMeta struct {
	// Beskar or plugin instance.
	InstanceType InstanceType
	// Ready state
	Ready bool
	// Groupcache service port for beskar instances or HTTP service for plugin instances.
	ServicePort uint16
	// Registry service port for beskar instances.
	RegistryPort uint16
	// Hostname, provided as part of metadata as gossip is randomizing node name,
	// for beskar instances it will return the configured hostname, for plugins it returns
	// the node hostname
	Hostname string
}

func NewBeskarMeta

func NewBeskarMeta() *BeskarMeta

func (*BeskarMeta) Decode

func (bm *BeskarMeta) Decode(buf []byte) error

Decode decodes gob format meta data and returns a NodeMeta corresponding structure.

func (*BeskarMeta) Encode

func (bm *BeskarMeta) Encode() ([]byte, error)

type Config added in v0.0.6

type Config struct {
	Addr  string   `yaml:"addr"`
	Key   string   `yaml:"key"`
	Peers []string `yaml:"peers"`
}

type InstanceType added in v0.0.3

type InstanceType uint8
const (
	BeskarInstance InstanceType = iota + 1
	PluginInstance
)

type Member

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

Member represents a member part of a gossip cluster.

func NewMember

func NewMember(name string, peers []string, memberOpt ...MemberOption) (*Member, error)

NewMember creates and/or participates to a gossip cluster.

func Start

func Start(gossipConfig Config, meta *BeskarMeta, client kubernetes.Interface, timeout time.Duration) (*Member, error)

func (*Member) LocalNode

func (member *Member) LocalNode() *memberlist.Node

LocalNode returns the current node information.

func (*Member) LocalState

func (member *Member) LocalState() ([]byte, error)

LocalState returns the state of the node if any.

func (*Member) MarkAsReady added in v0.0.3

func (member *Member) MarkAsReady(timeout time.Duration) error

MarkAsReady updates node metadata ready status and advertise nodes about change.

func (*Member) Nodes

func (member *Member) Nodes() []*memberlist.Node

Nodes returns all nodes participating to the cluster.

func (*Member) RemoteState

func (member *Member) RemoteState() ([]byte, error)

PeerState returns the state of the peer used to join the cluster if any.

func (*Member) Send

func (member *Member) Send(node *memberlist.Node, msg []byte) error

Send senda message to a particular node.

func (*Member) Shutdown

func (member *Member) Shutdown() error

Shutdown leaves the cluster.

func (*Member) Watch

func (member *Member) Watch() <-chan MemberEvent

Watch returns an event channel to react to various notifications coming from gossip protocol (join, leave, update ...).

type MemberEvent

type MemberEvent struct {
	EventType memberlist.NodeEventType
	Arg       interface{}
}

MemberEvent

type MemberOption

type MemberOption func(*memberlist.Config) error

MemberOption defines a member configuration function.

func WithBindAddress

func WithBindAddress(addr string) MemberOption

WithBindAddress sets the bind address to listen on.

func WithLocalState

func WithLocalState(state []byte) MemberOption

func WithNodeMeta

func WithNodeMeta(meta []byte) MemberOption

WithNodeMeta sets meta data associated to a node.

func WithSecretKey

func WithSecretKey(key []byte) MemberOption

WithSecretKey sets the secret key used to encrypt/decrypt communications.

Jump to

Keyboard shortcuts

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