Compare commits

..

9 Commits

Author SHA1 Message Date
amery 7035facf7b ceph: zones.Zones.WriteCephConfig() and ceph.Config.WriteTo() [WIP]
Signed-off-by: Alejandro Mery <amery@jpi.io>
2023-09-05 11:31:26 +00:00
amery 1150fbb7ef build-sys: use local asciigoat.org/ini
Signed-off-by: Alejandro Mery <amery@jpi.io>
2023-09-05 11:29:09 +00:00
amery 35a50659bd vscode: add special words to the dictionary
Signed-off-by: Alejandro Mery <amery@jpi.io>
2023-09-05 11:29:09 +00:00
amery 3a1b36070a Merge branch 'pr-amery-wireguard-ini' into next-amery
Signed-off-by: Alejandro Mery <amery@jpi.io>
2023-09-05 11:28:35 +00:00
amery b0fcf963d6 env: set ceph monitors variables
they indicate the ceph monitors on the specified zone

* MON{zoneID}_NAME
* MON{zoneID}_ID
* MON{zoneID}_IP

Signed-off-by: Alejandro Mery <amery@jpi.io>
2023-09-05 11:25:22 +00:00
amery 54effed139 zones: extend scan to ensure every zone has a ceph monitor
Signed-off-by: Alejandro Mery <amery@jpi.io>
2023-09-05 11:25:22 +00:00
amery 89b32177b2 zones: set Machine.CephMonitor if its referenced as monitor on ceph.conf
Signed-off-by: Alejandro Mery <amery@jpi.io>
2023-09-05 11:25:22 +00:00
amery a9399c8abf zones: introduce Zone.GetCephMonitors()
returning the local ceph monitors and setting one
if there is none. non-gateway nodes are preferred
when setting a monitor automatically

Signed-off-by: Alejandro Mery <amery@jpi.io>
2023-09-05 11:25:22 +00:00
amery 8f36f98da9 zones: introduce Machine.CephMonitor field
Signed-off-by: Alejandro Mery <amery@jpi.io>
2023-09-05 11:25:11 +00:00
3 changed files with 100 additions and 0 deletions
+45
View File
@@ -2,6 +2,7 @@ package zones
import (
"bytes"
"sort"
"git.jpi.io/amery/jpictl/pkg/ceph"
)
@@ -28,3 +29,47 @@ func (m *Zones) WriteCephConfig(cfg *ceph.Config) error {
_, err = cfg.WriteTo(f)
return err
}
// GetCephMonitors returns the set of Ceph monitors on
// the zone
func (z *Zone) GetCephMonitors() Machines {
var mons Machines
var first, second *Machine
z.ForEachMachine(func(p *Machine) bool {
switch {
case p.CephMonitor:
// it is a monitor
mons = append(mons, p)
case len(mons) > 0:
// zone has a monitor
case first == nil && !p.IsGateway():
// first option for monitor
first = p
case second == nil:
// second option for monitor
second = p
}
return false
})
switch {
case len(mons) > 0:
// ready
case first != nil:
// make first option our monitor
first.CephMonitor = true
mons = append(mons, first)
case second != nil:
// make second option our monitor
second.CephMonitor = true
mons = append(mons, second)
default:
// zone without machines??
panic("unreachable")
}
sort.Sort(mons)
return mons
}
+5
View File
@@ -167,5 +167,10 @@ func (m *Zones) scanCephMonitors(_ *ScanOptions) error {
return core.Wrap(err, "ceph")
}
// make sure every zone has one
m.ForEachZone(func(z *Zone) bool {
_ = z.GetCephMonitors()
return false
})
return nil
}
+50
View File
@@ -59,6 +59,15 @@ func (m *Env) writeEnvZone(w io.Writer, z *Zone) {
// ZONE{zoneID}_GW
gateways, _ := z.GatewayIDs()
m.writeEnvVarInts(w, gateways, "ZONE%v_%s", zoneID, "GW")
// Ceph
monitors := z.GetCephMonitors()
// MON{zoneID}_NAME
m.writeEnvVar(w, genEnvZoneCephMonNames(monitors), "MON%v_%s", zoneID, "NAME")
// MON{zoneID}_IP
m.writeEnvVar(w, genEnvZoneCephMonIPs(monitors), "MON%v_%s", zoneID, "IP")
// MON{zoneID}_ID
m.writeEnvVar(w, genEnvZoneCephMonIDs(monitors), "MON%v_%s", zoneID, "ID")
}
func (m *Env) writeEnvVarInts(w io.Writer, value []int, name string, args ...any) {
@@ -111,3 +120,44 @@ func genEnvZoneNodes(z *Zone) string {
}
return ""
}
func genEnvZoneCephMonNames(m Machines) string {
var buf strings.Builder
m.ForEachMachine(func(p *Machine) bool {
if buf.Len() > 0 {
_, _ = buf.WriteRune(' ')
}
_, _ = buf.WriteString(p.Name)
return false
})
return buf.String()
}
func genEnvZoneCephMonIPs(m Machines) string {
var buf strings.Builder
m.ForEachMachine(func(p *Machine) bool {
addr, _ := RingOneAddress(p.Zone(), p.ID)
if buf.Len() > 0 {
_, _ = buf.WriteRune(' ')
}
_, _ = buf.WriteString(addr.String())
return false
})
return buf.String()
}
func genEnvZoneCephMonIDs(m Machines) string {
var buf strings.Builder
m.ForEachMachine(func(p *Machine) bool {
if buf.Len() > 0 {
_, _ = buf.WriteRune(' ')
}
_, _ = fmt.Fprintf(&buf, "%v", p.ID)
return false
})
return buf.String()
}