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:
@@ -23,6 +23,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].
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package rings
|
||||
|
||||
import "net/netip"
|
||||
|
||||
// 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 := AddrFrom4(10, uint(region)<<4, 0, 0)
|
||||
subnet = netip.PrefixFrom(addr, RingThreeBits)
|
||||
}
|
||||
return subnet, err
|
||||
}
|
||||
Reference in New Issue
Block a user