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 ErrInvalidRing(ringID rings.RingID) error
- func SortRegions(regions []string) []string
- 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 rings.RingID) 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 rings.RingID) 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 rings.RingID) error
- func (m *Cluster) WriteWireguardKeys(ring rings.RingID) 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(ringID rings.RingID) (*wireguard.Config, error)
- func (m *Machine) GetWireguardKeys(ringID rings.RingID) (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 rings.RingID) error
- func (m *Machine) ReadFile(name string, args ...any) ([]byte, error)
- func (m *Machine) ReadLines(name string, args ...any) ([]string, error)
- func (m *Machine) Region() rings.RegionID
- func (m *Machine) RemoveFile(name string, args ...any) error
- func (m *Machine) RemoveWireguardConfig(ringID rings.RingID) error
- func (m *Machine) RemoveWireguardKeys(ringID rings.RingID) error
- func (m *Machine) RingOneAddress() netip.Addr
- func (m *Machine) RingOnePrefix() netip.Prefix
- func (m *Machine) RingZeroAddress() (netip.Addr, bool)
- func (m *Machine) SetGateway(enabled bool) error
- func (m *Machine) String() string
- func (m *Machine) SyncWireguardConfig(ring rings.RingID) 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 rings.RingID) error
- func (m *Machine) WriteWireguardKeys(ringID rings.RingID) error
- func (m *Machine) Zone() rings.ZoneID
- 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 WireguardInterfaceID
- type WireguardKeysWriter
- type Zone
- func (z *Zone) Eq(z2 *Zone) bool
- func (z *Zone) ForEachRegion(fn func(*Region) bool)
- func (z *Zone) GatewayIDs() ([]rings.NodeID, int)
- func (z *Zone) GetCephMonitors() Machines
- func (z *Zone) GetGateway() (*Machine, bool, error)
- func (z *Zone) Hosts() string
- func (z *Zone) Is(regionID rings.RegionID, zoneID rings.ZoneID) bool
- func (z *Zone) PruneWireguardConfig(ring rings.RingID) error
- func (z *Zone) RegionID() rings.RegionID
- func (z *Zone) RingOnePrefix() netip.Prefix
- func (z *Zone) SetGateway(gatewayID rings.NodeID, enabled bool) error
- func (z *Zone) String() string
- func (z *Zone) SyncRegions() error
- func (z *Zone) SyncWireguardConfig(ring rings.RingID) error
- func (z *Zone) WriteHosts() error
- func (z *Zone) WriteWireguardConfig(ring rings.RingID) error
- func (z *Zone) WriteWireguardKeys(ring rings.RingID) 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 ( // 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: rings.RingZeroID, Port: RingZeroPort, Decode: rings.DecodeRingZeroAddress, Encode: rings.RingZeroAddress, } // Rings provides indexed access to the ring address encoders Rings = []RingAddressEncoder{ RingZero, } )
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 ErrInvalidRing ¶ added in v0.8.4
ErrInvalidRing returns an error indicating the rings.RingID can't be used for the intended purpose
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
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
type Env ¶
type Env struct { ZoneIterator RegionIterator // contains filtered or unexported fields }
Env is a shell environment factory for this cluster
func (*Env) RegionsNames ¶ added in v0.8.5
RegionsNames returns a sorted list of primary regions names
type Machine ¶
type Machine struct { ID rings.NodeID 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) RingOneAddress ¶ added in v0.8.4
RingOneAddress returns the ring 1 address of the Machine
func (*Machine) RingOnePrefix ¶ added in v0.8.4
RingOnePrefix returns the ring 1 subnet this Machine belongs to.
func (*Machine) RingZeroAddress ¶ added in v0.8.4
RingZeroAddress returns the ring 0 address of the Machine if it can act as gateway.
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 ID rings.RegionID `json:",omitempty" yaml:",omitempty"` 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) IsPrimary ¶ added in v0.8.2
IsPrimary indicates the region is primary and corresponds to a kubernetes cluster.
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, ringID rings.RingID) (*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 rings.RingID Port uint16 Encode func(rings.RegionID, rings.ZoneID, rings.NodeID) (netip.Addr, error) Decode func(addr netip.Addr) (rings.RegionID, rings.ZoneID, rings.NodeID, bool) }
RingAddressEncoder provides encoder/decoder access for a particular Wireguard ring
type RingInfo ¶
type RingInfo struct { Ring WireguardInterfaceID Enabled bool Keys wireguard.KeyPair }
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
func (*RingPeer) AllowSubnet ¶ added in v0.8.4
AllowSubnet allows an IP range via this peer
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 WireguardInterfaceID ¶ added in v0.8.4
type WireguardInterfaceID uint
WireguardInterfaceID represents the number in the `wg%v` interface name.
func AsWireguardInterfaceID ¶ added in v0.8.4
func AsWireguardInterfaceID(ring rings.RingID) (WireguardInterfaceID, error)
AsWireguardInterfaceID returns the WireguardInterfaceID for a valid rings.RingID.
func MustWireguardInterfaceID ¶ added in v0.8.4
func MustWireguardInterfaceID(ring rings.RingID) WireguardInterfaceID
MustWireguardInterfaceID returns the WireguardInterfaceID for a valid rings.RingID, and panics if it's not.
func (WireguardInterfaceID) ConfFile ¶ added in v0.8.4
func (wi WireguardInterfaceID) ConfFile() string
ConfFile returns "wgN.conf"
func (WireguardInterfaceID) Files ¶ added in v0.8.4
func (wi WireguardInterfaceID) Files() (keyFile, pubFile, confFile string)
Files returns all wgN.ext file names.
func (WireguardInterfaceID) KeyFile ¶ added in v0.8.4
func (wi WireguardInterfaceID) KeyFile() string
KeyFile returns "wgN.key"
func (WireguardInterfaceID) PubFile ¶ added in v0.8.4
func (wi WireguardInterfaceID) PubFile() string
PubFile returns "wgN.pub"
func (WireguardInterfaceID) RingID ¶ added in v0.8.4
func (wi WireguardInterfaceID) RingID() rings.RingID
RingID tells the rings.RingID of the WireguardInterfaceID.
type WireguardKeysWriter ¶
A WireguardKeysWriter writes the Wireguard Keys for all machines under its scope for the specified ring
type Zone ¶
type Zone struct { ID rings.ZoneID 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) Is ¶ added in v0.8.4
Is checks if the given rings.RegionID and rings.ZoneID match the Zone.
func (*Zone) PruneWireguardConfig ¶
PruneWireguardConfig removes wgN.conf files of machines with the corresponding ring disabled.
func (*Zone) RingOnePrefix ¶ added in v0.8.4
RingOnePrefix returns the ring 1 subnet of this Zone.
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
type ZoneIterator ¶
A ZoneIterator is a set of Zones we can iterate on
Source Files ¶
- addr.go
- 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