Compare commits
6 Commits
fa0fa87c0e
...
v0.5.5
| Author | SHA1 | Date | |
|---|---|---|---|
| ab8ffdd507 | |||
| 422e119f88 | |||
|
d1198328f6
|
|||
| 7795610caf | |||
| 32046fc1ec | |||
| c038ad4431 |
+3
-2
@@ -52,8 +52,9 @@ const encoding = YAMLEncoding
|
||||
|
||||
// Command
|
||||
var dumpCmd = &cobra.Command{
|
||||
Use: "dump",
|
||||
Short: "generates a text representation of the config",
|
||||
Use: "dump",
|
||||
Short: "generates a text representation of the config",
|
||||
PreRun: setVerbosity,
|
||||
RunE: func(_ *cobra.Command, _ []string) error {
|
||||
var buf bytes.Buffer
|
||||
var enc Encoder
|
||||
|
||||
+3
-2
@@ -8,8 +8,9 @@ import (
|
||||
|
||||
// Command
|
||||
var envCmd = &cobra.Command{
|
||||
Use: "env",
|
||||
Short: "generates environment variables for shell scripts",
|
||||
Use: "env",
|
||||
Short: "generates environment variables for shell scripts",
|
||||
PreRun: setVerbosity,
|
||||
RunE: func(_ *cobra.Command, _ []string) error {
|
||||
m, err := cfg.LoadZones(false)
|
||||
if err != nil {
|
||||
|
||||
@@ -19,8 +19,9 @@ var gatewayCmd = &cobra.Command{
|
||||
|
||||
// gateway set
|
||||
var gatewaySetCmd = &cobra.Command{
|
||||
Use: "set",
|
||||
Short: "gateway set sets machines as gateways",
|
||||
Use: "set",
|
||||
Short: "gateway set sets machines as gateways",
|
||||
PreRun: setVerbosity,
|
||||
RunE: func(_ *cobra.Command, args []string) error {
|
||||
m, err := cfg.LoadZones(false)
|
||||
if err != nil {
|
||||
|
||||
@@ -3,15 +3,9 @@ package main
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"darvaza.org/sidecar/pkg/logger/zerolog"
|
||||
"darvaza.org/slog"
|
||||
)
|
||||
|
||||
// TODO: make log level configurable via flags
|
||||
var (
|
||||
log = zerolog.New(nil, slog.Debug)
|
||||
)
|
||||
|
||||
// fatal is a convenience wrapper for slog.Logger.Fatal().Print()
|
||||
func fatal(err error, msg string, args ...any) {
|
||||
l := log.Fatal()
|
||||
|
||||
+22
-4
@@ -2,6 +2,8 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"darvaza.org/sidecar/pkg/logger/zerolog"
|
||||
"darvaza.org/slog"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
@@ -10,13 +12,29 @@ const (
|
||||
CmdName = "jpictl"
|
||||
)
|
||||
|
||||
var rootCmd = &cobra.Command{
|
||||
Use: CmdName,
|
||||
Short: "control tool for jpi.cloud",
|
||||
}
|
||||
var (
|
||||
log = zerolog.New(nil, slog.Error)
|
||||
verbosity int
|
||||
rootCmd = &cobra.Command{
|
||||
Use: CmdName,
|
||||
Short: "control tool for jpi.cloud",
|
||||
}
|
||||
)
|
||||
|
||||
func main() {
|
||||
if err := rootCmd.Execute(); err != nil {
|
||||
fatal(err, "")
|
||||
}
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.PersistentFlags().CountVarP(&verbosity, "verbosity", "v", "increase the verbosity level to Warn, Info or Debug")
|
||||
}
|
||||
|
||||
func setVerbosity(_ *cobra.Command, _ []string) {
|
||||
desired := int8(slog.Error) + int8(verbosity)
|
||||
if desired > 6 {
|
||||
desired = 6
|
||||
}
|
||||
log = log.WithLevel(slog.LogLevel(desired))
|
||||
}
|
||||
|
||||
+3
-2
@@ -6,8 +6,9 @@ import (
|
||||
|
||||
// Command
|
||||
var writeCmd = &cobra.Command{
|
||||
Use: "write",
|
||||
Short: "rewrites all config files",
|
||||
Use: "write",
|
||||
Short: "rewrites all config files",
|
||||
PreRun: setVerbosity,
|
||||
RunE: func(_ *cobra.Command, _ []string) error {
|
||||
m, err := cfg.LoadZones(false)
|
||||
if err != nil {
|
||||
|
||||
+12
-92
@@ -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
|
||||
|
||||
@@ -9,8 +9,8 @@ import (
|
||||
|
||||
// A Machine is a machine on a Zone
|
||||
type Machine struct {
|
||||
zone *Zone
|
||||
logger
|
||||
zone *Zone
|
||||
logger `toml:"-" json:"-" yaml:"-"`
|
||||
|
||||
ID int `toml:"id"`
|
||||
Name string `toml:"-" json:"-" yaml:"-"`
|
||||
|
||||
+2
-2
@@ -87,8 +87,8 @@ func FilterMachines(m MachineIterator, cond func(*Machine) bool) (Machines, int)
|
||||
|
||||
// Zone represents one zone in a cluster
|
||||
type Zone struct {
|
||||
zones *Zones
|
||||
logger
|
||||
zones *Zones
|
||||
logger `toml:"-" json:"-" yaml:"-"`
|
||||
|
||||
ID int `toml:"id"`
|
||||
Name string `toml:"name"`
|
||||
|
||||
Reference in New Issue
Block a user