server add records the floating address where the summary can read it
keepalived's file holds its password and is root's alone; the control plane runs as llmgw and could not read it, so the CONTROL line never named the floating address. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
ec1918b23b
commit
adef25d709
3 files changed
+24
-32
No files matched your search
@@ -1,7 +1,6 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"context"
|
||||
"net"
|
||||
"net/http"
|
||||
@@ -15,8 +14,8 @@ import (
|
||||
"gitea.mynodes.xyz/ilker/llmgw/internal/store"
|
||||
)
|
||||
|
||||
// keepalivedPath is where `server add --vip` writes the floating address.
|
||||
const keepalivedPath = "/etc/keepalived/keepalived.conf"
|
||||
// floatingPath is where `server add --vip` records the floating address.
|
||||
const floatingPath = "/etc/llmgw/floating"
|
||||
|
||||
// controlPlaneProbe answers the summary's question of which control plane
|
||||
// leads: it asks each one's /leader, on the client port every one of them
|
||||
@@ -46,7 +45,7 @@ func newControlPlaneProbe(st *store.DB, listen string) *controlPlaneProbe {
|
||||
self, _ := os.Hostname()
|
||||
return &controlPlaneProbe{st: st, self: self,
|
||||
leaderURL: func(host string) string { return "http://" + net.JoinHostPort(host, port) + "/leader" },
|
||||
floating: floatingAddress(keepalivedPath),
|
||||
floating: floatingAddress(floatingPath),
|
||||
client: &http.Client{Timeout: time.Second}}
|
||||
}
|
||||
|
||||
@@ -104,30 +103,18 @@ func (p *controlPlaneProbe) ask(ctx context.Context, host string) string {
|
||||
return "not answering"
|
||||
}
|
||||
|
||||
// floatingAddress is the address in the keepalived configuration server add
|
||||
// wrote, without its prefix; "" when there is none, or the file is someone
|
||||
// else's.
|
||||
// floatingAddress is the address in the file server add keeps beside the
|
||||
// keepalived configuration, without its prefix; "" when nothing floats.
|
||||
// keepalived's own file holds its password and is root's alone, and this
|
||||
// process is not root.
|
||||
func floatingAddress(path string) string {
|
||||
f, err := os.Open(path) //nolint:gosec // a fixed system path
|
||||
b, err := os.ReadFile(path) //nolint:gosec // a fixed path of our own
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
defer f.Close()
|
||||
sc := bufio.NewScanner(f)
|
||||
ours, in := false, false
|
||||
for sc.Scan() {
|
||||
line := strings.TrimSpace(sc.Text())
|
||||
switch {
|
||||
case strings.HasPrefix(line, "# llmgw:"):
|
||||
ours = true
|
||||
case strings.HasPrefix(line, "virtual_ipaddress"):
|
||||
in = true
|
||||
case in && line == "}":
|
||||
return ""
|
||||
case in && ours && line != "":
|
||||
addr, _, _ := strings.Cut(strings.Fields(line)[0], "/")
|
||||
return addr
|
||||
}
|
||||
addr, _, _ := strings.Cut(strings.TrimSpace(string(b)), "/")
|
||||
if net.ParseIP(addr) == nil {
|
||||
return ""
|
||||
}
|
||||
return ""
|
||||
return addr
|
||||
}
|
||||
Reference in new issue
Block a user