Compare commits

..

10 Commits

Author SHA1 Message Date
amery 4200db12cb jpictl: write m/ceph.conf on sync
Signed-off-by: Alejandro Mery <amery@jpi.io>
2023-09-05 13:46:25 +00:00
amery 5e57fe5f30 ceph: zones.Zones.WriteCephConfig() and ceph.Config.WriteTo()
Signed-off-by: Alejandro Mery <amery@jpi.io>
2023-09-05 13:46:25 +00:00
amery 75dee617ef 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:44:40 +00:00
amery cc7526ceb5 zones: extend scan to ensure every zone has a ceph monitor
Signed-off-by: Alejandro Mery <amery@jpi.io>
2023-09-05 13:44:40 +00:00
amery d8657770d5 zones: store ceph FSID on scan
Signed-off-by: Alejandro Mery <amery@jpi.io>
2023-09-05 13:44:40 +00:00
amery 564a6c8af2 zones: set Machine.CephMonitor if its referenced as monitor on ceph.conf
Signed-off-by: Alejandro Mery <amery@jpi.io>
2023-09-05 13:39:04 +00:00
amery c083a144ea zones: introduce GenCephConfig()
Signed-off-by: Alejandro Mery <amery@jpi.io>
2023-09-05 13:39:04 +00:00
amery 226d529223 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:39:04 +00:00
amery 7489b15c52 zones: introduce Zones.GetCephConfig() accessor for m/ceph.conf
Signed-off-by: Alejandro Mery <amery@jpi.io>
2023-09-05 13:39:04 +00:00
amery d4757bebc2 ceph: add NewConfigFromReader() and initial ceph.conf parser
Signed-off-by: Alejandro Mery <amery@jpi.io>
2023-09-05 13:39:04 +00:00
4 changed files with 65 additions and 8 deletions
+31 -2
View File
@@ -1,8 +1,11 @@
package ceph
import (
"bytes"
"fmt"
"io"
"net/netip"
"strings"
"github.com/gofrs/uuid/v5"
@@ -17,11 +20,37 @@ type Config struct {
// GlobalConfig represents the [global] section of a ceph.conf file
type GlobalConfig struct {
FSID uuid.UUID `ini:"fsid"`
Monitors []string `ini:"mon_host,comma"`
MonitorsAddr []netip.Addr `ini:"mon_initial_members,comma"`
Monitors []string `ini:"mon_initial_members,comma"`
MonitorsAddr []netip.Addr `ini:"mon_host,comma"`
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
func NewConfigFromReader(r io.Reader) (*Config, error) {
doc, err := basic.Decode(r)
+12
View File
@@ -31,6 +31,18 @@ func (m *Zones) GetCephConfig() (*ceph.Config, error) {
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
func (m *Zones) GenCephConfig() (*ceph.Config, error) {
fsid, err := m.GetCephFSID()
+11 -6
View File
@@ -53,7 +53,7 @@ func (err CephMissingMonitorError) Error() string {
func (err *CephMissingMonitorError) writeNames(w *strings.Builder) {
if len(err.Names) > 0 {
_, _ = w.WriteString(" mon_host:")
_, _ = w.WriteString(" mon_initial_members:")
for i, name := range err.Names {
if i != 0 {
_, _ = w.WriteRune(',')
@@ -64,12 +64,14 @@ func (err *CephMissingMonitorError) writeNames(w *strings.Builder) {
}
func (err *CephMissingMonitorError) writeAddrs(w *strings.Builder) {
_, _ = w.WriteString(" mon_initial_members:")
for i, addr := range err.Addrs {
if i != 0 {
_, _ = w.WriteRune(',')
if len(err.Addrs) > 0 {
_, _ = w.WriteString(" mon_host:")
for i, addr := range err.Addrs {
if i != 0 {
_, _ = w.WriteRune(',')
}
_, _ = w.WriteString(addr.String())
}
_, _ = w.WriteString(addr.String())
}
}
@@ -157,6 +159,9 @@ func (m *Zones) scanCephMonitors(_ *ScanOptions) error {
return err
}
// store FSID
m.CephFSID = cfg.Global.FSID
// flag monitors based on config
todo := newCephScanTODO(cfg)
m.ForEachMachine(func(p *Machine) bool {
+11
View File
@@ -4,6 +4,7 @@ package zones
func (m *Zones) SyncAll() error {
for _, fn := range []func() error{
m.SyncAllWireguard,
m.SyncAllCeph,
} {
if err := fn(); err != nil {
return err
@@ -31,3 +32,13 @@ func (m *Zones) SyncAllWireguard() error {
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)
}