Browse Source

rings: RingThreePrefix()

Ring 3 corresponds to the pods of the kubernetes cluster of a region

Signed-off-by: Alejandro Mery <amery@jpi.io>
pull/48/head
Alejandro Mery 7 months ago
parent
commit
6142d0f7f0
  1. 25
      pkg/rings/encode.go
  2. 3
      pkg/rings/rings.go

25
pkg/rings/encode.go

@ -76,6 +76,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)
@ -93,3 +108,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)
}

3
pkg/rings/rings.go

@ -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].

Loading…
Cancel
Save