Documentation ¶
Overview ¶
Package rings provides logic to work with the four rings of a cluster
Index ¶
- Constants
- func AddrFrom4(a, b, c, d uint) netip.Addr
- func AddrFromU32(v uint32) netip.Addr
- func AddrToU32(addr netip.Addr) (v uint32, ok bool)
- func DecodeAddress[T ~uint | NodeID](addr netip.Addr) (RingID, RegionID, ZoneID, T)
- func DecodeRingOneAddress(addr netip.Addr) (RegionID, ZoneID, NodeID, bool)
- func DecodeRingZeroAddress(addr netip.Addr) (RegionID, ZoneID, NodeID, bool)
- func ErrOutOfRange[T ~int | ~uint32](value T, field string) error
- func PrefixToRange(subnet netip.Prefix) (from, to netip.Addr, ok bool)
- func RingOneAddress(region RegionID, zone ZoneID, node NodeID) (addr netip.Addr, err error)
- func RingOnePrefix(region RegionID, zone ZoneID) (cidr netip.Prefix, err error)
- func RingThreePrefix(region RegionID) (subnet netip.Prefix, err error)
- func RingTwoPrefix(region RegionID) (cidr netip.Prefix, err error)
- func RingZeroAddress(region RegionID, zone ZoneID, node NodeID) (addr netip.Addr, err error)
- func RingZeroPrefix(region RegionID, zone ZoneID) (cidr netip.Prefix, err error)
- func UnsafeRingOneAddress(region RegionID, zone ZoneID, node NodeID) netip.Addr
- func UnsafeRingThreeAddress(region RegionID, n uint) netip.Addr
- func UnsafeRingTwoAddress(region RegionID, n uint) netip.Addr
- func UnsafeRingZeroAddress(region RegionID, zone ZoneID, node NodeID) netip.Addr
- type NodeID
- type RegionID
- type Ring
- type RingID
- type ZoneID
Constants ¶
const ( // UnspecifiedRingID is the zero value of RingID and not considered // valid. UnspecifiedRingID RingID = iota RingZeroID // RingZeroID is the RingID for RingZero (backbone) RingOneID // RingOneID is the RingID for RingOne (local zone) RingTwoID // RingTwoID is the RingID for RingTwo (region services) RingThreeID // RingThreeID is the RingID for RingThree (region cluster pods) // RingMax indicates the highest [Ring] identifier RingMax = RingThreeID // RegionMax indicates the highest number that can be used for a [RegionID]. RegionMax = (1 << 4) - 1 // ZoneMax indicates the highest number that can be used for a [ZoneID]. ZoneMax = (1 << 4) - 1 // NodeMax indicates the highest number that can be used for a [NodeID]. NodeMax = (1 << 12) - 2 // NodeZeroMax indicates the highest number that can be used for a [NodeID] // when its a gateway connected to Ring 0 (backbone). NodeZeroMax = (1 << 8) - 2 // RingZeroBits indicates the size of the prefix on the ring 0 (backbone) network. RingZeroBits = 16 // RingOneBits indicates the size of the prefix on the ring 1 (lan) network. RingOneBits = 20 // RingTwoBits indicates the size of the prefix on the ring 2 (services) network // of all kubernetes clusters. RingTwoBits = 20 // RingThreeBits indicates the size of the prefix on the ring 3 (pods) network // of the kubernetes cluster of a region. RingThreeBits = 12 )
Variables ¶
This section is empty.
Functions ¶
func AddrFrom4 ¶
AddrFrom4 assembles an IPv4 address for 4 numbers. each number is truncated to 8-bits.
func AddrFromU32 ¶
AddrFromU32 converts a 32bit value into an IPv4 address.
func DecodeAddress ¶ added in v0.8.3
DecodeAddress extracts ring address fields from a given 10.0.0.0/8 address.
revive:disable:function-result-limit
func DecodeRingOneAddress ¶ added in v0.8.3
DecodeRingOneAddress attempts to extract region, zone and node identifiers from a given ring 1 address.
revive:disable:function-result-limit
func DecodeRingZeroAddress ¶ added in v0.8.3
DecodeRingZeroAddress attempts to extract region, zone and node identifiers from a given ring 0 address.
revive:disable:function-result-limit
func ErrOutOfRange ¶
ErrOutOfRange is an error indicating the value of a field is out of range.
func PrefixToRange ¶
PrefixToRange returns the beginning and end of a netip.Prefix (aka CIDR or subnet).
func RingOneAddress ¶
RingOneAddress returns a Ring 1 address for a particular node.
A ring 1 address is `10.(region_id).(zone_id << 4).(node_id)/20` but the node_id can take up to 12 bits.
func RingOnePrefix ¶
RingOnePrefix represents a (virtual) local network of a zone.
Ring 1 is `10.(region_id).(zone_id << 4).(node_id)/20` network grouped under what would be Ring 2 for region_id 0. There are 12 bits worth of nodes but nodes under 255 are special as they also get a slot on Ring 0.
func RingThreePrefix ¶
RingThreePrefix returns the subnet corresponding to the pods of a cluster.
Ring 3 is a `10.(region_id << 4).0.0/12` network
func RingTwoPrefix ¶
RingTwoPrefix represents the services of a cluster
Ring 2 subnets are of the form `10.(region_id).0.0/20`, using the address space that would belong to the ring 3 region_id 0.
func RingZeroAddress ¶
RingZeroAddress returns a Ring 0 address for a particular node.
A ring 0 address looks like 10.0.(region_id << 4 + zone_id).(node_id)/20
func RingZeroPrefix ¶
RingZeroPrefix represents the backbone that connects gateways of the different Ring 1 networks.
The ring 0 network corresponds to what would be ring 2 for region_id 0. 10.0.0.0-10.0.255.255
func UnsafeRingOneAddress ¶ added in v0.8.7
UnsafeRingOneAddress is equivalent ot RingOneAddress but without validating the input.
func UnsafeRingThreeAddress ¶ added in v0.8.7
UnsafeRingThreeAddress is equivalent ot RingThreeAddress but without validating the input.
func UnsafeRingTwoAddress ¶ added in v0.8.7
UnsafeRingTwoAddress is equivalent ot RingTwoAddress but without validating the input.
Types ¶
type NodeID ¶
type NodeID int
NodeID is the identifier of a machine within a zone of a region, valid between 1 and NodeMax, but between 1 and NodeZeroMax if it will be a zone gateway.
type RegionID ¶
type RegionID int
RegionID is the identifier of a region, valid between 1 and RegionMax.
func DecodeRingThreeAddress ¶ added in v0.8.3
DecodeRingThreeAddress attempts to extract region and unique identifier for a kubernetes pod from a given ring 3 address.
func DecodeRingTwoAddress ¶ added in v0.8.3
DecodeRingTwoAddress attempts to extract region and unique identifier for a kubernetes service from a given ring 2 address.
type Ring ¶ added in v0.8.3
type Ring interface {
ID() RingID
}
A Ring identifies what ring an address belongs to