Documentation
¶
Index ¶
- Constants
- Variables
- func AllocateFor(ctx context.Context, i *ipam.T, p naming.Path, rid string) (net.IP, error)
- func CNIConfigFile(dir string, nw Networker) string
- func Check(nws []Networker) map[string]error
- func CheckForwarding(ip net.IP) error
- func ClaimFits(ctx context.Context, networkName, namespace string, p naming.Path, rid string) (bool, string, error)
- func ClaimHeldByKey(ctx context.Context, networkName, namespace string) (int, map[string]bool, error)
- func ClaimLimit(namespace, networkName string) (int, bool, error)
- func ClusterWideAllocators(n *object.Node) []*ipam.T
- func DelLink(nw Networker, name string) error
- func Driver(t string) func() Networker
- func GetNodeAddr(nodename string, network string) (net.IP, error)
- func IPReachableFrom(peerIP net.IP) (net.IP, *net.IPNet, error)
- func InReverseZones(name string, zones []string) bool
- func IncIP(ip net.IP)
- func IncIPN(ip net.IP, n int)
- func InstanceAddrs(allocators []*ipam.T, p naming.Path, st instance.Status) map[string]map[string]string
- func IsDisabled(t Networker) bool
- func IsSameNetwork(localIP, peerIP net.IP) (bool, error)
- func IsValid(t Networker) bool
- func List(noder Noder) []string
- func MACFromIP4(ip net.IP) (net.HardwareAddr, error)
- func NewAllocator(nw Networker, nodename string) (*ipam.T, error)
- func NewSetupStatus(nw Networker, err error) netstatus.Status
- func PublishStatus(owner PublishOwner) (recorded bool, loaded bool, err error)
- func PublishStop(ctx context.Context, log *plog.Logger, owner PublishOwner) error
- func RedrawFor(ctx context.Context, i *ipam.T, p naming.Path, rid string, previous net.IP) (net.IP, error)
- func ReleaseRemoved(p naming.Path, rids map[string]bool) (int, error)
- func ReverseZones(nw Networker) ([]string, error)
- func Setup(n *object.Node, names ...string) error
- func StatusDir() string
- func ValidatePublish(value string) error
- type By
- type CNIer
- type ClusterWider
- type DevNamer
- type ErrForwardingOff
- type Gatewayer
- type Grants
- type HostDever
- type IPAMer
- type Moder
- type Nameserverer
- type Netmasker
- type Networker
- type NodeAddresser
- type Noder
- type PartialError
- type Peer
- type Peerer
- type Pooler
- type Publish
- func ParsePublish(s string) (Publish, error)
- func ParsePublishes(l []string) ([]Publish, error)
- func PublishResolved(owner PublishOwner) ([]Publish, error)
- func PublishStart(ctx context.Context, log *plog.Logger, owner PublishOwner, addr net.IP, ...) ([]Publish, error)
- func PublishesBound(addr net.IP, publishes []Publish) ([]Publish, error)
- type PublishOwner
- type Reporter
- type Route
- type Routes
- type Setuper
- type Status
- type StatusList
- type T
- func (t *T) AllowEmptyNetwork() bool
- func (t *T) Config() *xconfig.T
- func (t *T) FilterIPs(ips clusterip.L) clusterip.L
- func (t *T) GetBool(s string) bool
- func (t *T) GetInt(s string) int
- func (t *T) GetString(s string) string
- func (t *T) GetStringAs(s, nodename string) string
- func (t *T) GetStrings(s string) []string
- func (t *T) GetSubnetAs(nodename string) string
- func (t *T) IPNet() (*net.IPNet, error)
- func (t *T) IPsPerNode() (int, error)
- func (t *T) IsIP6() bool
- func (t *T) IsImplicit() bool
- func (t *T) Kops() keyop.L
- func (t *T) Log() *plog.Logger
- func (t *T) Name() string
- func (t *T) Nameservers() []string
- func (t *T) NeedCommit() bool
- func (t *T) Network() string
- func (t *T) NodeSubnet(nodename string) (*net.IPNet, error)
- func (t *T) NodeSubnetIP(nodename string) (net.IP, error)
- func (t *T) Nodes() ([]string, error)
- func (t *T) Set(option, value string) error
- func (t *T) SetAllowEmptyNetwork(v bool)
- func (t *T) SetDriver(name string)
- func (t *T) SetImplicit(v bool)
- func (t *T) SetName(name string)
- func (t *T) SetNeedCommit(v bool)
- func (t *T) SetNetwork(s string)
- func (t *T) SetNoder(noder Noder)
- func (t *T) Tables() []string
- func (t *T) Type() string
- type Teardowner
- type Usage
- type VLANer
Constants ¶
const (
// CNIVersion is the version we write in the generated CNI network configuration files
CNIVersion = "0.3.0"
)
const PublishTableName = "osvc-publish"
PublishTableName is the table the forwardings of the published ports go in.
It is not the table of the networks: a network setup deletes and defines that one again in full, and the forwardings of the running resources would go with it.
Variables ¶
var (
ErrInvalidType = errors.New("invalid network type")
)
Functions ¶
func AllocateFor ¶
AllocateFor reserves an address for a resource, refusing when the namespace has already taken all it claimed of the network.
The claim is checked only when the reservation is a new one. An allocator is idempotent for a key, and it is asked again on every start, so a resource that already holds its address is not taking one more: refusing it there would stop an object the cluster let take the address in the first place, and a namespace that reached its limit could no longer restart what it runs.
func CNIConfigFile ¶
func Check ¶
Check returns, by name, the error of each network of the list that cannot be used: its ranges do not parse or leave its segment, or they overlap the addresses of a network before it in the list, which is the order of the configuration. The network declared first keeps working, and the one declared after it is the one refused, so a network added overlapping another does not take the other down with it.
A network whose segment does not parse is left to IsValid, which the setup skips it on.
func CheckForwarding ¶
CheckForwarding returns an *ErrForwardingOff when the node does not forward the packets of the family of ip: the published ports are forwarded by the node, and a node not forwarding drops them silently.
om does not set the sysctl itself: it turns the node into a router, which is the administrator's decision.
func ClaimFits ¶
func ClaimFits(ctx context.Context, networkName, namespace string, p naming.Path, rid string) (bool, string, error)
ClaimFits says whether a namespace may take one more address of a network for a resource of an object, and why not when it may not.
A namespace with no claim on the network is not capped on it, and is answered from the local configuration alone, which is what most allocations are.
A capped one is brokered. The claim is asked of the daemon, which hands the question to the node speaking for the cluster: what the namespace holds is read from what the objects of the cluster publish, an object publishes its address after it has taken it, and two claims answered from the same reading both fit where together they do not. One node answering them, counting what it has granted since, is what makes them fit one at a time.
Failing to reach the daemon leaves the claim unchecked rather than refused, for the same reason a pool claim is: a cap is something the cluster brokers, and where there is no daemon to ask there is nothing brokering.
func ClaimHeldByKey ¶
func ClaimHeldByKey(ctx context.Context, networkName, namespace string) (int, map[string]bool, error)
ClaimHeldByKey is how many addresses of a network a namespace holds, and the reservations they are held for.
Addresses are counted, not reservations: a failover object holds the same address on every node it is configured on, and that is one address taken from the network, while the instances of a flex each hold one of their own. The reservations are answered alongside so that a claim granted a moment ago and not yet reported can be told apart from one the cluster has caught up with.
Two views are merged. The cluster reports the addresses its objects publish in their status, which is the only way to see the other nodes, but a status is published after the fact: an address reserved a moment ago is not in it yet. The allocator of this node has no such lag, and this is read where every claim is answered, so what it adds is this node's own reservations, including the ones made before there was anything brokering. An address in both is one address. A network every node draws from adds a third view, the stores of the other nodes.
func ClaimLimit ¶
ClaimLimit is the most addresses a namespace may hold in a network, and whether it is capped on it at all.
func ClusterWideAllocators ¶
ClusterWideAllocators returns the allocators of this node in the networks every node draws from.
func InReverseZones ¶
InReverseZones says whether the reverse name, as a PTR record names it, is in one of the zones.
func InstanceAddrs ¶
func InstanceAddrs(allocators []*ipam.T, p naming.Path, st instance.Status) map[string]map[string]string
InstanceAddrs returns the addresses an instance status reports holding in the ranges of the allocators, by network name, each the key of the resource reporting it.
func IsDisabled ¶
IsDisabled returns true if the network keyword value is "none"
func MACFromIP4 ¶
func MACFromIP4(ip net.IP) (net.HardwareAddr, error)
MACFromIP4 returns a mac address using a 0a:58 prefix followed by the bridge ipv4 address converted to hexa (same algorithm used in k8s).
When the device with the lowest mac is removed from the bridge or when a new device with the lowest mac is added to the bridge, all containers can experience tcp hangs while the arp table resynchronizes.
Setting a mac address to the bridge explicitly avoids these mac address changes.
func NewAllocator ¶
NewAllocator returns the allocator of a network on a node, or nil when the network is one om allocates no address in.
func NewSetupStatus ¶
NewSetupStatus returns what the setup of nw made on the node, err its failure.
func PublishStatus ¶
func PublishStatus(owner PublishOwner) (recorded bool, loaded bool, err error)
PublishStatus says whether the forwardings of owner are recorded and loaded: the table holds a rule of the owner for every publish recorded. An owner recorded with rules missing, as ones an administrator deleted or a table flushed, is forwarded no more.
func PublishStop ¶
PublishStop removes the forwardings of owner. A resource publishing nothing has nothing to remove.
func RedrawFor ¶
func RedrawFor(ctx context.Context, i *ipam.T, p naming.Path, rid string, previous net.IP) (net.IP, error)
RedrawFor releases the address a resource holds, previous, and reserves another one.
It is what a resource whose recorded address was taken away asks for: the address it holds is the one it is to give up, so neither the reservation of this node nor the one it holds on another node is taken back.
A redraw that fails holds previous again, so the next one still knows what to give up.
func ReleaseRemoved ¶
ReleaseRemoved releases the addresses this node holds for the resources of an object that its configuration no longer has, the resources of rids being the ones it still has.
A resource is released when it is unprovisioned, which a section taken away from the configuration skips: its reservation would stay, out of the pool and counted against the claim of the namespace, until the object is deleted.
func ReverseZones ¶
ReverseZones returns the reverse zones holding the PTR records of the addresses om hands out from the network, with no trailing dot: the ones of the ranges of a network handing out some of its segment only, as a lan network, else the ones of the whole network.
A zone is cut at an octet boundary for ipv4 and at a nibble boundary for ipv6, the finest covering the addresses and no others: the zones the cluster answers for hold none of the addresses it does not hand out, as the ones of the nodes, which the cluster nameservers would otherwise say do not exist. A /22 is four /24 zones, a /16 one, a range of a few addresses a zone each.
The lo network hands out no address, and has none.
func Setup ¶
Setup sets up the networks named, all of them when none is named, and the firewall rules of every network, and tears down the networks whose configuration was removed since the last setup.
The firewall rules of the networks are one ruleset, rewritten whole: rendered from the networks named only, as the daemon sets up the one whose configuration changed, it dropped the rules of the others, and the containers of their networks lost their way out.
func StatusDir ¶
func StatusDir() string
StatusDir is the directory the setup saves the status of each network in.
func ValidatePublish ¶
ValidatePublish validates the value of a publish keyword, a whitespace separated list of declarations.
Types ¶
type ClusterWider ¶
type ClusterWider interface {
IsClusterWide() bool
}
ClusterWider is implemented by the network drivers whose range is the same on every node, its addresses routable to whichever node holds them: an address drawn there is one of the cluster, which a failover object takes along to the node it moves to, rather than one of a node.
type DevNamer ¶
type DevNamer interface {
NamedDev() string
}
DevNamer is implemented by the network drivers naming the interface of the node in their configuration. Unlike HostDev, it returns nothing found on the node, empty when the configuration names none.
type ErrForwardingOff ¶
type ErrForwardingOff struct {
// Sysctl is the sysctl to set to 1, as net.ipv4.ip_forward.
Sysctl string
// Value is the value it has.
Value string
}
ErrForwardingOff is the node not forwarding the packets of a family, so not the ones of the published ports either. It says the fact only: the caller words it for where it is shown, and the publish keyword documents the fix.
func (*ErrForwardingOff) Error ¶
func (t *ErrForwardingOff) Error() string
type Gatewayer ¶
Gatewayer is implemented by the network drivers that name the router the addresses drawn from them reach beyond the segment through, nil when they name none.
type Grants ¶
type Grants struct {
// contains filtered or unexported fields
}
Grants is the addresses a node has let namespaces take of the networks, waiting for the cluster to report them.
A claim counts the addresses the namespace holds, read from what the objects of the cluster publish. An object publishes its address after it has taken it, so a claim answered from that reading alone misses every address taken since: two resources reserving at once are each answered as though the other had not. Counting the grants too closes that window, and holding them here is what makes the answer and the record one step rather than two.
A grant is held for the reservation it was granted for, which is a resource of an object, so that the cluster reporting an address for that resource is what releases it.
func (*Grants) Fits ¶
func (t *Grants) Fits(namespace, networkName, key string, limit, held int, seen map[string]bool, now time.Time) (bool, string)
Fits says whether a namespace may take one more address of a network for a reservation, and records the grant when it may.
held is how many addresses of the network the namespace is known to hold, and seen is the reservations those addresses are held for. A reservation already holding an address takes no new one: an object failing over to another node reserves the address it already has, and a claim asked twice for the same resource is the same address twice.
func (*Grants) Seed ¶
Seed records a grant this node did not answer.
It is how a table lost is rebuilt. The grants of a node are in memory, so a node that has just started, or has just become the one answering claims, has none of them and answers from what the objects of the cluster have published alone, which is the reading the grants exist to complete.
What was granted and reserved is not lost, though: the node that reserved it publishes it before the others hear of it. What was granted and never reserved is lost, and expiring is what would have become of it anyway.
type HostDever ¶
HostDever is implemented by the network drivers whose addresses are configured on an interface of the node, rather than on a bridge the network sets up. It returns the interface of this node.
type IPAMer ¶
type IPAMer interface {
// AllocatableRange returns the addresses a node draws from in this
// network. The gateway of that range is its first address plus one,
// which is how both drivers derive the address of their bridge.
AllocatableRange(nodename string) (*net.IPNet, error)
}
IPAMer is implemented by the network drivers whose addresses om allocates. A driver that does not implement it has om allocate nothing in it, which is what the lo network wants.
type Moder ¶
type Moder interface {
Modes() []string
}
Moder is implemented by the network drivers saying the modes an ip.netns may join their segment with, the first being the one of an ip.netns naming none. None when the network says nothing of them.
type Nameserverer ¶
type Nameserverer interface {
Nameservers() []string
}
Nameserverer is implemented by the networks saying the nameservers reachable from them, none when they say none.
type Netmasker ¶
Netmasker is implemented by the network drivers whose addresses are configured with the prefix length of the segment they are drawn from, rather than the one of a bridge.
type Networker ¶
type Networker interface {
// SetDriver sets the driver name, which is obtained from the
// "type" keyword in the network configuration.
SetDriver(string)
// SetName sets the network name. See Name().
SetName(string)
// SetImplicit sets isImplicit. See IsImplicit().
SetImplicit(bool)
// SetNetwork sets the network CIDR. Normally read from the
// merged cluster configuration.
SetNetwork(string)
// SetNeedCommit can be called by drivers to signal network
// configuration changes are staged and // need to be written
// to file.
SetNeedCommit(bool)
// SetNoder stores the Noder
SetNoder(Noder)
// IsImplicit returns true if the network is a builtin with
// no override section in the configuration.
IsImplicit() bool
// IsIP6 returns true if the network is a CIDR representation
// of a IPv6 network.
IsIP6() bool
// Name returns the name of the network. Which is the part
// after the dash in the configuration section name.
Name() string
// Kops returns the list of cluster config changes queued by the
// driver upon Setup.
Kops() keyop.L
// Network returns the CIDR representation of the network.
Network() string
// IPNet returns the result of ParseCIDR() on the Network()
// CIDR string, without the net.IP
IPNet() (*net.IPNet, error)
// NeedCommit return true if the network configuration cache
// has staged changes. This can be used by Networks() users to
// do one commit per action instead of one per network.
NeedCommit() bool
// Type return the driver name.
Type() string
FilterIPs(clusterip.L) clusterip.L
AllowEmptyNetwork() bool
// Config is a wrapper for the noder MergedConfig
Config() *xconfig.T
// Log returns a zerolog Logger configured to add the network
// name to log entries.
Log() *plog.Logger
// Nodes is a wrapper for the noder Nodes, which returns the
// list of cluster nodes to make the network available on.
Nodes() ([]string, error)
NodeSubnet(nodename string) (*net.IPNet, error)
NodeSubnetIP(nodename string) (net.IP, error)
}
func NewFromNoder ¶
type NodeAddresser ¶
NodeAddresser is implemented by the network drivers giving each node a subnet of its own, whose first address is the node's: what reaches a node in the network, as the drbd traffic a disk.drbd sends there.
type PartialError ¶
type PartialError struct {
Err error
}
PartialError is the error of a setup that left the network usable on the node, its failures confined to a part of it, as the route or the tunnel to one peer: the rest of the network is set up all the same, and its cni configuration written, so the objects of the node use it.
func (*PartialError) Error ¶
func (t *PartialError) Error() string
func (*PartialError) Unwrap ¶
func (t *PartialError) Unwrap() error
type Peerer ¶
Peerer is implemented by the network drivers reaching the other nodes themselves, by a route or a tunnel. It returns how this node reaches each of them.
type Pooler ¶
Pooler is implemented by the network drivers handing out some of the addresses of their range only, which it returns.
type Publish ¶
type Publish struct {
// HostAddr restricts the forwarding to the packets sent to that
// address of the node. Nil forwards the port of every address.
HostAddr net.IP `json:"host_addr,omitempty"`
// HostPort is the port of the node the clients connect to. Zero in a
// declaration is a port of the node drawn at start.
HostPort int `json:"host_port"`
// Port is the port of the address of the resource the connections are
// forwarded to.
Port int `json:"port"`
// Proto is tcp or udp.
Proto string `json:"proto"`
// Auto says the host port was drawn, as the declaration named none.
Auto bool `json:"auto,omitempty"`
}
Publish is a port of the node forwarded to a port of an address om plumbed, as the publish keyword of an ip resource declares it:
[<host addr>:][<host port>:]<port>[/<proto>]
A publish naming no host port is given a free port of the node when the resource starts, kept while it runs.
The forwarding is done by the node, against the address of the resource, so it works whatever runs in the namespace holding that address: no container engine flag is involved.
func ParsePublish ¶
ParsePublish reads one publish declaration:
25489:80 node port 25489 to port 80 of the address, tcp 25489:80/udp the same in udp 80 a free port of the node, drawn at start, to port 80 10.0.0.5:8443:443 only the packets sent to 10.0.0.5 10.0.0.5::443 a free port of 10.0.0.5, drawn at start [fd00::5]:8443:443 an ipv6 address of the node, in brackets
func ParsePublishes ¶
ParsePublishes reads the declarations of a resource, and refuses two of them claiming the same port of the node, or drawing one for the same port of the address on the same addresses of the node.
func PublishResolved ¶
func PublishResolved(owner PublishOwner) ([]Publish, error)
PublishResolved returns the publishes of owner as its start resolved them, the drawn host ports given, or nil when it publishes nothing.
func PublishStart ¶
func PublishStart(ctx context.Context, log *plog.Logger, owner PublishOwner, addr net.IP, subnet *net.IPNet, publishes []Publish) ([]Publish, error)
PublishStart forwards the publishes to addr, on the network subnet, and records them under key, the resource they are of. It refuses a port of the node another resource already publishes. Starting again with other publishes replaces the ones of the key.
func PublishesBound ¶
PublishesBound returns the publishes to addr whose port of the node a socket of the node holds too: the forwarding takes the connections that process waits for. A socket of a loopback address alone is no conflict, its connections not being forwarded, nor a socket of the other family than addr, which the forwarding of that family does not take the connections of, a v6only ipv6 wildcard socket for an ipv4 addr included.
Nothing keeps a process of the node from binding a published port, the one drawn for a publish naming none included: the status says it.
func (Publish) Declared ¶
Declared returns the publish as it was declared: a drawn host port is forgotten.
type PublishOwner ¶
PublishOwner is the resource the publishes of an entry are of.
func (PublishOwner) String ¶
func (t PublishOwner) String() string
String is the key of the owner, the comment of its rules.
type Reporter ¶
Reporter is implemented by the network drivers saying what their setup made on the node beyond what every network says: the part of the network the node hands out, and the peers as the setup reached them, with the failure of each.
type Route ¶
type Status ¶
type Status struct {
Name string `json:"name"`
Type string `json:"type"`
Network string `json:"network"`
IPs clusterip.L `json:"ips"`
Errors []string `json:"errors,omitempty"`
Usage
}
func GetStatus ¶
GetStatus returns the usage of the network. The usage counts are always set, rather than leaving its readers a nil count to dereference: a network whose range does not parse has a zero size and says why in its errors, and a network whose driver allows no range, as the loopback one, has a zero size and no error, as IsValid accepts it.
type StatusList ¶
type StatusList []Status
func NewStatusList ¶
func NewStatusList() StatusList
func ShowNetworks ¶
func ShowNetworks(noder Noder, ips clusterip.L) StatusList
func ShowNetworksByName ¶
func ShowNetworksByName(noder Noder, name string, ips clusterip.L) StatusList
func (StatusList) Add ¶
func (t StatusList) Add(p Networker, ips clusterip.L) StatusList
func (StatusList) Len ¶
func (t StatusList) Len() int
func (StatusList) Less ¶
func (t StatusList) Less(i, j int) bool
func (StatusList) Swap ¶
func (t StatusList) Swap(i, j int)
type T ¶
type T struct {
// contains filtered or unexported fields
}
func (*T) AllowEmptyNetwork ¶
AllowEmptyNetwork returns true if the driver supports empty "network" keyword value. For one, the loopback driver does support that.
func (*T) GetStringAs ¶
func (*T) GetStrings ¶
func (*T) GetSubnetAs ¶
func (*T) IPsPerNode ¶
func (*T) IsImplicit ¶
func (*T) Nameservers ¶
Nameservers returns the nameservers reachable from the network, which the dns keyword lists.
func (*T) NeedCommit ¶
func (*T) NodeSubnet ¶
NodeSubnet returns the network subnet assigned to a cluster node, as a *net.IPNet. This subnet is usually found in the network configuration, as a subnet@<nodename> option. If not found there, allocate and write one.
The subnet allocator uses ips_per_node to compute a netmask (narrower than the network mask). The subnet first ip is computed using the position of the node in the cluster nodes list.
Example: With
cluster.nodes = n1 n2 n3 net1.network = 10.0.0.0/24 net1.ips_per_node = 64
=>
subnet@n1 = 10.0.0.0/26 subnet@n2 = 10.0.0.64/26 subnet@n3 = 10.0.0.128/26
func (*T) SetAllowEmptyNetwork ¶
func (*T) SetImplicit ¶
func (*T) SetNeedCommit ¶
func (*T) SetNetwork ¶
type Teardowner ¶
type Teardowner interface {
Teardown() error
}
Teardowner is the interface of the networks undoing on the node what their setup made, their configuration removed.