Compare commits

...

6 Commits

Author SHA1 Message Date
amery a910bba406 Merge pull request 'cluster: introduce Machine.Inactive flag' (#38)
Reviewed-on: #38
2023-10-30 20:44:41 +01:00
amery 5ef6d45ef7 Merge pull request 'jpictl: fix cloud.yaml unmarshalling' (#32)
Reviewed-on: #32
2023-10-30 20:43:21 +01:00
amery 99998dc7e8 cluster: mark Machine as Inactive if the "region" file contains "none"
Signed-off-by: Alejandro Mery <amery@jpi.io>
2023-10-30 19:21:08 +00:00
amery 892d849740 cluster: introduce Machine.Inactive flag
if a Machine is Inactive, it won't be included on the DNS
aliases for the zone or it's regions.

v2:
- Machine.Active() renamed to Machine.IsActive()

Signed-off-by: Alejandro Mery <amery@jpi.io>
2023-10-30 19:20:45 +00:00
amery 125a4c0dbe wireguard: implement EndpointAddress.UnmarshalText
Signed-off-by: Alejandro Mery <amery@jpi.io>
2023-10-30 19:13:41 +00:00
amery 7c811d7813 wireguard: implement UnmarshalText for PrivateKey and PublicKey
Signed-off-by: Alejandro Mery <amery@jpi.io>
2023-10-30 19:13:41 +00:00
6 changed files with 62 additions and 3 deletions
+1 -1
View File
@@ -52,7 +52,7 @@ func populateDNSManager(mgr *dns.Manager, m *cluster.Cluster) 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(ctx, z.Name, p.ID, p.IsActive(), p.PublicAddresses...)
return err != nil return err != nil
}) })
+6
View File
@@ -15,6 +15,7 @@ type Machine struct {
ID int ID int
Name string `json:"-" yaml:"-"` Name string `json:"-" yaml:"-"`
Inactive bool `json:"inactive,omitempty" yaml:"inactive,omitempty"`
CephMonitor bool `json:"ceph_monitor,omitempty" yaml:"ceph_monitor,omitempty"` CephMonitor bool `json:"ceph_monitor,omitempty" yaml:"ceph_monitor,omitempty"`
PublicAddresses []netip.Addr `json:"public,omitempty" yaml:"public,omitempty"` PublicAddresses []netip.Addr `json:"public,omitempty" yaml:"public,omitempty"`
Rings []*RingInfo `json:"rings,omitempty" yaml:"rings,omitempty"` Rings []*RingInfo `json:"rings,omitempty" yaml:"rings,omitempty"`
@@ -43,6 +44,11 @@ func (m *Machine) FullName() string {
return strings.Join(name, ".") return strings.Join(name, ".")
} }
// IsActive indicates the machine is to be included in regions' DNS entries
func (m *Machine) IsActive() bool {
return !m.Inactive
}
// IsGateway tells if the Machine is a ring0 gateway // IsGateway tells if the Machine is a ring0 gateway
func (m *Machine) IsGateway() bool { func (m *Machine) IsGateway() bool {
_, ok := m.getRingInfo(0) _, ok := m.getRingInfo(0)
+24
View File
@@ -3,6 +3,7 @@ package cluster
import ( import (
"context" "context"
"net/netip" "net/netip"
"os"
"strconv" "strconv"
"strings" "strings"
"time" "time"
@@ -81,7 +82,30 @@ func (m *Machine) scan(_ *ScanOptions) error {
} }
} }
return m.loadInactive()
}
func (m *Machine) loadInactive() error {
data, err := m.ReadLines("region")
switch {
case os.IsNotExist(err):
// no file
return nil return nil
case err != nil:
// read error
return err
default:
// look for "none"
for _, r := range data {
switch r {
case "none":
m.Inactive = true
default:
m.Inactive = false
}
}
return nil
}
} }
// scanWrapUp is called once all machines have been scanned // scanWrapUp is called once all machines have been scanned
+2
View File
@@ -32,7 +32,9 @@ func (r *Region) ForEachMachine(fn func(*Machine) bool) {
var term bool var term bool
z.ForEachMachine(func(p *Machine) bool { z.ForEachMachine(func(p *Machine) bool {
if p.IsActive() {
term = fn(p) term = fn(p)
}
return term return term
}) })
+5
View File
@@ -107,6 +107,11 @@ func (ep EndpointAddress) String() string {
} }
} }
// UnmarshalText loads an endpoint address from text data
func (ep *EndpointAddress) UnmarshalText(b []byte) error {
return ep.FromString(string(b))
}
// FromString sets the EndpointAddress from a given "[host]:port" // FromString sets the EndpointAddress from a given "[host]:port"
func (ep *EndpointAddress) FromString(s string) error { func (ep *EndpointAddress) FromString(s string) error {
host, port, err := core.SplitHostPort(s) host, port, err := core.SplitHostPort(s)
+22
View File
@@ -51,6 +51,28 @@ func (pub PublicKey) String() string {
} }
} }
// UnmarshalText loads the value from base64
func (key *PrivateKey) UnmarshalText(b []byte) error {
v, err := PrivateKeyFromBase64(string(b))
if err != nil {
return err
}
*key = v
return nil
}
// UnmarshalText loads the value from base64
func (pub *PublicKey) UnmarshalText(b []byte) error {
v, err := PublicKeyFromBase64(string(b))
if err != nil {
return err
}
*pub = v
return nil
}
// MarshalJSON encodes the key for JSON, omitting empty. // MarshalJSON encodes the key for JSON, omitting empty.
func (key PrivateKey) MarshalJSON() ([]byte, error) { func (key PrivateKey) MarshalJSON() ([]byte, error) {
return encodeKeyJSON(key.String()) return encodeKeyJSON(key.String())