Compare commits

..

7 Commits

Author SHA1 Message Date
amery f1c40aa03c 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 13:26:58 +00:00
amery 7344de0406 zones: extend scan to ensure every zone has a ceph monitor
Signed-off-by: Alejandro Mery <amery@jpi.io>
2023-09-05 13:26:53 +00:00
amery 1984db9a8f zones: set Machine.CephMonitor if its referenced as monitor on ceph.conf
Signed-off-by: Alejandro Mery <amery@jpi.io>
2023-09-05 13:26:34 +00:00
amery ddab51386d zones: introduce GenCephConfig()
Signed-off-by: Alejandro Mery <amery@jpi.io>
2023-09-05 13:26:20 +00:00
amery 6ad6b4a855 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 13:26:07 +00:00
amery 77de40a8c0 zones: introduce Zones.GetCephConfig() accessor for m/ceph.conf
Signed-off-by: Alejandro Mery <amery@jpi.io>
2023-09-05 13:25:47 +00:00
amery 7c111c66ec ceph: add NewConfigFromReader() and initial ceph.conf parser
Signed-off-by: Alejandro Mery <amery@jpi.io>
2023-09-05 13:25:41 +00:00
5 changed files with 16 additions and 77 deletions
+2 -31
View File
@@ -1,11 +1,8 @@
package ceph package ceph
import ( import (
"bytes"
"fmt"
"io" "io"
"net/netip" "net/netip"
"strings"
"github.com/gofrs/uuid/v5" "github.com/gofrs/uuid/v5"
@@ -20,37 +17,11 @@ type Config struct {
// GlobalConfig represents the [global] section of a ceph.conf file // GlobalConfig represents the [global] section of a ceph.conf file
type GlobalConfig struct { type GlobalConfig struct {
FSID uuid.UUID `ini:"fsid"` FSID uuid.UUID `ini:"fsid"`
Monitors []string `ini:"mon_initial_members,comma"` Monitors []string `ini:"mon_host,comma"`
MonitorsAddr []netip.Addr `ini:"mon_host,comma"` MonitorsAddr []netip.Addr `ini:"mon_initial_members,comma"`
ClusterNetwork netip.Prefix `ini:"cluster_network"` ClusterNetwork netip.Prefix `ini:"cluster_network"`
} }
// WriteTo writes a Wireguard [Config] onto the provided [io.Writer]
func (cfg *Config) WriteTo(w io.Writer) (int64, error) {
var buf bytes.Buffer
writeGlobalToBuffer(&buf, &cfg.Global)
return buf.WriteTo(w)
}
func writeGlobalToBuffer(w *bytes.Buffer, c *GlobalConfig) {
_, _ = w.WriteString("[global]\n")
_, _ = fmt.Fprintf(w, "%s = %s\n", "fsid", c.FSID.String())
_, _ = fmt.Fprintf(w, "%s = %s\n", "mon_initial_members", strings.Join(c.Monitors, ", "))
_, _ = fmt.Fprintf(w, "%s = %s\n", "mon_host", joinAddrs(c.MonitorsAddr, ", "))
_, _ = fmt.Fprintf(w, "%s = %s\n", "cluster_network", c.ClusterNetwork.String())
}
func joinAddrs(addrs []netip.Addr, sep string) string {
s := make([]string, len(addrs))
for i, addr := range addrs {
s[i] = addr.String()
}
return strings.Join(s, sep)
}
// NewConfigFromReader parses the ceph.conf file // NewConfigFromReader parses the ceph.conf file
func NewConfigFromReader(r io.Reader) (*Config, error) { func NewConfigFromReader(r io.Reader) (*Config, error) {
doc, err := basic.Decode(r) doc, err := basic.Decode(r)
-2
View File
@@ -43,8 +43,6 @@ func loadGlobalConfField(cfg *GlobalConfig, field basic.Field) error {
// revive:enable:cyclomatic // revive:enable:cyclomatic
// revive:enable:cognitive-complexity // revive:enable:cognitive-complexity
// TODO: refactor when asciigoat's ini parser learns to do reflection
switch field.Key { switch field.Key {
case "fsid": case "fsid":
if !core.IsZero(cfg.FSID) { if !core.IsZero(cfg.FSID) {
-12
View File
@@ -31,18 +31,6 @@ func (m *Zones) GetCephConfig() (*ceph.Config, error) {
return ceph.NewConfigFromReader(r) return ceph.NewConfigFromReader(r)
} }
// WriteCephConfig writes the ceph.conf file
func (m *Zones) WriteCephConfig(cfg *ceph.Config) error {
f, err := m.CreateTruncFile("ceph.conf")
if err != nil {
return err
}
defer f.Close()
_, err = cfg.WriteTo(f)
return err
}
// GenCephConfig prepares a ceph.Config using the cluster information // GenCephConfig prepares a ceph.Config using the cluster information
func (m *Zones) GenCephConfig() (*ceph.Config, error) { func (m *Zones) GenCephConfig() (*ceph.Config, error) {
fsid, err := m.GetCephFSID() fsid, err := m.GetCephFSID()
+14 -21
View File
@@ -53,7 +53,7 @@ func (err CephMissingMonitorError) Error() string {
func (err *CephMissingMonitorError) writeNames(w *strings.Builder) { func (err *CephMissingMonitorError) writeNames(w *strings.Builder) {
if len(err.Names) > 0 { if len(err.Names) > 0 {
_, _ = w.WriteString(" mon_initial_members:") _, _ = w.WriteString(" mon_host:")
for i, name := range err.Names { for i, name := range err.Names {
if i != 0 { if i != 0 {
_, _ = w.WriteRune(',') _, _ = w.WriteRune(',')
@@ -64,14 +64,12 @@ func (err *CephMissingMonitorError) writeNames(w *strings.Builder) {
} }
func (err *CephMissingMonitorError) writeAddrs(w *strings.Builder) { func (err *CephMissingMonitorError) writeAddrs(w *strings.Builder) {
if len(err.Addrs) > 0 { _, _ = w.WriteString(" mon_initial_members:")
_, _ = w.WriteString(" mon_host:") for i, addr := range err.Addrs {
for i, addr := range err.Addrs { if i != 0 {
if i != 0 { _, _ = w.WriteRune(',')
_, _ = w.WriteRune(',')
}
_, _ = w.WriteString(addr.String())
} }
_, _ = w.WriteString(addr.String())
} }
} }
@@ -159,19 +157,14 @@ func (m *Zones) scanCephMonitors(_ *ScanOptions) error {
return err return err
} }
if cfg != nil { // flag monitors based on config
// store FSID todo := newCephScanTODO(cfg)
m.CephFSID = cfg.Global.FSID m.ForEachMachine(func(p *Machine) bool {
p.CephMonitor = todo.checkMachine(p)
// flag monitors based on config return false
todo := newCephScanTODO(cfg) })
m.ForEachMachine(func(p *Machine) bool { if err := todo.Missing(); err != nil {
p.CephMonitor = todo.checkMachine(p) return core.Wrap(err, "ceph")
return false
})
if err := todo.Missing(); err != nil {
return core.Wrap(err, "ceph")
}
} }
// make sure every zone has one // make sure every zone has one
-11
View File
@@ -4,7 +4,6 @@ package zones
func (m *Zones) SyncAll() error { func (m *Zones) SyncAll() error {
for _, fn := range []func() error{ for _, fn := range []func() error{
m.SyncAllWireguard, m.SyncAllWireguard,
m.SyncAllCeph,
} { } {
if err := fn(); err != nil { if err := fn(); err != nil {
return err return err
@@ -32,13 +31,3 @@ func (m *Zones) SyncAllWireguard() error {
return nil return nil
} }
// SyncAllCeph updates the ceph.conf file
func (m *Zones) SyncAllCeph() error {
cfg, err := m.GenCephConfig()
if err != nil {
return err
}
return m.WriteCephConfig(cfg)
}