mesh

package
v0.0.0-...-f021cd2 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (

	// DefaultKiloInterface is the default interface created and used by Kilo.
	DefaultKiloInterface = "kilo0"
	// DefaultKiloPort is the default UDP port Kilo uses.
	DefaultKiloPort = 51820
	// DefaultCNIPath is the default path to the CNI config file.
	DefaultCNIPath = "/etc/cni/net.d/10-kilo.conflist"
)

Variables

View Source
var DefaultKiloSubnet = &net.IPNet{IP: []byte{10, 4, 0, 0}, Mask: []byte{255, 255, 0, 0}}

DefaultKiloSubnet is the default CIDR for Kilo.

Functions

This section is empty.

Types

type Backend

type Backend interface {
	Nodes() NodeBackend
	Peers() PeerBackend
}

Backend can create clients for all of the primitive types that Kilo deals with, namely: * nodes; and * peers.

type EventType

type EventType string

EventType describes what kind of an action an event represents.

const (
	// AddEvent represents an action where an item was added.
	AddEvent EventType = "add"
	// DeleteEvent represents an action where an item was removed.
	DeleteEvent EventType = "delete"
	// UpdateEvent represents an action where an item was updated.
	UpdateEvent EventType = "update"
)

type Granularity

type Granularity string

Granularity represents the abstraction level at which the network should be meshed.

const (
	// LogicalGranularity indicates that the network should create
	// a mesh between logical locations, e.g. data-centers, but not between
	// all nodes within a single location.
	LogicalGranularity Granularity = "location"
	// FullGranularity indicates that the network should create
	// a mesh between every node.
	FullGranularity Granularity = "full"
	// AutoGranularity can be used with kgctl to obtain
	// the granularity automatically.
	AutoGranularity Granularity = "auto"
)

type Mesh

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

Mesh is able to create Kilo network meshes.

func New

func New(backend Backend, enc encapsulation.Encapsulator, granularity Granularity, hostname string, port int, subnet *net.IPNet, local, cni bool, cniPath, iface string, cleanup bool, cleanUpIface bool, createIface bool, mtu uint, resyncPeriod time.Duration, prioritisePrivateAddr, iptablesForwardRule bool, serviceCIDRs []*net.IPNet, logger log.Logger, registerer prometheus.Registerer) (*Mesh, error)

New returns a new Mesh instance.

func (*Mesh) Run

func (m *Mesh) Run(ctx context.Context) error

Run starts the mesh.

type Node

type Node struct {
	Endpoint     *wireguard.Endpoint
	Key          wgtypes.Key
	NoInternalIP bool
	InternalIP   *net.IPNet
	// LastSeen is a Unix time for the last time
	// the node confirmed it was live.
	LastSeen int64
	// Leader is a suggestion to Kilo that
	// the node wants to lead its segment.
	Leader              bool
	Location            string
	Name                string
	PersistentKeepalive time.Duration
	Subnet              *net.IPNet
	WireGuardIP         *net.IPNet
	// DiscoveredEndpoints cannot be DNS endpoints, only net.UDPAddr.
	DiscoveredEndpoints map[string]*net.UDPAddr
	AllowedLocationIPs  []net.IPNet
	Granularity         Granularity
}

Node represents a node in the network.

func (*Node) Ready

func (n *Node) Ready() bool

Ready indicates whether or not the node is ready.

type NodeBackend

type NodeBackend interface {
	CleanUp(context.Context, string) error
	Get(string) (*Node, error)
	Init(context.Context) error
	List() ([]*Node, error)
	Set(context.Context, string, *Node) error
	Watch() <-chan *NodeEvent
}

NodeBackend can get nodes by name, init itself, list the nodes that should be meshed, set Kilo properties for a node, clean up any changes applied to the backend, and watch for changes to nodes.

type NodeEvent

type NodeEvent struct {
	Type EventType
	Node *Node
	Old  *Node
}

NodeEvent represents an event concerning a node in the cluster.

type Peer

type Peer struct {
	wireguard.Peer
	Name string
}

Peer represents a peer in the network.

func (*Peer) Ready

func (p *Peer) Ready() bool

Ready indicates whether or not the peer is ready. Peers can have empty endpoints because they may not have an IP, for example if they are behind a NAT, and thus will not declare their endpoint and instead allow it to be discovered.

type PeerBackend

type PeerBackend interface {
	CleanUp(context.Context, string) error
	Get(string) (*Peer, error)
	Init(context.Context) error
	List() ([]*Peer, error)
	Set(context.Context, string, *Peer) error
	Watch() <-chan *PeerEvent
}

PeerBackend can get peers by name, init itself, list the peers that should be in the mesh, set fields for a peer, clean up any changes applied to the backend, and watch for changes to peers.

type PeerEvent

type PeerEvent struct {
	Type EventType
	Peer *Peer
	Old  *Peer
}

PeerEvent represents an event concerning a peer in the cluster.

type Topology

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

Topology represents the logical structure of the overlay network.

func NewTopology

func NewTopology(nodes map[string]*Node, peers map[string]*Peer, granularity Granularity, hostname string, port int, key wgtypes.Key, subnet *net.IPNet, serviceCIDRs []*net.IPNet, persistentKeepalive time.Duration, logger log.Logger) (*Topology, error)

NewTopology creates a new Topology struct from a given set of nodes and peers.

func (*Topology) AsPeer

func (t *Topology) AsPeer() *wireguard.Peer

AsPeer generates the WireGuard peer configuration for the local location of the given Topology. This configuration can be used to configure this location as a peer of another WireGuard interface.

func (*Topology) Conf

func (t *Topology) Conf() *wireguard.Conf

Conf generates a WireGuard configuration file for a given Topology.

func (*Topology) Dot

func (t *Topology) Dot() (string, error)

Dot generates a Graphviz graph of the Topology in DOT fomat.

func (*Topology) PeerConf

func (t *Topology) PeerConf(name string) *wireguard.Conf

PeerConf generates a WireGuard configuration file for a given peer in a Topology.

func (*Topology) PeerRoutes

func (t *Topology) PeerRoutes(name string, kiloIface int, additionalAllowedIPs []net.IPNet) ([]*netlink.Route, []*netlink.Rule)

PeerRoutes generates a slice of routes and rules for a given peer in the Topology.

func (*Topology) Routes

func (t *Topology) Routes(kiloIfaceName string, kiloIface, privIface, tunlIface int, local bool, enc encapsulation.Encapsulator) ([]*netlink.Route, []*netlink.Rule)

Routes generates a slice of routes for a given Topology.

func (*Topology) Rules

func (t *Topology) Rules(cni, iptablesForwardRule bool) iptables.RuleSet

Rules returns the iptables rules required by the local node.

Jump to

Keyboard shortcuts

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