From c038ad4431650d27797924cfb2324fdae8160075 Mon Sep 17 00:00:00 2001 From: Alejandro Mery Date: Thu, 7 Sep 2023 18:32:11 +0000 Subject: [PATCH] zones: warn but not fail when scanning finds unknown monitors Signed-off-by: Alejandro Mery --- pkg/zones/ceph_scan.go | 104 +++++------------------------------------ 1 file changed, 12 insertions(+), 92 deletions(-) diff --git a/pkg/zones/ceph_scan.go b/pkg/zones/ceph_scan.go index 2180c09..7cb4f37 100644 --- a/pkg/zones/ceph_scan.go +++ b/pkg/zones/ceph_scan.go @@ -1,89 +1,12 @@ package zones import ( - "net/netip" "os" - "strings" - "darvaza.org/core" + "darvaza.org/slog" "git.jpi.io/amery/jpictl/pkg/ceph" ) -// CephMissingMonitorError is an error that contains ceph -// monitors present in ceph.conf but not found on the cluster -type CephMissingMonitorError struct { - Names []string - Addrs []netip.Addr -} - -func (err *CephMissingMonitorError) appendName(name string) { - err.Names = append(err.Names, name) -} - -func (err *CephMissingMonitorError) appendAddr(addr netip.Addr) { - err.Addrs = append(err.Addrs, addr) -} - -// OK tells if this instance actual shouldn't be treated as an error -func (err CephMissingMonitorError) OK() bool { - switch { - case len(err.Names) > 0: - return false - case len(err.Addrs) > 0: - return false - default: - return true - } -} - -func (err CephMissingMonitorError) Error() string { - if !err.OK() { - var buf strings.Builder - - _, _ = buf.WriteString("missing:") - err.writeNames(&buf) - err.writeAddrs(&buf) - - return buf.String() - } - - // no error - return "" -} - -func (err *CephMissingMonitorError) writeNames(w *strings.Builder) { - if len(err.Names) > 0 { - _, _ = w.WriteString(" mon_initial_members:") - for i, name := range err.Names { - if i != 0 { - _, _ = w.WriteRune(',') - } - _, _ = w.WriteString(name) - } - } -} - -func (err *CephMissingMonitorError) writeAddrs(w *strings.Builder) { - if len(err.Addrs) > 0 { - _, _ = w.WriteString(" mon_host:") - for i, addr := range err.Addrs { - if i != 0 { - _, _ = w.WriteRune(',') - } - _, _ = w.WriteString(addr.String()) - } - } -} - -// AsError returns nil if the instance is actually OK -func (err *CephMissingMonitorError) AsError() error { - if err == nil || err.OK() { - return nil - } - - return err -} - type cephScanTODO struct { names map[string]bool addrs map[string]bool @@ -111,26 +34,24 @@ func (todo *cephScanTODO) checkMachine(p *Machine) bool { return false } -func (todo *cephScanTODO) Missing() error { - var check CephMissingMonitorError - +func (todo *cephScanTODO) LogMissing(log slog.Logger) { for name, found := range todo.names { if !found { - check.appendName(name) + log.Warn(). + WithField("subsystem", "ceph"). + WithField("monitor", name). + Print("unknown monitor") } } for addr, found := range todo.addrs { if !found { - var a netip.Addr - // it wouldn't be on the map if it wasn't valid - _ = a.UnmarshalText([]byte(addr)) - - check.appendAddr(a) + log.Warn(). + WithField("subsystem", "ceph"). + WithField("monitor", addr). + Print("unknown monitor") } } - - return check.AsError() } func newCephScanTODO(cfg *ceph.Config) *cephScanTODO { @@ -169,9 +90,8 @@ func (m *Zones) scanCephMonitors(_ *ScanOptions) error { p.CephMonitor = todo.checkMachine(p) return false }) - if err := todo.Missing(); err != nil { - return core.Wrap(err, "ceph") - } + + todo.LogMissing(m.log) } // make sure every zone has one