Compare commits

..

3 Commits

Author SHA1 Message Date
amery 3a1b00ad1b WIP
Signed-off-by: Alejandro Mery <amery@jpi.io>
2023-09-12 00:01:26 +00:00
amery 7564bdcc4d dns: introduce AddrRecord{} to abstract A/AAAA entries
Signed-off-by: Alejandro Mery <amery@jpi.io>
2023-09-12 00:01:26 +00:00
amery 3ff62a1ef4 vscode: add Lookuper, publicsuffix and libdns to the dictionary
Signed-off-by: Alejandro Mery <amery@jpi.io>
2023-09-12 00:01:12 +00:00
7 changed files with 236 additions and 216 deletions
+1
View File
@@ -8,6 +8,7 @@
"jpictl", "jpictl",
"libdns", "libdns",
"Lookuper", "Lookuper",
"publicsuffix",
"Wrapf", "Wrapf",
"zerolog" "zerolog"
] ]
+3 -11
View File
@@ -3,7 +3,6 @@ package main
import ( import (
"context" "context"
"os" "os"
"time"
"github.com/spf13/cobra" "github.com/spf13/cobra"
@@ -11,11 +10,7 @@ import (
"git.jpi.io/amery/jpictl/pkg/dns" "git.jpi.io/amery/jpictl/pkg/dns"
) )
const ( func newDNSManager(m *cluster.Cluster) (*dns.Manager, error) {
DNSTimeout = 10 * time.Second
)
func newDNSManager(ctx context.Context, m *cluster.Cluster) (*dns.Manager, error) {
domain := m.Domain domain := m.Domain
if m.Name != "" { if m.Name != "" {
domain = m.Name + "." + domain domain = m.Name + "." + domain
@@ -28,7 +23,7 @@ func newDNSManager(ctx context.Context, m *cluster.Cluster) (*dns.Manager, error
m.ForEachZone(func(z *cluster.Zone) bool { m.ForEachZone(func(z *cluster.Zone) bool {
z.ForEachMachine(func(p *cluster.Machine) bool { z.ForEachMachine(func(p *cluster.Machine) bool {
err = mgr.AddHost(ctx, z.Name, p.ID, true, p.PublicAddresses...) err = mgr.AddHost(context.TODO(), z.Name, p.ID, true, p.PublicAddresses...)
return err != nil return err != nil
}) })
@@ -56,10 +51,7 @@ var dnsWriteCmd = &cobra.Command{
return err return err
} }
ctx, cancel := context.WithTimeout(context.Background(), DNSTimeout) mgr, err := newDNSManager(m)
defer cancel()
mgr, err := newDNSManager(ctx, m)
if err != nil { if err != nil {
return err return err
} }
+1 -1
View File
@@ -18,6 +18,7 @@ require (
github.com/mgechev/revive v1.3.3 github.com/mgechev/revive v1.3.3
github.com/spf13/cobra v1.7.0 github.com/spf13/cobra v1.7.0
golang.org/x/crypto v0.12.0 golang.org/x/crypto v0.12.0
golang.org/x/net v0.14.0
gopkg.in/yaml.v3 v3.0.1 gopkg.in/yaml.v3 v3.0.1
) )
@@ -42,7 +43,6 @@ require (
github.com/rs/zerolog v1.30.0 // indirect github.com/rs/zerolog v1.30.0 // indirect
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/sys v0.12.0 // indirect golang.org/x/sys v0.12.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
+18 -14
View File
@@ -1,7 +1,10 @@
// Package dns manages DNS entries for the cluster // Package dns manages DNS entries for the cluster
package dns package dns
import "net/netip"
// // A Config defines a Region // // A Config defines a Region
//
// type Config struct { // type Config struct {
// // Name is the identifier of this Region // // Name is the identifier of this Region
// Name string // Name string
@@ -14,17 +17,18 @@ package dns
// type Region struct { // type Region struct {
// Name string // Name string
// } // }
//
//type Zone struct { // Zone represents a set of machines with high affinity
// Name string type Zone struct {
// Name string
// Machines map[int]*Machine
//} Machines map[int]*Machine
// }
//type Machine struct {
// ID int // Machine represents a member of the cluster
// type Machine struct {
// Active bool ID int
// Addrs []netip.Addr
//} Active bool
// Addrs []netip.Addr
}
+9 -4
View File
@@ -1,6 +1,12 @@
package dns package dns
//func (mgr *Manager) AddHost(_ context.Context, zone string, id int, active bool, addrs ...netip.Addr) error { import (
"context"
"net/netip"
)
// AddHost registers a machine
func (*Manager) AddHost(_ context.Context, _ string, _ int, _ bool, _ ...netip.Addr) error {
// if zone == "" || id <= 0 { // if zone == "" || id <= 0 {
// return fs.ErrInvalid // return fs.ErrInvalid
// } // }
@@ -21,6 +27,5 @@ package dns
// Addrs: addrs, // Addrs: addrs,
// } // }
// //
// return nil return nil
//} }
//
+86 -76
View File
@@ -1,30 +1,41 @@
package dns package dns
// // Manager is a DNS Manager instance import (
// type Manager struct { "strings"
// mu sync.Mutex "sync"
//
// domain string "darvaza.org/core"
// suffix string "darvaza.org/slog"
// zones map[string]*Zone "git.jpi.io/amery/jpictl/pkg/cluster"
// "golang.org/x/net/publicsuffix"
// p Provider )
// l slog.Logger
// } // Manager is a DNS Manager instance
// type Manager struct {
// // ManagerOption configures a Manager mu sync.Mutex
// type ManagerOption func(*Manager) error
// domain string
// func newErrorManagerOption(err error, hint string) ManagerOption { suffix string
// return func(*Manager) error { zones map[string]*Zone
// if hint != "" {
// err = core.Wrap(err, hint) p Provider
// } l slog.Logger
// return err }
// }
// } // ManagerOption configures a Manager
// type ManagerOption func(*Manager) error
func newErrorManagerOption(err error, hint string) ManagerOption {
return func(*Manager) error {
if hint != "" {
err = core.Wrap(err, hint)
}
return err
}
}
// // WithProvider attaches a libdns Provider to the Manager // // WithProvider attaches a libdns Provider to the Manager
//
// func WithProvider(p Provider) ManagerOption { // func WithProvider(p Provider) ManagerOption {
// var err error // var err error
// //
@@ -41,20 +52,20 @@ package dns
// return nil // return nil
// } // }
// } // }
//
// // WithLogger attaches a logger to the Manager // WithLogger attaches a logger to the Manager
// func WithLogger(log slog.Logger) ManagerOption { func WithLogger(log slog.Logger) ManagerOption {
// if log == nil { if log == nil {
// log = cluster.DefaultLogger() log = cluster.DefaultLogger()
// } }
//
// return func(mgr *Manager) error { return func(mgr *Manager) error {
// mgr.l = log mgr.l = log
// return nil return nil
// } }
// } }
//
// func (mgr *Manager) setDefaults() error { func (*Manager) setDefaults() error {
// var opts []ManagerOption // var opts []ManagerOption
// //
// if mgr.p == nil { // if mgr.p == nil {
@@ -76,41 +87,40 @@ package dns
// return err // return err
// } // }
// } // }
// return nil return nil
// } }
//
// // WithDomain specifies where the manager operates // WithDomain specifies where the manager operates
// func WithDomain(domain string) ManagerOption { func WithDomain(domain string) ManagerOption {
// base, err := publicsuffix.EffectiveTLDPlusOne(domain) base, err := publicsuffix.EffectiveTLDPlusOne(domain)
// if err != nil { if err != nil {
// return newErrorManagerOption(err, "publicsuffix") return newErrorManagerOption(err, "publicsuffix")
// } }
//
// suffix := strings.TrimSuffix(domain, base) suffix := strings.TrimSuffix(domain, base)
// if suffix != "" { if suffix != "" {
// suffix = "." + suffix[:len(suffix)-1] suffix = "." + suffix[:len(suffix)-1]
// } }
//
// return func(mgr *Manager) error { return func(mgr *Manager) error {
// mgr.domain = base mgr.domain = base
// mgr.suffix = suffix mgr.suffix = suffix
// return nil return nil
// } }
// } }
//
// // NewManager creates a DNS manager with the // NewManager creates a DNS manager with the
// func NewManager(opts ...ManagerOption) (*Manager, error) { func NewManager(opts ...ManagerOption) (*Manager, error) {
// mgr := new(Manager) mgr := new(Manager)
//
// for _, opt := range opts { for _, opt := range opts {
// if err := opt(mgr); err != nil { if err := opt(mgr); err != nil {
// return nil, err return nil, err
// } }
// } }
//
// if err := mgr.setDefaults(); err != nil { if err := mgr.setDefaults(); err != nil {
// return nil, err return nil, err
// } }
// return mgr, nil return mgr, nil
// } }
//
+14 -6
View File
@@ -1,7 +1,13 @@
package dns package dns
// func (mgr *Manager) WriteTo(w io.Writer) (int64, error) { import (
// var buf bytes.Buffer "bytes"
"io"
)
// WriteTo writes the DNS data for the cluster
func (*Manager) WriteTo(w io.Writer) (int64, error) {
var buf bytes.Buffer
// //
// var zoneNames sort.StringSlice // var zoneNames sort.StringSlice
// //
@@ -42,10 +48,12 @@ package dns
// mgr.writeRegionToBuffer(&buf, zones, "eu", "ssd-ams", "htz-fsn") // mgr.writeRegionToBuffer(&buf, zones, "eu", "ssd-ams", "htz-fsn")
// mgr.writeRegionToBuffer(&buf, zones, "europe", "ssd-ams", "ssd-lon", "htz-fsn") // mgr.writeRegionToBuffer(&buf, zones, "europe", "ssd-ams", "ssd-lon", "htz-fsn")
// mgr.writeRegionToBuffer(&buf, zones, "earth", "ssd-ams", "ssd-lon", "htz-fsn") // mgr.writeRegionToBuffer(&buf, zones, "earth", "ssd-ams", "ssd-lon", "htz-fsn")
//
// return buf.WriteTo(w) return buf.WriteTo(w)
// } }
//
// revive:disable:line-length-limit
// func (mgr *Manager) writeRecordsToBuffer(buf *bytes.Buffer, rename string, records ...libdns.Record) { // func (mgr *Manager) writeRecordsToBuffer(buf *bytes.Buffer, rename string, records ...libdns.Record) {
// for _, rr := range records { // for _, rr := range records {
// name := core.IIf(rename != "", rename, rr.Name) // name := core.IIf(rename != "", rename, rr.Name)