v1.13.1 Latest Latest

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

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




This section is empty.


View Source
var ErrNoNodeAvailable = errors.New("no Node available")

ErrNoNodeAvailable is the error returned if no Node is chosen in SelectNodeForIP and ShouldSelectIP.


func NewNodeConsistentHashMap added in v1.11.0

func NewNodeConsistentHashMap() *consistenthash.Map


type Cluster

type Cluster struct {
	// contains filtered or unexported fields

Cluster implements ClusterInterface.

func NewCluster

func NewCluster(
	nodeIP net.IP,
	clusterBindPort int,
	nodeName string,
	nodeInformer coreinformers.NodeInformer,
	externalIPPoolInformer crdinformers.ExternalIPPoolInformer,
	ml Memberlist,
) (*Cluster, error)

NewCluster returns a new *Cluster.

func (*Cluster) AddClusterEventHandler

func (c *Cluster) AddClusterEventHandler(handler ClusterNodeEventHandler)

AddClusterEventHandler adds a clusterNodeEventHandler, which will run when consistentHashMap is updated, due to an ExternalIPPool or Node event.

func (*Cluster) AliveNodes added in v1.5.0

func (c *Cluster) AliveNodes() sets.Set[string]

AliveNodes returns the list of nodeNames in the cluster.

func (*Cluster) RejoinNodes added in v1.7.2

func (c *Cluster) RejoinNodes()

RejoinNodes rejoins Nodes that were removed from the member list by memberlist because they were unreachable for more than 15 seconds (the GossipToTheDeadTime we are using). Without it, once there is a network downtime lasting more than 15 seconds, the agent wouldn't try to reach any other Node and would think it's the only alive Node until it's restarted.

func (*Cluster) Run

func (c *Cluster) Run(stopCh <-chan struct{})

Run will join all the other K8s Nodes in a memberlist cluster and will create defaultWorkers workers (go routines) which will process the ExternalIPPool or Node events from the work queue.

func (*Cluster) SelectNodeForIP added in v1.5.0

func (c *Cluster) SelectNodeForIP(ip, externalIPPool string, filters ...func(string) bool) (string, error)

SelectNodeForIP returns the closest item (Node name) in the hash to the provided key (IP) and ExternalIPPool.

func (*Cluster) ShouldSelectIP added in v1.5.0

func (c *Cluster) ShouldSelectIP(ip, externalIPPool string, filters ...func(string) bool) (bool, error)

ShouldSelectIP returns true if the local Node selected as the owner Node of the IP in the specific ExternalIPPool. The local Node in the cluster holds the same consistent hash ring for each ExternalIPPool, consistentHash.Get gets the closest item (Node name) in the hash to the provided key (IP), if the name of the local Node is equal to the name of the selected Node, returns true.

type ClusterNodeEventHandler added in v1.5.0

type ClusterNodeEventHandler func(objName string)

type Interface added in v1.5.0

type Interface interface {
	ShouldSelectIP(ip string, pool string, filters ...func(node string) bool) (bool, error)
	SelectNodeForIP(ip, externalIPPool string, filters ...func(string) bool) (string, error)
	AliveNodes() sets.Set[string]
	AddClusterEventHandler(handler ClusterNodeEventHandler)

type Memberlist added in v1.7.2

type Memberlist interface {
	Join(existing []string) (int, error)
	Members() []*memberlist.Node
	Leave(timeout time.Duration) error
	Shutdown() error


Path Synopsis
Package testing is a generated GoMock package.
Package testing is a generated GoMock package.

Jump to

Keyboard shortcuts

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