Skip to content

Commit 1481d4a

Browse files
kvapsclaude
andcommitted
fix(satellite): derive advertised endpoint from --listen port
Previously hardcoded :7000, so changing --listen alone left the advertised endpoint pointing at the old port — controller dialed back at the old port and got connection refused. Pull the port from --listen at startup. Operators can still override explicitly via --advertised-endpoint when the satellite is behind a proxy / NAT. Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: Andrei Kvapil <kvapss@gmail.com>
1 parent 8c041cf commit 1481d4a

1 file changed

Lines changed: 32 additions & 7 deletions

File tree

cmd/satellite/main.go

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ func run() int {
5959
nodeName string
6060
stateDir string
6161
listenAddr string
62+
advertised string
6263
lvmPoolName string
6364
lvmVG string
6465
lvmThinPool string
@@ -73,13 +74,11 @@ func run() int {
7374
flag.StringVar(&listenAddr, "listen", ":7000",
7475
"bind address for the satellite-side gRPC server (controller dials this for ApplyResources)")
7576

76-
advertised := os.Getenv("POD_IP")
77-
if advertised != "" {
78-
advertised += ":7000"
79-
}
80-
81-
flag.StringVar(&advertised, "advertised-endpoint", advertised,
82-
"host:port the controller should dial back at (defaults to $POD_IP:7000)")
77+
// advertised-endpoint flag — actual default is computed AFTER
78+
// flag.Parse() because it depends on --listen's port. Initial
79+
// value here is just an empty string + a placeholder doc.
80+
flag.StringVar(&advertised, "advertised-endpoint", "",
81+
"host:port the controller should dial back at (defaults to $POD_IP:<listen-port>)")
8382
flag.StringVar(&lvmPoolName, "lvm-pool-name", "",
8483
"register an LVM-thin pool under this LINSTOR pool name (empty disables LVM)")
8584
flag.StringVar(&lvmVG, "lvm-vg", "",
@@ -108,6 +107,19 @@ func run() int {
108107
return 1
109108
}
110109

110+
// Compute the advertised endpoint default if --advertised-endpoint
111+
// wasn't explicitly set. We pull the port from --listen so a
112+
// non-default listen port (e.g. when DRBD's tcp-port-range starts
113+
// at 7000 and gRPC has to move) doesn't require a second flag.
114+
if advertised == "" {
115+
host := os.Getenv("POD_IP")
116+
port := portFromListen(listenAddr)
117+
118+
if host != "" && port != "" {
119+
advertised = host + ":" + port
120+
}
121+
}
122+
111123
ctx, cancel := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
112124
defer cancel()
113125

@@ -182,6 +194,19 @@ func run() int {
182194
return 0
183195
}
184196

197+
// portFromListen extracts the port number from a Go-style listen
198+
// address ("host:port", ":port"). Returns empty when the address
199+
// doesn't include a port — caller falls back to whatever default
200+
// they chose. Doesn't validate the host part.
201+
func portFromListen(addr string) string {
202+
idx := strings.LastIndex(addr, ":")
203+
if idx < 0 {
204+
return ""
205+
}
206+
207+
return addr[idx+1:]
208+
}
209+
185210
// cleanStateDir wipes every *.res file in dir on satellite startup.
186211
// The controller re-Applies every Resource CRD on this node shortly
187212
// after Hello, so the contents are reproducible — we don't persist

0 commit comments

Comments
 (0)