rings: RingThreePrefix()
Ring 3 corresponds to the pods of the kubernetes cluster of a region Signed-off-by: Alejandro Mery <amery@jpi.io>
This commit is contained in:
@@ -24,6 +24,9 @@ const (
|
||||
RingZeroBits = 16
|
||||
// RingOneBits indicates the size of the prefix on the ring 1 (lan) network.
|
||||
RingOneBits = 20
|
||||
// RingThreeBits indicates the size of the prefix on the ring 3 (pods) network
|
||||
// of the kubernetes cluster of a region.
|
||||
RingThreeBits = 12
|
||||
)
|
||||
|
||||
// RegionID is the identifier of a region, valid between 1 and [RegionMax].
|
||||
@@ -128,6 +131,21 @@ func RingOneAddress(region RegionID, zone ZoneID, node NodeID) (addr netip.Addr,
|
||||
return addr, err
|
||||
}
|
||||
|
||||
// RingThreePrefix returns the subnet corresponding to
|
||||
// the pods of a cluster.
|
||||
//
|
||||
// Ring 3 is a `10.(region_id << 4).0.0/12` network
|
||||
func RingThreePrefix(region RegionID) (subnet netip.Prefix, err error) {
|
||||
switch {
|
||||
case !region.Valid():
|
||||
err = ErrOutOfRange(region, "region")
|
||||
default:
|
||||
addr := unsafeRingThreeAddress(region, 0)
|
||||
subnet = netip.PrefixFrom(addr, RingThreeBits)
|
||||
}
|
||||
return subnet, err
|
||||
}
|
||||
|
||||
func unsafeRingZeroAddress(region RegionID, zone ZoneID, node NodeID) netip.Addr {
|
||||
r := uint(region)
|
||||
z := uint(zone)
|
||||
@@ -146,3 +164,13 @@ func unsafeRingOneAddress(region RegionID, zone ZoneID, node NodeID) netip.Addr
|
||||
|
||||
return AddrFrom4(10, r, z<<4+n1, n0)
|
||||
}
|
||||
|
||||
func unsafeRingThreeAddress(region RegionID, n uint) netip.Addr {
|
||||
r := uint(region)
|
||||
|
||||
n2 := n >> 16
|
||||
n1 := n >> 8
|
||||
n0 := n >> 0
|
||||
|
||||
return AddrFrom4(10, r<<4+n2, n1, n0)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user