Compare commits

...

2 Commits

Author SHA1 Message Date
amery a725b66d14 cluster: mark Machine as Inactive if the "region" file contains "none"
Signed-off-by: Alejandro Mery <amery@jpi.io>
2023-10-30 18:52:38 +00:00
amery 851274954e cluster: introduce Machine.Inactive flag
if a Machine is Inactive, it won't be included on the DNS
aliases for the zone or it's regions.

Signed-off-by: Alejandro Mery <amery@jpi.io>
2023-10-30 18:52:34 +00:00
4 changed files with 35 additions and 3 deletions
+1 -1
View File
@@ -52,7 +52,7 @@ func populateDNSManager(mgr *dns.Manager, m *cluster.Cluster) error {
m.ForEachZone(func(z *cluster.Zone) bool {
z.ForEachMachine(func(p *cluster.Machine) bool {
err = mgr.AddHost(ctx, z.Name, p.ID, true, p.PublicAddresses...)
err = mgr.AddHost(ctx, z.Name, p.ID, p.Active(), p.PublicAddresses...)
return err != nil
})
+6
View File
@@ -15,6 +15,7 @@ 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"`
@@ -43,6 +44,11 @@ func (m *Machine) FullName() string {
return strings.Join(name, ".")
}
// Active indicates the machine is to be included in regions' DNS entries
func (m *Machine) Active() bool {
return !m.Inactive
}
// IsGateway tells if the Machine is a ring0 gateway
func (m *Machine) IsGateway() bool {
_, ok := m.getRingInfo(0)
+25 -1
View File
@@ -3,6 +3,7 @@ package cluster
import (
"context"
"net/netip"
"os"
"strconv"
"strings"
"time"
@@ -81,7 +82,30 @@ func (m *Machine) scan(_ *ScanOptions) error {
}
}
return nil
return m.loadInactive()
}
func (m *Machine) loadInactive() error {
data, err := m.ReadLines("region")
switch {
case os.IsNotExist(err):
// no file
return nil
case err != nil:
// read error
return err
default:
// look for "none"
for _, r := range data {
switch r {
case "none":
m.Inactive = true
default:
m.Inactive = false
}
}
return nil
}
}
// scanWrapUp is called once all machines have been scanned
+3 -1
View File
@@ -32,7 +32,9 @@ func (r *Region) ForEachMachine(fn func(*Machine) bool) {
var term bool
z.ForEachMachine(func(p *Machine) bool {
term = fn(p)
if p.Active() {
term = fn(p)
}
return term
})