Documentation ¶
Overview ¶
Package cluster contains information about the cluster
Index ¶
- Constants
- Variables
- func DefaultLogger() slog.Logger
- func DefaultLookuper() resolver.Lookuper
- func DirFS(dir string) (fs.FS, error)
- func ParseRingOneAddress(addr netip.Addr) (zoneID int, nodeID int, ok bool)
- func ParseRingZeroAddress(addr netip.Addr) (zoneID int, nodeID int, ok bool)
- func RingOneAddress(zoneID, nodeID int) (netip.Addr, bool)
- func RingZeroAddress(zoneID, nodeID int) (netip.Addr, bool)
- func SortRegions(regions []string) []string
- func ValidNodeID(nodeID int) bool
- func ValidZoneID(zoneID int) bool
- type Cluster
- func (m *Cluster) CreateFile(name string, args ...any) (io.WriteCloser, error)
- func (m *Cluster) CreateTruncFile(name string, args ...any) (io.WriteCloser, error)
- func (m *Cluster) Env(export bool) (*Env, error)
- func (m *Cluster) ForEachMachine(fn func(*Machine) bool)
- func (m *Cluster) ForEachRegion(fn func(r *Region) bool)
- func (m *Cluster) ForEachZone(fn func(*Zone) bool)
- func (m *Cluster) GenCephConfig() (*ceph.Config, error)
- func (m *Cluster) GetCephConfig() (*ceph.Config, error)
- func (m *Cluster) GetCephFSID() (uuid.UUID, error)
- func (m *Cluster) GetMachineByName(name string) (*Machine, bool)
- func (m *Cluster) MkdirAll(name string, args ...any) error
- func (m *Cluster) OpenFile(name string, flags int, args ...any) (fs.File, error)
- func (m *Cluster) PruneWireguardConfig(ring int) error
- func (m *Cluster) ReadFile(name string, args ...any) ([]byte, error)
- func (m *Cluster) ReadLines(name string, args ...any) ([]string, error)
- func (m *Cluster) RemoveFile(name string, args ...any) error
- func (m *Cluster) SyncAll() error
- func (m *Cluster) SyncAllCeph() error
- func (m *Cluster) SyncAllRegions() error
- func (m *Cluster) SyncAllWireguard() error
- func (m *Cluster) SyncMkdirAll() error
- func (m *Cluster) SyncWireguardConfig(ring int) error
- func (m *Cluster) WriteCephConfig(cfg *ceph.Config) error
- func (m *Cluster) WriteHosts() error
- func (m *Cluster) WriteStringFile(value string, name string, args ...any) error
- func (m *Cluster) WriteWireguardConfig(ring int) error
- func (m *Cluster) WriteWireguardKeys(ring int) error
- type Env
- type Machine
- func (m *Machine) CreateFile(name string, args ...any) (io.WriteCloser, error)
- func (m *Machine) CreateTruncFile(name string, args ...any) (io.WriteCloser, error)
- func (m *Machine) FullName() string
- func (m *Machine) GetWireguardConfig(ring int) (*wireguard.Config, error)
- func (m *Machine) GetWireguardKeys(ring int) (wireguard.KeyPair, error)
- func (m *Machine) IsActive() bool
- func (m *Machine) IsGateway() bool
- func (m *Machine) LookupNetIP(timeout time.Duration) ([]netip.Addr, error)
- func (m *Machine) MkdirAll(name string, args ...any) error
- func (m *Machine) OpenFile(name string, flags int, args ...any) (fs.File, error)
- func (m *Machine) PruneWireguardConfig(ring int) error
- func (m *Machine) ReadFile(name string, args ...any) ([]byte, error)
- func (m *Machine) ReadLines(name string, args ...any) ([]string, error)
- func (m *Machine) RemoveFile(name string, args ...any) error
- func (m *Machine) RemoveWireguardConfig(ring int) error
- func (m *Machine) RemoveWireguardKeys(ring int) error
- func (m *Machine) SetGateway(enabled bool) error
- func (m *Machine) String() string
- func (m *Machine) SyncWireguardConfig(ring int) error
- func (m *Machine) UpdatePublicAddresses() error
- func (p *Machine) WriteHosts() error
- func (m *Machine) WriteStringFile(value string, name string, args ...any) error
- func (m *Machine) WriteWireguardConfig(ring int) error
- func (m *Machine) WriteWireguardKeys(ring int) error
- func (m *Machine) Zone() int
- type MachineIterator
- type Machines
- type Region
- type RegionIterator
- type Ring
- type RingAddressEncoder
- type RingInfo
- type RingPeer
- type ScanOption
- type ScanOptions
- type WireguardConfigPruner
- type WireguardConfigSyncer
- type WireguardConfigWriter
- type WireguardKeysWriter
- type Zone
- func (z *Zone) ForEachRegion(fn func(*Region) bool)
- func (z *Zone) GatewayIDs() ([]int, int)
- func (z *Zone) GetCephMonitors() Machines
- func (z *Zone) GetGateway() (*Machine, bool, error)
- func (z *Zone) Hosts() string
- func (z *Zone) PruneWireguardConfig(ring int) error
- func (z *Zone) SetGateway(gatewayID int, enabled bool) error
- func (z *Zone) String() string
- func (z *Zone) SyncRegions() error
- func (z *Zone) SyncWireguardConfig(ring int) error
- func (z *Zone) WriteHosts() error
- func (z *Zone) WriteWireguardConfig(ring int) error
- func (z *Zone) WriteWireguardKeys(ring int) error
- type ZoneIterator
Constants ¶
const ( // ZoneRegionsFileName indicates the file containing // region names as references ZoneRegionsFileName = "regions" // RegionClusterTokenFileName contains the kubernetes // token of the cluster this region represents RegionClusterTokenFileName = "k8s_token" )
const ( // MaxZoneID indicates the highest ID allowed for a Zone MaxZoneID = 0xf // MaxNodeID indicates the highest Machine ID allowed within a Zone MaxNodeID = 0xff - 1 // RingsCount indicates how many wireguard rings we have RingsCount = 2 // RingZeroPort is the port wireguard uses for ring0 RingZeroPort = 51800 // RingOnePort is the port wireguard uses for ring1 RingOnePort = 51810 )
Variables ¶
var ( // ErrInvalidName indicates the name isn't valid ErrInvalidName = errors.New("invalid name") // ErrUnknownNode indicates there is a reference to a node // we don't have on the tree ErrUnknownNode = errors.New("node does not exist") // ErrInvalidNode indicates the nodes can't be used for // the intended purpose ErrInvalidNode = errors.New("invalid node") )
var ( // RingZero is a wg0 address encoder/decoder RingZero = RingAddressEncoder{ ID: 0, Port: RingZeroPort, Decode: ParseRingZeroAddress, Encode: RingZeroAddress, } // RingOne is a wg1 address encoder/decoder RingOne = RingAddressEncoder{ ID: 1, Port: RingOnePort, Decode: ParseRingOneAddress, Encode: RingOneAddress, } // Rings provides indexed access to the ring address encoders Rings = [RingsCount]RingAddressEncoder{ RingZero, RingOne, } )
Functions ¶
func DefaultLogger ¶
DefaultLogger returns a logger that doesn't log anything
func DefaultLookuper ¶
DefaultLookuper returns a resolver.Lookuper using Cloudflare's 1.1.1.1
func DirFS ¶ added in v0.6.2
DirFS returns a file system (an [fs.FS]) for the tree of files rooted at the directory dir.
func ParseRingOneAddress ¶
ParseRingOneAddress extracts zone and node ID from a wg1 netip.Addr wg1 addresses are of the form `10.{{zoneID << 4}}.{{nodeID}}`
func ParseRingZeroAddress ¶
ParseRingZeroAddress extracts zone and node ID from a wg0 netip.Addr wg0 addresses are of the form `10.0.{{zoneID}}.{{nodeID}}`
func RingOneAddress ¶
RingOneAddress returns a wg1 IP address
func RingZeroAddress ¶
RingZeroAddress returns a wg0 IP address
func SortRegions ¶ added in v0.6.11
SortRegions sorts regions. first by length those 3-character or shorter, and then by length. It's mostly aimed at supporting ISO-3166 order
func ValidNodeID ¶
ValidNodeID checks if the given nodeID is a valid 8 bit number. nodeID is unique within a Zone. 0 is reserved, and only allowed when composing CIDRs.
func ValidZoneID ¶
ValidZoneID checks if the given zoneID is a valid 4 bit zone number.
0 is reserved, and only allowed when composing CIDRs.
Types ¶
type Cluster ¶
type Cluster struct { BaseDir string `json:"dir,omitempty" yaml:"dir,omitempty"` Name string `json:"name,omitempty" yaml:"name,omitempty"` Domain string `json:"domain,omitempty" yaml:"domain,omitempty"` CephFSID uuid.UUID `json:"ceph_fsid,omitempty" yaml:"ceph_fsid,omitempty"` Regions []Region `json:",omitempty" yaml:",omitempty"` Zones []*Zone `json:",omitempty" yaml:",omitempty"` // contains filtered or unexported fields }
Cluster represents all zones in a cluster
func NewFromConfig ¶ added in v0.6.2
func NewFromConfig(filename string, opts ...ScanOption) (*Cluster, error)
NewFromConfig loads the cluster data from the given file
func NewFromDirectory ¶
func NewFromDirectory(dir, domain string, opts ...ScanOption) (*Cluster, error)
NewFromDirectory builds a Cluster tree using the given directory
func (*Cluster) CreateFile ¶
CreateFile creates a file on the cluster's config directory
func (*Cluster) CreateTruncFile ¶
CreateTruncFile creates or truncates a file on the cluster's config directory
func (*Cluster) ForEachMachine ¶
ForEachMachine calls a function for each Machine in the cluster until instructed to terminate the loop
func (*Cluster) ForEachRegion ¶ added in v0.6.6
ForEachRegion calls a function for each Region of the cluster until instructed to terminate the loop
func (*Cluster) ForEachZone ¶
ForEachZone calls a function for each Zone in the cluster until instructed to terminate the loop
func (*Cluster) GenCephConfig ¶
GenCephConfig prepares a ceph.Config using the cluster information
func (*Cluster) GetCephConfig ¶
GetCephConfig reads the ceph.conf file
func (*Cluster) GetCephFSID ¶
GetCephFSID returns our Ceph's FSID
func (*Cluster) GetMachineByName ¶
GetMachineByName looks for a machine with the specified name on any zone
func (*Cluster) MkdirAll ¶ added in v0.6.11
MkdirAll creates directories relative to the cluster's config directory
func (*Cluster) OpenFile ¶
OpenFile opens a file on the cluster's config directory with the specified flags
func (*Cluster) PruneWireguardConfig ¶
PruneWireguardConfig removes wgN.conf files of machines with the corresponding ring disabled on all zones
func (*Cluster) ReadLines ¶ added in v0.6.11
ReadLines reads a file from the cluster's config directory, split by lines, trimmed, and accepting `#` to comment lines out.
func (*Cluster) RemoveFile ¶ added in v0.6.11
RemoveFile deletes a file from the cluster's config directory
func (*Cluster) SyncAllCeph ¶
SyncAllCeph updates the ceph.conf file
func (*Cluster) SyncAllRegions ¶ added in v0.6.12
SyncAllRegions rewrites all region data
func (*Cluster) SyncAllWireguard ¶
SyncAllWireguard updates all wireguard config files
func (*Cluster) SyncMkdirAll ¶ added in v0.6.11
SyncMkdirAll creates the directories needed to store files required to represent the cluster.
func (*Cluster) SyncWireguardConfig ¶
SyncWireguardConfig updates all wgN.conf files for the specified ring
func (*Cluster) WriteCephConfig ¶
WriteCephConfig writes the ceph.conf file
func (*Cluster) WriteHosts ¶ added in v0.6.1
WriteHosts rewrites all hosts files on the tree
func (*Cluster) WriteStringFile ¶ added in v0.6.11
WriteStringFile writes the given content to a file on the machine's config directory
func (*Cluster) WriteWireguardConfig ¶
WriteWireguardConfig rewrites all wgN.conf on all machines attached to that ring
func (*Cluster) WriteWireguardKeys ¶
WriteWireguardKeys rewrites all wgN.{key,pub} files
type Env ¶
type Env struct { ZoneIterator RegionIterator // contains filtered or unexported fields }
Env is a shell environment factory for this cluster
type Machine ¶
type Machine struct { ID int Name string `json:"-" yaml:"-"` Inactive bool `json:"inactive,omitempty" yaml:"inactive,omitempty"` CephMonitor bool `json:"ceph_monitor,omitempty" yaml:"ceph_monitor,omitempty"` PublicAddresses []netip.Addr `json:"public,omitempty" yaml:"public,omitempty"` Rings []*RingInfo `json:"rings,omitempty" yaml:"rings,omitempty"` // contains filtered or unexported fields }
A Machine is a machine on a Zone
func (*Machine) CreateFile ¶
CreateFile creates a file on the machine's config directory
func (*Machine) CreateTruncFile ¶
CreateTruncFile creates or truncates a file on the machine's config directory
func (*Machine) GetWireguardConfig ¶
GetWireguardConfig reads a wgN.conf file
func (*Machine) GetWireguardKeys ¶
GetWireguardKeys reads a wgN.key/wgN.pub files
func (*Machine) IsActive ¶ added in v0.6.11
IsActive indicates the machine is to be included in regions' DNS entries
func (*Machine) LookupNetIP ¶
LookupNetIP uses the DNS Resolver to get the public addresses associated to a Machine
func (*Machine) MkdirAll ¶ added in v0.6.11
MkdirAll creates directories relative to the machine's config directory
func (*Machine) OpenFile ¶
OpenFile opens a file on the machine's config directory with the specified flags
func (*Machine) PruneWireguardConfig ¶
PruneWireguardConfig deletes the wgN.conf file if its presence on the ring is disabled
func (*Machine) ReadLines ¶ added in v0.6.11
ReadLines reads a file from the machine's config directory, split by lines, trimmed, and accepting `#` to comment lines out.
func (*Machine) RemoveFile ¶
RemoveFile deletes a file from the machine's config directory
func (*Machine) RemoveWireguardConfig ¶
RemoveWireguardConfig deletes wgN.conf from the machine's config directory.
func (*Machine) RemoveWireguardKeys ¶
RemoveWireguardKeys deletes wgN.key and wgN.pub from the machine's config directory
func (*Machine) SetGateway ¶
SetGateway enables/disables a Machine ring0 integration
func (*Machine) SyncWireguardConfig ¶
SyncWireguardConfig updates all wgN.conf files for the specified ring
func (*Machine) UpdatePublicAddresses ¶
UpdatePublicAddresses uses the DNS Resolver to set Machine.PublicAddresses
func (*Machine) WriteHosts ¶ added in v0.6.1
WriteHosts rewrites the hosts file
func (*Machine) WriteStringFile ¶
WriteStringFile writes the given content to a file on the machine's config directory
func (*Machine) WriteWireguardConfig ¶
WriteWireguardConfig rewrites the wgN.conf file of this Machine if enabled
func (*Machine) WriteWireguardKeys ¶
WriteWireguardKeys writes the wgN.key/wgN.pub files
type MachineIterator ¶
A MachineIterator is a set of Machines we can iterate on
type Machines ¶
type Machines []*Machine
Machines is a list of Machine objects
func FilterMachines ¶
func FilterMachines(m MachineIterator, cond func(*Machine) bool) (Machines, int)
FilterMachines produces a subset of the machines offered by the given iterator fulfilling a condition
func (Machines) ForEachMachine ¶
ForEachMachine calls a function for each Machine in the list until instructed to terminate the loop
type Region ¶ added in v0.6.4
type Region struct { Name string Cluster *string `json:",omitempty" yaml:",omitempty"` Regions []string `json:",omitempty" yaml:",omitempty"` // contains filtered or unexported fields }
Region represents a group of zones geographically related
func (*Region) ForEachMachine ¶ added in v0.6.6
ForEachMachine calls a function for each Machine in the region until instructed to terminate the loop
func (*Region) ForEachZone ¶ added in v0.6.6
ForEachZone calls a function for each Zone in the region until instructed to terminate the loop
func (*Region) SyncRegions ¶ added in v0.6.12
SyncRegions writes to the file system the regions covered by this meta-region
type RegionIterator ¶ added in v0.8.0
A RegionIterator is a set of Regions we can iterate on
type Ring ¶
type Ring struct { RingAddressEncoder ZoneIterator Peers []*RingPeer }
A Ring describes all peers on a ring
func NewRing ¶
func NewRing(z ZoneIterator, m MachineIterator, ring int) (*Ring, error)
NewRing composes a new Ring for Wireguard setup
func (*Ring) ExportConfig ¶
ExportConfig builds a wgN.conf for the specified machine on the ring
func (*Ring) ForEachMachine ¶
ForEachMachine calls a function for each Machine in the ring until instructed to terminate the loop
type RingAddressEncoder ¶
type RingAddressEncoder struct { ID int Port uint16 Encode func(zoneID, nodeID int) (netip.Addr, bool) Decode func(addr netip.Addr) (zoneID, nodeID int, ok bool) }
RingAddressEncoder provides encoder/decoder access for a particular Wireguard ring
type RingInfo ¶
RingInfo contains represents the Wireguard endpoint details for a Machine on a particular ring
type RingPeer ¶
type RingPeer struct { Node *Machine Address netip.Addr PrivateKey wireguard.PrivateKey PeerConfig wireguard.PeerConfig }
A RingPeer is a node on a Ring
type ScanOption ¶
type ScanOption func(*Cluster, *ScanOptions) error
A ScanOption pre-configures the Zones before scanning
func ResolvePublicAddresses ¶
func ResolvePublicAddresses(resolve bool) ScanOption
ResolvePublicAddresses instructs the scanner to use the DNS resolver to get PublicAddresses of nodes. Default is true
func WithLogger ¶
func WithLogger(log slog.Logger) ScanOption
WithLogger specifies what to use for logging
func WithLookuper ¶
func WithLookuper(h resolver.Lookuper) ScanOption
WithLookuper specifies what resolver.Lookuper to use to find public addresses
func WithResolver ¶
func WithResolver(h resolver.Resolver) ScanOption
WithResolver specifies what resolver to use to find public addresses. if nil is passed, the net.Resolver will be used. The default is using Cloudflare's 1.1.1.1.
type ScanOptions ¶
type ScanOptions struct { // DontResolvePublicAddresses indicates we shouldn't // pre-populate Machine.PublicAddresses during the // initial scan DontResolvePublicAddresses bool // Logger specifies the logger to be used. otherwise // the scanner will be mute slog.Logger }
ScanOptions contains flags used by the initial scan
type WireguardConfigPruner ¶
A WireguardConfigPruner deletes wgN.conf on all machines under its scope with the specified ring disabled
type WireguardConfigSyncer ¶
A WireguardConfigSyncer updates all wgN.conf on all machines under its scope reflecting the state of the ring
type WireguardConfigWriter ¶
A WireguardConfigWriter rewrites all wgN.conf on all machines under its scope attached to that ring
type WireguardKeysWriter ¶
A WireguardKeysWriter writes the Wireguard Keys for all machines under its scope for the specified ring
type Zone ¶
type Zone struct { ID int Name string Regions []string `json:",omitempty" yaml:",omitempty"` Machines // contains filtered or unexported fields }
A Zone is a set of machines in close proximity and strong affinity.
func (*Zone) ForEachRegion ¶ added in v0.8.0
ForEachRegion calls a function on all regions this zone belongs to.
func (*Zone) GatewayIDs ¶
GatewayIDs returns the list of IDs of machines that act as ring0 gateways
func (*Zone) GetCephMonitors ¶
GetCephMonitors returns the set of Ceph monitors on the zone
func (*Zone) GetGateway ¶
GetGateway returns the first gateway found, if none files will be created to enable the first Machine to be one
func (*Zone) PruneWireguardConfig ¶
PruneWireguardConfig removes wgN.conf files of machines with the corresponding ring disabled.
func (*Zone) SetGateway ¶
SetGateway configures a machine to be the zone's ring0 gateway
func (*Zone) SyncRegions ¶ added in v0.6.12
SyncRegions writes to the file system the regions this Zone belongs to.
func (*Zone) SyncWireguardConfig ¶
SyncWireguardConfig updates all wgN.conf files for the specified ring
func (*Zone) WriteHosts ¶ added in v0.6.1
WriteHosts rewrites all hosts files in the zone
func (*Zone) WriteWireguardConfig ¶
WriteWireguardConfig rewrites all wgN.conf on all machines on the Zone attached to that ring
func (*Zone) WriteWireguardKeys ¶
WriteWireguardKeys rewrites all wgN.{key,pub} files on this zone
type ZoneIterator ¶
A ZoneIterator is a set of Zones we can iterate on
Source Files ¶
- ceph.go
- ceph_scan.go
- cluster.go
- cluster_file.go
- cluster_fs.go
- cluster_import.go
- cluster_scan.go
- cluster_scan_options.go
- defaults.go
- env.go
- errors.go
- hosts.go
- log.go
- machine.go
- machine_file.go
- machine_rings.go
- machine_scan.go
- machines.go
- regions.go
- regions_utils.go
- rings.go
- sync.go
- wireguard.go
- zones.go