Compare commits
7 Commits
v0.5.4
..
b0fcf963d6
| Author | SHA1 | Date | |
|---|---|---|---|
| b0fcf963d6 | |||
| 54effed139 | |||
| 89b32177b2 | |||
| a9399c8abf | |||
| 8f36f98da9 | |||
| e0e2def833 | |||
| bfcd9f26be |
Vendored
-9
@@ -1,9 +0,0 @@
|
|||||||
{
|
|
||||||
"cSpell.words": [
|
|
||||||
"ceph",
|
|
||||||
"darvaza",
|
|
||||||
"gofrs",
|
|
||||||
"jpictl",
|
|
||||||
"zerolog"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -17,6 +17,5 @@ var cfg = &Config{
|
|||||||
func (cfg *Config) LoadZones(resolve bool) (*zones.Zones, error) {
|
func (cfg *Config) LoadZones(resolve bool) (*zones.Zones, error) {
|
||||||
return zones.New(cfg.Base, cfg.Domain,
|
return zones.New(cfg.Base, cfg.Domain,
|
||||||
zones.ResolvePublicAddresses(resolve),
|
zones.ResolvePublicAddresses(resolve),
|
||||||
zones.WithLogger(log),
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-5
@@ -16,11 +16,7 @@ var envCmd = &cobra.Command{
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
env, err := m.Env(*envExport)
|
_, err = m.Env(*envExport).WriteTo(os.Stdout)
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
_, err = env.WriteTo(os.Stdout)
|
|
||||||
return err
|
return err
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import (
|
|||||||
"darvaza.org/slog"
|
"darvaza.org/slog"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TODO: make log level configurable via flags
|
|
||||||
var (
|
var (
|
||||||
log = zerolog.New(nil, slog.Debug)
|
log = zerolog.New(nil, slog.Debug)
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -3,12 +3,11 @@ module git.jpi.io/amery/jpictl
|
|||||||
go 1.19
|
go 1.19
|
||||||
|
|
||||||
require (
|
require (
|
||||||
asciigoat.org/ini v0.2.5
|
asciigoat.org/ini v0.2.4
|
||||||
darvaza.org/core v0.9.8
|
darvaza.org/core v0.9.5
|
||||||
darvaza.org/resolver v0.5.4
|
darvaza.org/resolver v0.5.2
|
||||||
darvaza.org/sidecar v0.0.2
|
darvaza.org/sidecar v0.0.0-20230721122716-b9c54b8adbaf
|
||||||
darvaza.org/slog v0.5.3
|
darvaza.org/slog v0.5.2
|
||||||
darvaza.org/slog/handlers/discard v0.4.5
|
|
||||||
github.com/burntSushi/toml v0.3.1
|
github.com/burntSushi/toml v0.3.1
|
||||||
github.com/gofrs/uuid/v5 v5.0.0
|
github.com/gofrs/uuid/v5 v5.0.0
|
||||||
github.com/hack-pad/hackpadfs v0.2.1
|
github.com/hack-pad/hackpadfs v0.2.1
|
||||||
@@ -21,8 +20,8 @@ require (
|
|||||||
|
|
||||||
require (
|
require (
|
||||||
asciigoat.org/core v0.3.9 // indirect
|
asciigoat.org/core v0.3.9 // indirect
|
||||||
darvaza.org/slog/handlers/filter v0.4.5 // indirect
|
darvaza.org/slog/handlers/filter v0.4.4 // indirect
|
||||||
darvaza.org/slog/handlers/zerolog v0.4.5 // indirect
|
darvaza.org/slog/handlers/zerolog v0.4.4 // indirect
|
||||||
github.com/BurntSushi/toml v1.3.2 // indirect
|
github.com/BurntSushi/toml v1.3.2 // indirect
|
||||||
github.com/chavacava/garif v0.1.0 // indirect
|
github.com/chavacava/garif v0.1.0 // indirect
|
||||||
github.com/fatih/color v1.15.0 // indirect
|
github.com/fatih/color v1.15.0 // indirect
|
||||||
@@ -41,7 +40,7 @@ require (
|
|||||||
github.com/spf13/pflag v1.0.5 // indirect
|
github.com/spf13/pflag v1.0.5 // indirect
|
||||||
golang.org/x/mod v0.12.0 // indirect
|
golang.org/x/mod v0.12.0 // indirect
|
||||||
golang.org/x/net v0.14.0 // indirect
|
golang.org/x/net v0.14.0 // indirect
|
||||||
golang.org/x/sys v0.12.0 // indirect
|
golang.org/x/sys v0.11.0 // indirect
|
||||||
golang.org/x/text v0.13.0 // indirect
|
golang.org/x/text v0.13.0 // indirect
|
||||||
golang.org/x/tools v0.12.0 // indirect
|
golang.org/x/tools v0.12.0 // indirect
|
||||||
gopkg.in/warnings.v0 v0.1.2 // indirect
|
gopkg.in/warnings.v0 v0.1.2 // indirect
|
||||||
|
|||||||
@@ -1,21 +1,19 @@
|
|||||||
asciigoat.org/core v0.3.9 h1:hgDDz4ecm3ZvehX++m8A/IzAt+B5oDPiRtxatzfUHPQ=
|
asciigoat.org/core v0.3.9 h1:hgDDz4ecm3ZvehX++m8A/IzAt+B5oDPiRtxatzfUHPQ=
|
||||||
asciigoat.org/core v0.3.9/go.mod h1:CAaHwyw8MpAq4a1MYtN2dxJrsK+hmIdW50OndaQZYPI=
|
asciigoat.org/core v0.3.9/go.mod h1:CAaHwyw8MpAq4a1MYtN2dxJrsK+hmIdW50OndaQZYPI=
|
||||||
asciigoat.org/ini v0.2.5 h1:4gRIp9rU+XQt8+HMqZO5R7GavMv9Yl2+N+je6djDIAE=
|
asciigoat.org/ini v0.2.4 h1:fTswCCBle65kTq9AuyN7q7RjYJ5sVTxi9zCAKWSbP6A=
|
||||||
asciigoat.org/ini v0.2.5/go.mod h1:gmXzJ9XFqf1NLk5nQkj04USQ4tMtdRJHNQX6vp3DzjU=
|
asciigoat.org/ini v0.2.4/go.mod h1:gmXzJ9XFqf1NLk5nQkj04USQ4tMtdRJHNQX6vp3DzjU=
|
||||||
darvaza.org/core v0.9.8 h1:luLxgfUc2pzuusYPo/Z/dC/qr9XZPKpSQw8/kS7zNUM=
|
darvaza.org/core v0.9.5 h1:sS5pZFwicaxJIQixEiqkMr9GknVHYL+EbKDMkR/4jDM=
|
||||||
darvaza.org/core v0.9.8/go.mod h1:Dbme64naxeshQfxcVJX9ZT7AiGyIY8kldfuELVtf8mw=
|
darvaza.org/core v0.9.5/go.mod h1:O3tHBMlw+xB47uGh5CUx7dXAujBAMmD8BCRFPZmIw54=
|
||||||
darvaza.org/resolver v0.5.4 h1:dlSBNV14yYsp7Kg7ipwYOMNsLbrpeXa8Z0HBTa0Ryxs=
|
darvaza.org/resolver v0.5.2 h1:VjHhEr/MJBszeDb7tYlXQ9Bsyh4xrDR7Sd10WAmPD6k=
|
||||||
darvaza.org/resolver v0.5.4/go.mod h1:vHMkQUmHjaetFqG2ZLZJiQHsXEMGoTOFGm+NXwfndhE=
|
darvaza.org/resolver v0.5.2/go.mod h1:fFvsVPEFeMzUIWlLG47Go/6uJYtRLb9R8HIgYg3uaxE=
|
||||||
darvaza.org/sidecar v0.0.2 h1:4H8FUxc43kkLjxdShN1CoxLTcoHQsZjDVwm7kt6eIK0=
|
darvaza.org/sidecar v0.0.0-20230721122716-b9c54b8adbaf h1:ya5ZQicBb/GWll3rlqra8No7oJXks7y1m/cJGYBypv4=
|
||||||
darvaza.org/sidecar v0.0.2/go.mod h1:yFC3Qt3j+uS7n9CMpLxwrA68z+FNJhENoenBc9zBJJo=
|
darvaza.org/sidecar v0.0.0-20230721122716-b9c54b8adbaf/go.mod h1:by+bPsMa7Rxc/ZYG1qBunrtKocv/DkrPBmyFlmq/j2Q=
|
||||||
darvaza.org/slog v0.5.3 h1:sQzmZXgqRh9oFMKBwEYrEpucLvKJVZxaxa2bHIA6GJ0=
|
darvaza.org/slog v0.5.2 h1:8TG1WyHjOyh2vW6t3pjzZVaWzpko5MIIpeI7LWqHFvs=
|
||||||
darvaza.org/slog v0.5.3/go.mod h1:59d+yi+C7gn4pDDuwbbOKawERpdXthFFk1Yc+Sv6XB0=
|
darvaza.org/slog v0.5.2/go.mod h1:HAkEpxTA/mkiLNUXJo5qsCh8EVCtA3evje8GAaCDWHI=
|
||||||
darvaza.org/slog/handlers/discard v0.4.5 h1:RRykOItNolHyiUav57lG/GFBL33rcljoa0nWTpY+T0g=
|
darvaza.org/slog/handlers/filter v0.4.4 h1:b2e2T9fQzMdJ0ia+f6b7kw9/T9GFwhFCKob/2tqhGGU=
|
||||||
darvaza.org/slog/handlers/discard v0.4.5/go.mod h1:HYHfISQjMqcPbPoPZ92ib/u7s9JcXvF6OaygpPFwdF8=
|
darvaza.org/slog/handlers/filter v0.4.4/go.mod h1:cQlJWuolB6guLug09sX/8Zrzct++M6SPCGvXR37E7Cc=
|
||||||
darvaza.org/slog/handlers/filter v0.4.5 h1:CX1bMzldd67e3y3s3Sh4jK8Lyo0WMvTGBB2lD315jhc=
|
darvaza.org/slog/handlers/zerolog v0.4.4 h1:OR1ASvH1fBCq3t85t4OU6oJPPuqMB1tsDoSpsh6HVJU=
|
||||||
darvaza.org/slog/handlers/filter v0.4.5/go.mod h1:OuH9rHYg9CIErTJCZliMnFexBfP/HJ9PZ1V1VwSCZ1g=
|
darvaza.org/slog/handlers/zerolog v0.4.4/go.mod h1:t60TeEbFcMLo74CkXC2S0rKlnwF4ixZyBR4fqIJV1GE=
|
||||||
darvaza.org/slog/handlers/zerolog v0.4.5 h1:W4cgGORx4wImr+RL96CWSQGTdkZzKX6YHXPSYJvdoB4=
|
|
||||||
darvaza.org/slog/handlers/zerolog v0.4.5/go.mod h1:mCoh/mIl8Nsa6Yu1Um7d7cos6RuEJzgaTXaX5LDRUao=
|
|
||||||
github.com/BurntSushi/toml v1.3.2 h1:o7IhLm0Msx3BaB+n3Ag7L8EVlByGnpq14C4YWiu/gL8=
|
github.com/BurntSushi/toml v1.3.2 h1:o7IhLm0Msx3BaB+n3Ag7L8EVlByGnpq14C4YWiu/gL8=
|
||||||
github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
|
github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
|
||||||
github.com/burntSushi/toml v0.3.1 h1:Hu1cOEC2qtKULZJCzym5tyA35bZr3HREuolgiAzMlhY=
|
github.com/burntSushi/toml v0.3.1 h1:Hu1cOEC2qtKULZJCzym5tyA35bZr3HREuolgiAzMlhY=
|
||||||
@@ -92,8 +90,8 @@ golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBc
|
|||||||
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o=
|
golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM=
|
||||||
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k=
|
golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k=
|
||||||
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
|
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
|
||||||
golang.org/x/tools v0.12.0 h1:YW6HUoUmYBpwSgyaGaZq1fHjrBjX1rlpZ54T6mu2kss=
|
golang.org/x/tools v0.12.0 h1:YW6HUoUmYBpwSgyaGaZq1fHjrBjX1rlpZ54T6mu2kss=
|
||||||
|
|||||||
+2
-31
@@ -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)
|
||||||
|
|||||||
@@ -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) {
|
||||||
|
|||||||
@@ -2,28 +2,11 @@ package zones
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"net/netip"
|
|
||||||
"sort"
|
"sort"
|
||||||
|
|
||||||
"darvaza.org/core"
|
|
||||||
"github.com/gofrs/uuid/v5"
|
|
||||||
|
|
||||||
"git.jpi.io/amery/jpictl/pkg/ceph"
|
"git.jpi.io/amery/jpictl/pkg/ceph"
|
||||||
)
|
)
|
||||||
|
|
||||||
// GetCephFSID returns our Ceph's FSID
|
|
||||||
func (m *Zones) GetCephFSID() (uuid.UUID, error) {
|
|
||||||
if core.IsZero(m.CephFSID) {
|
|
||||||
// generate one
|
|
||||||
v, err := uuid.NewV4()
|
|
||||||
if err != nil {
|
|
||||||
return uuid.Nil, err
|
|
||||||
}
|
|
||||||
m.CephFSID = v
|
|
||||||
}
|
|
||||||
return m.CephFSID, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetCephConfig reads the ceph.conf file
|
// GetCephConfig reads the ceph.conf file
|
||||||
func (m *Zones) GetCephConfig() (*ceph.Config, error) {
|
func (m *Zones) GetCephConfig() (*ceph.Config, error) {
|
||||||
data, err := m.ReadFile("ceph.conf")
|
data, err := m.ReadFile("ceph.conf")
|
||||||
@@ -35,48 +18,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
|
|
||||||
func (m *Zones) GenCephConfig() (*ceph.Config, error) {
|
|
||||||
fsid, err := m.GetCephFSID()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
cfg := &ceph.Config{
|
|
||||||
Global: ceph.GlobalConfig{
|
|
||||||
FSID: fsid,
|
|
||||||
ClusterNetwork: netip.PrefixFrom(
|
|
||||||
netip.AddrFrom4([4]byte{10, 0, 0, 0}),
|
|
||||||
8,
|
|
||||||
),
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
m.ForEachZone(func(z *Zone) bool {
|
|
||||||
for _, p := range z.GetCephMonitors() {
|
|
||||||
addr, _ := RingOneAddress(z.ID, p.ID)
|
|
||||||
|
|
||||||
cfg.Global.Monitors = append(cfg.Global.Monitors, p.Name)
|
|
||||||
cfg.Global.MonitorsAddr = append(cfg.Global.MonitorsAddr, addr)
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
})
|
|
||||||
|
|
||||||
return cfg, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetCephMonitors returns the set of Ceph monitors on
|
// GetCephMonitors returns the set of Ceph monitors on
|
||||||
// the zone
|
// the zone
|
||||||
func (z *Zone) GetCephMonitors() Machines {
|
func (z *Zone) GetCephMonitors() Machines {
|
||||||
|
|||||||
+14
-21
@@ -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
|
||||||
|
|||||||
+3
-17
@@ -11,24 +11,15 @@ import (
|
|||||||
type Env struct {
|
type Env struct {
|
||||||
ZoneIterator
|
ZoneIterator
|
||||||
|
|
||||||
cephFSID string
|
export bool
|
||||||
export bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Env returns a shell environment factory
|
// Env returns a shell environment factory
|
||||||
func (m *Zones) Env(export bool) (*Env, error) {
|
func (m *Zones) Env(export bool) *Env {
|
||||||
fsid, err := m.GetCephFSID()
|
return &Env{
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
env := &Env{
|
|
||||||
ZoneIterator: m,
|
ZoneIterator: m,
|
||||||
cephFSID: fsid.String(),
|
|
||||||
export: export,
|
export: export,
|
||||||
}
|
}
|
||||||
|
|
||||||
return env, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Zones returns the list of Zone IDs
|
// Zones returns the list of Zone IDs
|
||||||
@@ -47,12 +38,7 @@ func (m *Env) Zones() []int {
|
|||||||
func (m *Env) WriteTo(w io.Writer) (int64, error) {
|
func (m *Env) WriteTo(w io.Writer) (int64, error) {
|
||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
|
|
||||||
if m.cephFSID != "" {
|
|
||||||
m.writeEnvVar(&buf, m.cephFSID, "FSID")
|
|
||||||
}
|
|
||||||
|
|
||||||
m.writeEnvVarInts(&buf, m.Zones(), "ZONES")
|
m.writeEnvVarInts(&buf, m.Zones(), "ZONES")
|
||||||
|
|
||||||
m.ForEachZone(func(z *Zone) bool {
|
m.ForEachZone(func(z *Zone) bool {
|
||||||
m.writeEnvZone(&buf, z)
|
m.writeEnvZone(&buf, z)
|
||||||
return false
|
return false
|
||||||
|
|||||||
@@ -1,16 +0,0 @@
|
|||||||
package zones
|
|
||||||
|
|
||||||
import "errors"
|
|
||||||
|
|
||||||
var (
|
|
||||||
// ErrInvalidName indicates the name isn't valid
|
|
||||||
ErrInvalidName = errors.New("invalid name")
|
|
||||||
|
|
||||||
// ErrUnknownNode indicates there is a reference to a node
|
|
||||||
// we don't have on the tree
|
|
||||||
ErrUnknownNode = errors.New("node does not exist")
|
|
||||||
|
|
||||||
// ErrInvalidNode indicates the nodes can't be used for
|
|
||||||
// the intended purpose
|
|
||||||
ErrInvalidNode = errors.New("invalid node")
|
|
||||||
)
|
|
||||||
@@ -1,49 +0,0 @@
|
|||||||
package zones
|
|
||||||
|
|
||||||
import "darvaza.org/slog"
|
|
||||||
|
|
||||||
type logger interface {
|
|
||||||
withDebug() (slog.Logger, bool)
|
|
||||||
withInfo() (slog.Logger, bool)
|
|
||||||
|
|
||||||
debug() slog.Logger
|
|
||||||
info() slog.Logger
|
|
||||||
warn(error) slog.Logger
|
|
||||||
error(error) slog.Logger
|
|
||||||
}
|
|
||||||
|
|
||||||
var (
|
|
||||||
_ logger = (*Zones)(nil)
|
|
||||||
)
|
|
||||||
|
|
||||||
func (z *Zones) withDebug() (slog.Logger, bool) {
|
|
||||||
return z.debug().WithEnabled()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (z *Zones) withInfo() (slog.Logger, bool) {
|
|
||||||
return z.debug().WithEnabled()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (z *Zones) debug() slog.Logger {
|
|
||||||
return z.log.Debug()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (z *Zones) info() slog.Logger {
|
|
||||||
return z.log.Info()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (z *Zones) warn(err error) slog.Logger {
|
|
||||||
l := z.log.Warn()
|
|
||||||
if err != nil {
|
|
||||||
l = l.WithField(slog.ErrorFieldName, err)
|
|
||||||
}
|
|
||||||
return l
|
|
||||||
}
|
|
||||||
|
|
||||||
func (z *Zones) error(err error) slog.Logger {
|
|
||||||
l := z.log.Error()
|
|
||||||
if err != nil {
|
|
||||||
l = l.WithField(slog.ErrorFieldName, err)
|
|
||||||
}
|
|
||||||
return l
|
|
||||||
}
|
|
||||||
@@ -9,9 +9,7 @@ import (
|
|||||||
|
|
||||||
// A Machine is a machine on a Zone
|
// A Machine is a machine on a Zone
|
||||||
type Machine struct {
|
type Machine struct {
|
||||||
zone *Zone
|
zone *Zone
|
||||||
logger `toml:"-" json:"-" yaml:"-"`
|
|
||||||
|
|
||||||
ID int `toml:"id"`
|
ID int `toml:"id"`
|
||||||
Name string `toml:"-" json:"-" yaml:"-"`
|
Name string `toml:"-" json:"-" yaml:"-"`
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package zones
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
@@ -136,11 +135,7 @@ func (m *Machine) applyWireguardConfig(ring int, wg *wireguard.Config) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, peer := range wg.Peer {
|
for _, peer := range wg.Peer {
|
||||||
err := m.applyWireguardPeerConfig(ring, peer)
|
if err := m.applyWireguardPeerConfig(ring, peer); err != nil {
|
||||||
switch {
|
|
||||||
case errors.Is(err, ErrUnknownNode):
|
|
||||||
// ignore unknown peers
|
|
||||||
case err != nil:
|
|
||||||
err = core.Wrapf(err, "%s: wg%v:%s", m.Name, ring, addr)
|
err = core.Wrapf(err, "%s: wg%v:%s", m.Name, ring, addr)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -188,10 +183,8 @@ func (m *Machine) applyWireguardPeerConfig(ring int, pc wireguard.PeerConfig) er
|
|||||||
switch {
|
switch {
|
||||||
case !found:
|
case !found:
|
||||||
// unknown
|
// unknown
|
||||||
return core.Wrap(ErrUnknownNode, pc.Endpoint.Host)
|
|
||||||
case ring == 1 && m.zone != peer.zone:
|
case ring == 1 && m.zone != peer.zone:
|
||||||
// invalid zone
|
// invalid zone
|
||||||
return core.Wrap(ErrInvalidNode, peer.Name)
|
|
||||||
default:
|
default:
|
||||||
// apply RingInfo
|
// apply RingInfo
|
||||||
ri := &RingInfo{
|
ri := &RingInfo{
|
||||||
@@ -204,6 +197,8 @@ func (m *Machine) applyWireguardPeerConfig(ring int, pc wireguard.PeerConfig) er
|
|||||||
|
|
||||||
return peer.applyRingInfo(ring, ri)
|
return peer.applyRingInfo(ring, ri)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return fmt.Errorf("%q: invalid peer endpoint", pc.Endpoint.Host)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Machine) applyZoneNodeID(zoneID, nodeID int) error {
|
func (m *Machine) applyZoneNodeID(zoneID, nodeID int) error {
|
||||||
|
|||||||
@@ -4,10 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"net/netip"
|
"net/netip"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"darvaza.org/core"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// LookupNetIP uses the DNS Resolver to get the public addresses associated
|
// LookupNetIP uses the DNS Resolver to get the public addresses associated
|
||||||
@@ -33,32 +30,21 @@ func (m *Machine) UpdatePublicAddresses() error {
|
|||||||
|
|
||||||
func (m *Machine) init() error {
|
func (m *Machine) init() error {
|
||||||
if err := m.setID(); err != nil {
|
if err := m.setID(); err != nil {
|
||||||
return core.Wrap(err, m.Name)
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < RingsCount; i++ {
|
for i := 0; i < RingsCount; i++ {
|
||||||
if err := m.tryReadWireguardKeys(i); err != nil {
|
if err := m.tryReadWireguardKeys(i); err != nil {
|
||||||
return core.Wrap(err, m.Name)
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Machine) setID() error {
|
func (m *Machine) setID() error {
|
||||||
zoneName := m.zone.Name
|
zoneName := m.zone.Name
|
||||||
|
suffix := m.Name[len(zoneName)+1:]
|
||||||
|
|
||||||
l := len(zoneName)
|
|
||||||
switch {
|
|
||||||
case len(m.Name) < l+2:
|
|
||||||
return ErrInvalidName
|
|
||||||
case !strings.HasPrefix(m.Name, zoneName):
|
|
||||||
return ErrInvalidName
|
|
||||||
case m.Name[l] != '-':
|
|
||||||
return ErrInvalidName
|
|
||||||
}
|
|
||||||
|
|
||||||
suffix := m.Name[l+1:]
|
|
||||||
id, err := strconv.ParseInt(suffix, 10, 8)
|
id, err := strconv.ParseInt(suffix, 10, 8)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
+1
-26
@@ -5,12 +5,10 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"darvaza.org/resolver"
|
"darvaza.org/resolver"
|
||||||
"darvaza.org/slog"
|
|
||||||
"darvaza.org/slog/handlers/discard"
|
|
||||||
"github.com/hack-pad/hackpadfs/os"
|
"github.com/hack-pad/hackpadfs/os"
|
||||||
)
|
)
|
||||||
|
|
||||||
// A ScanOption pre-configures the Zones before scanning
|
// A ScanOption preconfigures the Zones before scanning
|
||||||
type ScanOption func(*Zones, *ScanOptions) error
|
type ScanOption func(*Zones, *ScanOptions) error
|
||||||
|
|
||||||
// ScanOptions contains flags used by the initial scan
|
// ScanOptions contains flags used by the initial scan
|
||||||
@@ -19,10 +17,6 @@ type ScanOptions struct {
|
|||||||
// pre-populate Machine.PublicAddresses during the
|
// pre-populate Machine.PublicAddresses during the
|
||||||
// initial scan
|
// initial scan
|
||||||
DontResolvePublicAddresses bool
|
DontResolvePublicAddresses bool
|
||||||
|
|
||||||
// Logger specifies the logger to be used. otherwise
|
|
||||||
// the scanner will be mute
|
|
||||||
slog.Logger
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ResolvePublicAddresses instructs the scanner to use
|
// ResolvePublicAddresses instructs the scanner to use
|
||||||
@@ -61,19 +55,6 @@ func WithResolver(h resolver.Resolver) ScanOption {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// WithLogger specifies what to use for logging
|
|
||||||
func WithLogger(log slog.Logger) ScanOption {
|
|
||||||
return func(m *Zones, opt *ScanOptions) error {
|
|
||||||
if log == nil {
|
|
||||||
log = discard.New()
|
|
||||||
}
|
|
||||||
|
|
||||||
opt.Logger = log
|
|
||||||
m.log = log
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *Zones) setDefaults(opt *ScanOptions) error {
|
func (m *Zones) setDefaults(opt *ScanOptions) error {
|
||||||
if m.resolver == nil {
|
if m.resolver == nil {
|
||||||
h := resolver.NewCloudflareLookuper()
|
h := resolver.NewCloudflareLookuper()
|
||||||
@@ -83,12 +64,6 @@ func (m *Zones) setDefaults(opt *ScanOptions) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if opt.Logger == nil {
|
|
||||||
if err := WithLogger(nil)(m, opt); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+11
-24
@@ -3,8 +3,6 @@ package zones
|
|||||||
import (
|
import (
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"sort"
|
"sort"
|
||||||
|
|
||||||
"darvaza.org/core"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func (m *Zones) scan(opts *ScanOptions) error {
|
func (m *Zones) scan(opts *ScanOptions) error {
|
||||||
@@ -33,32 +31,22 @@ func (m *Zones) scanDirectory(_ *ScanOptions) error {
|
|||||||
|
|
||||||
for _, e := range entries {
|
for _, e := range entries {
|
||||||
if e.IsDir() {
|
if e.IsDir() {
|
||||||
z, err := m.newZone(e.Name())
|
z := &Zone{
|
||||||
switch {
|
zones: m,
|
||||||
case err != nil:
|
Name: e.Name(),
|
||||||
return core.Wrap(err, e.Name())
|
|
||||||
case z.Machines.Len() > 0:
|
|
||||||
m.Zones = append(m.Zones, z)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err := z.scan(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
m.Zones = append(m.Zones, z)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Zones) newZone(name string) (*Zone, error) {
|
|
||||||
z := &Zone{
|
|
||||||
zones: m,
|
|
||||||
logger: m,
|
|
||||||
Name: name,
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := z.scan(); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return z, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *Zones) scanMachines(opts *ScanOptions) error {
|
func (m *Zones) scanMachines(opts *ScanOptions) error {
|
||||||
var err error
|
var err error
|
||||||
m.ForEachMachine(func(p *Machine) bool {
|
m.ForEachMachine(func(p *Machine) bool {
|
||||||
@@ -144,9 +132,8 @@ func (z *Zone) scan() error {
|
|||||||
for _, e := range entries {
|
for _, e := range entries {
|
||||||
if e.IsDir() {
|
if e.IsDir() {
|
||||||
m := &Machine{
|
m := &Machine{
|
||||||
zone: z,
|
zone: z,
|
||||||
logger: z,
|
Name: e.Name(),
|
||||||
Name: e.Name(),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := m.init(); err != nil {
|
if err := m.init(); err != nil {
|
||||||
|
|||||||
@@ -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)
|
|
||||||
}
|
|
||||||
|
|||||||
+1
-11
@@ -6,8 +6,6 @@ import (
|
|||||||
"sort"
|
"sort"
|
||||||
|
|
||||||
"darvaza.org/resolver"
|
"darvaza.org/resolver"
|
||||||
"darvaza.org/slog"
|
|
||||||
"github.com/gofrs/uuid/v5"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -87,8 +85,7 @@ func FilterMachines(m MachineIterator, cond func(*Machine) bool) (Machines, int)
|
|||||||
|
|
||||||
// Zone represents one zone in a cluster
|
// Zone represents one zone in a cluster
|
||||||
type Zone struct {
|
type Zone struct {
|
||||||
zones *Zones
|
zones *Zones
|
||||||
logger `toml:"-" json:"-" yaml:"-"`
|
|
||||||
|
|
||||||
ID int `toml:"id"`
|
ID int `toml:"id"`
|
||||||
Name string `toml:"name"`
|
Name string `toml:"name"`
|
||||||
@@ -138,22 +135,15 @@ func (z *Zone) GatewayIDs() ([]int, int) {
|
|||||||
return out, len(out)
|
return out, len(out)
|
||||||
}
|
}
|
||||||
|
|
||||||
// revive:disable:line-length-limit
|
|
||||||
|
|
||||||
// Zones represents all zones in a cluster
|
// Zones represents all zones in a cluster
|
||||||
type Zones struct {
|
type Zones struct {
|
||||||
dir fs.FS
|
dir fs.FS
|
||||||
log slog.Logger
|
|
||||||
resolver resolver.Resolver
|
resolver resolver.Resolver
|
||||||
domain string
|
domain string
|
||||||
|
|
||||||
CephFSID uuid.UUID `toml:"ceph_fsid,omitempty" json:"ceph_fsid,omitempty" yaml:"ceph_fsid,omitempty"`
|
|
||||||
|
|
||||||
Zones []*Zone `toml:"zones"`
|
Zones []*Zone `toml:"zones"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// revive:enable:line-length-limit
|
|
||||||
|
|
||||||
// ForEachMachine calls a function for each Machine in the cluster
|
// ForEachMachine calls a function for each Machine in the cluster
|
||||||
// until instructed to terminate the loop
|
// until instructed to terminate the loop
|
||||||
func (m *Zones) ForEachMachine(fn func(*Machine) bool) {
|
func (m *Zones) ForEachMachine(fn func(*Machine) bool) {
|
||||||
|
|||||||
Reference in New Issue
Block a user